Skip to content

Commit 9fd5e37

Browse files
committed
Use resolved host names in CC integration tests
This commit makes CC infrastructure use resolved bolt addresses instead of URIs which checking member availability. It is done to make sure we always compare IP addresses and not just raw output of Boltkit with raw output of clustering procedures.
1 parent 6ce0084 commit 9fd5e37

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

driver/src/test/java/org/neo4j/driver/v1/util/cc/Cluster.java

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.neo4j.driver.v1.util.cc;
2020

2121
import java.net.URI;
22+
import java.net.UnknownHostException;
2223
import java.nio.file.Path;
2324
import java.util.Collections;
2425
import java.util.HashSet;
@@ -27,6 +28,7 @@
2728
import java.util.concurrent.ThreadLocalRandom;
2829
import java.util.concurrent.TimeUnit;
2930

31+
import org.neo4j.driver.internal.net.BoltServerAddress;
3032
import org.neo4j.driver.internal.util.Consumer;
3133
import org.neo4j.driver.v1.AccessMode;
3234
import org.neo4j.driver.v1.AuthTokens;
@@ -203,11 +205,11 @@ private Set<ClusterMember> membersWithRole( ClusterMemberRole role )
203205
{
204206
if ( role == extractRole( record ) )
205207
{
206-
URI boltUri = extractBoltUri( record );
207-
ClusterMember member = findByBoltUri( boltUri, members );
208+
BoltServerAddress boltAddress = extractBoltAddress( record );
209+
ClusterMember member = findByBoltAddress( boltAddress, members );
208210
if ( member == null )
209211
{
210-
throw new IllegalStateException( "Unknown cluster member: '" + boltUri + "'\n" + this );
212+
throw new IllegalStateException( "Unknown cluster member: '" + boltAddress + "'\n" + this );
211213
}
212214
membersWithRole.add( member );
213215
}
@@ -242,22 +244,22 @@ private static void waitForMembersToBeOnline( Set<ClusterMember> members, String
242244
throw new IllegalArgumentException( "No members to wait for" );
243245
}
244246

245-
Set<URI> expectedOnlineUris = extractBoltUris( members );
246-
Set<URI> actualOnlineUris = Collections.emptySet();
247+
Set<BoltServerAddress> expectedOnlineAddresses = extractBoltAddresses( members );
248+
Set<BoltServerAddress> actualOnlineAddresses = Collections.emptySet();
247249

248250
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis( STARTUP_TIMEOUT_SECONDS );
249251
Throwable error = null;
250252

251-
while ( !expectedOnlineUris.equals( actualOnlineUris ) )
253+
while ( !expectedOnlineAddresses.equals( actualOnlineAddresses ) )
252254
{
253255
sleep( ONLINE_MEMBERS_CHECK_SLEEP_MS );
254-
assertDeadlineNotReached( deadline, expectedOnlineUris, actualOnlineUris, error );
256+
assertDeadlineNotReached( deadline, expectedOnlineAddresses, actualOnlineAddresses, error );
255257

256258
try ( Driver driver = createDriver( members, password );
257259
Session session = driver.session( AccessMode.READ ) )
258260
{
259261
List<Record> records = findClusterOverview( session );
260-
actualOnlineUris = extractBoltUris( records );
262+
actualOnlineAddresses = extractBoltAddresses( records );
261263
}
262264
catch ( Throwable t )
263265
{
@@ -315,16 +317,16 @@ private static boolean isCoreMember( Session session )
315317
return role != ClusterMemberRole.READ_REPLICA;
316318
}
317319

318-
private static void assertDeadlineNotReached( long deadline, Set<URI> expectedUris, Set<URI> actualUris,
320+
private static void assertDeadlineNotReached( long deadline, Set<?> expectedAddresses, Set<?> actualAddresses,
319321
Throwable error ) throws ClusterUnavailableException
320322
{
321323
if ( System.currentTimeMillis() > deadline )
322324
{
323325
String baseMessage = "Cluster did not become available in " + STARTUP_TIMEOUT_SECONDS + " seconds.\n";
324326
String errorMessage = error == null ? "" : "There were errors checking cluster members.\n";
325-
String expectedUrisMessage = "Expected online URIs: " + expectedUris + "\n";
326-
String actualUrisMessage = "Actual last seen online URIs: " + actualUris + "\n";
327-
String message = baseMessage + errorMessage + expectedUrisMessage + actualUrisMessage;
327+
String expectedAddressesMessage = "Expected online addresses: " + expectedAddresses + "\n";
328+
String actualAddressesMessage = "Actual last seen online addresses: " + actualAddresses + "\n";
329+
String message = baseMessage + errorMessage + expectedAddressesMessage + actualAddressesMessage;
328330

329331
ClusterUnavailableException clusterUnavailable = new ClusterUnavailableException( message );
330332

@@ -337,31 +339,45 @@ private static void assertDeadlineNotReached( long deadline, Set<URI> expectedUr
337339
}
338340
}
339341

340-
private static Set<URI> extractBoltUris( Set<ClusterMember> members )
342+
private static Set<BoltServerAddress> extractBoltAddresses( Set<ClusterMember> members )
341343
{
342-
Set<URI> uris = new HashSet<>();
344+
Set<BoltServerAddress> addresses = new HashSet<>();
343345
for ( ClusterMember member : members )
344346
{
345-
uris.add( member.getBoltUri() );
347+
addresses.add( member.getBoltAddress() );
346348
}
347-
return uris;
349+
return addresses;
348350
}
349351

350-
private static Set<URI> extractBoltUris( List<Record> records )
352+
private static Set<BoltServerAddress> extractBoltAddresses( List<Record> records )
351353
{
352-
Set<URI> uris = new HashSet<>();
354+
Set<BoltServerAddress> addresses = new HashSet<>();
353355
for ( Record record : records )
354356
{
355-
uris.add( extractBoltUri( record ) );
357+
BoltServerAddress boltAddress = extractBoltAddress( record );
358+
addresses.add( boltAddress );
356359
}
357-
return uris;
360+
return addresses;
358361
}
359362

360-
private static URI extractBoltUri( Record record )
363+
private static BoltServerAddress extractBoltAddress( Record record )
361364
{
362365
List<Object> addresses = record.get( "addresses" ).asList();
363366
String boltUriString = (String) addresses.get( 0 );
364-
return URI.create( boltUriString );
367+
URI boltUri = URI.create( boltUriString );
368+
return newBoltServerAddress( boltUri );
369+
}
370+
371+
private static BoltServerAddress newBoltServerAddress( URI uri )
372+
{
373+
try
374+
{
375+
return BoltServerAddress.from( uri ).resolve();
376+
}
377+
catch ( UnknownHostException e )
378+
{
379+
throw new RuntimeException( "Unable to resolve host to IP in URI: '" + uri + "'" );
380+
}
365381
}
366382

367383
private static ClusterMemberRole extractRole( Record record )
@@ -370,11 +386,11 @@ private static ClusterMemberRole extractRole( Record record )
370386
return ClusterMemberRole.valueOf( roleString.toUpperCase() );
371387
}
372388

373-
private static ClusterMember findByBoltUri( URI boltUri, Set<ClusterMember> members )
389+
private static ClusterMember findByBoltAddress( BoltServerAddress boltAddress, Set<ClusterMember> members )
374390
{
375391
for ( ClusterMember member : members )
376392
{
377-
if ( member.getBoltUri().equals( boltUri ) )
393+
if ( member.getBoltAddress().equals( boltAddress ) )
378394
{
379395
return member;
380396
}

driver/src/test/java/org/neo4j/driver/v1/util/cc/ClusterMember.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
package org.neo4j.driver.v1.util.cc;
2020

2121
import java.net.URI;
22+
import java.net.UnknownHostException;
2223
import java.nio.file.Path;
2324

25+
import org.neo4j.driver.internal.net.BoltServerAddress;
26+
2427
import static java.util.Objects.requireNonNull;
2528

2629
public class ClusterMember
@@ -29,11 +32,13 @@ public class ClusterMember
2932
private static final String ROUTING_SCHEME = "bolt+routing://";
3033

3134
private final URI boltUri;
35+
private final BoltServerAddress boltAddress;
3236
private final Path path;
3337

3438
public ClusterMember( URI boltUri, Path path )
3539
{
3640
this.boltUri = requireNonNull( boltUri );
41+
this.boltAddress = newBoltServerAddress( boltUri );
3742
this.path = requireNonNull( path );
3843
}
3944

@@ -47,6 +52,11 @@ public URI getRoutingUri()
4752
return URI.create( boltUri.toString().replace( SIMPLE_SCHEME, ROUTING_SCHEME ) );
4853
}
4954

55+
public BoltServerAddress getBoltAddress()
56+
{
57+
return boltAddress;
58+
}
59+
5060
public Path getPath()
5161
{
5262
return path;
@@ -60,4 +70,16 @@ public String toString()
6070
", path=" + path +
6171
"}";
6272
}
73+
74+
private static BoltServerAddress newBoltServerAddress( URI uri )
75+
{
76+
try
77+
{
78+
return BoltServerAddress.from( uri ).resolve();
79+
}
80+
catch ( UnknownHostException e )
81+
{
82+
throw new RuntimeException( e );
83+
}
84+
}
6385
}

0 commit comments

Comments
 (0)