matcher_test.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package dispatch
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestMatcher(t *testing.T) {
  7. config := []byte(`{
  8. "ip_max_limit": 2,
  9. "default_domain" : "broadcastlv.chat.bilibili.com",
  10. "danmaku_common_dispatch": {
  11. "china" :{
  12. "china_telecom": {
  13. "master": {
  14. "tencent_shanghai": 10,
  15. "tencent_guangzhou": 6,
  16. "kingsoft": 24
  17. },
  18. "slave": {
  19. "tencent_shanghai": 10,
  20. "tencent_guangzhou": 6,
  21. "kingsoft": 24,
  22. "aliyun": 30
  23. }
  24. },
  25. "china_unicom": {
  26. "master": {
  27. "tencent_shanghai": 10,
  28. "tencent_guangzhou": 6,
  29. "kingsoft": 24
  30. },
  31. "slave": {
  32. "tencent_shanghai": 10,
  33. "tencent_guangzhou": 6,
  34. "kingsoft": 24,
  35. "aliyun": 30
  36. }
  37. },
  38. "cmcc": {
  39. "master": {
  40. "tencent_shanghai": 10,
  41. "tencent_guangzhou": 6,
  42. "kingsoft": 24
  43. },
  44. "slave": {
  45. "tencent_shanghai": 10,
  46. "tencent_guangzhou": 6,
  47. "kingsoft": 24,
  48. "aliyun": 30
  49. }
  50. },
  51. "other": {
  52. "master": {
  53. "tencent_shanghai": 10,
  54. "tencent_guangzhou": 6,
  55. "kingsoft": 24
  56. },
  57. "slave": {
  58. "tencent_shanghai": 10,
  59. "tencent_guangzhou": 6,
  60. "kingsoft": 24,
  61. "aliyun": 30
  62. }
  63. }
  64. },
  65. "oversea": [
  66. {
  67. "rule":"($lng >= -20) && ($lng <= 160)",
  68. "master": {
  69. "tencent_siliconvalley": 10
  70. },
  71. "slave": {
  72. "tencent_shanghai": 10,
  73. "tencent_guangzhou": 6,
  74. "kingsoft": 24,
  75. "aliyun": 30
  76. }
  77. },
  78. {
  79. "master": {
  80. "tencent_siliconvalley": 10
  81. },
  82. "slave": {
  83. "tencent_shanghai": 10,
  84. "tencent_guangzhou": 6,
  85. "kingsoft": 24,
  86. "aliyun": 30
  87. }
  88. }
  89. ],
  90. "unknown" : {
  91. "master": {
  92. "tencent_shanghai": 10,
  93. "tencent_guangzhou": 6,
  94. "kingsoft": 24
  95. },
  96. "slave": {
  97. "tencent_shanghai": 10,
  98. "tencent_guangzhou": 6,
  99. "kingsoft": 24,
  100. "aliyun": 30
  101. }
  102. }
  103. },
  104. "danmaku_vip_dispatch" : [
  105. {
  106. "rule":"$uid==120497668",
  107. "ip": ["118.89.14.174"]
  108. },
  109. {
  110. "rule":"$uid % 10 == 1",
  111. "group": ["tencent_guangzhou"]
  112. },
  113. {
  114. "rule":"$uid == 221122111"
  115. }
  116. ],
  117. "danmaku_comet_group": {
  118. "tencent_shanghai": [
  119. "118.89.14.174",
  120. "118.89.14.115",
  121. "118.89.14.103",
  122. "118.89.14.206",
  123. "118.89.13.229"
  124. ],
  125. "tencent_guangzhou": [
  126. "211.159.194.41",
  127. "211.159.194.115",
  128. "211.159.194.105"
  129. ],
  130. "tencent_hongkong": [
  131. "119.28.56.183"
  132. ],
  133. "tencent_siliconvalley": [
  134. "49.51.37.200"
  135. ],
  136. "kingsoft": [
  137. "120.92.78.57",
  138. "120.92.158.137",
  139. "120.92.112.150"
  140. ],
  141. "aliyun": [
  142. "101.132.195.89",
  143. "47.104.64.120",
  144. "59.110.167.237",
  145. "47.92.112.162",
  146. "47.96.139.69",
  147. "119.23.41.85"
  148. ]
  149. }
  150. }`)
  151. m, err := NewMatcher(config, nil, nil, nil)
  152. if err != nil {
  153. t.Error(err)
  154. t.Fail()
  155. }
  156. fmt.Println(m)
  157. }