Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2016-07-19 15:42:32 +0000
committerChristian W. Damus2016-07-19 19:08:10 +0000
commit43818bd9bc0e5dcd935ddfee0f67a87738231e52 (patch)
tree83db5404af668b51716543848df64bbbd12e5552 /tests/junit/plugins/infra
parent4420c5157a623efebb79e3ebbfd7665591fff039 (diff)
downloadorg.eclipse.papyrus-43818bd9bc0e5dcd935ddfee0f67a87738231e52.tar.gz
org.eclipse.papyrus-43818bd9bc0e5dcd935ddfee0f67a87738231e52.tar.xz
org.eclipse.papyrus-43818bd9bc0e5dcd935ddfee0f67a87738231e52.zip
Bug 496299: Controlled Units as Integral Fragments
https://bugs.eclipse.org/bugs/show_bug.cgi?id=496299 Add synchronization checkpoints in the index refresh test to ensure that the assertion doesn't get ahead of workspace resource notifications and fail spuriously. Change-Id: I6df81f425a7ad2524523586ed1a507284028c05d (cherry picked from commit 930ebcac8c74bc6d08b8ff42c906bac252a2b0c3)
Diffstat (limited to 'tests/junit/plugins/infra')
-rw-r--r--tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/resource/index/WorkspaceModelIndexTest.java104
1 files changed, 75 insertions, 29 deletions
diff --git a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/resource/index/WorkspaceModelIndexTest.java b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/resource/index/WorkspaceModelIndexTest.java
index 1c31edb53d1..08b673f306e 100644
--- a/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/resource/index/WorkspaceModelIndexTest.java
+++ b/tests/junit/plugins/infra/emf/org.eclipse.papyrus.infra.emf.tests/tests/org/eclipse/papyrus/infra/emf/resource/index/WorkspaceModelIndexTest.java
@@ -37,7 +37,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
-import java.util.function.Supplier;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -83,8 +82,8 @@ import com.google.common.io.Files;
*/
public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
- private static final SyncHolder syncHolder = new SyncHolder();
- private static final CrossReferenceIndexer index = new CrossReferenceIndexer(syncHolder);
+ private static final Sync sync = new Sync();
+ private static final CrossReferenceIndexer index = new CrossReferenceIndexer(sync);
private static IndexManager manager;
private static WorkspaceModelIndex<CrossReferenceIndex> fixture;
@@ -232,7 +231,7 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
Map<IFile, CrossReferenceIndex> index = fixture.getIndex().get();
// Interlock with the indexing for timing purposes
- Semaphore sync = syncHolder.createStandardSync();
+ sync.createIndexSync();
final String newFileName = "the_referencing_model.uml";
@@ -244,7 +243,7 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
referencingURI = uri(referencingFile);
// Let the indexing start
- sync.release();
+ sync.syncFromTest();
// Cancel the index control job
Job[] family = Job.getJobManager().find(manager);
@@ -262,7 +261,7 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
controlJob.cancel();
// Let the indexing finish
- sync.release();
+ sync.syncFromTest();
JobWaiter controlJobWaiter = JobWaiter.waitForStart(controlJob);
@@ -311,6 +310,10 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
tracker.assertNone(statusWithException(instanceOf(FileNotFoundException.class)));
+ // Interlock with the indexing to ensure that we don't try the index before it hears
+ // about the file delta
+ sync.createTestSync();
+
// Put the file back and synchronize it
new FileManipulationJob("Restore file", referencingFile) {
@Override
@@ -324,6 +327,10 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
}
}.go();
+ // Wait for the indexing to start. If it doesn't start within five seconds, then
+ // something is wrong with the resource change notifications
+ sync.syncFromTest();
+
// Synchronize with the index and verify that it got the file
index = fixture.getIndex().get();
assertIndex(index);
@@ -379,7 +386,7 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
@After
public void reset() {
- syncHolder.clear();
+ sync.clear();
}
static URI uri(IFile file) {
@@ -426,43 +433,89 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
// Nested types
//
- static class SyncHolder implements Supplier<Semaphore> {
+ static class Sync {
private volatile Semaphore sync;
+ private volatile Mode mode = Mode.NONE;
- @Override
- public Semaphore get() {
- return sync;
+ /**
+ * Create (in the test) a semaphore that gates the index on the test.
+ */
+ void createIndexSync() {
+ sync = new Semaphore(0);
+ mode = Mode.INDEX;
}
- Semaphore createStandardSync() {
+ /**
+ * Create (in the test) a semaphore that gates the test on the index.
+ */
+ void createTestSync() {
sync = new Semaphore(0);
- return sync;
+ mode = Mode.TEST;
+ }
+
+ /** Called by the index when it needs to sync up with the test. */
+ void syncFromIndex() {
+ switch (mode) {
+ case INDEX:
+ // Index is gated on the test
+ sync.acquireUninterruptibly();
+ break;
+ case TEST:
+ // Test is gated on the index
+ sync.release();
+ break;
+ default:
+ // Pass
+ }
+ }
+
+ /** Called by the test when it needs to sync up with the index. */
+ void syncFromTest() throws Exception {
+ switch (mode) {
+ case INDEX:
+ // Index is gated on the test
+ sync.release();
+ break;
+ case TEST:
+ // Test is gated on the index
+ if (!sync.tryAcquire(5L, TimeUnit.SECONDS)) {
+ fail("Timed out waiting for indexing job");
+ }
+ break;
+ default:
+ // Pass
+ }
}
void clear() {
+ mode = Mode.NONE;
if (sync != null) {
// Make sure that any blocked threads are released to whatever fate
- syncHolder.sync.release(100);
- syncHolder.sync = null;
+ sync.release(100);
+ sync = null;
}
}
+
+ private enum Mode {
+ NONE, INDEX, TEST,
+ }
}
static class CrossReferenceIndexer implements WorkspaceModelIndex.IndexHandler<CrossReferenceIndex> {
private final Map<IFile, CrossReferenceIndex> index = Maps.newHashMap();
- private final Supplier<? extends Semaphore> syncSupplier;
+ private final Sync sync;
/**
* Initializes me.
*
- * @param syncSupplier
- * a supplier of an optional semaphore to acquire at start and end of indexing a file
+ * @param sync
+ * a protocol for handshaking at start and end of indexing a file
*/
- public CrossReferenceIndexer(Supplier<? extends Semaphore> syncSupplier) {
+ public CrossReferenceIndexer(Sync sync) {
super();
- this.syncSupplier = syncSupplier;
+ this.sync = sync;
}
private CrossReferenceIndex get(IFile file) {
@@ -482,12 +535,8 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
@Override
public CrossReferenceIndex index(IFile file) {
final CrossReferenceIndex result = get(file);
- final Semaphore sync = syncSupplier.get();
- if (sync != null) {
- // Wait for the test to let us proceed
- sync.acquireUninterruptibly();
- }
+ sync.syncFromIndex();
try {
Set<URI> imports = result.imports;
@@ -520,10 +569,7 @@ public class WorkspaceModelIndexTest extends AbstractPapyrusTest {
EMFHelper.unload(resourceSet);
}
} finally {
- if (sync != null) {
- // Wait for the test to let us finish
- sync.acquireUninterruptibly();
- }
+ sync.syncFromIndex();
}
return result;

Back to the top