service_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/openplatform/monitor-end/conf"
  5. "go-common/app/interface/openplatform/monitor-end/model/kafka"
  6. "go-common/app/interface/openplatform/monitor-end/model/monitor"
  7. "go-common/library/cache/redis"
  8. "go-common/library/container/pool"
  9. "go-common/library/database/sql"
  10. "go-common/library/log/infoc"
  11. "go-common/library/time"
  12. )
  13. var (
  14. ctx = context.Background()
  15. svr *Service
  16. )
  17. type TestData map[string]string
  18. type TestCase struct {
  19. tag string
  20. testData string
  21. expected int
  22. }
  23. /*[mysql]
  24. dsn = "root:123456@tcp(172.16.33.203:3306)/public_monitor?timeout=500s&readTimeout=500s&writeTimeout=500s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
  25. active = 5
  26. idle = 2
  27. idleTimeout ="4h"
  28. queryTimeout = "1000s"
  29. execTimeout = "200s"#
  30. tranTimeout = "2000s"
  31. [redis]
  32. name = "article"
  33. proto = "tcp"
  34. addr = "172.16.33.203:6379"
  35. idle = 10
  36. active = 10
  37. dialTimeout = "1s"
  38. readTimeout = "1s"
  39. writeTimeout = "1s"
  40. idleTimeout = "10s"*/
  41. func init() {
  42. c := conf.Conf
  43. if c.Monitor == nil {
  44. c = &conf.Config{
  45. Monitor: &monitor.MonitorConfig{Proto: "tcp", Addr: "127.0.0.1:9988"},
  46. Kafka: &kafka.Config{
  47. Addr: []string{"1.1.1.1"},
  48. Topic: "test_topic",
  49. },
  50. NeedConsume: false,
  51. Redis: &redis.Config{
  52. Name: "article",
  53. Proto: "tcp",
  54. Addr: "172.16.33.203:6379",
  55. Config: &pool.Config{
  56. Idle: 2,
  57. Active: 5,
  58. },
  59. DialTimeout: time.Duration(int64(1000000000)),
  60. ReadTimeout: time.Duration(int64(1000000000)),
  61. WriteTimeout: time.Duration(int64(1000000000)),
  62. },
  63. MySQL: &sql.Config{
  64. DSN: "root:123456@tcp(172.16.33.203:3306)/public_monitor?timeout=500s&readTimeout=500s&writeTimeout=500s&parseTime=true&loc=Local&charset=utf8,utf8mb4",
  65. QueryTimeout: time.Duration(int64(10000000000)),
  66. ExecTimeout: time.Duration(int64(10000000000)),
  67. TranTimeout: time.Duration(int64(20000000000)),
  68. },
  69. Prom: &conf.Prom{Limit: 520},
  70. CollectInfoc: &infoc.Config{},
  71. }
  72. }
  73. svr = New(c)
  74. if err := svr.dao.Ping(context.Background()); err != nil {
  75. panic(err)
  76. }
  77. }