diff --git a/community/bolt/runtime/src/test/java/org/neo4j/bolt/runtime/integration/SessionIT.java b/community/bolt/runtime/src/test/java/org/neo4j/bolt/runtime/integration/SessionIT.java index 13c087b69a845..b44f1226c4217 100644 --- a/community/bolt/runtime/src/test/java/org/neo4j/bolt/runtime/integration/SessionIT.java +++ b/community/bolt/runtime/src/test/java/org/neo4j/bolt/runtime/integration/SessionIT.java @@ -38,6 +38,7 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; import static org.neo4j.bolt.runtime.integration.SessionMatchers.failedWith; import static org.neo4j.bolt.runtime.integration.SessionMatchers.streamContaining; import static org.neo4j.bolt.runtime.integration.SessionMatchers.success; @@ -273,7 +274,7 @@ public void completed( Object attachment ) } ); // Then - pullAllCallbackCalled.await( 30, TimeUnit.SECONDS ); + assertTrue( pullAllCallbackCalled.await( 30, TimeUnit.SECONDS ) ); final Neo4jError err = error.get(); assertThat( err.status(), equalTo( (Status)Status.General.UnknownFailure ) ); assertThat( err.message(), containsString( "Ooopsies!" ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxyTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxyTest.java index 3ea284f5c2fc3..b311c9699b000 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxyTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxyTest.java @@ -34,6 +34,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -137,7 +138,7 @@ public void shouldBlockAccessDuringFlipAndThenDelegateToCorrectContext() throws triggerFinishFlip, triggerExternalAccess ) ); // And I wait until the flipping thread is in the middle of "the flip" - triggerExternalAccess.await( 10, SECONDS ); + assertTrue( triggerExternalAccess.await( 10, SECONDS ) ); // And another thread comes along and drops the index Future dropIndexFuture = dropIndexThread.executeDontWait( dropTheIndex( flippable ) ); @@ -189,7 +190,7 @@ public Void doWork( Void state ) throws FlipFailedKernelException public Void call() { triggerExternalAccess.countDown(); - awaitLatch( triggerFinishFlip ); + assertTrue( awaitLatch( triggerFinishFlip ) ); return null; } }, null ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java index a905ba1ee49fb..2ad105aec8d99 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java @@ -97,11 +97,11 @@ public static T awaitFuture( Future future ) } } - public static void awaitLatch( CountDownLatch latch ) + public static boolean awaitLatch( CountDownLatch latch ) { try { - latch.await( 10, SECONDS ); + return latch.await( 10, SECONDS ); } catch ( InterruptedException e ) { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/community/RWLockTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/community/RWLockTest.java index efcde5627446b..43c1bc3a4ebe5 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/community/RWLockTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/community/RWLockTest.java @@ -322,8 +322,7 @@ public void testDeadlockDetection() throws InterruptedException executor.execute( readerLockNode1 ); // Deadlock should occur - deadLockDetector.await( 1000, TimeUnit.MILLISECONDS ); - Assert.assertTrue( "Deadlock was detected as expected.", true ); + Assert.assertTrue( "Deadlock was detected as expected.", deadLockDetector.await( 1000, TimeUnit.MILLISECONDS ) ); } @Test( timeout = 1000 ) diff --git a/community/kernel/src/test/java/org/neo4j/test/DoubleLatch.java b/community/kernel/src/test/java/org/neo4j/test/DoubleLatch.java index d5049b45e3db1..e28281be4421d 100644 --- a/community/kernel/src/test/java/org/neo4j/test/DoubleLatch.java +++ b/community/kernel/src/test/java/org/neo4j/test/DoubleLatch.java @@ -22,9 +22,11 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertTrue; + public class DoubleLatch { - private static final int FIVE_MINUTES = 5 * 60 * 1000; + private static final int FIVE_MINUTES = 5; private final CountDownLatch startSignal; private final CountDownLatch finishSignal; private final int numberOfContestants; @@ -75,24 +77,15 @@ public void awaitFinish() public static void awaitLatch( CountDownLatch latch ) { - long deadline = System.currentTimeMillis() + FIVE_MINUTES; - long remaining; - - while( ( remaining = deadline - System.currentTimeMillis() ) >= 0 ) + try + { + assertTrue( "Latch specified waiting time elapsed.", latch.await( FIVE_MINUTES, TimeUnit.MINUTES ) ); + } + catch ( InterruptedException e ) { - try - { - latch.await( remaining, TimeUnit.MILLISECONDS ); - return; - } - catch ( InterruptedException e ) - { - Thread.interrupted(); - new RuntimeException( "Thread interrupted while waiting on latch", e).printStackTrace(); - } - Thread.yield(); + Thread.interrupted(); + throw new RuntimeException( "Thread interrupted while waiting on latch", e ); } - throw new RuntimeException( "Failed to acquire latch" ); } @Override diff --git a/community/server/src/test/java/org/neo4j/server/rest/transactional/integration/DeadlockIT.java b/community/server/src/test/java/org/neo4j/server/rest/transactional/integration/DeadlockIT.java index 66fd1aa774d49..c5f38ab9951e9 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/transactional/integration/DeadlockIT.java +++ b/community/server/src/test/java/org/neo4j/server/rest/transactional/integration/DeadlockIT.java @@ -65,7 +65,7 @@ public void shouldReturnCorrectStatusCodeOnDeadlock() throws Exception otherThread.execute( writeToFirstAndSecond() ); // and I wait for those locks to be pending - secondNodeLocked.await(10, TimeUnit.SECONDS); + assertTrue( secondNodeLocked.await( 10, TimeUnit.SECONDS ) ); Thread.sleep( 1000 ); // and I then try and lock node:Second in the first transaction diff --git a/enterprise/cluster/src/test/java/org/neo4j/cluster/com/message/NetworkSenderReceiverTest.java b/enterprise/cluster/src/test/java/org/neo4j/cluster/com/message/NetworkSenderReceiverTest.java index 30ae1b55ba1e1..d5c8f53ab333e 100644 --- a/enterprise/cluster/src/test/java/org/neo4j/cluster/com/message/NetworkSenderReceiverTest.java +++ b/enterprise/cluster/src/test/java/org/neo4j/cluster/com/message/NetworkSenderReceiverTest.java @@ -88,7 +88,7 @@ public void shouldSendAMessageFromAClientWhichIsReceivedByAServer() throws Excep // then - latch.await( 5, TimeUnit.SECONDS ); + assertTrue( latch.await( 5, TimeUnit.SECONDS ) ); assertTrue( "server1 should have processed the message", server1.processedMessage() ); assertTrue( "server2 should have processed the message", server2.processedMessage() ); diff --git a/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdates.java b/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdates.java index 0a20234198580..420bafca545a6 100644 --- a/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdates.java +++ b/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdates.java @@ -193,10 +193,7 @@ public void leftCluster( InstanceId instanceId, URI member ) slave.shutdown(); // Make sure that the slave has left, because shutdown() may return before the master knows - if (!slaveLeftLatch.await(60, TimeUnit.SECONDS)) - { - throw new IllegalStateException( "Timeout waiting for slave to leave" ); - } + assertTrue( "Timeout waiting for slave to leave", slaveLeftLatch.await( 60, TimeUnit.SECONDS ) ); long nodeId; try ( Transaction tx = master.beginTx() ) diff --git a/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdatesApplied.java b/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdatesApplied.java index 7037f28d292a5..66a41cff5a984 100644 --- a/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdatesApplied.java +++ b/enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdatesApplied.java @@ -48,6 +48,7 @@ import org.neo4j.test.TargetDirectory; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * This test case ensures that updates in HA are first written out to the log @@ -120,10 +121,7 @@ public void leftCluster( InstanceId instanceId, URI member ) dbToKill.shutdown(); - if ( !latch1.await( 60, TimeUnit.SECONDS ) ) - { - throw new IllegalStateException( "Timeout waiting for instance to leave cluster" ); - } + assertTrue( "Timeout waiting for instance to leave cluster", latch1.await( 60, TimeUnit.SECONDS ) ); addNode( master ); // this will be pulled by tne next start up, applied // but not written to log. @@ -147,10 +145,7 @@ public void failed( InstanceId server ) runInOtherJvmToGetExitCode( targetDirectory.getAbsolutePath(), "" + toKill ); - if ( !latch2.await( 60, TimeUnit.SECONDS ) ) - { - throw new IllegalStateException( "Timeout waiting for instance to fail" ); - } + assertTrue( "Timeout waiting for instance to fail", latch2.await( 60, TimeUnit.SECONDS ) ); // This is to allow other instances to mark the dead instance as failed, otherwise on startup it will be denied. // TODO This is to demonstrate shortcomings in our design. Fix this, you ugly, ugly hacker diff --git a/enterprise/ha/src/test/java/org/neo4j/ha/TestSlaveOnlyCluster.java b/enterprise/ha/src/test/java/org/neo4j/ha/TestSlaveOnlyCluster.java index 6369701dfe5b4..5dd8a3200a714 100644 --- a/enterprise/ha/src/test/java/org/neo4j/ha/TestSlaveOnlyCluster.java +++ b/enterprise/ha/src/test/java/org/neo4j/ha/TestSlaveOnlyCluster.java @@ -43,6 +43,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable; import static org.neo4j.kernel.impl.ha.ClusterManager.fromXml; @@ -69,7 +70,7 @@ public void testMasterElectionAfterMasterRecoversInSlaveOnlyCluster() throws Thr final ClusterManager.RepairKit repairKit = cluster.fail( master ); - masterFailedLatch.await( 60, TimeUnit.SECONDS ); + assertTrue( masterFailedLatch.await( 60, TimeUnit.SECONDS ) ); repairKit.repair(); diff --git a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/ClusterTopologyChangesIT.java b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/ClusterTopologyChangesIT.java index f29319a1a386c..270aafde5c26c 100644 --- a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/ClusterTopologyChangesIT.java +++ b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/ClusterTopologyChangesIT.java @@ -65,6 +65,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.Assert.assertTrue; import static org.neo4j.cluster.protocol.cluster.ClusterConfiguration.COORDINATOR; import static org.neo4j.function.Predicates.not; import static org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable; @@ -155,11 +156,11 @@ else if ( instanceIdOf( slave2 ).equals( server ) ) // fail slave1 and await master to spot the failure RepairKit slave1RepairKit = cluster.fail( slave1 ); - slave1Left.await(60, SECONDS); + assertTrue( slave1Left.await( 60, SECONDS ) ); // fail slave2 and await master to spot the failure RepairKit slave2RepairKit = cluster.fail( slave2 ); - slave2Left.await(60, SECONDS); + assertTrue( slave2Left.await( 60, SECONDS ) ); // master loses quorum and goes to PENDING, cluster is unavailable cluster.await( not( masterAvailable() ) ); @@ -199,8 +200,9 @@ else if ( instanceIdOf( newSlave2 ).equals( unavailableId ) ) // attempt to perform transactions on both slaves throws, election is triggered attemptTransactions( newSlave1, newSlave2 ); - slave1Unavailable.await( 60, TimeUnit.SECONDS ); // set a timeout in case the instance does not have stale epoch - slave2Unavailable.await( 60, TimeUnit.SECONDS ); + // set a timeout in case the instance does not have stale epoch + assertTrue( slave1Unavailable.await( 60, TimeUnit.SECONDS ) ); + assertTrue( slave2Unavailable.await( 60, TimeUnit.SECONDS ) ); // THEN: done with election, cluster feels good and able to serve transactions cluster.info( "Waiting for cluster to stabilize" ); @@ -245,7 +247,7 @@ public void enteredCluster( ClusterConfiguration clusterConfiguration ) clusterClient.life.start(); // Then - latch.await( 20, SECONDS ); + assertTrue( latch.await( 20, SECONDS ) ); assertEquals( new InstanceId( 2 ), coordinatorIdWhenReJoined.get() ); } diff --git a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/HardKillIT.java b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/HardKillIT.java index 6598509fe3a7d..2091ca324eb89 100644 --- a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/HardKillIT.java +++ b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/HardKillIT.java @@ -101,7 +101,7 @@ public void receive( Payload value ) proc.destroy(); proc = null; - newMasterAvailableLatch.await( 60, SECONDS ); + assertTrue( newMasterAvailableLatch.await( 60, SECONDS ) ); assertTrue( dbWithId2.isMaster() ); assertTrue( !dbWithId3.isMaster() ); diff --git a/integrationtests/src/test/java/org/neo4j/ext/udc/impl/UdcExtensionImplTest.java b/integrationtests/src/test/java/org/neo4j/ext/udc/impl/UdcExtensionImplTest.java index 12e69a3eada14..2a8a896c546a9 100644 --- a/integrationtests/src/test/java/org/neo4j/ext/udc/impl/UdcExtensionImplTest.java +++ b/integrationtests/src/test/java/org/neo4j/ext/udc/impl/UdcExtensionImplTest.java @@ -252,7 +252,7 @@ public void run() t.run(); - latch.await( 1000, TimeUnit.MILLISECONDS ); + assertTrue( latch.await( 1000, TimeUnit.MILLISECONDS ) ); t.join(); }