Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-09-01 07:52:03 +0000
committerCaspar De Groot2011-09-01 07:52:03 +0000
commitd91b8908f8f2cfb84cb9ac258cf57c440970e739 (patch)
tree7e28c7ac6bbc9e69a2eeb75169783fe43d45d20d /plugins/org.eclipse.emf.cdo.tests/src/org
parent06652cd713e41e414f12e8254b9a3716d825371b (diff)
downloadcdo-d91b8908f8f2cfb84cb9ac258cf57c440970e739.tar.gz
cdo-d91b8908f8f2cfb84cb9ac258cf57c440970e739.tar.xz
cdo-d91b8908f8f2cfb84cb9ac258cf57c440970e739.zip
[351912] Lock coordination with SynchronizableRepositories
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351912
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src/org')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingNotificationsTest.java185
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java79
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_312879_Test.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_319552_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_325097_Test.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_326047_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_329014_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/FailoverTest.java20
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayed2Test.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayedTest.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineLockingTest.java247
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineRawTest.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener2.java54
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestSessionConfiguration.java31
16 files changed, 547 insertions, 112 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingNotificationsTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingNotificationsTest.java
index 424762bb4d..b43e368938 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingNotificationsTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingNotificationsTest.java
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo.Operation;
import org.eclipse.emf.cdo.common.lock.CDOLockOwner;
import org.eclipse.emf.cdo.common.lock.CDOLockState;
import org.eclipse.emf.cdo.common.lock.CDOLockUtil;
@@ -26,8 +27,10 @@ import org.eclipse.emf.cdo.tests.util.TestListener2;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;
-import org.eclipse.emf.cdo.view.CDOLocksChangedEvent;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.view.CDOViewLocksChangedEvent;
+
+import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
/**
* @author Caspar De Groot
@@ -41,32 +44,87 @@ public class LockingNotificationsTest extends AbstractLockingTest
return view;
}
- public void testSameBranchDifferentSession() throws CommitException
+ public void testSameBranchDifferentSession_explicitRelease() throws CommitException
+ {
+ sameBranchDifferentSession(LockReleaseMode.EXPLICIT);
+ }
+
+ public void testSameBranchDifferentSession_autoRelease() throws CommitException
+ {
+ sameBranchDifferentSession(LockReleaseMode.AUTO);
+ }
+
+ private void sameBranchDifferentSession(LockReleaseMode mode) throws CommitException
{
CDOSession session1 = openSession();
CDOSession session2 = openSession();
CDOView controlView = openViewWithLockNotifications(session2, null);
- test(session1, controlView, true);
+ if (mode == LockReleaseMode.EXPLICIT)
+ {
+ withExplicitRelease(session1, controlView, true);
+ }
+ else if (mode == LockReleaseMode.AUTO)
+ {
+ withAutoRelease(session1, controlView, true);
+ }
+
session1.close();
session2.close();
}
- public void testSameBranchSameSession() throws CommitException
+ public void testSameBranchSameSession_explicitRelease() throws CommitException
+ {
+ sameBranchSameSession(LockReleaseMode.EXPLICIT);
+ }
+
+ public void testSameBranchSameSession_autoRelease() throws CommitException
+ {
+ sameBranchSameSession(LockReleaseMode.AUTO);
+ }
+
+ private void sameBranchSameSession(LockReleaseMode mode) throws CommitException
{
CDOSession session1 = openSession();
CDOView controlView = openViewWithLockNotifications(session1, null);
- test(session1, controlView, true);
+ if (mode == LockReleaseMode.EXPLICIT)
+ {
+ withExplicitRelease(session1, controlView, true);
+ }
+ else if (mode == LockReleaseMode.AUTO)
+ {
+ withAutoRelease(session1, controlView, true);
+ }
+
session1.close();
}
@Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
public void testDifferentBranchDifferentSession() throws CommitException
{
+ differentBranchDifferentSession(LockReleaseMode.EXPLICIT);
+ }
+
+ @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
+ public void testDifferentBranchDifferentSession_autoRelease() throws CommitException
+ {
+ differentBranchDifferentSession(LockReleaseMode.AUTO);
+ }
+
+ private void differentBranchDifferentSession(LockReleaseMode mode) throws CommitException
+ {
CDOSession session1 = openSession();
CDOBranch subBranch = session1.getBranchManager().getMainBranch().createBranch("sub1");
CDOSession session2 = openSession();
CDOView controlView = openViewWithLockNotifications(session2, subBranch);
- test(session1, controlView, false);
+ if (mode == LockReleaseMode.EXPLICIT)
+ {
+ withExplicitRelease(session1, controlView, false);
+ }
+ else if (mode == LockReleaseMode.AUTO)
+ {
+ withAutoRelease(session1, controlView, false);
+ }
+
session1.close();
session2.close();
}
@@ -74,27 +132,47 @@ public class LockingNotificationsTest extends AbstractLockingTest
@Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
public void testDifferentBranchSameSession() throws CommitException
{
+ differentBranchSameSession(LockReleaseMode.EXPLICIT);
+ }
+
+ @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
+ public void testDifferentBranchSameSession_autoRelease() throws CommitException
+ {
+ differentBranchSameSession(LockReleaseMode.AUTO);
+ }
+
+ private void differentBranchSameSession(LockReleaseMode mode) throws CommitException
+ {
CDOSession session1 = openSession();
CDOBranch subBranch = session1.getBranchManager().getMainBranch().createBranch("sub2");
CDOView controlView = openViewWithLockNotifications(session1, subBranch);
- test(session1, controlView, false);
+ if (mode == LockReleaseMode.EXPLICIT)
+ {
+ withExplicitRelease(session1, controlView, false);
+ }
+ else if (mode == LockReleaseMode.AUTO)
+ {
+ withAutoRelease(session1, controlView, false);
+ }
+
session1.close();
}
- private void test(CDOSession session1, CDOView controlView, boolean mustReceiveNotifications) throws CommitException
+ private void withExplicitRelease(CDOSession session1, CDOView controlView, boolean mustReceiveNotifications)
+ throws CommitException
{
+ TestListener2 controlViewListener = new TestListener2(CDOViewLocksChangedEvent.class);
+ controlView.addListener(controlViewListener);
+
CDOTransaction tx1 = session1.openTransaction();
CDOResource res1 = tx1.getOrCreateResource(getResourcePath("r1"));
- TestListener2 transactionListener = new TestListener2(CDOLocksChangedEvent.class);
+ TestListener2 transactionListener = new TestListener2(CDOViewLocksChangedEvent.class);
tx1.addListener(transactionListener);
res1.getContents().clear();
Company company = getModel1Factory().createCompany();
res1.getContents().add(company);
tx1.commit();
- TestListener2 controlViewListener = new TestListener2(CDOLocksChangedEvent.class);
- controlView.addListener(controlViewListener);
-
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
CDOObject cdoCompanyInControlView = null;
@@ -111,7 +189,7 @@ public class LockingNotificationsTest extends AbstractLockingTest
controlViewListener.waitFor(1);
assertEquals(1, controlViewListener.getEvents().size());
- CDOLocksChangedEvent event = (CDOLocksChangedEvent)controlViewListener.getEvents().get(0);
+ CDOViewLocksChangedEvent event = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(0);
assertLockOwner(tx1, event.getLockOwner());
CDOLockState[] lockStates = event.getLockStates();
@@ -128,7 +206,7 @@ public class LockingNotificationsTest extends AbstractLockingTest
assertEquals(2, controlViewListener.getEvents().size());
- CDOLocksChangedEvent event = (CDOLocksChangedEvent)controlViewListener.getEvents().get(1);
+ CDOViewLocksChangedEvent event = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(1);
assertLockOwner(tx1, event.getLockOwner());
CDOLockState[] lockStates = event.getLockStates();
@@ -146,7 +224,7 @@ public class LockingNotificationsTest extends AbstractLockingTest
controlViewListener.waitFor(3);
assertEquals(3, controlViewListener.getEvents().size());
- CDOLocksChangedEvent event = (CDOLocksChangedEvent)controlViewListener.getEvents().get(2);
+ CDOViewLocksChangedEvent event = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(2);
assertLockOwner(tx1, event.getLockOwner());
CDOLockState[] lockStates = event.getLockStates();
@@ -165,7 +243,7 @@ public class LockingNotificationsTest extends AbstractLockingTest
assertEquals(4, controlViewListener.getEvents().size());
- CDOLocksChangedEvent event = (CDOLocksChangedEvent)controlViewListener.getEvents().get(3);
+ CDOViewLocksChangedEvent event = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(3);
assertLockOwner(tx1, event.getLockOwner());
CDOLockState[] lockStates = event.getLockStates();
@@ -182,7 +260,7 @@ public class LockingNotificationsTest extends AbstractLockingTest
controlViewListener.waitFor(5);
assertEquals(5, controlViewListener.getEvents().size());
- CDOLocksChangedEvent event = (CDOLocksChangedEvent)controlViewListener.getEvents().get(4);
+ CDOViewLocksChangedEvent event = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(4);
assertLockOwner(tx1, event.getLockOwner());
CDOLockState[] lockStates = event.getLockStates();
@@ -199,7 +277,7 @@ public class LockingNotificationsTest extends AbstractLockingTest
assertEquals(6, controlViewListener.getEvents().size());
- CDOLocksChangedEvent event = (CDOLocksChangedEvent)controlViewListener.getEvents().get(5);
+ CDOViewLocksChangedEvent event = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(5);
assertLockOwner(tx1, event.getLockOwner());
CDOLockState[] lockStates = event.getLockStates();
@@ -217,6 +295,58 @@ public class LockingNotificationsTest extends AbstractLockingTest
}
}
+ private void withAutoRelease(CDOSession session1, CDOView controlView, boolean mustReceiveNotifications)
+ throws CommitException
+ {
+ TestListener2 controlViewListener = new TestListener2(CDOViewLocksChangedEvent.class);
+ controlView.addListener(controlViewListener);
+
+ CDOTransaction tx1 = session1.openTransaction();
+ tx1.options().setAutoReleaseLocksEnabled(true);
+ CDOResource res1 = tx1.getOrCreateResource(getResourcePath("r1"));
+ res1.getContents().clear();
+ Company company = getModel1Factory().createCompany();
+ res1.getContents().add(company);
+ tx1.commit();
+
+ implicitRelease(company, LockType.WRITE, tx1, controlViewListener, mustReceiveNotifications);
+ implicitRelease(company, LockType.READ, tx1, controlViewListener, mustReceiveNotifications);
+ implicitRelease(company, LockType.OPTION, tx1, controlViewListener, mustReceiveNotifications);
+ }
+
+ private void implicitRelease(Company company, LockType type, CDOTransaction tx, TestListener2 controlViewListener,
+ boolean mustReceiveNotifications) throws CommitException
+ {
+ CDOViewLocksChangedEvent e;
+ CDOObject cdoCompany = CDOUtil.getCDOObject(company);
+
+ company.setName(company.getName() + "x"); // Make name field dirty
+ cdoCompany.cdoWriteLock().lock();
+
+ if (mustReceiveNotifications)
+ {
+ controlViewListener.waitFor(1);
+ e = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(0);
+ assertSame(Operation.LOCK, e.getOperation());
+ assertSame(LockType.WRITE, e.getLockType());
+ }
+
+ tx.commit();
+
+ if (mustReceiveNotifications)
+ {
+ controlViewListener.waitFor(2);
+ e = (CDOViewLocksChangedEvent)controlViewListener.getEvents().get(1);
+ assertSame(Operation.UNLOCK, e.getOperation());
+ assertNull(e.getLockType());
+ }
+
+ if (!mustReceiveNotifications)
+ {
+ assertEquals(0, controlViewListener.getEvents().size());
+ }
+ }
+
private void assertLockedObject(CDOObject obj, Object lockedObject)
{
if (lockedObject instanceof CDOIDAndBranch)
@@ -241,13 +371,13 @@ public class LockingNotificationsTest extends AbstractLockingTest
CDOSession session1 = openSession();
CDOSession session2 = openSession();
CDOView controlView = session2.openView();
- test(session1, controlView, false);
+ withExplicitRelease(session1, controlView, false);
controlView.options().setLockNotificationEnabled(true);
- test(session1, controlView, true);
+ withExplicitRelease(session1, controlView, true);
controlView.options().setLockNotificationEnabled(false);
- test(session1, controlView, false);
+ withExplicitRelease(session1, controlView, false);
session1.close();
session2.close();
@@ -275,7 +405,7 @@ public class LockingNotificationsTest extends AbstractLockingTest
Company company1 = (Company)resource.getContents().get(0);
CDOObject cdoObj = CDOUtil.getCDOObject(company1);
assertEquals(true, cdoObj.cdoWriteLock().isLockedByOthers());
- assertSame(CDOLockOwner.UNKNOWN, cdoObj.cdoLockState().getWriteLockOwner());
+ assertEquals(true, cdoObj.cdoLockState().getWriteLockOwner().isDurableView());
session2.close();
}
@@ -297,7 +427,14 @@ public class LockingNotificationsTest extends AbstractLockingTest
assertClean(cdoObj, tx1);
assertNotNull(cdoObj.cdoLockState());
- res1.getContents().add(company1);
- tx1.commit();
+ session1.close();
+ }
+
+ /**
+ * @author Caspar De Groot
+ */
+ private static enum LockReleaseMode
+ {
+ EXPLICIT, AUTO
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
index 409492315a..4186b96b2c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
@@ -637,35 +637,40 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
stopMasterTransport();
}
- @Override
- protected InternalRepository createRepository(String name)
+ protected InternalRepository createMasterRepository(String masterName, String name, Map<String, String> props,
+ boolean failover)
{
- boolean failover = getTestFailover();
- Map<String, String> props = getRepositoryProperties();
-
- final String masterName = name + "_master";
IStore masterStore = createStore(masterName);
-
- InternalRepository master;
if (failover)
{
InternalRepositorySynchronizer synchronizer = createSynchronizer("backup", name);
- master = (InternalRepository)CDOServerUtil.createFailoverParticipant(masterName, masterStore, props,
+ return (InternalRepository)CDOServerUtil.createFailoverParticipant(masterName, masterStore, props,
synchronizer, true);
}
- else
- {
- master = (InternalRepository)CDOServerUtil.createRepository(masterName, masterStore, props);
- }
+ return (InternalRepository)CDOServerUtil.createRepository(masterName, masterStore, props);
+ }
+
+ @Override
+ protected InternalRepository createRepository(String name)
+ {
+ boolean failover = getTestFailover();
+ Map<String, String> props = getRepositoryProperties();
+
+ final String masterName = "master";
+ InternalRepository master;
synchronized (repositories)
{
- repositories.put(masterName, master);
+ master = repositories.get(masterName);
+ if (master == null)
+ {
+ master = createMasterRepository(masterName, name, props, failover);
+ repositories.put(masterName, master);
+ LifecycleUtil.activate(master);
+ startMasterTransport();
+ }
}
- LifecycleUtil.activate(master);
- startMasterTransport();
-
InternalRepositorySynchronizer synchronizer = createSynchronizer("master", masterName);
IStore store = createStore(name);
@@ -673,33 +678,31 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
{
return (InternalRepository)CDOServerUtil.createFailoverParticipant(name, store, props, synchronizer, false);
}
- else
+
+ OfflineClone repository = new OfflineClone()
{
- OfflineClone repository = new OfflineClone()
+ @Override
+ public void handleCommitInfo(CDOCommitInfo commitInfo)
{
- @Override
- public void handleCommitInfo(CDOCommitInfo commitInfo)
- {
- waitIfLockAvailable();
- super.handleCommitInfo(commitInfo);
- }
+ waitIfLockAvailable();
+ super.handleCommitInfo(commitInfo);
+ }
- private void waitIfLockAvailable()
+ private void waitIfLockAvailable()
+ {
+ long millis = getTestDelayedCommitHandling();
+ if (millis != 0L)
{
- long millis = getTestDelayedCommitHandling();
- if (millis != 0L)
- {
- ConcurrencyUtil.sleep(millis);
- }
+ ConcurrencyUtil.sleep(millis);
}
- };
+ }
+ };
- repository.setName(name);
- repository.setStore((InternalStore)store);
- repository.setProperties(props);
- repository.setSynchronizer(synchronizer);
- return repository;
- }
+ repository.setName(name);
+ repository.setStore((InternalStore)store);
+ repository.setProperties(props);
+ repository.setSynchronizer(synchronizer);
+ return repository;
}
protected InternalRepositorySynchronizer createSynchronizer(final String acceptorName, final String repositoryName)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_312879_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_312879_Test.java
index 445bb9c939..2d208c952e 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_312879_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_312879_Test.java
@@ -71,8 +71,7 @@ public class Bugzilla_312879_Test extends AbstractSyncingTest
public void testSwitchMasterAndCommit() throws Exception
{
- InternalSynchronizableRepository repo1_master = (InternalSynchronizableRepository)getRepository(getRepository()
- .getName() + "_master");
+ InternalSynchronizableRepository repo1_master = (InternalSynchronizableRepository)getRepository("master");
InternalSynchronizableRepository repo1 = getRepository();
InternalSynchronizableRepository master = repo1_master;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_319552_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_319552_Test.java
index 479ff23821..0e532d5455 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_319552_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_319552_Test.java
@@ -42,7 +42,7 @@ public class Bugzilla_319552_Test extends AbstractSyncingTest
InternalRepository clone = getRepository();
waitForOnline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOSession session = openSession();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_325097_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_325097_Test.java
index fa8e2f8596..2fab297d66 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_325097_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_325097_Test.java
@@ -77,8 +77,7 @@ public class Bugzilla_325097_Test extends AbstractSyncingTest
public void testNewObjectAfterSwitch() throws Exception
{
- InternalSynchronizableRepository repo1_master = (InternalSynchronizableRepository)getRepository(getRepository()
- .getName() + "_master");
+ InternalSynchronizableRepository repo1_master = (InternalSynchronizableRepository)getRepository("master");
InternalSynchronizableRepository repo1 = getRepository();
InternalSynchronizableRepository master = repo1_master;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_326047_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_326047_Test.java
index 3961f0e596..d12a932c2d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_326047_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_326047_Test.java
@@ -48,7 +48,7 @@ public class Bugzilla_326047_Test extends AbstractSyncingTest
InternalRepository clone = getRepository();
waitForOnline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOSession session = openSession();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java
index 3011c2df92..37caf351af 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_328352_Test.java
@@ -54,7 +54,7 @@ public class Bugzilla_328352_Test extends AbstractSyncingTest
waitForOnline(clone);
// create master session & transaction.
- InternalRepository master = getRepository(clone.getName() + "_master");
+ InternalRepository master = getRepository("master");
CDOSession masterSession = openSession(master.getName());
CDOTransaction masterTransaction = masterSession.openTransaction();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_329014_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_329014_Test.java
index fe48027911..144648c21b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_329014_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/Bugzilla_329014_Test.java
@@ -61,7 +61,7 @@ public class Bugzilla_329014_Test extends AbstractSyncingTest
cloneSession.options().setPassiveUpdateMode(PassiveUpdateMode.CHANGES);
waitForOnline(clone);
- master = getRepository(clone.getName() + "_master");
+ master = getRepository("master");
masterSession = openSession(master.getName());
masterSession.options().setPassiveUpdateMode(PassiveUpdateMode.CHANGES);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/FailoverTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/FailoverTest.java
index 88c50875c3..69d2d7f10b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/FailoverTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/FailoverTest.java
@@ -69,7 +69,7 @@ public class FailoverTest extends AbstractSyncingTest
public void testMasterCommits_ArrivalInBackup() throws Exception
{
- CDOSession session = openSession(getRepository().getName() + "_master");
+ CDOSession session = openSession("master");
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));
@@ -112,7 +112,7 @@ public class FailoverTest extends AbstractSyncingTest
public void testMasterCommits_NotificationsFromBackup() throws Exception
{
- CDOSession masterSession = openSession(getRepository().getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction transaction = masterSession.openTransaction();
CDOResource resource = transaction.createResource("/my/resource");
@@ -158,8 +158,10 @@ public class FailoverTest extends AbstractSyncingTest
public void testClientCommitsToBackupForbidden() throws Exception
{
- InternalRepository backup = getRepository();
- InternalRepository master = getRepository(backup.getName() + "_master");
+ /* InternalRepository backup = */
+ getRepository();
+
+ InternalRepository master = getRepository("master");
TestListener listener = new TestListener();
CDOSession masterSession = openSession(master.getName());
@@ -189,7 +191,7 @@ public class FailoverTest extends AbstractSyncingTest
public void testPauseMasterTransport() throws Exception
{
- CDOSession session = openSession(getRepository().getName() + "_master");
+ CDOSession session = openSession("master");
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));
@@ -229,7 +231,7 @@ public class FailoverTest extends AbstractSyncingTest
public void testSwitchMaster() throws Exception
{
- CDOSession session = openSession(getRepository().getName() + "_master");
+ CDOSession session = openSession("master");
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));
@@ -262,7 +264,7 @@ public class FailoverTest extends AbstractSyncingTest
try
{
getRepository().setType(CDOCommonRepository.Type.MASTER);
- getRepository(getRepository().getName() + "_master").setType(CDOCommonRepository.Type.BACKUP);
+ getRepository("master").setType(CDOCommonRepository.Type.BACKUP);
company.setName("Commit should fail");
try
@@ -292,7 +294,7 @@ public class FailoverTest extends AbstractSyncingTest
public void testSwitchMasterAndCommit() throws Exception
{
- CDOSession session = openSession(getRepository().getName() + "_master");
+ CDOSession session = openSession("master");
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));
@@ -315,7 +317,7 @@ public class FailoverTest extends AbstractSyncingTest
try
{
getRepository().setType(CDOCommonRepository.Type.MASTER);
- getRepository(getRepository().getName() + "_master").setType(CDOCommonRepository.Type.BACKUP);
+ getRepository("master").setType(CDOCommonRepository.Type.BACKUP);
session.close();
session = openSession();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayed2Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayed2Test.java
index 1bada7bcda..e6b100f9bc 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayed2Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayed2Test.java
@@ -34,8 +34,7 @@ public class OfflineDelayed2Test extends AbstractSyncingTest
{
int nbrOfCommits = 5;
- InternalRepository clone = getRepository();
- InternalRepository master = getRepository(clone.getName() + "_master");
+ InternalRepository master = getRepository("master");
CDOSession masterSession = openSession(master.getName());
CDOTransaction masterTransaction = masterSession.openTransaction();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayedTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayedTest.java
index ae4dd9193d..a2055ca6e6 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayedTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineDelayedTest.java
@@ -43,7 +43,7 @@ public class OfflineDelayedTest extends AbstractSyncingTest
getOfflineConfig().stopMasterTransport();
waitForOffline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.createResource("/master/resource");
for (int i = 0; i < 10; i++)
@@ -81,7 +81,7 @@ public class OfflineDelayedTest extends AbstractSyncingTest
waitForOnline(clone);
{
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.createResource("/master/resource");
@@ -131,7 +131,7 @@ public class OfflineDelayedTest extends AbstractSyncingTest
getOfflineConfig().stopMasterTransport();
waitForOffline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.createResource("/master/resource");
for (int i = 0; i < 20; i++)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineLockingTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineLockingTest.java
index 7983d3919b..6c741957b1 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineLockingTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineLockingTest.java
@@ -11,15 +11,26 @@
package org.eclipse.emf.cdo.tests.offline;
import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo.Operation;
import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.internal.server.syncing.OfflineClone;
import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.session.CDOSessionInvalidationEvent;
+import org.eclipse.emf.cdo.session.CDOSessionLocksChangedEvent;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.tests.AbstractSyncingTest;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.util.TestListener2;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.CDOLocksChangedEvent;
+import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.view.CDOViewLocksChangedEvent;
+
+import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
/**
* @author Caspar De Groot
@@ -28,9 +39,10 @@ public class OfflineLockingTest extends AbstractSyncingTest
{
public void testLockAndUnlockThrough() throws Exception
{
- CDOSession masterSession = openSession(getRepository().getName() + "_master");
+ assertEquals(true, getRepository("repo1") instanceof OfflineClone);
- CDOSession cloneSession = openSession();
+ CDOSession masterSession = openSession("master");
+ CDOSession cloneSession = openSession("repo1");
waitForOnline(cloneSession.getRepositoryInfo());
CDOTransaction cloneTx = cloneSession.openTransaction();
@@ -44,7 +56,7 @@ public class OfflineLockingTest extends AbstractSyncingTest
CDOView masterView = masterSession.openView();
masterView.options().setLockNotificationEnabled(true);
- TestListener2 masterViewListener = new TestListener2(CDOLocksChangedEvent.class);
+ TestListener2 masterViewListener = new TestListener2(CDOViewLocksChangedEvent.class);
masterView.addListener(masterViewListener);
CDOObject cdoCompanyOnMaster = masterView.getObject(cdoCompany.cdoID());
@@ -60,7 +72,232 @@ public class OfflineLockingTest extends AbstractSyncingTest
masterSession.close();
}
- public void testMasterLocks_ArrivalInClone() throws Exception
+ public void testCloneLocks_arrivalInOtherClone() throws Exception
+ {
+ // Create a 2nd clone repository
+ assertEquals(true, getRepository("repo1") instanceof OfflineClone);
+ assertEquals(true, getRepository("repo2") instanceof OfflineClone);
+
+ CDOSession clone1Session = openSession("repo1");
+ TestListener2 session1lockListener = new TestListener2(CDOSessionLocksChangedEvent.class, "session1lockListener");
+ clone1Session.addListener(session1lockListener);
+ waitForOnline(clone1Session.getRepositoryInfo());
+
+ CDOSession clone2Session = openSession("repo2");
+ TestListener2 session2invalidationListener = new TestListener2(CDOSessionInvalidationEvent.class,
+ "session2invalidationListener");
+ clone2Session.addListener(session2invalidationListener);
+ TestListener2 session2lockListener = new TestListener2(CDOSessionLocksChangedEvent.class, "session2lockListener");
+ clone2Session.addListener(session2lockListener);
+ waitForOnline(clone2Session.getRepositoryInfo());
+
+ CDOTransaction clone1Tx = openTransaction(clone1Session);
+
+ CDOResource resourceInSession1 = clone1Tx.createResource(getResourcePath("test"));
+ Company companyA = getModel1Factory().createCompany();
+ Company companyB = getModel1Factory().createCompany();
+ Company companyC = getModel1Factory().createCompany();
+ resourceInSession1.getContents().add(companyA);
+ resourceInSession1.getContents().add(companyB);
+ resourceInSession1.getContents().add(companyC);
+ clone1Tx.commit();
+
+ CDOObject companyA_session1 = CDOUtil.getCDOObject(companyA);
+ CDOObject companyB_session1 = CDOUtil.getCDOObject(companyB);
+ CDOObject companyC_session1 = CDOUtil.getCDOObject(companyC);
+
+ session2invalidationListener.setTimeout(Integer.MAX_VALUE);
+ session2invalidationListener.waitFor(1); // Wait for the commit notification
+
+ CDOTransaction clone2Tx = openTransaction(clone2Session);
+
+ CDOResource resourceInSession2 = clone2Tx.getResource(getResourcePath("test"));
+ CDOObject companyA_session2 = CDOUtil.getCDOObject(resourceInSession2.getContents().get(0));
+ CDOObject companyB_session2 = CDOUtil.getCDOObject(resourceInSession2.getContents().get(1));
+ CDOObject companyC_session2 = CDOUtil.getCDOObject(resourceInSession2.getContents().get(2));
+
+ CDOSessionLocksChangedEvent e;
+
+ // Verify that thusfar we haven't received any locking events in session 1
+ assertEquals(0, session1lockListener.getEvents().size());
+
+ // Perform the lock in session 2, connected to clone 2
+ companyA_session2.cdoWriteLock().lock();
+
+ // Wait for the lock notification in session 1, which is connected to clone 1
+ session1lockListener.waitFor(1);
+
+ e = (CDOSessionLocksChangedEvent)session1lockListener.getEvents().get(0);
+ assertSame(LockType.WRITE, e.getLockType());
+ assertSame(Operation.LOCK, e.getOperation());
+ assertEquals(true, companyA_session1.cdoWriteLock().isLockedByOthers());
+
+ // Perform the unlock in session 2, connected to clone 2
+ companyA_session2.cdoWriteLock().unlock();
+
+ // Wait for the lock notification in session 1, which is connected to clone 1
+ session1lockListener.waitFor(2);
+
+ e = (CDOSessionLocksChangedEvent)session1lockListener.getEvents().get(1);
+ assertSame(LockType.WRITE, e.getLockType());
+ assertSame(Operation.UNLOCK, e.getOperation());
+ assertEquals(false, companyA_session1.cdoWriteLock().isLockedByOthers());
+
+ // Now vice versa . . .
+
+ session2lockListener.getEvents().clear();
+
+ // Perform the lock in session 1, connected to clone 1
+ companyA_session1.cdoWriteLock().lock();
+
+ // Wait for the lock notification in session 2, which is connected to clone 2
+ session2lockListener.waitFor(1);
+
+ e = (CDOSessionLocksChangedEvent)session2lockListener.getEvents().get(0);
+ assertSame(LockType.WRITE, e.getLockType());
+ assertSame(Operation.LOCK, e.getOperation());
+ assertEquals(true, companyA_session2.cdoWriteLock().isLockedByOthers());
+
+ // Perform the unlock in session 1, connected to clone 1
+ companyA_session1.cdoWriteLock().unlock();
+
+ // Wait for the lock notification in session 1, which is connected to clone 1
+ session2lockListener.waitFor(2);
+
+ e = (CDOSessionLocksChangedEvent)session2lockListener.getEvents().get(1);
+ assertSame(LockType.WRITE, e.getLockType());
+ assertSame(Operation.UNLOCK, e.getOperation());
+ assertEquals(false, companyA_session2.cdoWriteLock().isLockedByOthers());
+
+ // Now try an unlock-all . . .
+
+ session1lockListener.getEvents().clear();
+
+ companyA_session2.cdoReadLock().lock();
+ companyB_session2.cdoWriteLock().lock();
+ companyC_session2.cdoWriteOption().lock();
+
+ session1lockListener.waitFor(3);
+
+ assertEquals(true, companyA_session1.cdoReadLock().isLockedByOthers());
+ assertEquals(true, companyB_session1.cdoWriteLock().isLockedByOthers());
+ assertEquals(true, companyC_session1.cdoWriteOption().isLockedByOthers());
+
+ clone2Tx.unlockObjects();
+
+ session1lockListener.waitFor(4);
+
+ assertEquals(false, companyA_session1.cdoReadLock().isLockedByOthers());
+ assertEquals(false, companyA_session1.cdoWriteLock().isLockedByOthers());
+ assertEquals(false, companyA_session1.cdoWriteOption().isLockedByOthers());
+
+ clone1Session.close();
+ clone2Session.close();
+ }
+
+ public void testCloneLocks_replicationToOtherClone() throws CommitException
+ {
+ InternalRepository repo1 = getRepository("repo1");
+ assertEquals(true, repo1 instanceof OfflineClone);
+ InternalRepository repo2 = getRepository("repo2");
+ assertEquals(true, repo2 instanceof OfflineClone);
+
+ OfflineClone clone2 = (OfflineClone)repo2;
+
+ waitForOnline(getRepository("repo1"));
+ waitForOnline(getRepository("repo2"));
+
+ CDOSession clone1session = openSession("repo1");
+
+ // Store 3 objects in repo1
+ CDOTransaction tx1_sess1 = openTransaction(clone1session);
+ CDOResource resource_tx1_sess1 = tx1_sess1.createResource(getResourcePath("test"));
+ Company companyA = getModel1Factory().createCompany();
+ Company companyB = getModel1Factory().createCompany();
+ Company companyC = getModel1Factory().createCompany();
+ resource_tx1_sess1.getContents().add(companyA);
+ resource_tx1_sess1.getContents().add(companyB);
+ resource_tx1_sess1.getContents().add(companyC);
+ tx1_sess1.commit();
+
+ {
+ // Verify that they're visible in repo2
+ CDOSession clone2session = openSession("repo2");
+ CDOTransaction tx1_sess2 = openTransaction(clone2session);
+ CDOResource resource_tx1_sess2 = tx1_sess2.getResource(getResourcePath("test"));
+ assertEquals(3, resource_tx1_sess2.getContents().size());
+ tx1_sess2.close();
+ clone2session.close();
+ }
+
+ clone2.goOffline();
+ waitForOffline(clone2);
+
+ // Lock the objects in repo1. Since repo1 is ONLINE, this will also lock them
+ // in the master.
+ CDOUtil.getCDOObject(companyA).cdoReadLock().lock();
+ CDOUtil.getCDOObject(companyB).cdoWriteLock().lock();
+ CDOUtil.getCDOObject(companyC).cdoWriteOption().lock();
+
+ clone2.goOnline();
+ waitForOnline(clone2);
+
+ {
+ // Verify that the locks are visible in repo2
+ CDOSession clone2session = openSession("repo2");
+ CDOTransaction tx1_sess2 = openTransaction(clone2session);
+ CDOResource resource_tx1_sess2 = tx1_sess2.getResource(getResourcePath("test"));
+ EList<EObject> contents = resource_tx1_sess2.getContents();
+ CDOObject companyA_in_sess2 = CDOUtil.getCDOObject(contents.get(0));
+ CDOObject companyB_in_sess2 = CDOUtil.getCDOObject(contents.get(1));
+ CDOObject companyC_in_sess2 = CDOUtil.getCDOObject(contents.get(2));
+
+ assertEquals(true, companyA_in_sess2.cdoReadLock().isLockedByOthers());
+ assertEquals(true, companyB_in_sess2.cdoWriteLock().isLockedByOthers());
+ assertEquals(true, companyC_in_sess2.cdoWriteOption().isLockedByOthers());
+
+ tx1_sess2.close();
+ clone2session.close();
+ }
+
+ clone2.goOffline();
+ waitForOffline(clone2);
+
+ // Unlock the objects in repo1. Since repo1 is ONLINE, this will also lock them
+ // in the master.
+ CDOUtil.getCDOObject(companyA).cdoReadLock().unlock();
+ CDOUtil.getCDOObject(companyB).cdoWriteLock().unlock();
+ CDOUtil.getCDOObject(companyC).cdoWriteOption().unlock();
+
+ clone2.goOnline();
+ waitForOnline(clone2);
+
+ {
+ // Verify in repo2
+ CDOSession clone2session = openSession("repo2");
+ CDOTransaction tx1_sess2 = openTransaction(clone2session);
+ CDOResource resource_tx1_sess2 = tx1_sess2.getResource(getResourcePath("test"));
+ EList<EObject> contents = resource_tx1_sess2.getContents();
+ CDOObject companyA_in_sess2 = CDOUtil.getCDOObject(contents.get(0));
+ CDOObject companyB_in_sess2 = CDOUtil.getCDOObject(contents.get(1));
+ CDOObject companyC_in_sess2 = CDOUtil.getCDOObject(contents.get(2));
+
+ assertEquals(false, companyA_in_sess2.cdoReadLock().isLockedByOthers());
+ assertEquals(false, companyB_in_sess2.cdoWriteLock().isLockedByOthers());
+ assertEquals(false, companyC_in_sess2.cdoWriteOption().isLockedByOthers());
+
+ tx1_sess2.close();
+ clone2session.close();
+ }
+
+ clone1session.close();
+ }
+
+ private static CDOTransaction openTransaction(CDOSession session)
{
+ CDOTransaction tx = session.openTransaction();
+ tx.options().setLockNotificationEnabled(true);
+ tx.enableDurableLocking(true);
+ return tx;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineRawTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineRawTest.java
index a23a1aa775..e9f3d02e8b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineRawTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineRawTest.java
@@ -69,7 +69,7 @@ public class OfflineRawTest extends OfflineTest
transaction.addListener(transactionListener);
{
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.getResource("/my/resource");
@@ -136,7 +136,7 @@ public class OfflineRawTest extends OfflineTest
transaction.addListener(transactionListener);
{
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.getResource("/my/resource");
@@ -198,7 +198,7 @@ public class OfflineRawTest extends OfflineTest
waitForOffline(clone);
{
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.getResource("/my/resource");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java
index 5c848502cc..8787e1a332 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/offline/OfflineTest.java
@@ -40,7 +40,7 @@ public class OfflineTest extends AbstractSyncingTest
{
public void testMasterCommits_ArrivalInClone() throws Exception
{
- CDOSession session = openSession(getRepository().getName() + "_master");
+ CDOSession session = openSession("master");
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource("/my/resource");
@@ -83,7 +83,7 @@ public class OfflineTest extends AbstractSyncingTest
protected void masterCommits_NotificationsFromClone() throws Exception
{
- CDOSession masterSession = openSession(getRepository().getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction transaction = masterSession.openTransaction();
CDOResource resource = transaction.createResource("/my/resource");
@@ -130,7 +130,7 @@ public class OfflineTest extends AbstractSyncingTest
public void testClientCommits() throws Exception
{
InternalRepository clone = getRepository();
- InternalRepository master = getRepository(clone.getName() + "_master");
+ InternalRepository master = getRepository("master");
TestListener listener = new TestListener();
CDOSession masterSession = openSession(master.getName());
@@ -165,7 +165,7 @@ public class OfflineTest extends AbstractSyncingTest
getOfflineConfig().stopMasterTransport();
waitForOffline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.createResource("/master/resource");
@@ -205,7 +205,7 @@ public class OfflineTest extends AbstractSyncingTest
getOfflineConfig().stopMasterTransport();
waitForOffline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.createResource("/master/resource");
@@ -238,7 +238,7 @@ public class OfflineTest extends AbstractSyncingTest
getOfflineConfig().stopMasterTransport();
waitForOffline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction masterTransaction = masterSession.openTransaction();
CDOResource masterResource = masterTransaction.createResource("/master/resource");
@@ -356,7 +356,7 @@ public class OfflineTest extends AbstractSyncingTest
getOfflineConfig().stopMasterTransport();
waitForOffline(clone);
- CDOSession masterSession = openSession(clone.getName() + "_master");
+ CDOSession masterSession = openSession("master");
CDOTransaction transaction = masterSession.openTransaction();
CDOResource resource = transaction.createResource("/my/resource");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener2.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener2.java
index b05050dac8..3e77c7ca93 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener2.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestListener2.java
@@ -24,18 +24,31 @@ import junit.framework.Assert;
*/
public class TestListener2 implements IListener
{
+ private final static long DEFAULT_TIMEOUT = 3000; // 3 seconds
+
private List<IEvent> events = new LinkedList<IEvent>();
private Class<? extends IEvent> eventClass;
+ private long timeout;
+
+ private String name;
+
public TestListener2(Class<? extends IEvent> eventClass)
{
+ this(eventClass, null);
+ }
+
+ public TestListener2(Class<? extends IEvent> eventClass, String name)
+ {
this.eventClass = eventClass;
+ this.name = name;
+ timeout = DEFAULT_TIMEOUT;
}
public synchronized void notifyEvent(IEvent event)
{
- if (eventClass.isAssignableFrom(event.getClass()))
+ if (eventClass == null || eventClass.isAssignableFrom(event.getClass()))
{
events.add(event);
notify();
@@ -47,9 +60,13 @@ public class TestListener2 implements IListener
return events;
}
- public synchronized void waitFor(int n)
+ public void setTimeout(long timeout)
+ {
+ this.timeout = timeout;
+ }
+
+ public synchronized void waitFor(int n, long timeout)
{
- long timeout = 2000;
long t = 0;
while (events.size() < n)
@@ -72,4 +89,35 @@ public class TestListener2 implements IListener
timeout -= System.currentTimeMillis() - t;
}
}
+
+ public void waitFor(int i)
+ {
+ waitFor(i, timeout);
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder(TestListener2.class.getSimpleName());
+ builder.append('[');
+ if (name != null)
+ {
+ builder.append("name=\"");
+ builder.append(name);
+ builder.append('\"');
+ }
+
+ if (eventClass != null)
+ {
+ if (builder.charAt(builder.length() - 1) != '[')
+ {
+ builder.append(';');
+ }
+ builder.append("eventClass=");
+ builder.append(eventClass.getSimpleName());
+ }
+
+ builder.append(']');
+ return builder.toString();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestSessionConfiguration.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestSessionConfiguration.java
index 81c2408d9e..f9b3b7a379 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestSessionConfiguration.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/TestSessionConfiguration.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.emf.cdo.tests.util;
+import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode;
import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
import org.eclipse.emf.cdo.common.id.CDOIDGenerator;
import org.eclipse.emf.cdo.common.protocol.CDOAuthenticator;
@@ -23,47 +24,52 @@ import org.eclipse.net4j.util.event.Notifier;
*/
public abstract class TestSessionConfiguration extends Notifier implements CDOSessionConfiguration
{
- public void setPassiveUpdateMode(PassiveUpdateMode passiveUpdateMode)
+ public boolean isSessionOpen()
{
throw new UnsupportedOperationException();
}
- public void setPassiveUpdateEnabled(boolean passiveUpdateEnabled)
+ public boolean isActivateOnOpen()
{
throw new UnsupportedOperationException();
}
- public void setExceptionHandler(CDOSession.ExceptionHandler exceptionHandler)
+ public void setActivateOnOpen(boolean activateOnOpen)
{
throw new UnsupportedOperationException();
}
- public void setIDGenerator(CDOIDGenerator idGenerator)
+ public CDOAuthenticator getAuthenticator()
{
throw new UnsupportedOperationException();
}
- public void setActivateOnOpen(boolean activateOnOpen)
+ public boolean isPassiveUpdateEnabled()
{
throw new UnsupportedOperationException();
}
- public boolean isSessionOpen()
+ public void setPassiveUpdateEnabled(boolean passiveUpdateEnabled)
{
throw new UnsupportedOperationException();
}
- public boolean isPassiveUpdateEnabled()
+ public PassiveUpdateMode getPassiveUpdateMode()
{
throw new UnsupportedOperationException();
}
- public boolean isActivateOnOpen()
+ public void setPassiveUpdateMode(PassiveUpdateMode passiveUpdateMode)
{
throw new UnsupportedOperationException();
}
- public PassiveUpdateMode getPassiveUpdateMode()
+ public LockNotificationMode getLockNotificationMode()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setLockNotificationMode(LockNotificationMode mode)
{
throw new UnsupportedOperationException();
}
@@ -73,12 +79,17 @@ public abstract class TestSessionConfiguration extends Notifier implements CDOSe
throw new UnsupportedOperationException();
}
+ public void setExceptionHandler(CDOSession.ExceptionHandler exceptionHandler)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public CDOIDGenerator getIDGenerator()
{
throw new UnsupportedOperationException();
}
- public CDOAuthenticator getAuthenticator()
+ public void setIDGenerator(CDOIDGenerator idGenerator)
{
throw new UnsupportedOperationException();
}

Back to the top