diff --git a/enterprise/neo4j-harness-enterprise/pom.xml b/enterprise/neo4j-harness-enterprise/pom.xml
index 13130f79e7d64..3d81055a5f75e 100644
--- a/enterprise/neo4j-harness-enterprise/pom.xml
+++ b/enterprise/neo4j-harness-enterprise/pom.xml
@@ -115,5 +115,38 @@
test
test-jar
+
+
+ org.neo4j
+ neo4j-com
+ ${project.version}
+ test
+ test-jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
+ 1C
+
+
+ 1
+
+ 1200
+ 1800
+
+ ${project.build.directory}/FORK_DIRECTORY_${surefire.forkNumber}
+
+
+ ${user.dir}/target/port-authority-${maven.build.timestamp}
+
+
+
+
+
diff --git a/enterprise/neo4j-harness-enterprise/src/main/java/org/neo4j/harness/CausalClusterInProcessRunner.java b/enterprise/neo4j-harness-enterprise/src/main/java/org/neo4j/harness/CausalClusterInProcessRunner.java
index 60f54e3ce954d..0d2f465521e82 100644
--- a/enterprise/neo4j-harness-enterprise/src/main/java/org/neo4j/harness/CausalClusterInProcessRunner.java
+++ b/enterprise/neo4j-harness-enterprise/src/main/java/org/neo4j/harness/CausalClusterInProcessRunner.java
@@ -60,7 +60,7 @@ public static void main( String[] args ) throws IOException, ExecutionException,
Path clusterPath = Files.createTempDirectory( "causal-cluster" );
System.out.println( "clusterPath = " + clusterPath );
- CausalCluster cluster = new CausalCluster( 3, 3, clusterPath, toOutputStream( System.out ) );
+ CausalCluster cluster = new CausalCluster( 3, 3, clusterPath, toOutputStream( System.out ), PortPickingStrategy.DEFAULT );
System.out.println( "Waiting for cluster to boot up..." );
cluster.boot();
@@ -85,96 +85,83 @@ abstract static class PortPickingStrategy
public static final PortPickingStrategy DEFAULT = new PortPickingStrategy()
{
@Override
- int hazelcastPort( int coreId )
+ int port( int offset, int id )
{
- return 55000 + coreId;
+ return offset + id;
}
+ };
- @Override
- int txCorePort( int coreId )
- {
- return 56000 + coreId;
- }
+ abstract int port( int offset, int id );
- @Override
- int raftCorePort( int coreId )
- {
- return 57000 + coreId;
- }
+ int hazelcastPort( int coreId )
+ {
+ return port( 55000, coreId );
+ }
- @Override
- int boltCorePort( int coreId )
- {
- return 58000 + coreId;
- }
+ int txCorePort( int coreId )
+ {
+ return port( 56000, coreId );
+ }
- @Override
- int httpCorePort( int coreId )
- {
- return 59000 + coreId;
- }
+ int raftCorePort( int coreId )
+ {
+ return port( 57000, coreId );
+ }
- @Override
- int httpsCorePort( int coreId )
- {
- return 60000 + coreId;
- }
+ int boltCorePort( int coreId )
+ {
+ return port( 58000, coreId );
+ }
- @Override
- int txReadReplicaPort( int replicaId )
- {
- return 56500 + replicaId;
- }
+ int httpCorePort( int coreId )
+ {
+ return port( 59000, coreId );
+ }
- @Override
- int boltReadReplicaPort( int replicaId )
- {
- return 58500 + replicaId;
- }
+ int httpsCorePort( int coreId )
+ {
+ return port( 60000, coreId );
+ }
- @Override
- int httpReadReplicaPort( int replicaId )
- {
- return 59500 + replicaId;
- }
+ int txReadReplicaPort( int replicaId )
+ {
+ return port( 56500, replicaId );
+ }
- @Override
- int httpsReadReplicaPort( int replicaId )
- {
- return 60500 + replicaId;
- }
- };
+ int boltReadReplicaPort( int replicaId )
+ {
+ return port( 58500, replicaId );
+ }
- abstract int hazelcastPort( int coreId );
- abstract int txCorePort( int coreId );
- abstract int raftCorePort( int coreId );
- abstract int boltCorePort( int coreId );
- abstract int httpCorePort( int coreId );
- abstract int httpsCorePort( int coreId );
- abstract int txReadReplicaPort( int replicaId );
- abstract int boltReadReplicaPort( int replicaId );
- abstract int httpReadReplicaPort( int replicaId );
- abstract int httpsReadReplicaPort( int replicaId );
+ int httpReadReplicaPort( int replicaId )
+ {
+ return port( 59500, replicaId );
+ }
+
+ int httpsReadReplicaPort( int replicaId )
+ {
+ return port( 60500, replicaId );
+ }
}
static class CausalCluster
{
- private static final PortPickingStrategy PortPickingStrategy = CausalClusterInProcessRunner.PortPickingStrategy.DEFAULT;
-
private final int nCores;
private final int nReplicas;
private final Path clusterPath;
private final Log log;
+ private final PortPickingStrategy portPickingStrategy;
private List coreControls = synchronizedList( new ArrayList<>() );
private List replicaControls = synchronizedList( new ArrayList<>() );
- CausalCluster( int nCores, int nReplicas, Path clusterPath, LogProvider logProvider )
+ CausalCluster( int nCores, int nReplicas, Path clusterPath, LogProvider logProvider, PortPickingStrategy portPickingStrategy )
{
this.nCores = nCores;
this.nReplicas = nReplicas;
this.clusterPath = clusterPath;
this.log = logProvider.getLog( getClass() );
+ this.portPickingStrategy = portPickingStrategy;
}
void boot() throws IOException, InterruptedException
@@ -183,7 +170,7 @@ void boot() throws IOException, InterruptedException
for ( int coreId = 0; coreId < nCores; coreId++ )
{
- int hazelcastPort = PortPickingStrategy.hazelcastPort( coreId );
+ int hazelcastPort = portPickingStrategy.hazelcastPort( coreId );
initialMembers.add( "localhost:" + hazelcastPort );
}
@@ -192,12 +179,12 @@ void boot() throws IOException, InterruptedException
for ( int coreId = 0; coreId < nCores; coreId++ )
{
- int hazelcastPort = PortPickingStrategy.hazelcastPort( coreId );
- int txPort = PortPickingStrategy.txCorePort( coreId );
- int raftPort = PortPickingStrategy.raftCorePort( coreId );
- int boltPort = PortPickingStrategy.boltCorePort( coreId );
- int httpPort = PortPickingStrategy.httpCorePort( coreId );
- int httpsPort = PortPickingStrategy.httpsCorePort( coreId );
+ int hazelcastPort = portPickingStrategy.hazelcastPort( coreId );
+ int txPort = portPickingStrategy.txCorePort( coreId );
+ int raftPort = portPickingStrategy.raftCorePort( coreId );
+ int boltPort = portPickingStrategy.boltCorePort( coreId );
+ int httpPort = portPickingStrategy.httpCorePort( coreId );
+ int httpsPort = portPickingStrategy.httpsCorePort( coreId );
String homeDir = "core-" + coreId;
TestServerBuilder builder = new EnterpriseInProcessServerBuilder( clusterPath.toFile(), homeDir );
@@ -239,10 +226,10 @@ void boot() throws IOException, InterruptedException
for ( int replicaId = 0; replicaId < nReplicas; replicaId++ )
{
- int txPort = PortPickingStrategy.txReadReplicaPort( replicaId );
- int boltPort = PortPickingStrategy.boltReadReplicaPort( replicaId );
- int httpPort = PortPickingStrategy.httpReadReplicaPort( replicaId );
- int httpsPort = PortPickingStrategy.httpsReadReplicaPort( replicaId );
+ int txPort = portPickingStrategy.txReadReplicaPort( replicaId );
+ int boltPort = portPickingStrategy.boltReadReplicaPort( replicaId );
+ int httpPort = portPickingStrategy.httpReadReplicaPort( replicaId );
+ int httpsPort = portPickingStrategy.httpsReadReplicaPort( replicaId );
String homeDir = "replica-" + replicaId;
TestServerBuilder builder = new EnterpriseInProcessServerBuilder( clusterPath.toFile(), homeDir );
diff --git a/enterprise/neo4j-harness-enterprise/src/test/java/org/neo4j/harness/CausalClusterInProcessRunnerIT.java b/enterprise/neo4j-harness-enterprise/src/test/java/org/neo4j/harness/CausalClusterInProcessRunnerIT.java
index 5936c7a723a99..8af54f4333a9b 100644
--- a/enterprise/neo4j-harness-enterprise/src/test/java/org/neo4j/harness/CausalClusterInProcessRunnerIT.java
+++ b/enterprise/neo4j-harness-enterprise/src/test/java/org/neo4j/harness/CausalClusterInProcessRunnerIT.java
@@ -19,10 +19,14 @@
*/
package org.neo4j.harness;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
import org.junit.ClassRule;
-import org.junit.Rule;
import org.junit.Test;
+import org.neo4j.com.ports.allocation.PortAuthority;
import org.neo4j.harness.CausalClusterInProcessRunner.CausalCluster;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.rule.TestDirectory;
@@ -35,7 +39,24 @@ public class CausalClusterInProcessRunnerIT
@Test
public void shouldBootAndShutdownCluster() throws Exception
{
- CausalCluster cluster = new CausalCluster( 3, 3, testDirectory.absolutePath().toPath(), NullLogProvider.getInstance() );
+ Path clusterPath = testDirectory.absolutePath().toPath();
+ CausalClusterInProcessRunner.PortPickingStrategy portPickingStrategy = new CausalClusterInProcessRunner.PortPickingStrategy()
+ {
+ Map cache = new HashMap<>();
+
+ @Override
+ int port( int offset, int id )
+ {
+ int key = offset + id;
+ if ( ! cache.containsKey( key ) )
+ {
+ cache.put( key, PortAuthority.allocatePort() );
+ }
+
+ return cache.get( key );
+ }
+ };
+ CausalCluster cluster = new CausalCluster( 3, 3, clusterPath, NullLogProvider.getInstance(), portPickingStrategy );
cluster.boot();
cluster.shutdown();