Skip to content

DNS change fix #818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.net.UnknownHostException;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.neo4j.driver.net.ServerAddress;
Expand Down Expand Up @@ -154,6 +153,11 @@ public int port()
return port;
}

public boolean isResolved()
{
return resolved != null;
}

private static String hostFrom( URI uri )
{
String host = uri.getHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ private ClusterComposition handleRoutingProcedureError( Throwable error, Routing
public List<BoltServerAddress> resolve()
{
return resolver.resolve( initialRouter )
.stream()
.flatMap( resolved -> resolveAll( BoltServerAddress.from( resolved ) ) )
.collect( toList() ); // collect to list to preserve the order
.stream()
.map( BoltServerAddress::from )
.collect( toList() ); // collect to list to preserve the order
}

private Stream<BoltServerAddress> resolveAll( BoltServerAddress address )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.neo4j.driver.Logger;
Expand All @@ -49,6 +50,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -400,22 +402,36 @@ void shouldNotLogWhenSingleRetryAttemptFails()
Rediscovery rediscovery = new RediscoveryImpl( A, settings, compositionProvider, eventExecutor, resolver, logger );
RoutingTable table = routingTableMock( A );

ServiceUnavailableException e = assertThrows( ServiceUnavailableException.class, () -> await( rediscovery.lookupClusterComposition( table, pool, empty() ) ) );
ServiceUnavailableException e =
assertThrows( ServiceUnavailableException.class, () -> await( rediscovery.lookupClusterComposition( table, pool, empty() ) ) );
assertThat( e.getMessage(), containsString( "Could not perform discovery" ) );

// rediscovery should not log about retries and should not schedule any retries
verify( logger, never() ).info( startsWith( "Unable to fetch new routing table, will try again in " ) );
assertEquals( 0, eventExecutor.scheduleDelays().size() );
}

@Test
void shouldNotResolveToIPs()
{
ServerAddressResolver resolver = resolverMock( A, A );
Rediscovery rediscovery = new RediscoveryImpl( A, null, null, null, resolver, null );

List<BoltServerAddress> addresses = rediscovery.resolve();

verify( resolver, times( 1 ) ).resolve( A );
assertEquals( 1, addresses.size() );
assertFalse( addresses.get( 0 ).isResolved() );
}

private Rediscovery newRediscovery( BoltServerAddress initialRouter, ClusterCompositionProvider compositionProvider,
ServerAddressResolver resolver )
ServerAddressResolver resolver )
{
return newRediscovery( initialRouter, compositionProvider, resolver, DEV_NULL_LOGGER );
}

private Rediscovery newRediscovery( BoltServerAddress initialRouter, ClusterCompositionProvider compositionProvider,
ServerAddressResolver resolver, Logger logger )
ServerAddressResolver resolver, Logger logger )
{
RoutingSettings settings = new RoutingSettings( 1, 0, 0 );
return new RediscoveryImpl( initialRouter, settings, compositionProvider, GlobalEventExecutor.INSTANCE, resolver, logger );
Expand Down