Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java164
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ChangeSubscriptionTest.java47
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DetachTest.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java201
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MEMStoreQueryTest.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TransactionHandlerTest.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_250036_Test.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_251087_Test.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_254489_Test.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_260764_Test.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_266857_Test.java10
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_267050_Test.java10
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java58
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java281
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java13
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java2
17 files changed, 488 insertions, 355 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
index b08578f513..3a54278108 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
@@ -22,16 +22,8 @@ import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.internal.cdo.CDOLegacyWrapper;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
-import org.eclipse.net4j.tests.AbstractTransportTest;
-
import org.eclipse.emf.ecore.EObject;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-
/**
* @author Eike Stepper
*/
@@ -49,45 +41,13 @@ public abstract class AbstractCDOTest extends ConfigTest
{
org.eclipse.emf.cdo.internal.net4j.bundle.OM.PREF_COMMIT_MONITOR_PROGRESS_SECONDS.setValue(60);
org.eclipse.emf.cdo.internal.net4j.bundle.OM.PREF_COMMIT_MONITOR_TIMEOUT_SECONDS.setValue(60 * 60);
- org.eclipse.internal.net4j.bundle.OM.DEBUG.setEnabled(false);
- org.eclipse.net4j.internal.tcp.bundle.OM.DEBUG.setEnabled(false);
+ org.eclipse.internal.net4j.bundle.OM.DEBUG.setEnabled(true);
+ org.eclipse.net4j.internal.tcp.bundle.OM.DEBUG.setEnabled(true);
CDOPackageTypeRegistry.INSTANCE.reset();
startTransport();
}
}
- public static void assertEquals(Object expected, Object actual)
- {
- // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
- if (actual != null && actual.equals(expected))
- {
- return;
- }
-
- AbstractTransportTest.assertEquals(expected, actual);
- }
-
- public static void assertEquals(String message, Object expected, Object actual)
- {
- if (expected == null && actual == null)
- {
- return;
- }
-
- if (expected != null && expected.equals(actual))
- {
- return;
- }
-
- // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
- if (actual != null && actual.equals(expected))
- {
- return;
- }
-
- failNotEquals(message, expected, actual);
- }
-
protected static void assertTransient(EObject eObject)
{
CDOObject object = CDOUtil.getCDOObject(eObject);
@@ -193,124 +153,4 @@ public abstract class AbstractCDOTest extends ConfigTest
}
}
}
-
- /**
- * @author Eike Stepper
- */
- public static class AsyncResult<T>
- {
- public static final long DEFAULT_TIMEOUT = 30 * 1000;
-
- private volatile T value;
-
- private CountDownLatch latch = new CountDownLatch(1);
-
- public AsyncResult()
- {
- }
-
- public void setValue(T value)
- {
- this.value = value;
- latch.countDown();
- }
-
- public T getValue(long timeout) throws Exception
- {
- if (!latch.await(timeout, TimeUnit.MILLISECONDS))
- {
- throw new TimeoutException("Result value not available after " + timeout + " milli seconds");
- }
-
- return value;
- }
-
- public T getValue() throws Exception
- {
- return getValue(DEFAULT_TIMEOUT);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static interface ITimeOuter
- {
- public boolean timedOut() throws InterruptedException;
- }
-
- /**
- * @author Eike Stepper
- */
- public static abstract class PollingTimeOuter implements ITimeOuter
- {
- private int retries;
-
- private long interval;
-
- public PollingTimeOuter(int retries, long interval)
- {
- this.retries = retries;
- this.interval = interval;
- }
-
- public int getRetries()
- {
- return retries;
- }
-
- public long getInterval()
- {
- return interval;
- }
-
- public boolean timedOut() throws InterruptedException
- {
- for (int i = 0; i < retries; i++)
- {
- if (successful())
- {
- return false;
- }
-
- sleep(interval);
- }
-
- return true;
- }
-
- protected abstract boolean successful();
- }
-
- /**
- * @author Eike Stepper
- */
- public static class LockTimeOuter implements ITimeOuter
- {
- private Lock lock;
-
- private long millis;
-
- public LockTimeOuter(Lock lock, long millis)
- {
- this.lock = lock;
- this.millis = millis;
- }
-
- public Lock getLock()
- {
- return lock;
- }
-
- public long getMillis()
- {
- return millis;
- }
-
- public boolean timedOut() throws InterruptedException
- {
- Condition condition = lock.newCondition();
- return !condition.await(millis, TimeUnit.MILLISECONDS);
- }
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ChangeSubscriptionTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ChangeSubscriptionTest.java
index 175dc31c6f..fbe98d7845 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ChangeSubscriptionTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ChangeSubscriptionTest.java
@@ -105,7 +105,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
Thread.sleep(1000);
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
@@ -113,9 +113,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
return policy == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1 || policy == null
&& adapter.getNotifications().size() == 0;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
// Switching policy to the other
transaction.options().removeChangeSubscriptionPolicy(policy);
@@ -140,7 +138,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
Thread.sleep(1000);
msg("Checking after commit");
- timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
@@ -148,9 +146,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
return enabled2 == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1 || enabled2 == null
&& adapter.getNotifications().size() == 0;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
public void testSeparateSession() throws Exception
@@ -220,7 +216,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
transaction2.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
@@ -228,9 +224,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
return policy == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1 || policy == null
&& adapter.getNotifications().size() == 0;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
// Switching policy to the other
transaction.options().removeChangeSubscriptionPolicy(policy);
@@ -251,7 +245,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
transaction2.commit();
msg("Checking after commit");
- timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
@@ -259,9 +253,7 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
return enabled2 == CDOAdapterPolicy.ALL && adapter.getNotifications().size() == 1 || enabled2 == null
&& adapter.getNotifications().size() == 0;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
public void testTemporaryObject() throws Exception
@@ -319,16 +311,14 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
transaction2.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return adapter.getNotifications().size() == 1;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
public void testSeparateSession_CUSTOM() throws Exception
@@ -394,16 +384,14 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
transaction2.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(5, 200)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return adapter.getNotifications().size() == 1;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
// Switching policy to the other
transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
@@ -420,16 +408,14 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
transaction2.commit();
msg("Checking after commit");
- timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return adapter.getNotifications().size() == 2;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
public void testNotificationChain() throws Exception
@@ -492,16 +478,15 @@ public class ChangeSubscriptionTest extends AbstractCDOTest
transaction2.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(5, 200)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return adapter.getNotifications().size() == 3;
}
- }.timedOut();
+ }.assertNoTimeOut();
- assertEquals(false, timedOut);
int count = 0;
for (Notification notification : adapter.getNotifications())
{
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DetachTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DetachTest.java
index da3847c403..5c58ff22ea 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DetachTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DetachTest.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Simon McDuff - initial API and implementation
* Eike Stepper - maintenance
@@ -350,17 +350,16 @@ public class DetachTest extends AbstractCDOTest
assertTrue(transaction1.isDirty());
transaction1.commit();
- boolean timedOut = new PollingTimeOuter(20, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return rSet2.getResources().size() == 0;
}
- }.timedOut();
+ }.assertNoTimeOut();
assertEquals(1, rSet1.getResources().size());
- assertEquals(false, timedOut);
assertTransient(res);
assertInvalid(res2);
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
index ac8ab6226d..28dec95fb1 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
@@ -132,7 +132,7 @@ public class InvalidationTest extends AbstractCDOTest
transaction.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(200, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
@@ -140,9 +140,7 @@ public class InvalidationTest extends AbstractCDOTest
String name = category1B.getName();
return "CHANGED NAME".equals(name);
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
public void testSeparateViewNotification() throws Exception
@@ -242,8 +240,8 @@ public class InvalidationTest extends AbstractCDOTest
category1A.setName("CHANGED NAME");
msg("Checking before commit");
- LockTimeOuter timeOuter = new LockTimeOuter(lock, 500);
- boolean timedOut = timeOuter.timedOut();
+ LockTimeOuter timeOuter = new LockTimeOuter(lock);
+ boolean timedOut = timeOuter.timedOut(10000);
assertEquals(true, timedOut);
assertEquals(false, unlocked[0]);
@@ -253,7 +251,7 @@ public class InvalidationTest extends AbstractCDOTest
msg("Checking after commit");
if (!unlocked[0])
{
- timedOut = timeOuter.timedOut();
+ timedOut = timeOuter.timedOut(10000);
assertEquals(true, timedOut);
}
}
@@ -292,22 +290,27 @@ public class InvalidationTest extends AbstractCDOTest
trans1.commit();
- ITimeOuter timeOuter = new PollingTimeOuter(20, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return CDOUtil.getCDOObject(res2).cdoState() == CDOState.CONFLICT;
}
- };
-
- assertEquals(false, timeOuter.timedOut());
+ }.assertNoTimeOut();
final Customer customerA2 = getModel1Factory().createCustomer();
res1.getContents().add(customerA2);
trans1.commit();
- assertEquals(false, timeOuter.timedOut());
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return CDOUtil.getCDOObject(res2).cdoState() == CDOState.CONFLICT;
+ }
+ }.assertNoTimeOut();
trans2.rollback();
assertEquals(2, res1.getContents().size());
@@ -348,16 +351,14 @@ public class InvalidationTest extends AbstractCDOTest
trans1.commit();
- ITimeOuter timeOuter = new PollingTimeOuter(20, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return CDOUtil.getCDOObject(res2).cdoState() == CDOState.INVALID_CONFLICT;
}
- };
-
- assertEquals(false, timeOuter.timedOut());
+ }.assertNoTimeOut();
trans2.rollback();
assertEquals(CDOState.INVALID, CDOUtil.getCDOObject(res2).cdoState());
@@ -450,23 +451,28 @@ public class InvalidationTest extends AbstractCDOTest
msg("Changing name");
category1A.setName("CHANGED NAME");
- ITimeOuter timeOuter = new PollingTimeOuter(20, 100)
+ msg("Checking before commit");
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return "CHANGED NAME".equals(category1B.getName());
}
- };
-
- msg("Checking before commit");
- assertEquals(true, timeOuter.timedOut());
+ }.assertTimeOut();
msg("Committing");
transaction.commit();
msg("Checking after commit");
- assertEquals(false, timeOuter.timedOut());
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return "CHANGED NAME".equals(category1B.getName());
+ }
+ }.assertNoTimeOut();
}
/**
@@ -521,7 +527,7 @@ public class InvalidationTest extends AbstractCDOTest
transactionB.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(200, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
@@ -530,9 +536,7 @@ public class InvalidationTest extends AbstractCDOTest
String name = categoryA.getName();
return "CHANGED NAME".equals(name);
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
public void testRefreshEmptyRepository() throws Exception
@@ -599,28 +603,40 @@ public class InvalidationTest extends AbstractCDOTest
msg("Changing name");
category1A.setName("CHANGED NAME");
- ITimeOuter timeOuter = new PollingTimeOuter(20, 100)
+ msg("Checking before commit");
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return "CHANGED NAME".equals(category1B.getName());
}
- };
-
- msg("Checking before commit");
- assertEquals(true, timeOuter.timedOut());
+ }.assertTimeOut();
msg("Committing");
transaction.commit();
msg("Checking after commit");
- assertEquals(true, timeOuter.timedOut());
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return "CHANGED NAME".equals(category1B.getName());
+ }
+ }.assertTimeOut();
assertEquals(1, sessionB.refresh().size());
msg("Checking after sync");
- assertEquals(false, timeOuter.timedOut());
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return "CHANGED NAME".equals(category1B.getName());
+ }
+ }.assertNoTimeOut();
}
public void testPassiveUpdateOnAndOff() throws Exception
@@ -687,71 +703,72 @@ public class InvalidationTest extends AbstractCDOTest
msg("Changing name");
category1A.setName("CHANGED NAME");
- ITimeOuter timeOuterB = new PollingTimeOuter(10, 100)
+ class TimeOuterB extends PollingTimeOuter
{
@Override
protected boolean successful()
{
return "CHANGED NAME".equals(category1B.getName());
}
- };
+ }
- ITimeOuter timeOuterC = new PollingTimeOuter(10, 100)
+ class TimeOuterC extends PollingTimeOuter
{
@Override
protected boolean successful()
{
return "CHANGED NAME".equals(category1C.getName());
}
- };
+ }
msg("Checking before commit");
- assertEquals(true, timeOuterB.timedOut());
- assertEquals(true, timeOuterC.timedOut());
+ new TimeOuterB().assertTimeOut();
+ new TimeOuterC().assertTimeOut();
msg("Committing");
transaction.commit();
msg("Checking after commit");
- assertEquals(true, timeOuterB.timedOut());
- assertEquals(false, timeOuterC.timedOut());
+ new TimeOuterB().assertTimeOut();
+ new TimeOuterC().assertNoTimeOut();
// It should refresh the session
sessionB.options().setPassiveUpdateEnabled(true);
msg("Checking after sync");
- assertEquals(false, timeOuterB.timedOut());
- assertEquals(false, timeOuterC.timedOut());
+ new TimeOuterB().assertNoTimeOut();
+ new TimeOuterC().assertNoTimeOut();
category1A.setName("CHANGED NAME-VERSION2");
- ITimeOuter timeOuterB_2 = new PollingTimeOuter(10, 100)
+ class TimeOuterB_2 extends PollingTimeOuter
{
@Override
protected boolean successful()
{
return "CHANGED NAME-VERSION2".equals(category1B.getName());
}
- };
+ }
- ITimeOuter timeOuterC_2 = new PollingTimeOuter(10, 100)
+ class TimeOuterC_2 extends PollingTimeOuter
{
@Override
protected boolean successful()
{
return "CHANGED NAME-VERSION2".equals(category1C.getName());
}
- };
+ }
msg("Checking after sync");
- assertEquals(true, timeOuterB_2.timedOut());
- assertEquals(true, timeOuterC_2.timedOut());
+ new TimeOuterB_2().assertTimeOut();
+ new TimeOuterC_2().assertTimeOut();
msg("Committing");
transaction.commit();
- assertEquals(false, timeOuterB_2.timedOut());
- assertEquals(false, timeOuterC_2.timedOut());
+ msg("Checking after sync");
+ new TimeOuterB_2().assertNoTimeOut();
+ new TimeOuterC_2().assertNoTimeOut();
}
public void testDetach() throws Exception
@@ -796,34 +813,39 @@ public class InvalidationTest extends AbstractCDOTest
// ************************************************************* //
resourceA.getContents().remove(categoryA);
- ITimeOuter timeOuter = new PollingTimeOuter(20, 100)
+
+ msg("Checking before commit");
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return FSMUtil.isInvalid(CDOUtil.getCDOObject(categoryB));
+ }
+ }.assertTimeOut();
+
+ assertEquals(0, testAdapter.getNotifications().size());
+ msg("Committing");
+ transaction.commit();
+
+ msg("Checking after commit");
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return FSMUtil.isInvalid(CDOUtil.getCDOObject(categoryB));
}
- };
+ }.assertNoTimeOut();
- ITimeOuter timeOuterNotification = new PollingTimeOuter(20, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return testAdapter.getNotifications().size() == 1;
}
- };
-
- msg("Checking before commit");
- assertEquals(true, timeOuter.timedOut());
-
- assertEquals(0, testAdapter.getNotifications().size());
- msg("Committing");
- transaction.commit();
-
- msg("Checking after commit");
- assertEquals(false, timeOuter.timedOut());
- assertEquals(false, timeOuterNotification.timedOut());
+ }.assertNoTimeOut();
}
public void testDetachAndPassiveUpdate() throws Exception
@@ -880,26 +902,16 @@ public class InvalidationTest extends AbstractCDOTest
// ************************************************************* //
resourceA.getContents().remove(categoryA);
- ITimeOuter timeOuter = new PollingTimeOuter(20, 100)
- {
- @Override
- protected boolean successful()
- {
- return FSMUtil.isInvalid(CDOUtil.getCDOObject(categoryB));
- }
- };
- ITimeOuter timeOuterNotification = new PollingTimeOuter(20, 100)
+ msg("Checking before commit");
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
- return testAdapter.getNotifications().size() == 1;
+ return FSMUtil.isInvalid(CDOUtil.getCDOObject(categoryB));
}
- };
-
- msg("Checking before commit");
- assertEquals(true, timeOuter.timedOut());
+ }.assertTimeOut();
assertEquals(0, testAdapter.getNotifications().size());
msg("Committing");
@@ -918,14 +930,37 @@ public class InvalidationTest extends AbstractCDOTest
}
msg("Checking after commit");
- assertEquals(true, timeOuter.timedOut());
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return FSMUtil.isInvalid(CDOUtil.getCDOObject(categoryB));
+ }
+ }.assertTimeOut();
+
assertEquals(0, testAdapter.getNotifications().size());
sessionB.refresh();
msg("Checking after commit");
- assertEquals(false, timeOuter.timedOut());
- assertEquals(false, timeOuterNotification.timedOut());
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return FSMUtil.isInvalid(CDOUtil.getCDOObject(categoryB));
+ }
+ }.assertNoTimeOut();
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return testAdapter.getNotifications().size() == 1;
+ }
+ }.assertNoTimeOut();
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
index 82a29e0d23..843f8b34ee 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
@@ -114,16 +114,14 @@ public class LockingManagerTest extends AbstractCDOTest
keys.add(2);
keys.add(3);
lockingManager.unlock(LockType.READ, 2, keys);
- ITimeOuter timeOuter = new PollingTimeOuter(200, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return lockingManager.hasLock(LockType.WRITE, 1, 1);
}
- };
-
- assertEquals(false, timeOuter.timedOut());
+ }.assertNoTimeOut();
}
public void testBasicWrongUnlock() throws Exception
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MEMStoreQueryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MEMStoreQueryTest.java
index bb06cafe4b..38c6afdb1b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MEMStoreQueryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MEMStoreQueryTest.java
@@ -111,16 +111,14 @@ public class MEMStoreQueryTest extends AbstractCDOTest
final CloseableIterator<Object> result = query.getResultAsync(Object.class);
result.close();
- boolean timedOut = new PollingTimeOuter(500, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID());
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
CDOSession session = transaction.getSession();
transaction.close();
@@ -137,16 +135,15 @@ public class MEMStoreQueryTest extends AbstractCDOTest
final CloseableIterator<Object> result = query.getResultAsync(Object.class);
CDOSession session = transaction.getSession();
transaction.close();
- boolean timedOut = new PollingTimeOuter(500, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID());
}
- }.timedOut();
+ }.assertNoTimeOut();
- assertEquals(false, timedOut);
session.close();
}
@@ -160,16 +157,14 @@ public class MEMStoreQueryTest extends AbstractCDOTest
final CloseableIterator<Object> result = query.getResultAsync(Object.class);
transaction.getSession().close();
- boolean timedOut = new PollingTimeOuter(500, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID());
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
public void testMEMStoreQueryAsync_UnsupportedLanguage() throws Exception
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TransactionHandlerTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TransactionHandlerTest.java
index e721124412..58a222eb9d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TransactionHandlerTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TransactionHandlerTest.java
@@ -367,7 +367,7 @@ public class TransactionHandlerTest extends AbstractCDOTest
resource.getContents().add(order); // 1 modif + 1 attach
resource.getContents().remove(order); // 1 modif + 1 detach
- boolean timedOut = new PollingTimeOuter(200, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
@@ -375,9 +375,8 @@ public class TransactionHandlerTest extends AbstractCDOTest
return handler.listOfAddingObject.size() == 1 && handler.listOfDetachingObject.size() == 1
&& handler.listOfModifyinObject.size() == 2;
}
- }.timedOut();
+ }.assertNoTimeOut();
- assertEquals(false, timedOut);
// Wait a little bit to let the async finish. It is only there to not have Transaction not active exception and
// mislead the test.
Thread.sleep(300);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_250036_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_250036_Test.java
index a5fb5f67f3..c8a007ad5b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_250036_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_250036_Test.java
@@ -90,16 +90,14 @@ public class Bugzilla_250036_Test extends AbstractCDOTest
transaction.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(200, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return counter.getNotifications().size() == 1;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
/********* transaction 2 ***************/
EMap<String, EObject> mapOfEObjectAfterCommit = genRefMap.getElements();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_251087_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_251087_Test.java
index ac71e7e1da..2a2a312793 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_251087_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_251087_Test.java
@@ -91,16 +91,15 @@ public class Bugzilla_251087_Test extends AbstractCDOTest
transaction1.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(10, 200)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return testAdapter.getNotifications().size() == 1;
}
- }.timedOut();
+ }.assertNoTimeOut();
- assertEquals(false, timedOut);
assertEquals(false, ((InternalCDOTransaction)transB1).hasSubscription(companyID));
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_254489_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_254489_Test.java
index 98aaa80384..b6c9a33c3c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_254489_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_254489_Test.java
@@ -68,16 +68,14 @@ public class Bugzilla_254489_Test extends AbstractCDOTest
transaction1.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(5, 200)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return companyA2Adapter.getNotifications().size() == 1;
}
- }.timedOut();
-
- assertFalse(timedOut);
+ }.assertNoTimeOut();
Category category2 = (Category)companyA2Adapter.getNotifications().get(0).getNewValue();
assertNotSame(category2, category1A);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_260764_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_260764_Test.java
index 277d3abe2a..fb29c5e406 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_260764_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_260764_Test.java
@@ -71,16 +71,15 @@ public class Bugzilla_260764_Test extends AbstractCDOTest
assertEquals(0, adapter.getNotifications().size());
transaction2.commit();
- boolean timedOut = new PollingTimeOuter(5, 200)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return adapter.getNotifications().size() == 1;
}
- }.timedOut();
+ }.assertNoTimeOut();
- assertEquals(false, timedOut);
CDODeltaNotification cdoNotification = (CDODeltaNotification)adapter.getNotifications().get(0);
assertEquals(false, cdoNotification.hasNext());
assertEquals(getModel1Package().getOrder_OrderDetails(), cdoNotification.getFeature());
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_266857_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_266857_Test.java
index f9473f07cc..6d8e60958c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_266857_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_266857_Test.java
@@ -4,9 +4,9 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
- * Simon McDuff - initial API and implementation
+ * Simon McDuff - initial API and implementation
*/
package org.eclipse.emf.cdo.tests.bugzilla;
@@ -55,16 +55,14 @@ public class Bugzilla_266857_Test extends AbstractCDOTest
transaction2.commit();
msg("Checking after commit");
- boolean timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return testAdapterForResource.getNotifications().size() == 1;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_267050_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_267050_Test.java
index f51c1c69d7..c525b63d8b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_267050_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_267050_Test.java
@@ -4,9 +4,9 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
- * Simon McDuff - initial API and implementation
+ * Simon McDuff - initial API and implementation
*/
package org.eclipse.emf.cdo.tests.bugzilla;
@@ -58,16 +58,14 @@ public class Bugzilla_267050_Test extends AbstractCDOTest
res.getContents().add(specialPurchaseOrder);
transaction.commit();
- boolean timedOut = new PollingTimeOuter(10, 100)
+ new PollingTimeOuter()
{
@Override
protected boolean successful()
{
return newPackagesUnits[0] != null;
}
- }.timedOut();
-
- assertEquals(false, timedOut);
+ }.assertNoTimeOut();
assertEquals(1, newPackagesUnits[0].size());
assertEquals(getModel1Package().getNsURI(), newPackagesUnits[0].iterator().next().getTopLevelPackageInfo()
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java
index c975a7d0a9..39f97ccff1 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java
@@ -199,33 +199,16 @@ public class CDORemoteSessionManagerImpl extends Container<CDORemoteSession> imp
}
}
- public void handleRemoteSessionSubscribed(int sessionID, final boolean subscribed)
+ public void handleRemoteSessionSubscribed(int sessionID, boolean subscribed)
{
IEvent event = null;
synchronized (this)
{
- final CDORemoteSessionManager source = this;
- final InternalCDORemoteSession remoteSession = (InternalCDORemoteSession)remoteSessions.get(sessionID);
+ InternalCDORemoteSession remoteSession = (InternalCDORemoteSession)remoteSessions.get(sessionID);
if (remoteSession != null)
{
remoteSession.setSubscribed(subscribed);
- event = new CDORemoteSessionEvent.SubscriptionChanged()
- {
- public CDORemoteSessionManager getSource()
- {
- return source;
- }
-
- public CDORemoteSession getRemoteSession()
- {
- return remoteSession;
- }
-
- public boolean isSubscribed()
- {
- return subscribed;
- }
- };
+ event = new SubscriptionChangedEventImpl(remoteSession, subscribed);
}
}
@@ -372,4 +355,39 @@ public class CDORemoteSessionManagerImpl extends Container<CDORemoteSession> imp
return subscribed;
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class SubscriptionChangedEventImpl extends Event implements CDORemoteSessionEvent.SubscriptionChanged
+ {
+ private static final long serialVersionUID = 1L;
+
+ private InternalCDORemoteSession remoteSession;
+
+ private boolean subscribed;
+
+ public SubscriptionChangedEventImpl(InternalCDORemoteSession remoteSession, boolean subscribed)
+ {
+ super(CDORemoteSessionManagerImpl.this);
+ this.remoteSession = remoteSession;
+ this.subscribed = subscribed;
+ }
+
+ @Override
+ public CDORemoteSessionManager getSource()
+ {
+ return (CDORemoteSessionManager)super.getSource();
+ }
+
+ public CDORemoteSession getRemoteSession()
+ {
+ return remoteSession;
+ }
+
+ public boolean isSubscribed()
+ {
+ return subscribed;
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
index f2cd037903..17b0a78011 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
@@ -12,7 +12,11 @@ package org.eclipse.net4j.util.tests;
import org.eclipse.net4j.tests.bundle.OM;
import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.event.EventUtil;
+import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.log.FileLogHandler;
@@ -23,7 +27,13 @@ import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import junit.framework.Assert;
import junit.framework.TestCase;
import junit.framework.TestResult;
@@ -32,6 +42,10 @@ import junit.framework.TestResult;
*/
public abstract class AbstractOMTest extends TestCase
{
+ public static final long DEFAULT_TIMEOUT = 30 * 1000;
+
+ public static final long DEFAULT_TIMEOUT_EXPECTED = 2 * 1000;
+
public static boolean SUPPRESS_OUTPUT;
private static boolean consoleEnabled;
@@ -184,6 +198,38 @@ public abstract class AbstractOMTest extends TestCase
{
}
+ public static void assertEquals(Object expected, Object actual)
+ {
+ // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
+ if (actual != null && actual.equals(expected))
+ {
+ return;
+ }
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ public static void assertEquals(String message, Object expected, Object actual)
+ {
+ if (expected == null && actual == null)
+ {
+ return;
+ }
+
+ if (expected != null && expected.equals(actual))
+ {
+ return;
+ }
+
+ // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
+ if (actual != null && actual.equals(expected))
+ {
+ return;
+ }
+
+ failNotEquals(message, expected, actual);
+ }
+
public static void sleep(long millis)
{
ConcurrencyUtil.sleep(millis);
@@ -194,14 +240,62 @@ public abstract class AbstractOMTest extends TestCase
assertTrue("Not an instance of " + expected + ": " + object.getClass().getName(), expected.isInstance(object));
}
- public static void assertActive(Object object)
+ public static void assertActive(Object object) throws InterruptedException
{
- assertEquals(true, LifecycleUtil.isActive(object));
+ final LatchTimeOuter timeOuter = new LatchTimeOuter();
+ IListener listener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onActivated(ILifecycle lifecycle)
+ {
+ timeOuter.countDown();
+ }
+ };
+
+ EventUtil.addListener(object, listener);
+
+ try
+ {
+ if (LifecycleUtil.isActive(object))
+ {
+ timeOuter.countDown();
+ }
+
+ timeOuter.assertNoTimeOut();
+ }
+ finally
+ {
+ EventUtil.removeListener(object, listener);
+ }
}
- public static void assertInactive(Object object)
+ public static void assertInactive(Object object) throws InterruptedException
{
- assertEquals(false, LifecycleUtil.isActive(object));
+ final LatchTimeOuter timeOuter = new LatchTimeOuter();
+ IListener listener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ timeOuter.countDown();
+ }
+ };
+
+ EventUtil.addListener(object, listener);
+
+ try
+ {
+ if (!LifecycleUtil.isActive(object))
+ {
+ timeOuter.countDown();
+ }
+
+ timeOuter.assertNoTimeOut();
+ }
+ finally
+ {
+ EventUtil.removeListener(object, listener);
+ }
}
public static void assertSimilar(double expected, double actual, int precision)
@@ -253,4 +347,183 @@ public abstract class AbstractOMTest extends TestCase
{
private static final long serialVersionUID = 1L;
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class AsyncResult<T>
+ {
+ private volatile T value;
+
+ private CountDownLatch latch = new CountDownLatch(1);
+
+ public AsyncResult()
+ {
+ }
+
+ public void setValue(T value)
+ {
+ this.value = value;
+ latch.countDown();
+ }
+
+ public T getValue(long timeout) throws Exception
+ {
+ if (!latch.await(timeout, TimeUnit.MILLISECONDS))
+ {
+ throw new TimeoutException("Result value not available after " + timeout + " milli seconds");
+ }
+
+ return value;
+ }
+
+ public T getValue() throws Exception
+ {
+ return getValue(DEFAULT_TIMEOUT);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static interface ITimeOuter
+ {
+ public boolean timedOut(long timeoutMillis) throws InterruptedException;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static abstract class TimeOuter implements ITimeOuter
+ {
+ public boolean timedOut() throws InterruptedException
+ {
+ return timedOut(DEFAULT_TIMEOUT);
+ }
+
+ public void assertTimeOut(long timeoutMillis) throws InterruptedException
+ {
+ assertEquals("Timeout expected", true, timedOut(timeoutMillis));
+ }
+
+ public void assertTimeOut() throws InterruptedException
+ {
+ assertTimeOut(DEFAULT_TIMEOUT_EXPECTED);
+ }
+
+ public void assertNoTimeOut(long timeoutMillis) throws InterruptedException
+ {
+ assertEquals(false, timedOut(timeoutMillis));
+ }
+
+ public void assertNoTimeOut() throws InterruptedException
+ {
+ assertNoTimeOut(DEFAULT_TIMEOUT);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static abstract class PollingTimeOuter extends TimeOuter
+ {
+ private static final long SLEEP_MILLIS = 100;
+
+ public PollingTimeOuter()
+ {
+ }
+
+ public boolean timedOut(long timeoutMillis) throws InterruptedException
+ {
+ int retries = (int)Math.round(timeoutMillis / SLEEP_MILLIS + .5d);
+ for (int i = 0; i < retries; i++)
+ {
+ if (successful())
+ {
+ return false;
+ }
+
+ sleep(SLEEP_MILLIS);
+ }
+
+ return true;
+ }
+
+ protected abstract boolean successful();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LockTimeOuter extends TimeOuter
+ {
+ private Lock lock;
+
+ public LockTimeOuter(Lock lock)
+ {
+ this.lock = lock;
+ }
+
+ public Lock getLock()
+ {
+ return lock;
+ }
+
+ public boolean timedOut(long timeoutMillis) throws InterruptedException
+ {
+ Condition condition = lock.newCondition();
+ return !condition.await(timeoutMillis, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LatchTimeOuter extends TimeOuter
+ {
+ private CountDownLatch latch;
+
+ public LatchTimeOuter(CountDownLatch latch)
+ {
+ this.latch = latch;
+ }
+
+ public LatchTimeOuter(int count)
+ {
+ this(new CountDownLatch(count));
+ }
+
+ public LatchTimeOuter()
+ {
+ this(1);
+ }
+
+ public CountDownLatch getLatch()
+ {
+ return latch;
+ }
+
+ public long getCount()
+ {
+ return latch.getCount();
+ }
+
+ public void countDown()
+ {
+ latch.countDown();
+ }
+
+ public void countDown(int n)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ countDown();
+ }
+ }
+
+ public boolean timedOut(long timeoutMillis) throws InterruptedException
+ {
+ return !latch.await(timeoutMillis, TimeUnit.MILLISECONDS);
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java
index d8030a4384..ddc34435ec 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java
@@ -59,15 +59,15 @@ public class StringCompressorTest extends AbstractOMTest
run(10, 10);
}
- public void testBidi100() throws Exception
+ public void testBidi50() throws Exception
{
- run(100, 100);
+ run(50, 50);
}
- public void testBidi1Plus100() throws Exception
+ public void testBidi1Plus50() throws Exception
{
run(1, 1);
- run(100, 100);
+ run(50, 50);
}
@Override
@@ -91,7 +91,6 @@ public class StringCompressorTest extends AbstractOMTest
private void run(int toServer, int toClient) throws IOException, InterruptedException
{
CountDownLatch latch = new CountDownLatch(toServer + toClient);
-
while (toServer > 0 || toClient > 0)
{
if (toServer > 0)
@@ -107,7 +106,7 @@ public class StringCompressorTest extends AbstractOMTest
}
}
- latch.await(60, TimeUnit.SECONDS);
+ latch.await(300, TimeUnit.SECONDS);
}
private static String[] createStrings(int count, long seed)
@@ -229,6 +228,7 @@ public class StringCompressorTest extends AbstractOMTest
for (int i = 0; i < indices.length; i++)
{
int index = indices[i];
+ msg(getName() + " --> " + i);
compressor.write(out, strings[index]);
if (SLEEP_WRITER > 0)
{
@@ -275,6 +275,7 @@ public class StringCompressorTest extends AbstractOMTest
for (int i = 0; i < indices.length; i++)
{
int index = indices[i];
+ msg(getName() + " --> " + i);
String toBeRead = strings[index];
String read = compressor.read(in);
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 9aaaecf855..9c65bce657 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
@@ -37,7 +37,7 @@ public class SynchronizingCorrelatorTest extends AbstractOMTest
sleep(100);
correlator.put("eike", true); //$NON-NLS-1$
- consumer.join(1000);
+ consumer.join(DEFAULT_TIMEOUT);
assertEquals(Boolean.TRUE, result[0]);
}

Back to the top