@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package gossip
17
+ package msgstore
18
18
19
19
import (
20
20
"math/rand"
@@ -52,24 +52,24 @@ func compareInts(this interface{}, that interface{}) common.InvalidationResult {
52
52
}
53
53
54
54
func TestSize (t * testing.T ) {
55
- msgStore := newMessageStore (alwaysNoAction , noopTrigger )
56
- msgStore .add (0 )
57
- msgStore .add (1 )
58
- msgStore .add (2 )
59
- assert .Equal (t , 3 , msgStore .size ())
55
+ msgStore := NewMessageStore (alwaysNoAction , noopTrigger )
56
+ msgStore .Add (0 )
57
+ msgStore .Add (1 )
58
+ msgStore .Add (2 )
59
+ assert .Equal (t , 3 , msgStore .Size ())
60
60
}
61
61
62
62
func TestNewMessagesInvalidates (t * testing.T ) {
63
63
invalidated := make ([]int , 9 )
64
- msgStore := newMessageStore (compareInts , func (m interface {}) {
64
+ msgStore := NewMessageStore (compareInts , func (m interface {}) {
65
65
invalidated = append (invalidated , m .(int ))
66
66
})
67
- assert .True (t , msgStore .add (0 ))
67
+ assert .True (t , msgStore .Add (0 ))
68
68
for i := 1 ; i < 10 ; i ++ {
69
- assert .True (t , msgStore .add (i ))
69
+ assert .True (t , msgStore .Add (i ))
70
70
assert .Equal (t , i - 1 , invalidated [len (invalidated )- 1 ])
71
- assert .Equal (t , 1 , msgStore .size ())
72
- assert .Equal (t , i , msgStore .get ()[0 ].(int ))
71
+ assert .Equal (t , 1 , msgStore .Size ())
72
+ assert .Equal (t , i , msgStore .Get ()[0 ].(int ))
73
73
}
74
74
}
75
75
@@ -83,33 +83,33 @@ func TestMessagesGet(t *testing.T) {
83
83
return false
84
84
}
85
85
86
- msgStore := newMessageStore (alwaysNoAction , noopTrigger )
86
+ msgStore := NewMessageStore (alwaysNoAction , noopTrigger )
87
87
expected := []int {}
88
88
for i := 0 ; i < 2 ; i ++ {
89
89
n := rand .Int ()
90
90
expected = append (expected , n )
91
- msgStore .add (n )
91
+ msgStore .Add (n )
92
92
}
93
93
94
94
for _ , num2Search := range expected {
95
- assert .True (t , contains (msgStore .get (), num2Search ), "Value %v not found in array" , num2Search )
95
+ assert .True (t , contains (msgStore .Get (), num2Search ), "Value %v not found in array" , num2Search )
96
96
}
97
97
98
98
}
99
99
100
100
func TestNewMessagesInvalidated (t * testing.T ) {
101
- msgStore := newMessageStore (compareInts , noopTrigger )
102
- assert .True (t , msgStore .add (10 ))
101
+ msgStore := NewMessageStore (compareInts , noopTrigger )
102
+ assert .True (t , msgStore .Add (10 ))
103
103
for i := 9 ; i >= 0 ; i -- {
104
- assert .False (t , msgStore .add (i ))
105
- assert .Equal (t , 1 , msgStore .size ())
106
- assert .Equal (t , 10 , msgStore .get ()[0 ].(int ))
104
+ assert .False (t , msgStore .Add (i ))
105
+ assert .Equal (t , 1 , msgStore .Size ())
106
+ assert .Equal (t , 10 , msgStore .Get ()[0 ].(int ))
107
107
}
108
108
}
109
109
110
110
func TestConcurrency (t * testing.T ) {
111
111
stopFlag := int32 (0 )
112
- msgStore := newMessageStore (compareInts , noopTrigger )
112
+ msgStore := NewMessageStore (compareInts , noopTrigger )
113
113
looper := func (f func ()) func () {
114
114
return func () {
115
115
for {
@@ -122,15 +122,15 @@ func TestConcurrency(t *testing.T) {
122
122
}
123
123
124
124
addProcess := looper (func () {
125
- msgStore .add (rand .Int ())
125
+ msgStore .Add (rand .Int ())
126
126
})
127
127
128
128
getProcess := looper (func () {
129
- msgStore .get ()
129
+ msgStore .Get ()
130
130
})
131
131
132
132
sizeProcess := looper (func () {
133
- msgStore .size ()
133
+ msgStore .Size ()
134
134
})
135
135
136
136
go addProcess ()
0 commit comments