11package org .tarantool .cluster ;
22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
4+ import static org .junit .jupiter .api .Assertions .assertFalse ;
45import static org .junit .jupiter .api .Assertions .assertNotNull ;
56import static org .junit .jupiter .api .Assertions .assertThrows ;
67import static org .junit .jupiter .api .Assertions .assertTrue ;
2324
2425import java .util .Arrays ;
2526import java .util .Collections ;
27+ import java .util .HashSet ;
2628import java .util .List ;
2729import java .util .Set ;
2830
@@ -72,7 +74,7 @@ public void testSuccessfulAddressParsing() {
7274 testHelper .executeLua (functionCode );
7375
7476 TarantoolClusterStoredFunctionDiscoverer discoverer =
75- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
77+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
7678
7779 Set <String > instances = discoverer .getInstances ();
7880
@@ -91,7 +93,7 @@ public void testSuccessfulUniqueAddressParsing() {
9193 testHelper .executeLua (functionCode );
9294
9395 TarantoolClusterStoredFunctionDiscoverer discoverer =
94- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
96+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
9597
9698 Set <String > instances = discoverer .getInstances ();
9799
@@ -110,7 +112,7 @@ public void testFunctionReturnedEmptyList() {
110112 testHelper .executeLua (functionCode );
111113
112114 TarantoolClusterStoredFunctionDiscoverer discoverer =
113- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
115+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
114116
115117 Set <String > instances = discoverer .getInstances ();
116118
@@ -124,7 +126,7 @@ public void testWrongFunctionName() {
124126 clusterConfig .clusterDiscoveryEntryFunction = "wrongFunction" ;
125127
126128 TarantoolClusterStoredFunctionDiscoverer discoverer =
127- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
129+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
128130
129131 assertThrows (TarantoolException .class , discoverer ::getInstances );
130132 }
@@ -136,7 +138,7 @@ public void testWrongInstanceAddress() {
136138
137139 client .close ();
138140 TarantoolClusterStoredFunctionDiscoverer discoverer =
139- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
141+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
140142
141143 assertThrows (CommunicationException .class , discoverer ::getInstances );
142144 }
@@ -148,7 +150,7 @@ public void testWrongTypeResultData() {
148150 testHelper .executeLua (functionCode );
149151
150152 TarantoolClusterStoredFunctionDiscoverer discoverer =
151- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
153+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
152154
153155 assertThrows (IllegalDiscoveryFunctionResult .class , discoverer ::getInstances );
154156 }
@@ -157,7 +159,7 @@ public void testWrongTypeResultData() {
157159 @ DisplayName ("fetched with an exception when a single string returned" )
158160 public void testSingleStringResultData () {
159161 String functionCode = makeDiscoveryFunction (ENTRY_FUNCTION_NAME , "'host1:3301'" );
160- control . openConsole ( INSTANCE_NAME ). exec (functionCode );
162+ testHelper . executeLua (functionCode );
161163
162164 TarantoolClusterStoredFunctionDiscoverer discoverer =
163165 new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
@@ -184,7 +186,7 @@ public void testWrongMultiResultData() {
184186 testHelper .executeLua (functionCode );
185187
186188 TarantoolClusterStoredFunctionDiscoverer discoverer =
187- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
189+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
188190
189191 Set <String > instances = discoverer .getInstances ();
190192
@@ -200,9 +202,68 @@ public void testFunctionWithError() {
200202 testHelper .executeLua (functionCode );
201203
202204 TarantoolClusterStoredFunctionDiscoverer discoverer =
203- new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
205+ new TarantoolClusterStoredFunctionDiscoverer (clusterConfig , client );
204206
205207 assertThrows (TarantoolException .class , discoverer ::getInstances );
206208 }
207209
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+
208269}
0 commit comments