Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian W. Damus2015-02-11 04:55:59 +0000
committerChristian W. Damus2015-02-11 04:55:59 +0000
commitb0887d194a9ed9a825616bb0a3ee63633147aab7 (patch)
treeaea58a5611d966cd18f1870e92ff97754e8cb545 /tests
parentaacc2baf18c0599c719ebd8ce9fff9293e4c0f5a (diff)
downloadorg.eclipse.papyrus-b0887d194a9ed9a825616bb0a3ee63633147aab7.tar.gz
org.eclipse.papyrus-b0887d194a9ed9a825616bb0a3ee63633147aab7.tar.xz
org.eclipse.papyrus-b0887d194a9ed9a825616bb0a3ee63633147aab7.zip
Bug 456934: Random errors causing org.eclipse.uml2.uml.rsa content type to be disabled
https://bugs.eclipse.org/bugs/show_bug.cgi?id=456934 Serialize the determination of content types of files on a single work queue shared by all WorkspaceModelIndex instances. This ensures at least that the multiple concurrent indexing threads don't concurrently initialize EPackages while leaving the heavy lifting of indexing models (based on EPackages a priori initialized already on the single worker thread) to be done in parallel jobs. This also reverts the earlier changes to hack a bootstrapping of package initialization at start-up before starting the DecoratorModelIndex, which never actually worked anyways. Finally, this adds a step that was previously missing in the lifecycle of the DecoratorModelIndex: to shut it down when the oep.uml.decoratormodel.ui plug-in is stopped.
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/tests/AllTests.java6
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/utils/JobExecutorServiceTest.java145
2 files changed, 149 insertions, 2 deletions
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/tests/AllTests.java b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/tests/AllTests.java
index 7d67230b111..c40999a75e2 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/tests/AllTests.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/tests/AllTests.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST and others.
+ * Copyright (c) 2010, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -12,6 +12,7 @@
* Christian W. Damus (CEA) - bug 402525
* Christian W. Damus (CEA) - bug 422257
* Christian W. Damus (CEA) - bug 399859
+ * Christian W. Damus - bug 456934
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.tests;
@@ -26,6 +27,7 @@ import org.eclipse.papyrus.infra.core.services.ComposedServiceTest;
import org.eclipse.papyrus.infra.core.services.ServicesRegistryTest;
import org.eclipse.papyrus.infra.core.utils.AdapterUtilsTest;
import org.eclipse.papyrus.infra.core.utils.JobBasedFutureTest;
+import org.eclipse.papyrus.infra.core.utils.JobExecutorServiceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -42,7 +44,7 @@ import org.junit.runners.Suite.SuiteClasses;
/* SaveAndDirtyServiceTest.class, */LifeCycleEventsProviderTest.class,
NestedEditorDelegatedOutlinePageTest.class,
// {oep}.core.utils
- AdapterUtilsTest.class, JobBasedFutureTest.class
+ AdapterUtilsTest.class, JobBasedFutureTest.class, JobExecutorServiceTest.class
})
/**
* Suite Class for all tests in the plugin
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/utils/JobExecutorServiceTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/utils/JobExecutorServiceTest.java
new file mode 100644
index 00000000000..2259848c31f
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/utils/JobExecutorServiceTest.java
@@ -0,0 +1,145 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.utils;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Automated tests for the {@link JobExecutorService} class.
+ */
+public class JobExecutorServiceTest {
+
+ @Rule
+ public final HouseKeeper houseKeeper = new HouseKeeper();
+
+ public JobExecutorServiceTest() {
+ super();
+ }
+
+ @Test
+ public void executeAndShutDown() throws Exception {
+ ExecutorService exec = createFixture();
+
+ LatchedRunnable run1 = new LatchedRunnable();
+ LatchedRunnable run2 = new LatchedRunnable();
+
+ exec.execute(run1);
+ exec.execute(run2);
+
+ run1.release();
+ run2.release();
+
+ run1.assertDone();
+ run2.assertDone();
+
+ exec.shutdown();
+ assertTerminated(exec);
+ }
+
+ @Test
+ public void executeAndShutDownNow() throws Exception {
+ ExecutorService exec = createFixture();
+
+ LatchedRunnable run1 = new LatchedRunnable();
+ LatchedRunnable run2 = new LatchedRunnable();
+
+ exec.execute(run1);
+ exec.execute(run2);
+
+ // Do not release the runnables!
+
+ List<Runnable> pending = exec.shutdownNow();
+
+ assertShutdown(exec);
+ assertThat(pending, hasItem(run2)); // Serial execution didn't get this far
+
+ run1.assertNotDone();
+ run2.assertNotDone();
+
+ // Just to clean up
+ run1.release();
+ run2.release();
+
+ assertTerminated(exec);
+ }
+
+ //
+ // Test framework
+ //
+
+ ExecutorService createFixture() {
+ return houseKeeper.cleanUpLater(new JobExecutorService(), "shutdownNow");
+ }
+
+ void assertShutdown(ExecutorService executorService) throws Exception {
+ assertThat("Executor not terminated", executorService.isShutdown(), is(true));
+ }
+
+ void assertTerminated(ExecutorService executorService) throws Exception {
+ assertThat("Executor not shut down", executorService.awaitTermination(1L, TimeUnit.SECONDS), is(true));
+ assertShutdown(executorService);
+ assertThat("Executor not terminated", executorService.isTerminated(), is(true));
+ }
+
+ static class LatchedRunnable implements Runnable {
+ private final CountDownLatch startLatch = new CountDownLatch(1);
+ private final CountDownLatch doneLatch = new CountDownLatch(1);
+
+ private volatile boolean interrupted;
+ private volatile boolean done;
+
+ public void run() {
+ try {
+ startLatch.await();
+
+ done = true;
+ doneLatch.countDown();
+ } catch (InterruptedException e) {
+ interrupted = true;
+ }
+ }
+
+ void release() {
+ startLatch.countDown();
+ }
+
+ void assertNotInterrupted() {
+ assertThat("Runnable was interrupted", interrupted, is(false));
+ }
+
+ void assertDone() throws InterruptedException {
+ assertNotInterrupted();
+
+ doneLatch.await(1L, TimeUnit.SECONDS);
+ assertThat("Runnable not done", done, is(true));
+ }
+
+ void assertNotDone() throws InterruptedException {
+ assertNotInterrupted();
+
+ assertThat("Runnable is done", done, is(false));
+ }
+ }
+}

Back to the top