Skip to content

Commit

Permalink
Use automatic port selection for bolt connectors instead of
Browse files Browse the repository at this point in the history
preliminary allocated
  • Loading branch information
MishaDemianenko committed Aug 21, 2017
1 parent 15e3665 commit 20c4274
Showing 1 changed file with 18 additions and 9 deletions.
Expand Up @@ -35,7 +35,6 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import org.neo4j.com.ports.allocation.PortAuthority;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
Expand All @@ -50,6 +49,7 @@
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.configuration.BoltConnector;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.ConnectorPortRegister;
import org.neo4j.kernel.guard.GuardTimeoutException;
import org.neo4j.kernel.guard.TimeoutGuard;
import org.neo4j.kernel.impl.api.KernelStatement;
Expand Down Expand Up @@ -103,6 +103,8 @@ public class TransactionGuardIntegrationTest
@ClassRule
public static TestDirectory testDirectory = TestDirectory.testDirectory();

private static final String BOLT_CONNECTOR_KEY = "bolt";

private static final FakeClock fakeClock = Clocks.fakeClock();
private TickingGuard tickingGuard = new TickingGuard( fakeClock, NullLog.getInstance(), 1, TimeUnit.SECONDS );
private static GraphDatabaseAPI databaseWithTimeout;
Expand Down Expand Up @@ -423,10 +425,10 @@ private GraphDatabaseAPI startDatabaseWithTimeoutCustomGuard()
{
if ( databaseWithTimeoutAndGuard == null )
{
boltPortCustomGuard = PortAuthority.allocatePort();
Map<Setting<?>,String> configMap = getSettingsWithTimeoutAndBolt( boltPortCustomGuard );
Map<Setting<?>,String> configMap = getSettingsWithTimeoutAndBolt();
databaseWithTimeoutAndGuard =
startCustomGuardedDatabase( testDirectory.directory( "dbWithoutTimeoutAndGuard" ), configMap );
boltPortCustomGuard = getBoltConnectorPort( databaseWithTimeoutAndGuard );
}
return databaseWithTimeoutAndGuard;
}
Expand All @@ -435,13 +437,20 @@ private GraphDatabaseAPI startDatabaseWithTimeout()
{
if ( databaseWithTimeout == null )
{
boltPortDatabaseWithTimeout = PortAuthority.allocatePort();
Map<Setting<?>,String> configMap = getSettingsWithTimeoutAndBolt( boltPortDatabaseWithTimeout );
Map<Setting<?>,String> configMap = getSettingsWithTimeoutAndBolt();
databaseWithTimeout = startCustomDatabase( testDirectory.directory( "dbWithTimeout" ), configMap );
boltPortDatabaseWithTimeout = getBoltConnectorPort( databaseWithTimeout );
}
return databaseWithTimeout;
}

private int getBoltConnectorPort( GraphDatabaseAPI databaseAPI )
{
ConnectorPortRegister connectorPortRegister = databaseAPI.getDependencyResolver()
.resolveDependency( ConnectorPortRegister.class );
return connectorPortRegister.getLocalAddress( BOLT_CONNECTOR_KEY ).getPort();
}

private GraphDatabaseAPI startDatabaseWithoutTimeout()
{
if ( databaseWithoutTimeout == null )
Expand All @@ -465,7 +474,7 @@ private EnterpriseNeoServer startNeoServer( GraphDatabaseFacade database ) throw
if ( neoServer == null )
{
GuardingServerBuilder serverBuilder = new GuardingServerBuilder( database );
BoltConnector boltConnector = new BoltConnector( "bolt" );
BoltConnector boltConnector = new BoltConnector( BOLT_CONNECTOR_KEY );
serverBuilder.withProperty( boltConnector.type.name(), "BOLT" )
.withProperty( boltConnector.enabled.name(), "true" )
.withProperty( boltConnector.encryption_level.name(),
Expand All @@ -478,12 +487,12 @@ private EnterpriseNeoServer startNeoServer( GraphDatabaseFacade database ) throw
return neoServer;
}

private Map<Setting<?>,String> getSettingsWithTimeoutAndBolt( int boltPort )
private Map<Setting<?>,String> getSettingsWithTimeoutAndBolt()
{
BoltConnector boltConnector = new BoltConnector( "bolt" );
BoltConnector boltConnector = new BoltConnector( BOLT_CONNECTOR_KEY );
return MapUtil.genericMap(
transaction_timeout, DEFAULT_TIMEOUT,
boltConnector.address, "localhost:" + boltPort,
boltConnector.address, "localhost:0",
boltConnector.type, "BOLT",
boltConnector.enabled, "true",
boltConnector.encryption_level, BoltConnector.EncryptionLevel.DISABLED.name(),
Expand Down

0 comments on commit 20c4274

Please sign in to comment.