media_cache_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package ugc
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "testing"
  7. ugcmdl "go-common/app/job/main/tv/model/ugc"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDao_TotalVideos(t *testing.T) {
  11. Convey("TestDao_TotalVideos", t, WithDao(func(d *Dao) {
  12. res, err := d.TotalVideos(ctx)
  13. So(err, ShouldBeNil)
  14. So(res, ShouldBeGreaterThan, 0)
  15. fmt.Println(res)
  16. }))
  17. }
  18. func TestDao_ArcVideoCnt(t *testing.T) {
  19. Convey("TestDao_ArcVideoCnt", t, WithDao(func(d *Dao) {
  20. var aid int64
  21. d.DB.QueryRow(ctx, "select aid from ugc_video where deleted = 0 limit 1").Scan(&aid)
  22. if aid == 0 {
  23. fmt.Println("empty arc")
  24. return
  25. }
  26. cnt, errcnt := d.ArcVideoCnt(ctx, aid)
  27. So(errcnt, ShouldBeNil)
  28. fmt.Println(aid)
  29. So(cnt, ShouldBeGreaterThan, 0)
  30. fmt.Println(cnt)
  31. resVideos, lastIDVideo, errVd := d.PickArcVideo(ctx, aid, 0, 10)
  32. So(errVd, ShouldBeNil)
  33. So(len(resVideos), ShouldBeGreaterThan, 0)
  34. So(lastIDVideo, ShouldBeGreaterThan, 0)
  35. str, _ := json.Marshal(resVideos)
  36. fmt.Println(string(str))
  37. }))
  38. }
  39. func TestDao_SetArc(t *testing.T) {
  40. Convey("TestDao_SetArc", t, WithDao(func(d *Dao) {
  41. err := d.SetArcCMS(ctx, &ugcmdl.ArcCMS{
  42. Title: "testtest",
  43. AID: 777,
  44. })
  45. So(err, ShouldBeNil)
  46. }))
  47. }
  48. func TestDao_UpArcsCnt(t *testing.T) {
  49. Convey("TestDao_UpArcsCnt", t, WithDao(func(d *Dao) {
  50. var mid int64
  51. d.DB.QueryRow(ctx, "select mid from ugc_archive where deleted = 0 limit 1").Scan(&mid)
  52. if mid == 0 {
  53. fmt.Println("empty arc")
  54. return
  55. }
  56. count, err := d.UpArcsCnt(ctx, mid)
  57. So(err, ShouldBeNil)
  58. So(count, ShouldBeGreaterThan, 0)
  59. fmt.Println("mid ", mid, " cnt", count)
  60. if count > 1 {
  61. d.DB.Exec(context.Background(), "update ugc_archive set deleted = 1 where mid = ? and deleted = 0 limit 1", mid)
  62. cntNonDeleted, err2 := d.CountUpArcs(context.Background(), mid)
  63. So(err2, ShouldBeNil)
  64. So(count, ShouldBeGreaterThan, cntNonDeleted)
  65. fmt.Println("all: ", count, " non-deleted: ", cntNonDeleted)
  66. }
  67. }))
  68. }
  69. func TestDao_TransFailVideos(t *testing.T) {
  70. Convey("TestDao_TransFailVideos", t, WithDao(func(d *Dao) {
  71. query := "SELECT aid FROM ugc_video WHERE cid > 12780000 AND transcoded = 2 and deleted = 0 limit 1"
  72. var aid int64
  73. d.DB.QueryRow(context.Background(), query).Scan(&aid)
  74. if aid == 0 {
  75. fmt.Println("Empty archives")
  76. return
  77. }
  78. cids, err := d.TransFailVideos(ctx, aid)
  79. So(err, ShouldBeNil)
  80. So(len(cids), ShouldBeGreaterThan, 0)
  81. fmt.Println("aid ", aid, " cids ", cids)
  82. }))
  83. }
  84. func TestDao_ActVideos(t *testing.T) {
  85. Convey("TestDao_ActVideos", t, WithDao(func(d *Dao) {
  86. var (
  87. aid = int64(88888888)
  88. cid = 99999999
  89. )
  90. insertSQL := "REPLACE INTO ugc_video (aid, cid, deleted) VALUES (%d, %d, 1)"
  91. d.DB.Exec(ctx, fmt.Sprintf(insertSQL, aid, cid))
  92. has, err := d.ActVideos(ctx, aid)
  93. So(err, ShouldBeNil)
  94. So(has, ShouldBeFalse)
  95. d.DB.Exec(ctx, "UPDATE ugc_video SET deleted = 0 WHERE cid = ?", cid)
  96. has, err = d.ActVideos(ctx, aid)
  97. So(err, ShouldBeNil)
  98. So(has, ShouldBeTrue)
  99. }))
  100. }
  101. func TestDao_PickArcMC(t *testing.T) {
  102. Convey("TestDao_PickArcMC", t, WithDao(func(d *Dao) {
  103. pickMid := "select mid from ugc_archive where deleted = 0 group by mid order by count(aid) desc limit 1"
  104. var mid = 0
  105. d.DB.QueryRow(ctx, pickMid).Scan(&mid)
  106. if mid == 0 {
  107. fmt.Println("empty archive")
  108. return
  109. }
  110. fmt.Println("mid ", mid)
  111. res1, err1 := d.PickUpArcs(ctx, mid, 0, 5)
  112. So(err1, ShouldBeNil)
  113. So(len(res1), ShouldBeGreaterThan, 0)
  114. res2, err2 := d.PickUpArcs(ctx, mid, 7, 5)
  115. So(err2, ShouldBeNil)
  116. So(len(res2), ShouldBeGreaterThan, 0)
  117. str1, _ := json.Marshal(res1)
  118. str2, _ := json.Marshal(res2)
  119. fmt.Println(string(str1))
  120. fmt.Println(string(str2))
  121. }))
  122. }