From 0dcf28b75aaee5dc92f5188ed9e55c34ecc89225 Mon Sep 17 00:00:00 2001 From: Lasse Westh-Nielsen Date: Tue, 10 Oct 2017 15:33:43 +0200 Subject: [PATCH] fixing port conflicts --- .../neo4j/kernel/impl/ha/ClusterManager.java | 19 ++++---- .../java/org/neo4j/test/ha/ClusterRule.java | 4 +- .../org/neo4j/TransactionTerminationIT.java | 3 +- .../java/org/neo4j/bolt/BoltFailuresIT.java | 47 ++++++++++++------- .../org/neo4j/bolt/BoltMessageLoggingIT.java | 4 +- .../java/org/neo4j/bolt/SessionResetIT.java | 4 +- .../src/test/java/org/neo4j/ha/BoltHAIT.java | 2 +- .../java/org/neo4j/ha/HAClusterStartupIT.java | 7 ++- .../org/neo4j/server/BatchEndpointIT.java | 5 +- .../org/neo4j/server/BoltQueryLoggingIT.java | 12 +++-- 10 files changed, 68 insertions(+), 39 deletions(-) diff --git a/enterprise/ha/src/test/java/org/neo4j/kernel/impl/ha/ClusterManager.java b/enterprise/ha/src/test/java/org/neo4j/kernel/impl/ha/ClusterManager.java index 356ab5713a043..898aa1dfd177b 100644 --- a/enterprise/ha/src/test/java/org/neo4j/kernel/impl/ha/ClusterManager.java +++ b/enterprise/ha/src/test/java/org/neo4j/kernel/impl/ha/ClusterManager.java @@ -162,7 +162,7 @@ public static IntFunction constant( final String value ) private final boolean consistencyCheck; private final int firstInstanceId; private LifeSupport life; - private int baseBoltPort; + private boolean boltEnabled; private ClusterManager( Builder builder ) { @@ -176,7 +176,7 @@ private ClusterManager( Builder builder ) this.availabilityChecks = builder.availabilityChecks; this.consistencyCheck = builder.consistencyCheck; this.firstInstanceId = builder.firstInstanceId; - this.baseBoltPort = builder.baseBoltPort; + this.boltEnabled = builder.boltEnabled; } private Map> withDefaults( Map> commonConfig ) @@ -622,10 +622,9 @@ public interface ClusterBuilder SELF withInstanceConfig( Map> commonConfig ); /** - * Enables bolt across the cluster, which is off by default. The port argument specifies the base port to - * use for calculating per instance ports. + * Enables bolt across the cluster, which is off by default. */ - SELF withBolt( int port ); + SELF withBoltEnabled(); /** * Like {@link #withInstanceConfig(Map)}, but for individual settings, conveniently using @@ -683,7 +682,7 @@ public static class Builder implements ClusterBuilder private List> availabilityChecks = Collections.emptyList(); private boolean consistencyCheck; private int firstInstanceId = FIRST_SERVER_ID; - private int baseBoltPort = -1; // -1 stands for no bolt enabled, anything > 0 means bolt enabled + private boolean boltEnabled; public Builder( File root ) { @@ -742,9 +741,9 @@ public Builder withInstanceConfig( Map> commonConfig return this; } - public Builder withBolt( int basePort ) + public Builder withBoltEnabled() { - this.baseBoltPort = basePort; + this.boltEnabled = true; return this; } @@ -1144,10 +1143,10 @@ private HighlyAvailableGraphDatabase startMemberNow( InstanceId serverId ) builder.setConfig( conf.getKey(), conf.getValue().apply( serverId.toIntegerIndex() ) ); } - if ( baseBoltPort > 0 ) + if ( boltEnabled ) { String listenAddress = "127.0.0.1"; - int boltPort = baseBoltPort + serverId.toIntegerIndex(); + int boltPort = PortAuthority.allocatePort(); AdvertisedSocketAddress advertisedSocketAddress = socketAddressForServer( listenAddress, boltPort ); String advertisedAddress = advertisedSocketAddress.getHostname(); String boltAdvertisedAddress = advertisedAddress + ":" + boltPort; diff --git a/enterprise/ha/src/test/java/org/neo4j/test/ha/ClusterRule.java b/enterprise/ha/src/test/java/org/neo4j/test/ha/ClusterRule.java index b80534f7adf3a..7a432560b62d6 100644 --- a/enterprise/ha/src/test/java/org/neo4j/test/ha/ClusterRule.java +++ b/enterprise/ha/src/test/java/org/neo4j/test/ha/ClusterRule.java @@ -129,9 +129,9 @@ public ClusterRule withInstanceConfig( Map> commonCon } @Override - public ClusterRule withBolt( int port ) + public ClusterRule withBoltEnabled() { - return set( clusterManagerBuilder.withBolt( port ) ); + return set( clusterManagerBuilder.withBoltEnabled() ); } @Override diff --git a/integrationtests/src/test/java/org/neo4j/TransactionTerminationIT.java b/integrationtests/src/test/java/org/neo4j/TransactionTerminationIT.java index f822bd10b9539..39eec89af1de3 100644 --- a/integrationtests/src/test/java/org/neo4j/TransactionTerminationIT.java +++ b/integrationtests/src/test/java/org/neo4j/TransactionTerminationIT.java @@ -50,6 +50,7 @@ import org.neo4j.kernel.ha.HaSettings; import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase; import org.neo4j.kernel.impl.api.KernelTransactions; +import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.ha.ClusterManager; import org.neo4j.kernel.impl.locking.LockClientStoppedException; @@ -92,7 +93,6 @@ public class TransactionTerminationIT private final CleanupRule cleanupRule = new CleanupRule(); private final ClusterRule clusterRule = new ClusterRule( getClass() ) .withCluster( clusterOfSize( 3 ) ) - .withSharedSetting( HaSettings.ha_server, ":6001-6005" ) .withSharedSetting( HaSettings.tx_push_factor, "2" ) .withSharedSetting( HaSettings.lock_read_timeout, "1m" ); @@ -113,6 +113,7 @@ public void terminateSingleInstanceRestTransactionThatWaitsForLock() throws Exce ServerControls server = cleanupRule.add( TestServerBuilders.newInProcessBuilder() .withConfig( GraphDatabaseSettings.auth_enabled, Settings.FALSE ) .withConfig( GraphDatabaseFacadeFactory.Configuration.lock_manager, lockManagerName ) + .withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ) .newServer() ); GraphDatabaseService db = server.graph(); diff --git a/integrationtests/src/test/java/org/neo4j/bolt/BoltFailuresIT.java b/integrationtests/src/test/java/org/neo4j/bolt/BoltFailuresIT.java index cd3ac6c9a65d8..bb9d932249878 100644 --- a/integrationtests/src/test/java/org/neo4j/bolt/BoltFailuresIT.java +++ b/integrationtests/src/test/java/org/neo4j/bolt/BoltFailuresIT.java @@ -50,11 +50,13 @@ import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.io.IOUtils; +import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings; import org.neo4j.kernel.impl.logging.LogService; import org.neo4j.kernel.monitoring.Monitors; import org.neo4j.logging.AssertableLogProvider; import org.neo4j.logging.AssertableLogProvider.LogMatcher; import org.neo4j.logging.LogProvider; +import org.neo4j.ports.allocation.PortAuthority; import org.neo4j.scheduler.JobScheduler; import org.neo4j.test.TestEnterpriseGraphDatabaseFactory; import org.neo4j.test.rule.TestDirectory; @@ -110,12 +112,14 @@ public void throwsWhenWorkerCreationFails() BoltKernelExtension extension = new BoltKernelExtensionWithWorkerFactory( workerFactory ); - db = startDbWithBolt( new GraphDatabaseFactoryWithCustomBoltKernelExtension( extension ) ); + int port = PortAuthority.allocatePort(); + + db = startDbWithBolt( new GraphDatabaseFactoryWithCustomBoltKernelExtension( extension ), port ); try { // attempt to create a driver when server is unavailable - driver = createDriver(); + driver = createDriver( port ); fail( "Exception expected" ); } catch ( Exception e ) @@ -131,11 +135,13 @@ public void throwsWhenMonitoredWorkerCreationFails() sessionMonitor.throwInSessionStarted(); Monitors monitors = newMonitorsSpy( sessionMonitor ); - db = startDbWithBolt( new GraphDatabaseFactory().setMonitors( monitors ) ); + int port = PortAuthority.allocatePort(); + + db = startDbWithBolt( new GraphDatabaseFactory().setMonitors( monitors ), port ); try { // attempt to create a driver when server is unavailable - driver = createDriver(); + driver = createDriver( port ); fail( "Exception expected" ); } catch ( Exception e ) @@ -184,7 +190,8 @@ public void throwsWhenRunMessageProcessingFailsToComplete() public void boltServerLogsRealErrorWhenDriverIsClosedWithRunningTransactions() throws Exception { AssertableLogProvider internalLogProvider = new AssertableLogProvider(); - db = startTestDb( internalLogProvider ); + int port = PortAuthority.allocatePort(); + db = startTestDb( internalLogProvider, port ); // create a dummy node db.execute( "CREATE (:Node)" ).close(); @@ -194,7 +201,7 @@ public void boltServerLogsRealErrorWhenDriverIsClosedWithRunningTransactions() t Node node = single( db.findNodes( label( "Node" ) ) ); tx.acquireWriteLock( node ); - Driver driver = createDriver(); + Driver driver = createDriver( port ); // try to execute write query for the same node through the driver Future writeThroughDriverFuture = updateAllNodesAsync( driver ); @@ -223,11 +230,13 @@ private void throwsWhenInitMessageFails( Consumer monito monitorSetup.accept( sessionMonitor ); Monitors monitors = newMonitorsSpy( sessionMonitor ); - db = startTestDb( monitors ); + int port = PortAuthority.allocatePort(); + + db = startTestDb( monitors, port ); try { - driver = GraphDatabase.driver( "bolt://localhost", Config.build().withoutEncryption().toConfig() ); + driver = GraphDatabase.driver( "bolt://localhost:" + port, Config.build().withoutEncryption().toConfig() ); if ( shouldBeAbleToBeginTransaction ) { try ( Session session = driver.session(); @@ -252,8 +261,10 @@ private void throwsWhenRunMessageFails( Consumer monitor ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor(); Monitors monitors = newMonitorsSpy( sessionMonitor ); - db = startTestDb( monitors ); - driver = createDriver(); + int port = PortAuthority.allocatePort(); + + db = startTestDb( monitors, port ); + driver = createDriver( port ); // open a session and start a transaction, this will force driver to obtain // a network connection and bind it to the transaction @@ -276,22 +287,24 @@ private void throwsWhenRunMessageFails( Consumer monitor } } - private GraphDatabaseService startTestDb( Monitors monitors ) + private GraphDatabaseService startTestDb( Monitors monitors, int port ) { - return startDbWithBolt( newDbFactory().setMonitors( monitors ) ); + return startDbWithBolt( newDbFactory().setMonitors( monitors ), port ); } - private GraphDatabaseService startTestDb( LogProvider internalLogProvider ) + private GraphDatabaseService startTestDb( LogProvider internalLogProvider, int port ) { - return startDbWithBolt( newDbFactory().setInternalLogProvider( internalLogProvider ) ); + return startDbWithBolt( newDbFactory().setInternalLogProvider( internalLogProvider ), port ); } - private GraphDatabaseService startDbWithBolt( GraphDatabaseFactory dbFactory ) + private GraphDatabaseService startDbWithBolt( GraphDatabaseFactory dbFactory, int port ) { return dbFactory.newEmbeddedDatabaseBuilder( dir.graphDbDir() ) .setConfig( boltConnector( "0" ).type, BOLT.name() ) .setConfig( boltConnector( "0" ).enabled, TRUE ) + .setConfig( boltConnector( "0" ).listen_address, "localhost:" + port ) .setConfig( GraphDatabaseSettings.auth_enabled, FALSE ) + .setConfig( OnlineBackupSettings.online_backup_enabled, FALSE ) .newGraphDatabase(); } @@ -349,9 +362,9 @@ private static TestEnterpriseGraphDatabaseFactory newDbFactory() return new TestEnterpriseGraphDatabaseFactory(); } - private static Driver createDriver() + private static Driver createDriver( int port ) { - return GraphDatabase.driver( "bolt://localhost", Config.build().withoutEncryption().toConfig() ); + return GraphDatabase.driver( "bolt://localhost:" + port, Config.build().withoutEncryption().toConfig() ); } private static Monitors newMonitorsSpy( ThrowingSessionMonitor sessionMonitor ) diff --git a/integrationtests/src/test/java/org/neo4j/bolt/BoltMessageLoggingIT.java b/integrationtests/src/test/java/org/neo4j/bolt/BoltMessageLoggingIT.java index 087ae68b5a8ee..5a15333f9a8f7 100644 --- a/integrationtests/src/test/java/org/neo4j/bolt/BoltMessageLoggingIT.java +++ b/integrationtests/src/test/java/org/neo4j/bolt/BoltMessageLoggingIT.java @@ -38,6 +38,8 @@ import org.neo4j.kernel.configuration.BoltConnector; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.ConnectorPortRegister; +import org.neo4j.kernel.configuration.Settings; +import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.rule.DatabaseRule; @@ -85,7 +87,7 @@ protected void configure( GraphDatabaseBuilder builder ) builder.setConfig( new BoltConnector( CONNECTOR_KEY ).listen_address, "localhost:0" ); builder.setConfig( new BoltConnector( CONNECTOR_KEY ).encryption_level, DISABLED.toString() ); } - }.startLazily(); + }.withSetting( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ).startLazily(); private Driver driver; diff --git a/integrationtests/src/test/java/org/neo4j/bolt/SessionResetIT.java b/integrationtests/src/test/java/org/neo4j/bolt/SessionResetIT.java index d7ee7401ababe..1c499583ac000 100644 --- a/integrationtests/src/test/java/org/neo4j/bolt/SessionResetIT.java +++ b/integrationtests/src/test/java/org/neo4j/bolt/SessionResetIT.java @@ -58,7 +58,9 @@ import org.neo4j.harness.junit.EnterpriseNeo4jRule; import org.neo4j.harness.junit.Neo4jRule; import org.neo4j.io.IOUtils; +import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.impl.api.KernelTransactions; +import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.test.ThreadTestUtils; import org.neo4j.test.rule.VerboseTimeout; @@ -101,7 +103,7 @@ public class SessionResetIT private static final String[] STRESS_IT_QUERIES = {SHORT_QUERY_1, SHORT_QUERY_2, LONG_QUERY}; private final VerboseTimeout timeout = VerboseTimeout.builder().withTimeout( 3, MINUTES ).build(); - private final Neo4jRule db = new EnterpriseNeo4jRule(); + private final Neo4jRule db = new EnterpriseNeo4jRule().withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ); @Rule public final RuleChain ruleChain = RuleChain.outerRule( timeout ).around( db ); diff --git a/integrationtests/src/test/java/org/neo4j/ha/BoltHAIT.java b/integrationtests/src/test/java/org/neo4j/ha/BoltHAIT.java index 5cbb3a5af309e..e7484dee9d891 100644 --- a/integrationtests/src/test/java/org/neo4j/ha/BoltHAIT.java +++ b/integrationtests/src/test/java/org/neo4j/ha/BoltHAIT.java @@ -46,7 +46,7 @@ public class BoltHAIT { @Rule - public final ClusterRule clusterRule = new ClusterRule( getClass() ).withBolt( 8000 ).withCluster( clusterOfSize( 3 ) ); + public final ClusterRule clusterRule = new ClusterRule( getClass() ).withBoltEnabled().withCluster( clusterOfSize( 3 ) ); @Test public void shouldContinueServingBoltRequestsBetweenInternalRestarts() throws Throwable diff --git a/integrationtests/src/test/java/org/neo4j/ha/HAClusterStartupIT.java b/integrationtests/src/test/java/org/neo4j/ha/HAClusterStartupIT.java index 1903ddf8c0dc7..3471e79955eae 100644 --- a/integrationtests/src/test/java/org/neo4j/ha/HAClusterStartupIT.java +++ b/integrationtests/src/test/java/org/neo4j/ha/HAClusterStartupIT.java @@ -36,9 +36,11 @@ import org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory; import org.neo4j.io.fs.FileUtils; import org.neo4j.kernel.api.KernelTransaction; +import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext; import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase; import org.neo4j.kernel.impl.coreapi.InternalTransaction; +import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings; import org.neo4j.kernel.impl.ha.ClusterManager; import org.neo4j.kernel.impl.storemigration.LogFiles; import org.neo4j.test.ha.ClusterRule; @@ -203,7 +205,10 @@ private static File dbWithOutLogs() GraphDatabaseService db = null; try { - db = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( seedDir ); + db = new EnterpriseGraphDatabaseFactory() + .newEmbeddedDatabaseBuilder( seedDir ) + .setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ) + .newGraphDatabase(); createSomeData( db ); } finally diff --git a/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java b/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java index 45204192c724d..3186af6ec5059 100644 --- a/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java +++ b/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java @@ -24,7 +24,9 @@ import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.harness.junit.Neo4jRule; +import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.configuration.ssl.LegacySslPolicyConfig; +import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings; import org.neo4j.server.configuration.ServerSettings; import static org.junit.Assert.assertEquals; @@ -43,7 +45,8 @@ public class BatchEndpointIT .withConfig( GraphDatabaseSettings.logs_directory, getRelativePath( getSharedTestTemporaryFolder(), GraphDatabaseSettings.logs_directory ) ) .withConfig( ServerSettings.http_logging_enabled, "true" ) - .withConfig( GraphDatabaseSettings.auth_enabled, "false" ); + .withConfig( GraphDatabaseSettings.auth_enabled, "false" ) + .withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ); @Test public void requestsShouldNotFailWhenHttpLoggingIsOn() diff --git a/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java b/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java index f40c414e1c05e..0431b8a6bf070 100644 --- a/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java +++ b/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java @@ -33,7 +33,10 @@ import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.harness.junit.Neo4jRule; import org.neo4j.kernel.configuration.BoltConnector; +import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.configuration.ssl.LegacySslPolicyConfig; +import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings; +import org.neo4j.ports.allocation.PortAuthority; import org.neo4j.server.configuration.ServerSettings; import static org.hamcrest.MatcherAssert.assertThat; @@ -58,8 +61,9 @@ public BoltQueryLoggingIT() throws IOException .withConfig( GraphDatabaseSettings.log_queries, "true") .withConfig( new BoltConnector( "bolt" ).type, "BOLT" ) .withConfig( new BoltConnector( "bolt" ).enabled, "true" ) - .withConfig( new BoltConnector( "bolt" ).address, "localhost:8776" ) - .withConfig( new BoltConnector( "bolt" ).encryption_level, "DISABLED" ); + .withConfig( new BoltConnector( "bolt" ).address, "localhost:" + PortAuthority.allocatePort() ) + .withConfig( new BoltConnector( "bolt" ).encryption_level, "DISABLED" ) + .withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ); } @Test @@ -67,7 +71,7 @@ public void shouldLogQueriesViaBolt() throws IOException { // *** GIVEN *** - Socket socket = new Socket( "localhost", 8776 ); + Socket socket = new Socket( "localhost", neo4j.boltURI().getPort() ); DataInputStream dataIn = new DataInputStream( socket.getInputStream() ); DataOutputStream dataOut = new DataOutputStream( socket.getOutputStream() ); @@ -119,7 +123,7 @@ public void shouldLogQueriesViaBolt() throws IOException assertTrue( line.contains( "ms: bolt-session\tbolt\tneo4j\tMyClient/1.0" ) ); assertTrue( line.contains( "client/127.0.0.1:" ) ); assertTrue( line.contains( "client/127.0.0.1:" ) ); - assertTrue( line.contains( "server/127.0.0.1:8776" ) ); + assertTrue( line.contains( "server/127.0.0.1:" + neo4j.boltURI().getPort() ) ); assertTrue( line.contains( " - RETURN 1 AS num - {}" ) ); }