document_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "testing"
  6. "time"
  7. conf "go-common/app/interface/main/kvo/conf"
  8. "go-common/app/interface/main/kvo/model/module"
  9. "go-common/library/cache/memcache"
  10. "go-common/library/container/pool"
  11. "go-common/library/database/sql"
  12. "go-common/library/net/netutil/breaker"
  13. xtime "go-common/library/time"
  14. . "github.com/smartystreets/goconvey/convey"
  15. )
  16. func getService() *Service {
  17. s := New(&conf.Config{
  18. Rule: &conf.Rule{DocLimit: 1024 * 1024 * 1024},
  19. Memcache: &conf.KvoMemcache{
  20. Kvo: &memcache.Config{
  21. Config: &pool.Config{
  22. Active: 10,
  23. Idle: 4,
  24. IdleTimeout: xtime.Duration(time.Second),
  25. },
  26. Name: "kvo",
  27. Proto: "tcp",
  28. Addr: "127.0.0.1:11211",
  29. DialTimeout: xtime.Duration(time.Second),
  30. ReadTimeout: xtime.Duration(time.Second),
  31. WriteTimeout: xtime.Duration(time.Second),
  32. },
  33. Expire: xtime.Duration(time.Hour),
  34. },
  35. Mysql: &sql.Config{
  36. Addr: "localhost:3306",
  37. DSN: "root:123@tcp(localhost:3306)/bilibili?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4",
  38. Active: 10,
  39. Idle: 4,
  40. IdleTimeout: xtime.Duration(time.Second),
  41. QueryTimeout: xtime.Duration(time.Second),
  42. ExecTimeout: xtime.Duration(time.Second),
  43. TranTimeout: xtime.Duration(time.Second),
  44. Breaker: &breaker.Config{
  45. Window: xtime.Duration(time.Second),
  46. Sleep: xtime.Duration(time.Second),
  47. Bucket: 10,
  48. Ratio: 0.5,
  49. Request: 100,
  50. },
  51. },
  52. })
  53. return s
  54. }
  55. func TestAddDocument(t *testing.T) {
  56. Convey("", t, func() {
  57. s := getService()
  58. p := &module.Player{
  59. PlayerWebDanmakuAutoscaling: false,
  60. }
  61. bs, _ := json.Marshal(p)
  62. _, err := s.AddDocument(context.Background(), 1, "player", string(bs), 0, 0, time.Now())
  63. So(nil, ShouldEqual, err)
  64. })
  65. }
  66. func TestDocument(t *testing.T) {
  67. Convey("", t, func() {
  68. s := getService()
  69. _, err := s.Document(context.Background(), 1, "player", 1234, 12345)
  70. So(nil, ShouldEqual, err)
  71. })
  72. }