Skip to content

Commit

Permalink
fixing BackupReadReplicaIT to use PortAuthority
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Jun 29, 2017
1 parent f3621f6 commit 4347797
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 39 deletions.
2 changes: 1 addition & 1 deletion enterprise/causal-clustering/pom.xml
Expand Up @@ -254,7 +254,7 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<forkCount>4</forkCount>
<forkCount>2C</forkCount>
<parallel>classes</parallel>
<threadCount>4</threadCount>
<!-- slowest test class takes up to 10 minutes, so let's cater for that, with contingency -->
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 4347797

Please sign in to comment.