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
@@ -70,7 +72,7 @@ public void testSuccessfulAddressParsing() {
70
72
control .openConsole (INSTANCE_NAME ).exec (functionCode );
71
73
72
74
TarantoolClusterStoredFunctionDiscoverer discoverer =
73
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
75
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
74
76
75
77
Set <String > instances = discoverer .getInstances ();
76
78
@@ -89,7 +91,7 @@ public void testSuccessfulUniqueAddressParsing() {
89
91
control .openConsole (INSTANCE_NAME ).exec (functionCode );
90
92
91
93
TarantoolClusterStoredFunctionDiscoverer discoverer =
92
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
94
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
93
95
94
96
Set <String > instances = discoverer .getInstances ();
95
97
@@ -108,7 +110,7 @@ public void testFunctionReturnedEmptyList() {
108
110
control .openConsole (INSTANCE_NAME ).exec (functionCode );
109
111
110
112
TarantoolClusterStoredFunctionDiscoverer discoverer =
111
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
113
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
112
114
113
115
Set <String > instances = discoverer .getInstances ();
114
116
@@ -122,7 +124,7 @@ public void testWrongFunctionName() {
122
124
clusterConfig .clusterDiscoveryEntryFunction = "wrongFunction" ;
123
125
124
126
TarantoolClusterStoredFunctionDiscoverer discoverer =
125
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
127
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
126
128
127
129
assertThrows (TarantoolException .class , discoverer ::getInstances );
128
130
}
@@ -134,21 +136,24 @@ public void testWrongInstanceAddress() {
134
136
135
137
client .close ();
136
138
TarantoolClusterStoredFunctionDiscoverer discoverer =
137
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
139
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
138
140
139
141
assertThrows (CommunicationException .class , discoverer ::getInstances );
140
142
}
141
143
142
144
@ Test
143
- @ DisplayName ("fetched with an exception when wrong data type returned" )
145
+ @ DisplayName ("fetched an empty list when wrong data type returned" )
144
146
public void testWrongTypeResultData () {
145
147
String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , 42 );
146
148
control .openConsole (INSTANCE_NAME ).exec (functionCode );
147
149
148
150
TarantoolClusterStoredFunctionDiscoverer discoverer =
149
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
151
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
150
152
151
- assertThrows (IllegalDiscoveryFunctionResult .class , discoverer ::getInstances );
153
+ Set <String > instances = discoverer .getInstances ();
154
+
155
+ assertNotNull (instances );
156
+ assertTrue (instances .isEmpty ());
152
157
}
153
158
154
159
@ Test
@@ -170,7 +175,7 @@ public void testWrongMultiResultData() {
170
175
control .openConsole (INSTANCE_NAME ).exec (functionCode );
171
176
172
177
TarantoolClusterStoredFunctionDiscoverer discoverer =
173
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
178
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
174
179
175
180
Set <String > instances = discoverer .getInstances ();
176
181
@@ -186,9 +191,68 @@ public void testFunctionWithError() {
186
191
control .openConsole (INSTANCE_NAME ).exec (functionCode );
187
192
188
193
TarantoolClusterStoredFunctionDiscoverer discoverer =
189
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
194
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
190
195
191
196
assertThrows (TarantoolException .class , discoverer ::getInstances );
192
197
}
193
198
199
+ @ Test
200
+ @ DisplayName ("fetched a subset of valid addresses" )
201
+ public void testFilterBadAddressesData () {
202
+ final List <String > allHosts = Arrays .asList (
203
+ "host1:3313" ,
204
+ "host:abc" ,
205
+ "192.168.33.90" ,
206
+ "myHost" ,
207
+ "10.30.10.4:7814" ,
208
+ "host:311:sub-host" ,
209
+ "instance-2:" ,
210
+ "host:0" ,
211
+ "host:321981"
212
+ );
213
+
214
+ final Set <String > expectedFiltered = new HashSet <>(
215
+ Arrays .asList (
216
+ "host1:3313" ,
217
+ "192.168.33.90" ,
218
+ "myHost" ,
219
+ "10.30.10.4:7814"
220
+ )
221
+ );
222
+
223
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , allHosts );
224
+ control .openConsole (INSTANCE_NAME ).exec (functionCode );
225
+
226
+ TarantoolClusterStoredFunctionDiscoverer discoverer =
227
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
228
+
229
+ Set <String > instances = discoverer .getInstances ();
230
+
231
+ assertNotNull (instances );
232
+ assertFalse (instances .isEmpty ());
233
+ assertEquals (expectedFiltered , instances );
234
+ }
235
+
236
+ @ Test
237
+ @ DisplayName ("fetched an empty set after filtration" )
238
+ public void testFullBrokenAddressesList () {
239
+ List <String > allHosts = Arrays .asList (
240
+ "abc:edf" ,
241
+ "192.168.33.90:" ,
242
+ "host:-123" ,
243
+ "host:0"
244
+ );
245
+
246
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , allHosts );
247
+ control .openConsole (INSTANCE_NAME ).exec (functionCode );
248
+
249
+ TarantoolClusterStoredFunctionDiscoverer discoverer =
250
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
251
+
252
+ Set <String > instances = discoverer .getInstances ();
253
+
254
+ assertNotNull (instances );
255
+ assertTrue (instances .isEmpty ());
256
+ }
257
+
194
258
}
0 commit comments