1
1
package org .tarantool .cluster ;
2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
4
5
import static org .junit .jupiter .api .Assertions .assertNotNull ;
5
6
import static org .junit .jupiter .api .Assertions .assertThrows ;
6
7
import static org .junit .jupiter .api .Assertions .assertTrue ;
23
24
24
25
import java .util .Arrays ;
25
26
import java .util .Collections ;
27
+ import java .util .HashSet ;
26
28
import java .util .List ;
27
29
import java .util .Set ;
28
30
@@ -72,7 +74,7 @@ public void testSuccessfulAddressParsing() {
72
74
testHelper .executeLua (functionCode );
73
75
74
76
TarantoolClusterStoredFunctionDiscoverer discoverer =
75
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
77
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
76
78
77
79
Set <String > instances = discoverer .getInstances ();
78
80
@@ -91,7 +93,7 @@ public void testSuccessfulUniqueAddressParsing() {
91
93
testHelper .executeLua (functionCode );
92
94
93
95
TarantoolClusterStoredFunctionDiscoverer discoverer =
94
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
96
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
95
97
96
98
Set <String > instances = discoverer .getInstances ();
97
99
@@ -110,7 +112,7 @@ public void testFunctionReturnedEmptyList() {
110
112
testHelper .executeLua (functionCode );
111
113
112
114
TarantoolClusterStoredFunctionDiscoverer discoverer =
113
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
115
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
114
116
115
117
Set <String > instances = discoverer .getInstances ();
116
118
@@ -124,7 +126,7 @@ public void testWrongFunctionName() {
124
126
clusterConfig .clusterDiscoveryEntryFunction = "wrongFunction" ;
125
127
126
128
TarantoolClusterStoredFunctionDiscoverer discoverer =
127
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
129
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
128
130
129
131
assertThrows (TarantoolException .class , discoverer ::getInstances );
130
132
}
@@ -136,7 +138,7 @@ public void testWrongInstanceAddress() {
136
138
137
139
client .close ();
138
140
TarantoolClusterStoredFunctionDiscoverer discoverer =
139
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
141
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
140
142
141
143
assertThrows (CommunicationException .class , discoverer ::getInstances );
142
144
}
@@ -148,7 +150,7 @@ public void testWrongTypeResultData() {
148
150
testHelper .executeLua (functionCode );
149
151
150
152
TarantoolClusterStoredFunctionDiscoverer discoverer =
151
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
153
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
152
154
153
155
assertThrows (IllegalDiscoveryFunctionResult .class , discoverer ::getInstances );
154
156
}
@@ -157,7 +159,7 @@ public void testWrongTypeResultData() {
157
159
@ DisplayName ("fetched with an exception when a single string returned" )
158
160
public void testSingleStringResultData () {
159
161
String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , "'host1:3301'" );
160
- control . openConsole ( INSTANCE_NAME ). exec (functionCode );
162
+ testHelper . executeLua (functionCode );
161
163
162
164
TarantoolClusterStoredFunctionDiscoverer discoverer =
163
165
new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
@@ -184,7 +186,7 @@ public void testWrongMultiResultData() {
184
186
testHelper .executeLua (functionCode );
185
187
186
188
TarantoolClusterStoredFunctionDiscoverer discoverer =
187
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
189
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
188
190
189
191
Set <String > instances = discoverer .getInstances ();
190
192
@@ -200,9 +202,68 @@ public void testFunctionWithError() {
200
202
testHelper .executeLua (functionCode );
201
203
202
204
TarantoolClusterStoredFunctionDiscoverer discoverer =
203
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
205
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
204
206
205
207
assertThrows (TarantoolException .class , discoverer ::getInstances );
206
208
}
207
209
210
+ @ Test
211
+ @ DisplayName ("fetched a subset of valid addresses" )
212
+ public void testFilterBadAddressesData () {
213
+ final List <String > allHosts = Arrays .asList (
214
+ "host1:3313" ,
215
+ "host:abc" ,
216
+ "192.168.33.90" ,
217
+ "myHost" ,
218
+ "10.30.10.4:7814" ,
219
+ "host:311:sub-host" ,
220
+ "instance-2:" ,
221
+ "host:0" ,
222
+ "host:321981"
223
+ );
224
+
225
+ final Set <String > expectedFiltered = new HashSet <>(
226
+ Arrays .asList (
227
+ "host1:3313" ,
228
+ "192.168.33.90" ,
229
+ "myHost" ,
230
+ "10.30.10.4:7814"
231
+ )
232
+ );
233
+
234
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , allHosts );
235
+ testHelper .executeLua (functionCode );
236
+
237
+ TarantoolClusterStoredFunctionDiscoverer discoverer =
238
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
239
+
240
+ Set <String > instances = discoverer .getInstances ();
241
+
242
+ assertNotNull (instances );
243
+ assertFalse (instances .isEmpty ());
244
+ assertEquals (expectedFiltered , instances );
245
+ }
246
+
247
+ @ Test
248
+ @ DisplayName ("fetched an empty set after filtration" )
249
+ public void testFullBrokenAddressesList () {
250
+ List <String > allHosts = Arrays .asList (
251
+ "abc:edf" ,
252
+ "192.168.33.90:" ,
253
+ "host:-123" ,
254
+ "host:0"
255
+ );
256
+
257
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , allHosts );
258
+ testHelper .executeLua (functionCode );
259
+
260
+ TarantoolClusterStoredFunctionDiscoverer discoverer =
261
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
262
+
263
+ Set <String > instances = discoverer .getInstances ();
264
+
265
+ assertNotNull (instances );
266
+ assertTrue (instances .isEmpty ());
267
+ }
268
+
208
269
}
0 commit comments