From ea07ffe8267f235f7ad487f53c01feb7b83de869 Mon Sep 17 00:00:00 2001 From: Stefan Plantikow Date: Fri, 16 Sep 2016 15:44:20 +0200 Subject: [PATCH] Fix use of latches in NeverEndingProcedure --- .../BuiltInProceduresInteractionTestBase.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BuiltInProceduresInteractionTestBase.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BuiltInProceduresInteractionTestBase.java index 5a302d7735e47..fc2facf7fa33e 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BuiltInProceduresInteractionTestBase.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/BuiltInProceduresInteractionTestBase.java @@ -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 @@ -610,7 +609,7 @@ public void shouldTerminateLongRunningProcedureThatChecksTheGuardRegularlyOnTime neo.tearDown(); Map config = new HashMap<>(); - config.put( GraphDatabaseSettings.transaction_timeout.name(), "3s" ); + config.put( GraphDatabaseSettings.transaction_timeout.name(), "2s" ); neo = setUpNeoServer( config ); reSetUp(); @@ -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() @@ -979,7 +974,7 @@ protected ThreadingRule threading() public static class NeverEndingProcedure { - private static final AtomicReference testLatch = new AtomicReference<>(); + public static volatile DoubleLatch testLatch = null; @Context public TerminationGuard guard; @@ -987,14 +982,19 @@ public static class NeverEndingProcedure @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 ) { @@ -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 ); - } } }