Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-06-05 08:13:37 +0000
committerEike Stepper2012-06-05 08:13:37 +0000
commitb12aed9c8dfad583700aec85387a6380d3bed74d (patch)
treec1881fd26cc46870957f98b936d1a5f1a38dfa16 /plugins
parentea070eba28ae6a7fef64ca6a7bc5e437140975f6 (diff)
downloadcdo-b12aed9c8dfad583700aec85387a6380d3bed74d.tar.gz
cdo-b12aed9c8dfad583700aec85387a6380d3bed74d.tar.xz
cdo-b12aed9c8dfad583700aec85387a6380d3bed74d.zip
[381472] Design a repository administration API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=381472 Make tests tolerant against async event emission
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java140
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener.java164
2 files changed, 175 insertions, 129 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java
index 2a79de4e13..86c05e226c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java
@@ -29,17 +29,16 @@ import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
import org.eclipse.emf.cdo.tests.config.impl.SessionConfig;
import org.eclipse.emf.cdo.tests.util.TestListener;
+import org.eclipse.emf.cdo.tests.util.TestListener.EventAssertion;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.util.container.IContainerDelta;
import org.eclipse.net4j.util.container.IContainerEvent;
import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.factory.ProductCreationException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -320,13 +319,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
getRepository("repo2");
admin.waitForRepository("repo2");
- IEvent[] events = listener.getEvents();
- assertEquals(1, events.length);
-
- @SuppressWarnings("unchecked")
- IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
- assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
- assertEquals("repo2", event.getDeltaElement().getName());
+ listener.assertEvent(new EventAssertion<IContainerEvent<CDOAdminRepository>>()
+ {
+ public void execute(IContainerEvent<CDOAdminRepository> event) throws Exception
+ {
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ });
}
finally
{
@@ -356,13 +356,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
}
}.assertNoTimeOut();
- IEvent[] events = listener.getEvents();
- assertEquals(1, events.length);
-
- @SuppressWarnings("unchecked")
- IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
- assertEquals(IContainerDelta.Kind.REMOVED, event.getDeltaKind());
- assertEquals("repo1", event.getDeltaElement().getName());
+ listener.assertEvent(new EventAssertion<IContainerEvent<CDOAdminRepository>>()
+ {
+ public void execute(IContainerEvent<CDOAdminRepository> event) throws Exception
+ {
+ assertEquals(IContainerDelta.Kind.REMOVED, event.getDeltaKind());
+ assertEquals("repo1", event.getDeltaElement().getName());
+ }
+ });
}
finally
{
@@ -378,28 +379,19 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
{
CDOAdminRepository repo1 = admin.getRepository("repo1");
- final TestListener listener = new TestListener();
+ TestListener listener = new TestListener();
repo1.addListener(listener);
getRepository().setType(Type.BACKUP);
- new PollingTimeOuter()
+ listener.assertEvent(new EventAssertion<RepositoryTypeChangedEvent>()
{
- @Override
- protected boolean successful()
+ public void execute(RepositoryTypeChangedEvent event) throws Exception
{
- IEvent[] events = listener.getEvents();
- if (events.length != 1)
- {
- return false;
- }
-
- RepositoryTypeChangedEvent event = (RepositoryTypeChangedEvent)events[0];
assertEquals(Type.MASTER, event.getOldType());
assertEquals(Type.BACKUP, event.getNewType());
- return true;
}
- }.assertNoTimeOut();
+ });
}
finally
{
@@ -420,23 +412,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
getRepository().setState(State.OFFLINE);
- new PollingTimeOuter()
+ listener.assertEvent(new EventAssertion<RepositoryStateChangedEvent>()
{
- @Override
- protected boolean successful()
+ public void execute(RepositoryStateChangedEvent event) throws Exception
{
- IEvent[] events = listener.getEvents();
- if (events.length != 1)
- {
- return false;
- }
-
- RepositoryStateChangedEvent event = (RepositoryStateChangedEvent)events[0];
assertEquals(State.ONLINE, event.getOldState());
assertEquals(State.OFFLINE, event.getNewState());
- return true;
}
- }.assertNoTimeOut();
+ });
}
finally
{
@@ -461,13 +444,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
assertEquals(getRepository().getName(), repositories[0].getName());
assertEquals(repo2.getName(), repositories[1].getName());
- IEvent[] events = listener.getEvents();
- assertEquals(Arrays.asList(events).toString(), 1, events.length);
-
- @SuppressWarnings("unchecked")
- IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
- assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
- assertEquals("repo2", event.getDeltaElement().getName());
+ listener.assertEvent(new EventAssertion<IContainerEvent<CDOAdminRepository>>()
+ {
+ public void execute(IContainerEvent<CDOAdminRepository> event) throws Exception
+ {
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ });
}
finally
{
@@ -493,13 +477,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
assertEquals(getRepository().getName(), repositories[0].getName());
assertEquals(repo2.getName(), repositories[1].getName());
- IEvent[] events = listener.getEvents();
- assertEquals(Arrays.asList(events).toString(), 1, events.length);
-
- @SuppressWarnings("unchecked")
- IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
- assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
- assertEquals("repo2", event.getDeltaElement().getName());
+ listener.assertEvent(new EventAssertion<IContainerEvent<CDOAdminRepository>>()
+ {
+ public void execute(IContainerEvent<CDOAdminRepository> event) throws Exception
+ {
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ });
}
finally
{
@@ -527,13 +512,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
assertEquals(getRepository().getName(), repositories[0].getName());
assertEquals(repo2.getName(), repositories[1].getName());
- IEvent[] events = listener.getEvents();
- assertEquals(Arrays.asList(events).toString(), 1, events.length);
-
- @SuppressWarnings("unchecked")
- IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
- assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
- assertEquals("repo2", event.getDeltaElement().getName());
+ listener.assertEvent(new EventAssertion<IContainerEvent<CDOAdminRepository>>()
+ {
+ public void execute(IContainerEvent<CDOAdminRepository> event) throws Exception
+ {
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ });
}
finally
{
@@ -561,13 +547,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
assertEquals(getRepository().getName(), repositories[0].getName());
assertEquals(repo2.getName(), repositories[1].getName());
- IEvent[] events = listener.getEvents();
- assertEquals(Arrays.asList(events).toString(), 1, events.length);
-
- @SuppressWarnings("unchecked")
- IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
- assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
- assertEquals("repo2", event.getDeltaElement().getName());
+ listener.assertEvent(new EventAssertion<IContainerEvent<CDOAdminRepository>>()
+ {
+ public void execute(IContainerEvent<CDOAdminRepository> event) throws Exception
+ {
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ });
}
finally
{
@@ -607,13 +594,14 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
repo1.delete(ADMIN_HANDLER_TYPE);
assertEquals(null, admin.getRepository("repo1"));
- IEvent[] events = listener.getEvents();
- assertEquals(Arrays.asList(events).toString(), 1, events.length);
-
- @SuppressWarnings("unchecked")
- IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
- assertEquals(IContainerDelta.Kind.REMOVED, event.getDeltaKind());
- assertEquals("repo1", event.getDeltaElement().getName());
+ listener.assertEvent(new EventAssertion<IContainerEvent<CDOAdminRepository>>()
+ {
+ public void execute(IContainerEvent<CDOAdminRepository> event) throws Exception
+ {
+ assertEquals(IContainerDelta.Kind.REMOVED, event.getDeltaKind());
+ assertEquals("repo1", event.getDeltaElement().getName());
+ }
+ });
}
finally
{
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener.java
index be2484152e..900a4e33e7 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener.java
@@ -1,53 +1,111 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.tests.util;
-
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public class TestListener implements IListener
-{
- private List<IEvent> events = new ArrayList<IEvent>();
-
- public TestListener()
- {
- }
-
- public IEvent[] getEvents()
- {
- synchronized (events)
- {
- return events.toArray(new IEvent[events.size()]);
- }
- }
-
- public void clearEvents()
- {
- synchronized (events)
- {
- events.clear();
- }
- }
-
- public void notifyEvent(IEvent event)
- {
- synchronized (events)
- {
- events.add(event);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.util;
+
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class TestListener implements IListener
+{
+ private List<IEvent> events = new ArrayList<IEvent>();
+
+ public TestListener()
+ {
+ }
+
+ public void assertEvent(final EventAssertion assertion) throws Exception
+ {
+ final Exception[] exception = { null };
+ final Error[] error = { null };
+
+ new AbstractOMTest.PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ IEvent event;
+ synchronized (events)
+ {
+ if (events.size() != 1)
+ {
+ return false;
+ }
+
+ event = events.get(0);
+ }
+
+ try
+ {
+ assertion.execute(event);
+ }
+ catch (Exception ex)
+ {
+ exception[0] = ex;
+ }
+ catch (Error err)
+ {
+ error[0] = err;
+ }
+
+ return true;
+ }
+ }.assertNoTimeOut();
+
+ if (exception[0] != null)
+ {
+ throw exception[0];
+ }
+
+ if (error[0] != null)
+ {
+ throw error[0];
+ }
+ }
+
+ public IEvent[] getEvents()
+ {
+ synchronized (events)
+ {
+ return events.toArray(new IEvent[events.size()]);
+ }
+ }
+
+ public void clearEvents()
+ {
+ synchronized (events)
+ {
+ events.clear();
+ }
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ synchronized (events)
+ {
+ events.add(event);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public interface EventAssertion<T extends IEvent>
+ {
+ public void execute(T event) throws Exception;
+ }
+}

Back to the top