Skip to content

Commit

Permalink
Fix use of latches in NeverEndingProcedure
Browse files Browse the repository at this point in the history
  • Loading branch information
boggle committed Sep 16, 2016
1 parent ff090a3 commit ea07ffe
Showing 1 changed file with 16 additions and 18 deletions.
Expand Up @@ -568,12 +568,11 @@ public void shouldTerminateLongRunningProcedureThatChecksTheGuardRegularlyIfKill
.registerProcedure( NeverEndingProcedure.class );

final DoubleLatch latch = new DoubleLatch( 2 );
NeverEndingProcedure.setTestLatch( new ClassWithProcedures.LatchedRunnables( latch, () -> {}, () -> {} ) );
NeverEndingProcedure.testLatch = latch;

String loopQuery = "CALL test.loop";

new Thread( () -> assertFail( readSubject, loopQuery, "Explicitly terminated by the user." ) )
.start();
new Thread( () -> assertFail( readSubject, loopQuery, "Explicitly terminated by the user." ) ).start();
latch.startAndWaitForAllToStart();

try
Expand Down Expand Up @@ -610,7 +609,7 @@ public void shouldTerminateLongRunningProcedureThatChecksTheGuardRegularlyOnTime

neo.tearDown();
Map<String, String> config = new HashMap<>();
config.put( GraphDatabaseSettings.transaction_timeout.name(), "3s" );
config.put( GraphDatabaseSettings.transaction_timeout.name(), "2s" );
neo = setUpNeoServer( config );
reSetUp();

Expand All @@ -620,11 +619,7 @@ public void shouldTerminateLongRunningProcedureThatChecksTheGuardRegularlyOnTime
.resolveDependency( Procedures.class )
.registerProcedure( NeverEndingProcedure.class );

assertFail(
adminSubject,
"CALL test.loop",
"Transaction guard check failed"
);
assertFail( adminSubject, "CALL test.loop", "Transaction guard check failed" );

Result result = neo
.getLocalGraph()
Expand Down Expand Up @@ -979,22 +974,27 @@ protected ThreadingRule threading()

public static class NeverEndingProcedure
{
private static final AtomicReference<ClassWithProcedures.LatchedRunnables> testLatch = new AtomicReference<>();
public static volatile DoubleLatch testLatch = null;

@Context
public TerminationGuard guard;

@Procedure(name = "test.loop")
public void loop()
{
testLatch.get().doubleLatch.startAndWaitForAllToStart();
DoubleLatch latch = testLatch;

if ( latch != null )
{
latch.startAndWaitForAllToStart();
}
try
{
while ( true )
{
try
{
Thread.sleep( 100 );
Thread.sleep( 250 );
}
catch ( InterruptedException e )
{
Expand All @@ -1005,13 +1005,11 @@ public void loop()
}
finally
{
testLatch.get().doubleLatch.finish();
if ( latch != null )
{
latch.finish();
}
}
}

static void setTestLatch( ClassWithProcedures.LatchedRunnables testLatch )
{
NeverEndingProcedure.testLatch.set( testLatch );
}
}
}

0 comments on commit ea07ffe

Please sign in to comment.