You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

matching_test.go 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package modules
  2. //
  3. //import (
  4. // "fmt"
  5. // "github.com/stretchr/testify/assert"
  6. // "math/rand"
  7. // "strconv"
  8. // "testing"
  9. // "time"
  10. //)
  11. //
  12. //
  13. //func makePubData(IsAlpha bool) MsgUnit{
  14. // rand.Seed(time.Now().UnixNano())
  15. // // Set Ipaddr
  16. // msg := Message{"", "1.0", "", PM}
  17. // for i := 0; i < 4; i++{
  18. // itoa := strconv.Itoa(rand.Int() % 256)
  19. // msg.From += itoa
  20. // if i != 3{
  21. // msg.From += "."
  22. // }
  23. // }
  24. //
  25. // // Set Time
  26. // msg.Time += strconv.Itoa(rand.Int()%24) + ":"
  27. // msg.Time += strconv.Itoa(rand.Int()%60)
  28. //
  29. // Topic := []int64{}
  30. // Value := []int64{}
  31. // content := []int64{}
  32. //
  33. // // Set Topic
  34. // topicLen := rand.Int() % 10 + 1
  35. // for i := 0 ; i < topicLen; i++{
  36. // Topic = append(Topic, rand.Int63())
  37. // }
  38. //
  39. // // Set Value
  40. // if IsAlpha {
  41. // valueLen := rand.Int() % 10 + 1
  42. // for i := 0 ; i < valueLen; i++{
  43. // Value = append(Value, rand.Int63())
  44. // }
  45. // } else {
  46. // Topic = append(Topic, rand.Int63())
  47. // Value = append(Value, rand.Int63())
  48. // }
  49. //
  50. // // Set content
  51. // contentLen := rand.Int() % 10
  52. // for i := 0; i < contentLen; i++{
  53. // content = append(content, rand.Int63())
  54. // }
  55. //
  56. // return &PublishMsg{msg, Topic, Value, content}
  57. //}
  58. //
  59. //func makeSubData(IsAlpha bool, Topic []int64, Value []int64) MsgUnit{
  60. // rand.Seed(time.Now().UnixNano())
  61. // // Set Ipaddr
  62. // msg := Message{"", "1.0", "", SM}
  63. // for i := 0; i < 4; i++{
  64. // itoa := strconv.Itoa(rand.Int() % 256)
  65. // msg.From += itoa
  66. // if i != 3{
  67. // msg.From += "."
  68. // }
  69. // }
  70. //
  71. // // Set Time
  72. // msg.Time += strconv.Itoa(rand.Int()%24) + ":"
  73. // msg.Time += strconv.Itoa(rand.Int()%60)
  74. //
  75. // // Set Topic, Value, Operator
  76. // Operator := []string{}
  77. // candOp := []string{">", ">=", "<=" ,"<", "=="}
  78. // logicalOp := []string{"&&", "||"}
  79. //
  80. // if IsAlpha {
  81. // Operator = append(Operator, "==")
  82. // } else {
  83. // randSeed := rand.Int() % 2
  84. // if randSeed == 0 {
  85. // lop := rand.Int() % 2
  86. // Operator = append(Operator, candOp[rand.Int()%2])
  87. // if lop == 0 {
  88. // Operator = append(Operator, logicalOp[0])
  89. // for {
  90. // x := rand.Int63()
  91. // if x > Value[0] {
  92. // Value = append(Value, x)
  93. // break
  94. // }
  95. // }
  96. // } else {
  97. // Operator = append(Operator, logicalOp[1])
  98. // Value = append(Value, rand.Int63())
  99. // }
  100. // Operator = append(Operator, candOp[rand.Int()%2+2])
  101. // } else {
  102. // op := candOp[rand.Int()%5]
  103. // Operator = append(Operator, op)
  104. // }
  105. // }
  106. //
  107. // return &SubscriptionMsg{msg, Topic, Value, Operator, IsAlpha}
  108. //}
  109. //
  110. //func Test_matching(t *testing.T) {
  111. // rand.Seed(time.Now().UnixNano())
  112. // assert.Equal(t, 1, 1)
  113. // mos := Moscato{ sub_mng: *newSubmng(),}
  114. // mos.queue.queue_init()
  115. //
  116. // // 1. Make Publish Data
  117. // pubLen := rand.Int()%100 + 1 // Set dataLength
  118. // var pubDataList []MsgUnit
  119. //
  120. // for i := 0; i < pubLen; i++{
  121. // if i % 2 == 1 {
  122. // msg := makePubData(true)
  123. // mos.queue.push(msg)
  124. // pubDataList = append(pubDataList, msg)
  125. // } else{
  126. // msg := makePubData(false)
  127. // mos.queue.push(msg)
  128. // pubDataList = append(pubDataList, msg)
  129. // }
  130. // }
  131. //
  132. // // 2. Creates subscription data with (the same <Topic, Value> or (the same <Topic, difValue>
  133. // // And Add Subscription
  134. // subLen := pubLen
  135. // var subDataList []MsgUnit
  136. // for i := 0; i < subLen; i++{
  137. // Topic := pubDataList[i].(*PublishMsg).Topic
  138. // Value := pubDataList[i].(*PublishMsg).Value
  139. // if i % 2 == 1{
  140. // msg := makeSubData(true, Topic, Value)
  141. // mos.sub_mng.addSubscription(msg)
  142. // subDataList = append(subDataList, msg)
  143. //
  144. // } else{
  145. // msg := makeSubData(false, Topic, Value)
  146. // mos.sub_mng.addSubscription(msg)
  147. // subDataList = append(subDataList, msg)
  148. // }
  149. // }
  150. //
  151. // // 3. Watch Data
  152. //
  153. // // fmt.Println("PubData")
  154. // // watchData(pubDataList, pubLen, false)
  155. // // fmt.Println("\nSubData")
  156. // // watchData(subDataList, subLen, true)
  157. //
  158. // // 4. Matching
  159. // for i := 0; i < pubLen; i++ {
  160. // matching, pubmsg, err := mos.MatchingManager.Matching(&mos.queue, &mos.sub_mng)
  161. //
  162. // // Check if matching is correct
  163. // assert.Equal(t, nil, err)
  164. //
  165. // fmt.Println("matching list = ", matching)
  166. // fmt.Println("pub msg = ", pubmsg)
  167. // fmt.Println("err ?= ", err)
  168. // }
  169. //}