aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2012-02-19 11:13:34 (EST)
committerJohn Ross2012-02-19 11:13:34 (EST)
commita412d9bf7bd8873b9215aa8c2353367920d6582f (patch)
treedbab00b91593a108443d85cc3665c1a53ab70e37
parent55ab63744dc6fc94cdd73b1e099817b373322e52 (diff)
downloadrt.equinox.bundles-a412d9bf7bd8873b9215aa8c2353367920d6582f.zip
rt.equinox.bundles-a412d9bf7bd8873b9215aa8c2353367920d6582f.tar.gz
rt.equinox.bundles-a412d9bf7bd8873b9215aa8c2353367920d6582f.tar.bz2
Bug 371980: Added new reverse participation order notification test. Added abstract test class and refactored existing tests accordingly.
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java1
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java17
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java22
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java57
4 files changed, 83 insertions, 14 deletions
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java
index b7d988e..2b6c413 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/AllTests.java
@@ -17,6 +17,7 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Tests for Equinox Coordinator"); //$NON-NLS-1$
suite.addTestSuite(CoordinationMaxTimeoutTest.class);
+ suite.addTestSuite(ReverseParticipantOrderNotifyTest.class);
return suite;
}
}
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java
index 7741d7a..a44294e 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinationMaxTimeoutTest.java
@@ -10,9 +10,7 @@
*******************************************************************************/
package org.eclipse.equinox.coordinator.tests;
-import junit.framework.TestCase;
import org.eclipse.equinox.compendium.tests.Activator;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.coordinator.*;
/*
@@ -21,14 +19,11 @@ import org.osgi.service.coordinator.*;
*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=362137
*/
-public class CoordinationMaxTimeoutTest extends TestCase {
+public class CoordinationMaxTimeoutTest extends CoordinatorTest {
private static final long DEVIATION = 500;
private static final String PROPERTY_NAME = "org.eclipse.equinox.coordinator.timeout"; //$NON-NLS-1$
private static final long TIMEOUT = 5000;
- private Coordinator coordinator;
- private ServiceReference coordinatorRef;
-
public void testMaxTimeoutWithNoTimeout() throws Exception {
long start = System.currentTimeMillis();
Coordination c = coordinator.create("c", 0); //$NON-NLS-1$
@@ -144,14 +139,8 @@ public class CoordinationMaxTimeoutTest extends TestCase {
System.setProperty(PROPERTY_NAME, String.valueOf(TIMEOUT));
assertSystemProperty(PROPERTY_NAME, String.valueOf(TIMEOUT));
assertFrameworkProperty(PROPERTY_NAME, String.valueOf(TIMEOUT));
- Activator.getBundle(Activator.BUNDLE_COORDINATOR).start();
- coordinatorRef = Activator.getBundleContext().getServiceReference(Coordinator.class.getName());
- coordinator = (Coordinator) Activator.getBundleContext().getService(coordinatorRef);
- }
-
- protected void tearDown() throws Exception {
- Activator.getBundleContext().ungetService(coordinatorRef);
- Activator.getBundle(Activator.BUNDLE_COORDINATOR).stop();
+ // The above system property initialization must occur before calling super.setUp().
+ super.setUp();
}
private void assertFrameworkProperty(String name, String value) {
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java
new file mode 100644
index 0000000..2b575f5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/CoordinatorTest.java
@@ -0,0 +1,22 @@
+package org.eclipse.equinox.coordinator.tests;
+
+import junit.framework.TestCase;
+import org.eclipse.equinox.compendium.tests.Activator;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.coordinator.Coordinator;
+
+public abstract class CoordinatorTest extends TestCase {
+ protected Coordinator coordinator;
+ protected ServiceReference coordinatorRef;
+
+ protected void setUp() throws Exception {
+ Activator.getBundle(Activator.BUNDLE_COORDINATOR).start();
+ coordinatorRef = Activator.getBundleContext().getServiceReference(Coordinator.class.getName());
+ coordinator = (Coordinator) Activator.getBundleContext().getService(coordinatorRef);
+ }
+
+ protected void tearDown() throws Exception {
+ Activator.getBundleContext().ungetService(coordinatorRef);
+ Activator.getBundle(Activator.BUNDLE_COORDINATOR).stop();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java
new file mode 100644
index 0000000..f5297dd
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/coordinator/tests/ReverseParticipantOrderNotifyTest.java
@@ -0,0 +1,57 @@
+package org.eclipse.equinox.coordinator.tests;
+
+import java.util.*;
+import org.osgi.service.coordinator.Coordination;
+import org.osgi.service.coordinator.Participant;
+
+/*
+ * Ensures participants are notified in reverse participation order when ending
+ * or failing a coordination.
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=371980
+ */
+public class ReverseParticipantOrderNotifyTest extends CoordinatorTest {
+ private static class TestParticipant implements Participant {
+ private final List participants;
+
+ public TestParticipant(List participants) {
+ this.participants = participants;
+ }
+
+ public void ended(Coordination coordination) throws Exception {
+ participants.add(this);
+ }
+
+ public void failed(Coordination coordination) throws Exception {
+ participants.add(this);
+ }
+ }
+
+ public void testReverseParticipateOrderNotifyEnded() {
+ List before = new ArrayList();
+ List after = Collections.synchronizedList(new ArrayList());
+ Coordination c = coordinator.create("c", 0); //$NON-NLS-1$
+ for (int i = 0; i < 10; i++) {
+ Participant p = new TestParticipant(after);
+ before.add(p);
+ c.addParticipant(p);
+ }
+ c.end();
+ Collections.reverse(before);
+ assertEquals("Not notified in reverse participation order", before, after); //$NON-NLS-1$
+ }
+
+ public void testReverseParticipateOrderNotifyFailed() {
+ List before = new ArrayList();
+ List after = Collections.synchronizedList(new ArrayList());
+ Coordination c = coordinator.begin("c", 0); //$NON-NLS-1$
+ for (int i = 0; i < 10; i++) {
+ Participant p = new TestParticipant(after);
+ before.add(p);
+ c.addParticipant(p);
+ }
+ c.fail(new Exception());
+ Collections.reverse(before);
+ assertEquals("Not notified in reverse participation order", before, after); //$NON-NLS-1$
+ }
+}