Skip to content

Commit

Permalink
Make sure to close server when done in test
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Jan 9, 2017
1 parent 9e6c512 commit 4cbe20e
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
import org.neo4j.io.pagecache.PageSwapper;
import org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory;
import org.neo4j.test.ThreadTestUtils;
import org.neo4j.test.server.ExclusiveServerTestBase;

import static org.junit.Assert.fail;

public abstract class NeoServerRestartTest
public abstract class NeoServerRestartTest extends ExclusiveServerTestBase
{
public static final String CUSTOM_SWAPPER = "CustomSwapper";
private static Semaphore semaphore;
Expand Down Expand Up @@ -62,20 +63,26 @@ public void shouldBeAbleToRestartWhenStoppedDuringStartup() throws IOException,
// Get a server that uses our custom swapper.
NeoServer server = getNeoServer( CUSTOM_SWAPPER );

AtomicBoolean failure = new AtomicBoolean();
Thread serverStoppingThread = ThreadTestUtils.fork( stopServerAfterStartingHasStarted( server, failure ) );
server.start();
// Wait for the server to stop.
serverStoppingThread.join();
// Check if the server stopped successfully.
if ( failure.get() )
try
{
fail( "Server failed to stop." );
AtomicBoolean failure = new AtomicBoolean();
Thread serverStoppingThread = ThreadTestUtils.fork( stopServerAfterStartingHasStarted( server, failure ) );
server.start();
// Wait for the server to stop.
serverStoppingThread.join();
// Check if the server stopped successfully.
if ( failure.get() )
{
fail( "Server failed to stop." );
}
// Verify that we can start the server again.
server = getNeoServer( CUSTOM_SWAPPER );
server.start();
}
finally
{
server.stop();
}
// Verify that we can start the server again.
server = getNeoServer( CUSTOM_SWAPPER );
server.start();
server.stop();
}

protected abstract NeoServer getNeoServer( String customPageSwapperName ) throws IOException;
Expand Down

0 comments on commit 4cbe20e

Please sign in to comment.