av_charge_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package income
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. model "go-common/app/job/main/growup/model/income"
  7. xtime "go-common/library/time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func Test_GetAvCharge(t *testing.T) {
  11. Convey("GetAvCharge", t, func() {
  12. _, err := charge.GetAvCharge(context.Background(), time.Now(), charge.dao.AvMonthlyCharge)
  13. So(err, ShouldBeNil)
  14. })
  15. }
  16. func Test_AvChargeDBStore(t *testing.T) {
  17. Convey("AvChargeDBStore", t, func() {
  18. monthlyChargeMap := make(map[int64]*model.AvCharge)
  19. value := &model.AvCharge{
  20. AvID: 11,
  21. MID: 11,
  22. TagID: 11,
  23. DBState: 1,
  24. }
  25. monthlyChargeMap[11] = value
  26. err := charge.AvChargeDBStore(context.Background(), monthlyChargeMap, monthlyChargeMap)
  27. So(err, ShouldBeNil)
  28. })
  29. }
  30. func benchmarkAvChargeDBStore(bsize int, size int64, b *testing.B) {
  31. batchSize = bsize
  32. for n := 0; n < b.N; n++ {
  33. var i int64
  34. weeklyChargeMap := make(map[int64]*model.AvCharge, size)
  35. for i = 0; i < size; i++ {
  36. v := int64(n+1) * i
  37. weeklyChargeMap[v] = &model.AvCharge{
  38. AvID: v,
  39. MID: v,
  40. TagID: v,
  41. IsOriginal: int(v),
  42. DanmakuCount: v,
  43. CommentCount: v,
  44. CollectCount: v,
  45. CoinCount: v,
  46. ShareCount: v,
  47. ElecPayCount: v,
  48. TotalPlayCount: v,
  49. WebPlayCount: v,
  50. AppPlayCount: v,
  51. H5PlayCount: v,
  52. LvUnknown: v,
  53. Lv0: v,
  54. Lv1: v,
  55. Lv2: v,
  56. Lv3: v,
  57. Lv4: v,
  58. Lv5: v,
  59. Lv6: v,
  60. VScore: v,
  61. IncCharge: v,
  62. TotalCharge: v,
  63. UploadTime: xtime.Time(time.Now().Unix()),
  64. Date: xtime.Time(time.Now().Unix()),
  65. DBState: 1,
  66. }
  67. }
  68. charge.AvChargeDBStore(context.Background(), weeklyChargeMap, weeklyChargeMap)
  69. }
  70. }
  71. func BenchmarkAvChargeDBStore100(b *testing.B) {
  72. benchmarkAvChargeDBStore(100, 100000, b)
  73. }
  74. func BenchmarkAvChargeDBStore1000(b *testing.B) {
  75. benchmarkAvChargeDBStore(1000, 100000, b)
  76. }
  77. func BenchmarkAvChargeDBStore2000(b *testing.B) {
  78. benchmarkAvChargeDBStore(2000, 100000, b)
  79. }
  80. func BenchmarkAvChargeDBStore10000(b *testing.B) {
  81. benchmarkAvChargeDBStore(10000, 100000, b)
  82. }