diff options
author | Eike Stepper | 2007-11-08 08:14:34 +0000 |
---|---|---|
committer | Eike Stepper | 2007-11-08 08:14:34 +0000 |
commit | 6599c34e3d469134aac4e6365e43c193c230bc6d (patch) | |
tree | 09bdb2816feb70714d551065cb733c9b74135eea /plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java | |
parent | 8b8a446a2b4ce09ec9b158793c87f8602a2a9883 (diff) | |
download | cdo-6599c34e3d469134aac4e6365e43c193c230bc6d.tar.gz cdo-6599c34e3d469134aac4e6365e43c193c230bc6d.tar.xz cdo-6599c34e3d469134aac4e6365e43c193c230bc6d.zip |
Made CDOView.hasConflict() public
Adde RollbackTest
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java new file mode 100644 index 0000000000..2f7f404e5a --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java @@ -0,0 +1,105 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * 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: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.emf.cdo.tests; + +import org.eclipse.emf.cdo.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.tests.model1.Category; +import org.eclipse.emf.cdo.tests.model1.Company; +import org.eclipse.emf.cdo.tests.model1.Model1Factory; +import org.eclipse.emf.cdo.tests.model1.Model1Package; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.net4j.util.transaction.TransactionException; + +/** + * @author Eike Stepper + */ +public class RollbackTest extends AbstractCDOTest +{ + public void testRollbackSameSession() throws Exception + { + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE); + + CDOTransaction transaction1 = session.openTransaction(); + CDOTransaction transaction2 = session.openTransaction(); + + flow1(transaction1, transaction2); + } + + public void testRollbackSeparateSession() throws Exception + { + // Client1 + CDOSession session1 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session1.getPackageRegistry().putEPackage(Model1Package.eINSTANCE); + CDOTransaction transaction1 = session1.openTransaction(); + + // Client2 + CDOSession session2 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session2.getPackageRegistry().putEPackage(Model1Package.eINSTANCE); + CDOTransaction transaction2 = session2.openTransaction(); + + flow1(transaction1, transaction2); + } + + protected void flow1(CDOTransaction transaction1, CDOTransaction transaction2) + { + // Client1 + CDOResource resource1 = transaction1.createResource("/test1"); + Company company1 = Model1Factory.eINSTANCE.createCompany(); + resource1.getContents().add(company1); + Category category1 = Model1Factory.eINSTANCE.createCategory(); + company1.getCategories().add(category1); + transaction1.commit(); + + // Client2 + CDOResource resource2 = transaction2.getResource("/test1"); + Company company2 = (Company)resource2.getContents().get(0); + Category category2 = company2.getCategories().get(0); + category2.setName("client2"); + + // Client1 + category1.setName("client1"); + transaction1.commit(); + sleep(500); + + // Client2 + assertEquals(true, transaction2.isDirty()); + assertEquals(true, transaction2.hasConflict()); + + try + { + transaction2.commit(); + fail("Commit on transaction2 should fail"); + } + catch (TransactionException ex) + { + transaction2.rollback(true); + } + + assertEquals(false, transaction2.isDirty()); + assertEquals(false, transaction2.hasConflict()); + assertEquals("client1", category2.getName()); + category2.setName("client2"); + transaction2.commit(); + assertEquals(false, transaction2.isDirty()); + assertEquals(false, transaction2.hasConflict()); + assertEquals("client2", category2.getName()); + sleep(500); + + // Client1 + assertEquals(false, transaction1.isDirty()); + assertEquals(false, transaction1.hasConflict()); + assertEquals("client2", category1.getName()); + } +} |