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,7 +136,7 @@ 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
}
@@ -146,15 +148,27 @@ public void testWrongTypeResultData() {
146
148
control .openConsole (INSTANCE_NAME ).exec (functionCode );
147
149
148
150
TarantoolClusterStoredFunctionDiscoverer discoverer =
149
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
151
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
152
+
153
+ assertThrows (IllegalDiscoveryFunctionResult .class , discoverer ::getInstances );
154
+ }
155
+
156
+ @ Test
157
+ @ DisplayName ("fetched with an exception when a single string returned" )
158
+ public void testSingleStringResultData () {
159
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , "'host1:3301'" );
160
+ control .openConsole (INSTANCE_NAME ).exec (functionCode );
161
+
162
+ TarantoolClusterStoredFunctionDiscoverer discoverer =
163
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
150
164
151
165
assertThrows (IllegalDiscoveryFunctionResult .class , discoverer ::getInstances );
152
166
}
153
167
154
168
@ Test
155
169
@ DisplayName ("fetched with an exception using no return function" )
156
170
public void testFunctionWithNoReturn () {
157
- String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , "" );
171
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , "'host' " );
158
172
control .openConsole (INSTANCE_NAME ).exec (functionCode );
159
173
160
174
TarantoolClusterStoredFunctionDiscoverer discoverer =
@@ -170,7 +184,7 @@ public void testWrongMultiResultData() {
170
184
control .openConsole (INSTANCE_NAME ).exec (functionCode );
171
185
172
186
TarantoolClusterStoredFunctionDiscoverer discoverer =
173
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
187
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
174
188
175
189
Set <String > instances = discoverer .getInstances ();
176
190
@@ -186,9 +200,68 @@ public void testFunctionWithError() {
186
200
control .openConsole (INSTANCE_NAME ).exec (functionCode );
187
201
188
202
TarantoolClusterStoredFunctionDiscoverer discoverer =
189
- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
203
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
190
204
191
205
assertThrows (TarantoolException .class , discoverer ::getInstances );
192
206
}
193
207
208
+ @ Test
209
+ @ DisplayName ("fetched a subset of valid addresses" )
210
+ public void testFilterBadAddressesData () {
211
+ final List <String > allHosts = Arrays .asList (
212
+ "host1:3313" ,
213
+ "host:abc" ,
214
+ "192.168.33.90" ,
215
+ "myHost" ,
216
+ "10.30.10.4:7814" ,
217
+ "host:311:sub-host" ,
218
+ "instance-2:" ,
219
+ "host:0" ,
220
+ "host:321981"
221
+ );
222
+
223
+ final Set <String > expectedFiltered = new HashSet <>(
224
+ Arrays .asList (
225
+ "host1:3313" ,
226
+ "192.168.33.90" ,
227
+ "myHost" ,
228
+ "10.30.10.4:7814"
229
+ )
230
+ );
231
+
232
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , allHosts );
233
+ control .openConsole (INSTANCE_NAME ).exec (functionCode );
234
+
235
+ TarantoolClusterStoredFunctionDiscoverer discoverer =
236
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
237
+
238
+ Set <String > instances = discoverer .getInstances ();
239
+
240
+ assertNotNull (instances );
241
+ assertFalse (instances .isEmpty ());
242
+ assertEquals (expectedFiltered , instances );
243
+ }
244
+
245
+ @ Test
246
+ @ DisplayName ("fetched an empty set after filtration" )
247
+ public void testFullBrokenAddressesList () {
248
+ List <String > allHosts = Arrays .asList (
249
+ "abc:edf" ,
250
+ "192.168.33.90:" ,
251
+ "host:-123" ,
252
+ "host:0"
253
+ );
254
+
255
+ String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , allHosts );
256
+ control .openConsole (INSTANCE_NAME ).exec (functionCode );
257
+
258
+ TarantoolClusterStoredFunctionDiscoverer discoverer =
259
+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
260
+
261
+ Set <String > instances = discoverer .getInstances ();
262
+
263
+ assertNotNull (instances );
264
+ assertTrue (instances .isEmpty ());
265
+ }
266
+
194
267
}
0 commit comments