hbase_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/interface/main/push-archive/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func Test_onekey(t *testing.T) {
  9. var included bool
  10. var err error
  11. included, err = d.filterFanByUpper(context.TODO(), int64(12312313), int64(275152561), "ai:pushlist_follow_recent", []string{"m"})
  12. convey.Convey("hbase过滤up主, 不存在", t, func() {
  13. convey.So(err, convey.ShouldBeNil)
  14. convey.So(included, convey.ShouldEqual, false)
  15. })
  16. included, err = d.filterFanByUpper(context.TODO(), int64(27515303), int64(27515256), "ai:pushlist_follow_recent", []string{"m", "m1"})
  17. convey.Convey("hbase过滤up主,增加1个", t, func() {
  18. convey.So(err, convey.ShouldBeNil)
  19. convey.So(included, convey.ShouldEqual, true)
  20. })
  21. included, err = d.filterFanByUpper(context.TODO(), int64(27515401), int64(27515256), "ai:pushlist_follow_recent", []string{"m"})
  22. convey.Convey("hbase过滤up主,增加1个", t, func() {
  23. convey.So(err, convey.ShouldBeNil)
  24. convey.So(included, convey.ShouldEqual, true)
  25. })
  26. included, err = d.filterFanByUpper(context.TODO(), int64(27515300), int64(27515256), "ai:pushlist_follow_recent", []string{"m"})
  27. convey.Convey("hbase过滤up主,增加1个", t, func() {
  28. convey.So(err, convey.ShouldBeNil)
  29. convey.So(included, convey.ShouldEqual, true)
  30. })
  31. }
  32. func Test_keys(t *testing.T) {
  33. var result, excluded []int64
  34. params := map[string]interface{}{
  35. "base": int64(27515256),
  36. "table": "ai:pushlist_follow_recent",
  37. "family": []string{"m"},
  38. "result": &result,
  39. "excluded": &excluded,
  40. "handler": d.filterFanByUpper,
  41. }
  42. err := d.FilterFans(&[]int64{27515303, 27515401, 27515300, 12312313}, params)
  43. convey.Convey("多协程过滤up主,3个符合,1个排除", t, func() {
  44. convey.So(err, convey.ShouldBeNil)
  45. convey.So(len(result), convey.ShouldEqual, 3)
  46. convey.So(len(excluded), convey.ShouldEqual, 1)
  47. })
  48. }
  49. func Test_batchfilter(t *testing.T) {
  50. var result, excluded []int64
  51. params := model.NewBatchParam(map[string]interface{}{
  52. "base": int64(27515256),
  53. "table": "ai:pushlist_follow_recent",
  54. "family": []string{"m"},
  55. "result": &result,
  56. "excluded": &excluded,
  57. "handler": d.filterFanByUpper,
  58. }, nil)
  59. Batch(&[]int64{27515303, 27515401, 27515300, 12312313}, 1, 2, params, d.FilterFans)
  60. convey.Convey("批量过滤up主, ,3个符合,1个排除", t, func() {
  61. convey.So(len(result), convey.ShouldEqual, 3)
  62. convey.So(len(excluded), convey.ShouldEqual, 1)
  63. })
  64. t.Logf("the result(%v), excluded(%v)", result, excluded)
  65. }
  66. func Test_addfans(t *testing.T) {
  67. err := d.AddFans(context.TODO(), int64(275152561), int64(121212), model.RelationAttention)
  68. convey.Convey("添加粉丝到up主", t, func() {
  69. convey.So(err, convey.ShouldBeNil)
  70. })
  71. }
  72. func Test_delfans(t *testing.T) {
  73. err := d.DelFans(context.TODO(), int64(275152561), int64(121212))
  74. convey.Convey("删除up主的粉丝", t, func() {
  75. convey.So(err, convey.ShouldBeNil)
  76. })
  77. }
  78. func Test_fansbyupper(t *testing.T) {
  79. Test_addfans(t)
  80. fans, err := d.Fans(context.TODO(), int64(275152561), false)
  81. convey.Convey("up主增加一个粉丝后", t, func() {
  82. convey.So(err, convey.ShouldBeNil)
  83. convey.So(len(fans), convey.ShouldEqual, 1)
  84. })
  85. fans, err = d.Fans(context.TODO(), int64(275152561), true)
  86. convey.Convey("up主增加一个普通关注粉丝后, pgc稿件只有特殊关注粉丝", t, func() {
  87. convey.So(err, convey.ShouldBeNil)
  88. convey.So(len(fans), convey.ShouldEqual, 0)
  89. })
  90. Test_delfans(t)
  91. fans, err = d.Fans(context.TODO(), int64(275152561), false)
  92. convey.Convey("up主删除一个粉丝后", t, func() {
  93. convey.So(err, convey.ShouldBeNil)
  94. convey.So(len(fans), convey.ShouldEqual, 0)
  95. })
  96. }
  97. func Test_fansbyactive(t *testing.T) {
  98. // 18507659 + 37118721 + 88889069
  99. fan := int64(88889069)
  100. hour := 21
  101. table := "dm_member_push_active_hour"
  102. family := []string{"p"}
  103. included, err := d.filterFanByActive(context.TODO(), fan, hour, table, family)
  104. t.Logf("the included(%v) err(%v)", included, err)
  105. }