File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,15 @@ func (c *CHash) RemoveGroup(groupName string) {
48
48
delete (c .groups , groupName )
49
49
}
50
50
51
+ func (c * CHash ) RemoveAllGroup () {
52
+ c .Lock ()
53
+ defer c .Unlock ()
54
+
55
+ for k := range c .groups {
56
+ delete (c .groups , k )
57
+ }
58
+ }
59
+
51
60
func (c * CHash ) Insert (groupName string , key string , payload []byte ) error {
52
61
c .Lock ()
53
62
group , ok := c .groups [groupName ]
Original file line number Diff line number Diff line change @@ -83,6 +83,21 @@ func TestCHashRemoveGroup(t *testing.T) {
83
83
assert .Equal (t , ErrGroupNotFound , err )
84
84
}
85
85
86
+ func TestCHashRemoveAllGroup (t * testing.T ) {
87
+ hash := New ()
88
+ group1 , err := hash .CreateGroup ("werbenhu1" , 2000 )
89
+ assert .Nil (t , err )
90
+ assert .NotNil (t , group1 )
91
+
92
+ group2 , err := hash .CreateGroup ("werbenhu2" , 1000 )
93
+ assert .Nil (t , err )
94
+ assert .NotNil (t , group2 )
95
+
96
+ assert .Equal (t , 2 , len (hash .groups ))
97
+ hash .RemoveAllGroup ()
98
+ assert .Equal (t , 0 , len (hash .groups ))
99
+ }
100
+
86
101
func TestCHashInsert (t * testing.T ) {
87
102
hash := New ()
88
103
hash .CreateGroup ("werbenhu1" , 10000 )
You can’t perform that action at this time.
0 commit comments