From 4347797eb896691f3093f1d616e895dda378dfe4 Mon Sep 17 00:00:00 2001 From: Lasse Westh-Nielsen Date: Wed, 26 Apr 2017 11:58:42 +0200 Subject: [PATCH] fixing BackupReadReplicaIT to use PortAuthority --- enterprise/causal-clustering/pom.xml | 2 +- .../backup/BackupReadReplicaIT.java | 48 ++++--------------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/enterprise/causal-clustering/pom.xml b/enterprise/causal-clustering/pom.xml index 8dc16a04569e0..333c81e6e2be2 100644 --- a/enterprise/causal-clustering/pom.xml +++ b/enterprise/causal-clustering/pom.xml @@ -254,7 +254,7 @@ maven-failsafe-plugin 2.19.1 - 4 + 2C classes 4 diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/backup/BackupReadReplicaIT.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/backup/BackupReadReplicaIT.java index 93ec846fb1db0..3b26c4ea5789d 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/backup/BackupReadReplicaIT.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/backup/BackupReadReplicaIT.java @@ -24,16 +24,14 @@ import org.junit.Test; import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.ServerSocket; import java.util.concurrent.TimeUnit; import org.neo4j.backup.OnlineBackupSettings; -import org.neo4j.causalclustering.core.CausalClusteringSettings; +import org.neo4j.causalclustering.PortAuthority; import org.neo4j.causalclustering.core.CoreGraphDatabase; import org.neo4j.causalclustering.discovery.Cluster; import org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase; +import org.neo4j.helpers.HostnamePort; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.impl.transaction.log.TransactionIdStore; @@ -50,14 +48,13 @@ public class BackupReadReplicaIT { - private int backupPort = findFreePort( 22000, 23000); - @Rule - public ClusterRule clusterRule = new ClusterRule( BackupReadReplicaIT.class ).withNumberOfCoreMembers( 3 ) + public ClusterRule clusterRule = new ClusterRule( BackupReadReplicaIT.class ) + .withNumberOfCoreMembers( 3 ) .withSharedCoreParam( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ) .withNumberOfReadReplicas( 1 ) .withSharedReadReplicaParam( OnlineBackupSettings.online_backup_enabled, Settings.TRUE ) - .withInstanceReadReplicaParam( OnlineBackupSettings.online_backup_server, serverId -> ":" + backupPort ); + .withInstanceReadReplicaParam( OnlineBackupSettings.online_backup_server, ignored -> ":" + PortAuthority.allocatePort() ); private Cluster cluster; private File backupPath; @@ -106,36 +103,11 @@ public void makeSureBackupCanBePerformed() throws Throwable private String backupAddress( ReadReplicaGraphDatabase readReplica ) { - InetSocketAddress inetSocketAddress = readReplica.getDependencyResolver() - .resolveDependency( Config.class ).get( CausalClusteringSettings.transaction_advertised_address ) - .socketAddress(); - return inetSocketAddress.getHostName() + ":" + backupPort; - } + HostnamePort hostnamePort = readReplica + .getDependencyResolver() + .resolveDependency( Config.class ) + .get( OnlineBackupSettings.online_backup_server ); - private static int findFreePort( int startRange, int endRange ) - { - InetSocketAddress address = null; - RuntimeException ex = null; - for ( int port = startRange; port <= endRange; port++ ) - { - address = new InetSocketAddress( port ); - - try - { - new ServerSocket( address.getPort(), 100, address.getAddress() ).close(); - ex = null; - break; - } - catch ( IOException e ) - { - ex = new RuntimeException( e ); - } - } - if ( ex != null ) - { - throw ex; - } - assert address != null; - return address.getPort(); + return hostnamePort.toString(); } }