av_charge_statis_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_GetAvChargeStatisMap(t *testing.T) {
  11. Convey("GetAvChargeStatisMap", t, func() {
  12. _, err := charge.GetAvChargeStatisMap(context.Background())
  13. So(err, ShouldBeNil)
  14. })
  15. }
  16. func Test_GetAvChargeStatis(t *testing.T) {
  17. Convey("GetAvChargeStatis", t, func() {
  18. _, err := charge.GetAvChargeStatis(context.Background())
  19. So(err, ShouldBeNil)
  20. })
  21. }
  22. func Test_AvChargeStatisDBStore(t *testing.T) {
  23. Convey("AvChargeStatisDBStore", t, func() {
  24. chargeStatisMap := make(map[int64]*model.AvChargeStatis)
  25. value := &model.AvChargeStatis{
  26. AvID: 11,
  27. MID: 11,
  28. TagID: 11,
  29. DBState: 1,
  30. }
  31. chargeStatisMap[11] = value
  32. err := charge.AvChargeStatisDBStore(context.Background(), chargeStatisMap)
  33. So(err, ShouldBeNil)
  34. })
  35. }
  36. func benchmarkAvChargeStatisDBStore(bsize int, size int64, b *testing.B) {
  37. batchSize = bsize
  38. var i int64
  39. chargeStatisMap := make(map[int64]*model.AvChargeStatis)
  40. for i = 0; i < size; i++ {
  41. chargeStatisMap[i] = &model.AvChargeStatis{
  42. AvID: i,
  43. MID: i,
  44. TagID: i,
  45. IsOriginal: int(i),
  46. UploadTime: xtime.Time(time.Now().Unix()),
  47. TotalCharge: i,
  48. DBState: int(i % 2),
  49. }
  50. }
  51. for n := 0; n < b.N; n++ {
  52. charge.AvChargeStatisDBStore(context.Background(), chargeStatisMap)
  53. }
  54. }
  55. func BenchmarkAvChargeStatisDBStore100(b *testing.B) {
  56. benchmarkAvChargeStatisDBStore(100, 100000, b)
  57. }
  58. func BenchmarkAvChargeStatisDBStore1000(b *testing.B) {
  59. benchmarkAvChargeStatisDBStore(1000, 100000, b)
  60. }
  61. func BenchmarkAvChargeStatisDBStore2000(b *testing.B) {
  62. benchmarkAvChargeStatisDBStore(2000, 100000, b)
  63. }
  64. func BenchmarkAvChargeStatisDBStore10000(b *testing.B) {
  65. benchmarkAvChargeStatisDBStore(10000, 100000, b)
  66. }