@@ -2,6 +2,8 @@ package balancer_test
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
6
+ "path"
5
7
"testing"
6
8
"time"
7
9
@@ -14,15 +16,23 @@ import (
14
16
"github.com/milvus-io/milvus/internal/streamingcoord/server/balancer"
15
17
_ "github.com/milvus-io/milvus/internal/streamingcoord/server/balancer/policy"
16
18
"github.com/milvus-io/milvus/internal/streamingcoord/server/resource"
19
+ "github.com/milvus-io/milvus/internal/util/sessionutil"
17
20
"github.com/milvus-io/milvus/pkg/v2/proto/streamingpb"
18
21
"github.com/milvus-io/milvus/pkg/v2/streaming/util/types"
22
+ "github.com/milvus-io/milvus/pkg/v2/util/etcd"
19
23
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
20
24
"github.com/milvus-io/milvus/pkg/v2/util/syncutil"
21
25
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
22
26
)
23
27
24
28
func TestBalancer (t * testing.T ) {
25
29
paramtable .Init ()
30
+ err := etcd .InitEtcdServer (true , "" , t .TempDir (), "stdout" , "info" )
31
+ assert .NoError (t , err )
32
+ defer etcd .StopEtcdServer ()
33
+
34
+ etcdClient , err := etcd .GetEmbedEtcdClient ()
35
+ assert .NoError (t , err )
26
36
27
37
streamingNodeManager := mock_manager .NewMockManagerClient (t )
28
38
streamingNodeManager .EXPECT ().WatchNodeChanged (mock .Anything ).Return (make (chan struct {}), nil )
@@ -57,7 +67,7 @@ func TestBalancer(t *testing.T) {
57
67
}, nil )
58
68
59
69
catalog := mock_metastore .NewMockStreamingCoordCataLog (t )
60
- resource .InitForTest (resource .OptStreamingCatalog (catalog ), resource .OptStreamingManagerClient (streamingNodeManager ))
70
+ resource .InitForTest (resource .OptETCD ( etcdClient ), resource . OptStreamingCatalog (catalog ), resource .OptStreamingManagerClient (streamingNodeManager ))
61
71
catalog .EXPECT ().ListPChannel (mock .Anything ).Unset ()
62
72
catalog .EXPECT ().ListPChannel (mock .Anything ).RunAndReturn (func (ctx context.Context ) ([]* streamingpb.PChannelMeta , error ) {
63
73
return []* streamingpb.PChannelMeta {
@@ -89,11 +99,36 @@ func TestBalancer(t *testing.T) {
89
99
})
90
100
catalog .EXPECT ().SavePChannels (mock .Anything , mock .Anything ).Return (nil ).Maybe ()
91
101
102
+ // Test for lower datanode and proxy version protection.
103
+ metaRoot := paramtable .Get ().EtcdCfg .MetaRootPath .GetValue ()
104
+ proxyPath1 := path .Join (metaRoot , sessionutil .DefaultServiceRoot , typeutil .ProxyRole + "-1" )
105
+ r := sessionutil.SessionRaw {Version : "2.5.11" , ServerID : 1 }
106
+ data , _ := json .Marshal (r )
107
+ resource .Resource ().ETCD ().Put (context .Background (), proxyPath1 , string (data ))
108
+ proxyPath2 := path .Join (metaRoot , sessionutil .DefaultServiceRoot , typeutil .ProxyRole + "-2" )
109
+ r = sessionutil.SessionRaw {Version : "2.5.11" , ServerID : 2 }
110
+ data , _ = json .Marshal (r )
111
+ resource .Resource ().ETCD ().Put (context .Background (), proxyPath2 , string (data ))
112
+ metaRoot = paramtable .Get ().EtcdCfg .MetaRootPath .GetValue ()
113
+ dataNodePath := path .Join (metaRoot , sessionutil .DefaultServiceRoot , typeutil .DataNodeRole )
114
+ resource .Resource ().ETCD ().Put (context .Background (), dataNodePath , string (data ))
115
+
92
116
ctx := context .Background ()
93
117
b , err := balancer .RecoverBalancer (ctx , "pchannel_count_fair" )
94
118
assert .NoError (t , err )
95
119
assert .NotNil (t , b )
96
120
121
+ ctx1 , cancel := context .WithTimeout (context .Background (), 50 * time .Millisecond )
122
+ defer cancel ()
123
+ err = b .WatchChannelAssignments (ctx1 , func (version typeutil.VersionInt64Pair , relations []types.PChannelInfoAssigned ) error {
124
+ assert .Len (t , relations , 2 )
125
+ return nil
126
+ })
127
+ assert .ErrorIs (t , err , context .DeadlineExceeded )
128
+ resource .Resource ().ETCD ().Delete (context .Background (), proxyPath1 )
129
+ resource .Resource ().ETCD ().Delete (context .Background (), proxyPath2 )
130
+ resource .Resource ().ETCD ().Delete (context .Background (), dataNodePath )
131
+
97
132
b .MarkAsUnavailable (ctx , []types.PChannelInfo {{
98
133
Name : "test-channel-1" ,
99
134
Term : 1 ,
0 commit comments