Skip to content

Commit

Permalink
cleaning up PullUpdatesAppliedIT: no point trying to use list of init…
Browse files Browse the repository at this point in the history
…ial hosts when running single threaded
  • Loading branch information
lassewesth committed Jul 25, 2017
1 parent fc4a8b6 commit e4cde77
Showing 1 changed file with 12 additions and 48 deletions.
60 changes: 12 additions & 48 deletions enterprise/ha/src/test/java/org/neo4j/ha/PullUpdatesAppliedIT.java
Expand Up @@ -98,7 +98,6 @@ private class Configuration
public void doBefore() throws Exception public void doBefore() throws Exception
{ {
configurations = createConfigurations(); configurations = createConfigurations();

databases = startDatabases(); databases = startDatabases();
} }


Expand Down Expand Up @@ -130,9 +129,9 @@ private Map<Integer, HighlyAvailableGraphDatabase> startDatabases()
int haPort = configuration.haPort; int haPort = configuration.haPort;
File directory = configuration.directory; File directory = configuration.directory;


int[] initialHostPorts = getInitialHostPorts( configurations ); int initialHostPort = configurations.values().iterator().next().clusterPort;


HighlyAvailableGraphDatabase hagdb = database( serverId, clusterPort, haPort, directory, initialHostPorts ); HighlyAvailableGraphDatabase hagdb = database( serverId, clusterPort, haPort, directory, initialHostPort );


databases.put( serverId, hagdb); databases.put( serverId, hagdb);
} }
Expand Down Expand Up @@ -207,7 +206,7 @@ public void failed( InstanceId server )
} }
} ); } );


runInOtherJvm( directory, serverIdOfDatabaseToKill, clusterPort, haPort, getInitialHostPorts() ); runInOtherJvm( directory, serverIdOfDatabaseToKill, clusterPort, haPort, configurations.get( serverIdOfMaster ).clusterPort );


assertTrue( "Timeout waiting for instance to fail", latch2.await( 60, TimeUnit.SECONDS ) ); assertTrue( "Timeout waiting for instance to fail", latch2.await( 60, TimeUnit.SECONDS ) );


Expand All @@ -232,16 +231,6 @@ private int findSomeoneNotMaster( int serverIdOfMaster )
.findAny().orElseThrow( IllegalStateException::new ); .findAny().orElseThrow( IllegalStateException::new );
} }


private int[] getInitialHostPorts()
{
return getInitialHostPorts( configurations );
}

private int[] getInitialHostPorts( Map<Integer, Configuration> configurations )
{
return configurations.values().stream().mapToInt( configuration -> configuration.clusterPort ).toArray();
}

private void restart( int serverId ) private void restart( int serverId )
{ {
Configuration configuration = configurations.get( serverId ); Configuration configuration = configurations.get( serverId );
Expand All @@ -251,47 +240,27 @@ private void restart( int serverId )
File directory = configuration.directory; File directory = configuration.directory;


HighlyAvailableGraphDatabase highlyAvailableGraphDatabase = HighlyAvailableGraphDatabase highlyAvailableGraphDatabase =
database( serverId, clusterPort, haPort, directory, getInitialHostPorts() ); database( serverId, clusterPort, haPort, directory, configurations.values().iterator().next().clusterPort );


databases.put( serverId, highlyAvailableGraphDatabase ); databases.put( serverId, highlyAvailableGraphDatabase );
} }


private static HighlyAvailableGraphDatabase database( int serverId, int clusterPort, int haPort, File path, int... initialHostPorts ) private static HighlyAvailableGraphDatabase database( int serverId, int clusterPort, int haPort, File path, int initialHostPort )
{ {
String initialHosts = buildInitialHosts( initialHostPorts );

return (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory(). return (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().
newEmbeddedDatabaseBuilder( path ) newEmbeddedDatabaseBuilder( path )
.setConfig( ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + serverId) ) .setConfig( ClusterSettings.cluster_server, "127.0.0.1:" + clusterPort )
// because we run single threaded: if we specified all 3x cluster members, // because we run single threaded: if we specified all 3x cluster members,
// first database would block, wait, and time out because it would be the only member // first database would block, wait, and time out because it would be the only member
// this makes the test less robust, because it _could_ happen that first instance didn't become or remain master // this makes the test less robust, because it _could_ happen that first instance didn't become or remain master
.setConfig( ClusterSettings.initial_hosts, "127.0.0.1:" + initialHostPorts[0] ) .setConfig( ClusterSettings.initial_hosts, "127.0.0.1:" + initialHostPort )
.setConfig( ClusterSettings.server_id, Integer.toString( serverId ) ) .setConfig( ClusterSettings.server_id, Integer.toString( serverId ) )
.setConfig( HaSettings.ha_server, "localhost:" + (6666 + serverId) ) .setConfig( HaSettings.ha_server, "localhost:" + haPort )
.setConfig( HaSettings.pull_interval, "0ms" ) .setConfig( HaSettings.pull_interval, "0ms" )
.newGraphDatabase(); .newGraphDatabase();
} }


private static String buildInitialHosts( int[] initialHostPorts ) private void runInOtherJvm( File directory, int serverIdOfDatabaseToKill, int clusterPort, int haPort, int initialHostPort ) throws Exception
{
StringBuilder initialHosts = new StringBuilder();

for ( int i = 0; i < initialHostPorts.length; i++ )
{
if ( i > 0 )
{
initialHosts.append( ',' );
}

initialHosts.append( "127.0.0.1:" ).append( initialHostPorts[i] );
}

return initialHosts.toString();
}

private void runInOtherJvm( File directory, int serverIdOfDatabaseToKill,
int clusterPort, int haPort, int... initialHostPorts ) throws Exception
{ {
List<String> commandLine = new ArrayList<>( Arrays.asList( List<String> commandLine = new ArrayList<>( Arrays.asList(
"java", "java",
Expand All @@ -302,7 +271,7 @@ private void runInOtherJvm( File directory, int serverIdOfDatabaseToKill,
commandLine.add( String.valueOf( serverIdOfDatabaseToKill ) ); commandLine.add( String.valueOf( serverIdOfDatabaseToKill ) );
commandLine.add( String.valueOf( clusterPort ) ); commandLine.add( String.valueOf( clusterPort ) );
commandLine.add( String.valueOf( haPort ) ); commandLine.add( String.valueOf( haPort ) );
IntStream.of( initialHostPorts ).mapToObj( String::valueOf ).forEach( commandLine::add ); commandLine.add( String.valueOf( initialHostPort ) );


Process p = Runtime.getRuntime().exec( commandLine.toArray( new String[commandLine.size()] ) ); Process p = Runtime.getRuntime().exec( commandLine.toArray( new String[commandLine.size()] ) );
List<Thread> threads = new LinkedList<>(); List<Thread> threads = new LinkedList<>();
Expand All @@ -328,14 +297,9 @@ public static void main( String[] args ) throws Exception
int serverId = Integer.parseInt( args[1] ); int serverId = Integer.parseInt( args[1] );
int clusterPort = Integer.parseInt( args[2] ); int clusterPort = Integer.parseInt( args[2] );
int haPort = Integer.parseInt( args[3] ); int haPort = Integer.parseInt( args[3] );
int[] initialHostPorts = new int[args.length - 4]; int initialHostPort = Integer.parseInt( args[4] );

for ( int i = 0; i < args.length - 4; i++ )
{
initialHostPorts[i] = Integer.parseInt( args[i + 4] );
}


HighlyAvailableGraphDatabase hagdb = database( serverId, clusterPort, haPort, storePath, initialHostPorts ); HighlyAvailableGraphDatabase hagdb = database( serverId, clusterPort, haPort, storePath, initialHostPort );


hagdb.getDependencyResolver().resolveDependency( UpdatePuller.class ).pullUpdates(); hagdb.getDependencyResolver().resolveDependency( UpdatePuller.class ).pullUpdates();
// this is the bug trigger // this is the bug trigger
Expand Down

0 comments on commit e4cde77

Please sign in to comment.