Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/org.eclipse.emf.transaction.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ Bundle-Localization: plugin
Require-Bundle: org.eclipse.emf.transaction;bundle-version="1.9.0",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.emf.examples.library.edit;bundle-version="[2.3.0,3.0.0)",
org.junit;bundle-version="[4.0.0,5.0.0)",
junit-jupiter-api;bundle-version="5.11.3",
junit-jupiter-engine;bundle-version="5.11.3",
junit-vintage-engine;bundle-version="5.11.3",
junit-platform-commons;bundle-version="1.11.3",
junit-platform-engine;bundle-version="1.11.3",
junit-platform-runner;bundle-version="1.11.3",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)",
org.eclipse.emf.workspace;bundle-version="1.5.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,37 @@
*/
package org.eclipse.emf.transaction.multithread.tests;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.tests.AbstractTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

/**
* Abstract JUnit test suite for the <em>EMF-TX API</em> multi-threading tests.
*
*
* @author Christian W. Damus (cdamus)
*/
public class AbstractMultithreadTest
extends TestCase {
public class AbstractMultithreadTest {

private TransactionalEditingDomain domain = null;

public AbstractMultithreadTest() {
super(""); //$NON-NLS-1$
}

public static Test suite() {
TestSuite suite = new TestSuite("Multi-threading Tests"); //$NON-NLS-1$

suite.addTest(ReadOperationTest.suite());
suite.addTest(WriteOperationTest.suite());
suite.addTest(ReadWriteOperationTest.suite());
suite.addTest(EMFTransansactionTest.suite());

return suite;
}

//
// Fixture methods
//

protected TransactionalEditingDomain getDomain() {
return domain;
}

@Override
protected void setUp()
throws Exception {

AbstractTest.trace("===> Begin : " + getName()); //$NON-NLS-1$

super.setUp();


@BeforeEach
public void setUp() throws Exception {
AbstractTest.trace("===> Begin : " + this.getClass().getName());
domain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
}

@Override
protected void tearDown()
throws Exception {


@AfterEach
public void tearDown() throws Exception {
domain = null;

AbstractTest.trace("===> End : " + getName()); //$NON-NLS-1$

super.tearDown();
AbstractTest.trace("===> End : " + this.getClass().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@

/**
* Constants and comparison utilities for the multi-threading tests.
*
*
* @author mgoyal
*/
public class Constants {
public static final int SLEEP_TIME = 100;

/**
* Returns true if the <code>testedTask</code> started after <code>mainTask</code>.
* and finished before <code>mainTask</code>.
*
*
* @param mainTask Main Task
* @param testedTask Tested Task
* @return true if the condition is met.
*/
public static final boolean occurredDuring(SimpleOperationThread mainTask, SimpleOperationThread testedTask) {
return occurredDuring(mainTask.getStartTime(), mainTask.getEndTime(), testedTask.getStartTime(), testedTask.getEndTime());
}

/**
* Returns true if the <code>testedStartTime</code> is after <code>mainStartTime</code>.
* and <code>testedEndTime</code> is before <code>mainEndTime</code>.
*
*
* @param mainStartTime
* @param mainEndTime
* @param testedStartTime
Expand All @@ -46,10 +46,10 @@ public static final boolean occurredDuring(long mainStartTime, long mainEndTime,
return (testedStartTime - mainStartTime > 0 && testedStartTime - mainEndTime < 0) &&
(testedEndTime - mainStartTime > 0 && testedEndTime - mainEndTime < 0);
}

/**
* Returns true if the <code>testedTask</code> started and finished before the <code>mainTask</code>
*
*
* @param mainTask
* @param testedTask
* @return true if the condition is met.
Expand All @@ -60,19 +60,19 @@ public static final boolean occurredBefore(SimpleOperationThread mainTask, Simpl

/**
* Returns true if the <code>testedTask</code> started and finished after the <code>mainTask</code>.
*
*
* @param mainTask
* @param testedTask
* @return true if the condition is met.
*/
public static final boolean occurredAfter(SimpleOperationThread mainTask, SimpleOperationThread testedTask) {
return testedTask.getStartTime() - mainTask.getEndTime() >= 0 && testedTask.getEndTime() - mainTask.getEndTime() > 0;
}

/**
* Returns true if the <code>testedTask</code> started before the <code>mainTask</code> and finished during the <code>mainTask</code>
* Also returns true if the <code>testedTask</code> started during the <code>mainTask</code> and finished after the <code>mainTask</code>
*
*
* @param mainTask
* @param testedTask
* @return true if the condition is met.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
package org.eclipse.emf.transaction.multithread.tests;

import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList;
Expand All @@ -37,17 +39,15 @@
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.internal.EMFTransactionPlugin;
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* This class contains a test case for EMF transaction.
*
*
* @author mchauvin
*/
public class EMFTransansactionTest extends TestCase {
public class EMFTransansactionTest {

private TransactionalEditingDomain editingDomain;

Expand All @@ -57,14 +57,10 @@ public class EMFTransansactionTest extends TestCase {

private AtomicBoolean errorDetected = new AtomicBoolean();

public static Test suite() {
return new TestSuite(EMFTransansactionTest.class, "Concurrent Transaction Tests"); //$NON-NLS-1$
}

@Override
protected void setUp() throws Exception {
super.setUp();
@BeforeEach
public void setUp() throws Exception {
exceptionHandler = new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
errorDetected.set(true);
}
Expand All @@ -74,9 +70,10 @@ public void uncaughtException(Thread t, Throwable e) {
/**
* Due to threads synchronization complexity, this test may succeed. It should
* be run several times (at least 4) to be sure than the bug is not present.
*
*
* @throws Exception
*/
@Test
public void testSynchronizationBug() throws Exception {
/* create a resource set */
final ResourceSet rset = new ResourceSetImpl();
Expand All @@ -88,7 +85,7 @@ public void testSynchronizationBug() throws Exception {
final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
ePackage.getEClassifiers().add(eClass);
final EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eClass.getEReferences().add(eReference);
eClass.getEStructuralFeatures().add(eReference);

/* create resource and and add it initialized model */
final URI fileUri = URI.createFileURI(new File("test.ecore").getAbsolutePath());
Expand All @@ -105,7 +102,7 @@ protected void doExecute() {
final EClass eClass2 = EcoreFactory.eINSTANCE.createEClass();
ePackage2.getEClassifiers().add(eClass2);
final EReference eReference2 = EcoreFactory.eINSTANCE.createEReference();
eClass2.getEReferences().add(eReference2);
eClass2.getEStructuralFeatures().add(eReference2);

/* create resource and and add it initialized model */
final URI file2Uri = URI.createFileURI(new File("test2.ecore").getAbsolutePath());
Expand Down Expand Up @@ -135,7 +132,7 @@ protected void doExecute() {

EMFTransactionPlugin.getPlugin().getLog().addLogListener(listener);

final Collection<Thread> threads = new ArrayList<Thread>();
final Collection<Thread> threads = new ArrayList<>();
/* Launch a unload and a resolution */
for (int i = 0; i < 100; i++) {
threads.add(launchNotificationInANewThread(eReference, eReference2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class LongRunningReadThread extends ReadThread {
long timeYielded = 0L;

/**
* Constructor
* @param waitObject
Expand All @@ -37,6 +37,7 @@ public LongRunningReadThread(TransactionalEditingDomain domain, Object waitObjec
public void run() {
try {
getDomain().runExclusive(new Runnable() {
@Override
public void run() {
if(notifyObject != null) {
synchronized(notifyObject) {
Expand All @@ -53,12 +54,12 @@ public void run() {
}
}
}

startTime = System.currentTimeMillis();
for(int i = 0; i < 10; i++) {
try {
sleep(Constants.SLEEP_TIME);

long startYield = System.currentTimeMillis();
getDomain().yield();
timeYielded += System.currentTimeMillis() - startYield;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* Thread representing nested Operations.
*
*
* @author mgoyal
*/
class NestedOperationThread
Expand All @@ -35,7 +35,7 @@ class NestedOperationThread

/**
* Constructor
*
*
* @param waitObject
* @param notifyObject
*/
Expand All @@ -45,7 +45,7 @@ public NestedOperationThread(TransactionalEditingDomain domain, Object waitObjec

/**
* Returns the start time for the inner operation
*
*
* @return innerStartTime
*/
public long getInnerStartTime() {
Expand All @@ -54,7 +54,7 @@ public long getInnerStartTime() {

/**
* Returns the end time for the inner operation
*
*
* @return innerEndTime
*/
public long getInnerEndTime() {
Expand All @@ -63,7 +63,7 @@ public long getInnerEndTime() {

/**
* Returns true if the inner operation was successful
*
*
* @return isInnerExecuted
*/
public boolean isInnerExecuted() {
Expand All @@ -72,7 +72,7 @@ public boolean isInnerExecuted() {

/**
* Returns true if the inner operation failed.
*
*
* @return isInnerFailed
*/
public boolean isInnerFailed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

/**
* Thread representing Read Operation nested in Write Operation.
*
*
* @author mgoyal
*/
class NestedReadInWriteThread
extends NestedOperationThread {

/**
* Constructor
*
*
* @param waitObject
* @param notifyObject
*/
Expand Down Expand Up @@ -63,11 +63,13 @@ public void run() {
try {
getCommandStack().execute(new TestCommand() {

@Override
public void execute() {
startTime = System.currentTimeMillis();
final boolean bWriting = true;
try {
getDomain().runExclusive(new Runnable() {
@Override
public void run() {
innerStartTime = System
.currentTimeMillis();
Expand All @@ -76,8 +78,9 @@ public void run() {
} catch (InterruptedException e) {
// ignore this.
}
if (bWriting && !isExecuted)
if (bWriting && !isExecuted) {
isInnerExecuted = true;
}
innerEndTime = System
.currentTimeMillis();
}
Expand Down
Loading