diff options
author | Eike Stepper | 2020-03-13 16:58:51 +0000 |
---|---|---|
committer | Eike Stepper | 2020-03-13 16:58:51 +0000 |
commit | 07fbbaa233eda4a08887e2c2f87176387bbd062e (patch) | |
tree | 42acc9c7a24ceb2e6557a20a3180a426a39101b7 | |
parent | 8256decef6a1bb4ddf3dbcbad1d5ef74979cea1e (diff) | |
download | cdo-07fbbaa233eda4a08887e2c2f87176387bbd062e.tar.gz cdo-07fbbaa233eda4a08887e2c2f87176387bbd062e.tar.xz cdo-07fbbaa233eda4a08887e2c2f87176387bbd062e.zip |
Fix timing in SynchronizingCorrelatorTestcommitters/estepper/websockets
2 files changed, 19 insertions, 9 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java index 9923fe15da..28020b6d5f 100644 --- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java @@ -13,6 +13,8 @@ package org.eclipse.net4j.util.tests; import org.eclipse.net4j.util.concurrent.ISynchronizer; import org.eclipse.net4j.util.concurrent.SynchronizingCorrelator; +import java.util.concurrent.CountDownLatch; + /** * @author Eike Stepper */ @@ -20,30 +22,34 @@ public class SynchronizingCorrelatorTest extends AbstractOMTest { public void testPutConsumerFirst() throws Exception { - final Boolean[] result = { false }; final SynchronizingCorrelator<String, Boolean> correlator = new SynchronizingCorrelator<String, Boolean>(); + final CountDownLatch correlationEstablished = new CountDownLatch(1); + final Boolean[] result = { false }; + final Thread consumer = new Thread() { @Override public void run() { ISynchronizer<Boolean> eike = correlator.correlate("eike"); //$NON-NLS-1$ + correlationEstablished.countDown(); + result[0] = eike.get(5000); msg("RESULT: " + result[0]); //$NON-NLS-1$ } }; consumer.start(); - sleep(100); + await(correlationEstablished); correlator.put("eike", true, DEFAULT_TIMEOUT); //$NON-NLS-1$ consumer.join(DEFAULT_TIMEOUT); assertEquals(Boolean.TRUE, result[0]); } - public void testPutConsumerFirst10() throws Exception + public void testPutConsumerFirst1000() throws Exception { - for (int i = 0; i < 10; i++) + for (int i = 0; i < 1000; i++) { testPutConsumerFirst(); } @@ -51,21 +57,25 @@ public class SynchronizingCorrelatorTest extends AbstractOMTest public void testBlockingPutConsumerFirst() throws Exception { - final Boolean[] result = { false }; final SynchronizingCorrelator<String, Boolean> correlator = new SynchronizingCorrelator<String, Boolean>(); + final CountDownLatch correlationEstablished = new CountDownLatch(1); + final Boolean[] result = { false }; + final Thread consumer = new Thread() { @Override public void run() { ISynchronizer<Boolean> eike = correlator.correlate("eike"); //$NON-NLS-1$ + correlationEstablished.countDown(); + result[0] = eike.get(5000); msg("RESULT: " + result[0]); //$NON-NLS-1$ } }; consumer.start(); - Thread.sleep(10); + await(correlationEstablished); boolean consumed = correlator.put("eike", true, 1000); //$NON-NLS-1$ msg("Consumed: " + consumed); //$NON-NLS-1$ @@ -75,9 +85,9 @@ public class SynchronizingCorrelatorTest extends AbstractOMTest assertEquals(Boolean.TRUE, result[0]); } - public void testBlockingPutConsumerFirst10() throws Exception + public void testBlockingPutConsumerFirst1000() throws Exception { - for (int i = 0; i < 10; i++) + for (int i = 0; i < 1000; i++) { testBlockingPutConsumerFirst(); } diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java index 599d9d64fc..bc1d444b31 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java @@ -18,7 +18,7 @@ import java.util.concurrent.ConcurrentMap; */ public class SynchronizingCorrelator<CORRELATION, RESULT> implements ICorrelator<CORRELATION, ISynchronizer<RESULT>> { - private ConcurrentMap<CORRELATION, ISynchronizer<RESULT>> map = new ConcurrentHashMap<CORRELATION, ISynchronizer<RESULT>>(0); + private final ConcurrentMap<CORRELATION, ISynchronizer<RESULT>> map = new ConcurrentHashMap<CORRELATION, ISynchronizer<RESULT>>(0); /** * @since 3.0 |