Skip to content

Commit

Permalink
6 minutes faster server enterprise tests
Browse files Browse the repository at this point in the history
by properly shutting down the standalone cluster client as to not
wait for the semaphore for 60 seconds for shutting down, for every one of
the 6 tests in StandaloneClusterClientIT
  • Loading branch information
tinwelint committed Mar 9, 2016
1 parent 3f7df29 commit 7095c28
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
Expand Up @@ -58,14 +58,15 @@
*
* @author Mattias Persson
*/
public class StandaloneClusterClient
public class StandaloneClusterClient implements AutoCloseable
{
private final LifeSupport life;
private final LifeSupport life = new LifeSupport();
private final Timer timer;

private StandaloneClusterClient( LifeSupport life )
public StandaloneClusterClient( Config config ) throws IOException
{
this.life = life;
start( config );

timer = new Timer( true );
addShutdownHook();
life.start();
Expand Down Expand Up @@ -95,22 +96,19 @@ public void run()
} );
}

public static void main( String[] args ) throws IOException
private void start( Config config ) throws IOException
{
try
{
LifeSupport life = new LifeSupport();
life.add( new Neo4jJobScheduler() );

new ClusterClientModule(
life,
new Dependencies(),
new Monitors(),
getConfig( args ),
config,
logService( new DefaultFileSystemAbstraction() ),
new NotElectableElectionCredentialsProvider() );

new StandaloneClusterClient( life );
}
catch ( LifecycleException e )
{
Expand All @@ -129,7 +127,18 @@ public static void main( String[] args ) throws IOException
}
}

private static Config getConfig( String[] args ) throws IOException
public static void main( String[] args ) throws IOException
{
new StandaloneClusterClient( getConfig( args ) );
}

@Override
public void close()
{
life.shutdown();
}

public static Config getConfig( String[] args ) throws IOException
{
Map<String, String> config = new HashMap<>();
String configPath = System.getProperty( ServerSettings.SERVER_CONFIG_FILE_KEY );
Expand Down
Expand Up @@ -28,6 +28,7 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.AccessibleObject;
import java.net.URI;
import java.nio.file.Files;
Expand Down Expand Up @@ -286,8 +287,16 @@ private boolean startStandaloneClusterClient( File configFile, Map<String, Strin
{
if ( process != null )
{
kill( process );
process.waitFor();
// Tell it to leave the cluster and shut down now
try ( OutputStream inputToOtherProcess = process.getOutputStream() )
{
inputToOtherProcess.write( 0 );
inputToOtherProcess.flush();
}
if ( !process.waitFor( 10, SECONDS ) )
{
kill( process );
}
}
if ( handler != null )
{
Expand Down
Expand Up @@ -21,6 +21,8 @@

import java.io.IOException;

import static org.neo4j.server.enterprise.StandaloneClusterClient.getConfig;

public class StandaloneClusterClientTestProxy
{
public static final String START_SIGNAL = "starting";
Expand All @@ -29,8 +31,11 @@ public static void main( String[] args ) throws IOException
{
// This sysout will be intercepted by the parent process and will trigger
// a start of a timeout. The whole reason for this class to be here is to
// split awaiting for the process to start and actually awaiting the cluster client to start.
// split awaiting for the process to start and actually awaiting the cluster client to start.
System.out.println( START_SIGNAL );
StandaloneClusterClient.main( args );
try ( StandaloneClusterClient client = new StandaloneClusterClient( getConfig( args ) ) )
{
System.in.read();
}
}
}

0 comments on commit 7095c28

Please sign in to comment.