diff options
author | Eike Stepper | 2012-01-14 10:27:01 +0000 |
---|---|---|
committer | Eike Stepper | 2012-01-14 10:27:01 +0000 |
commit | 0266166cb9ff9535c150250073ea1e57b42d2693 (patch) | |
tree | c006a3bc0ba1f6e1d8a2bc032eedc346f71eab0d /plugins/org.eclipse.emf.cdo.tests.objectivity/src | |
parent | 7416443692cdda72d1f704ea4fc5ececcc669df7 (diff) | |
download | cdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.gz cdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.xz cdo-0266166cb9ff9535c150250073ea1e57b42d2693.zip |
Adjusted copyrights to 2012
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests.objectivity/src')
10 files changed, 1575 insertions, 1575 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyAudit.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyAudit.java index e064f4b0db..a005233e0e 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyAudit.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyAudit.java @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - * Victor Roldan Betancort - 289360: [DB] [maintenance] Support FeatureMaps - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author Eike Stepper - */ -public class AllTestsObjyAudit extends ObjyDBConfigs -{ - public static Test suite() - { - return new AllTestsObjyAudit().getTestSuite("CDO Tests (ObjectivityStore - audit mode)"); //$NON-NLS-1$ - } - - @Override - protected void initConfigSuites(TestSuite parent) - { - addScenario(parent, COMBINED, new ObjyConfig(true, false), JVM, NATIVE); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - 289360: [DB] [maintenance] Support FeatureMaps
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Eike Stepper
+ */
+public class AllTestsObjyAudit extends ObjyDBConfigs
+{
+ public static Test suite()
+ {
+ return new AllTestsObjyAudit().getTestSuite("CDO Tests (ObjectivityStore - audit mode)"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void initConfigSuites(TestSuite parent)
+ {
+ addScenario(parent, COMBINED, new ObjyConfig(true, false), JVM, NATIVE);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyBranching.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyBranching.java index 033f1531a1..7840f802e8 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyBranching.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyBranching.java @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - * Victor Roldan Betancort - 289360: [DB] [maintenance] Support FeatureMaps - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author Eike Stepper - */ -public class AllTestsObjyBranching extends ObjyDBConfigs -{ - public static Test suite() - { - return new AllTestsObjyBranching().getTestSuite("CDO Tests (ObjectivityStore - branching mode)"); //$NON-NLS-1$ - } - - @Override - protected void initConfigSuites(TestSuite parent) - { - addScenario(parent, COMBINED, new ObjyConfig(true, true), JVM, NATIVE); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - 289360: [DB] [maintenance] Support FeatureMaps
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Eike Stepper
+ */
+public class AllTestsObjyBranching extends ObjyDBConfigs
+{
+ public static Test suite()
+ {
+ return new AllTestsObjyBranching().getTestSuite("CDO Tests (ObjectivityStore - branching mode)"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void initConfigSuites(TestSuite parent)
+ {
+ addScenario(parent, COMBINED, new ObjyConfig(true, true), JVM, NATIVE);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyNonAudit.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyNonAudit.java index 7cf4ad78b3..a1c0b79faa 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyNonAudit.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/AllTestsObjyNonAudit.java @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - * Victor Roldan Betancort - 289360: [DB] [maintenance] Support FeatureMaps - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import org.eclipse.emf.cdo.tests.ExternalReferenceTest; -import org.eclipse.emf.cdo.tests.config.IScenario; -import org.eclipse.emf.cdo.tests.config.impl.ConfigTest; - -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author Eike Stepper - */ -public class AllTestsObjyNonAudit extends ObjyDBConfigs -{ - public static Test suite() - { - return new AllTestsObjyNonAudit().getTestSuite("CDO Tests (ObjectivityStore - non-audit mode)"); //$NON-NLS-1$ - } - - @Override - protected void initConfigSuites(TestSuite parent) - { - addScenario(parent, COMBINED, new ObjyConfig(false, false), JVM, NATIVE); - } - - @Override - protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario) - { - super.initTestClasses(testClasses, scenario); - - // There is a problem with the root resource sharing, so for now we're commenting - // out ExternalReferenceTest and Bugzilla_259869_Test - testClasses.remove(ExternalReferenceTest.class); - } - -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - 289360: [DB] [maintenance] Support FeatureMaps
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import org.eclipse.emf.cdo.tests.ExternalReferenceTest;
+import org.eclipse.emf.cdo.tests.config.IScenario;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Eike Stepper
+ */
+public class AllTestsObjyNonAudit extends ObjyDBConfigs
+{
+ public static Test suite()
+ {
+ return new AllTestsObjyNonAudit().getTestSuite("CDO Tests (ObjectivityStore - non-audit mode)"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void initConfigSuites(TestSuite parent)
+ {
+ addScenario(parent, COMBINED, new ObjyConfig(false, false), JVM, NATIVE);
+ }
+
+ @Override
+ protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario)
+ {
+ super.initTestClasses(testClasses, scenario);
+
+ // There is a problem with the root resource sharing, so for now we're commenting
+ // out ExternalReferenceTest and Bugzilla_259869_Test
+ testClasses.remove(ExternalReferenceTest.class);
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyArrayListTest.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyArrayListTest.java index 02eaccdbd1..716f598c8e 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyArrayListTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyArrayListTest.java @@ -1,150 +1,150 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyArrayList; - -import com.objy.as.app.Class_Object; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; - -/** - * Class to be used for testing, all persistence related calls are overriden by local ones. - * - * @author ibrahim - */ -class ObjyLocalArrayListLong extends ObjyArrayList<Long> -{ - public ObjyLocalArrayListLong(Class_Object classObject) - { - super(classObject); - } - - ArrayList<Long> arrayList = new ArrayList<Long>(); - - long arraySize = 0; - - @Override - protected void setValue(long index, Long newValue) - { - arrayList.set((int)index, newValue); - } - - @Override - protected Long getValue(long index) - { - return arrayList.get((int)index); - } - - @Override - protected long cachedSize() - { - if (cacheSize == -1) - { - cacheSize = arraySize; - } - return cacheSize; - } - - @Override - protected void update() - { - // do nothing. - } - - @Override - protected long getVArraySize() - { - return arrayList.size(); - } - - @Override - protected void saveSize() - { - arraySize = cacheSize; - cacheSize = -1; - } - - @Override - protected void grow(int item) - { - for (int i = 0; i < Math.max(item + 10, 10); i++) - { - arrayList.add(new Long(0)); - } - } - - @Override - public long size() - { - return arraySize; - } -} - -public class ObjyArrayListTest -{ - ObjyLocalArrayListLong arrayListLong; - - int numItems = 10; - - @Before - public void setUp() - { - arrayListLong = new ObjyLocalArrayListLong(null); - // fill the array. - for (int i = 0; i < numItems; i++) - { - arrayListLong.add(new Long(i)); - } - } - - @Test - public void moveItems() - { - // move elemnt 7 to spot 2. - arrayListLong.move(2, 7); - assertEquals(numItems, arrayListLong.size()); - assertEquals(new Long(7), arrayListLong.get(2)); - } - - @Test - public void removeLastItem() - { - // - arrayListLong.remove((int)arrayListLong.size()); - assertEquals((numItems - 1), arrayListLong.size()); - } - - @Test - public void removeMiddleItem() - { - // - arrayListLong.remove(5); - assertEquals((numItems - 1), arrayListLong.size()); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void empty() - { - new ArrayList<Object>().get(0); - } - - @After - public void tearDown() - { - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyArrayList;
+
+import com.objy.as.app.Class_Object;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+/**
+ * Class to be used for testing, all persistence related calls are overriden by local ones.
+ *
+ * @author ibrahim
+ */
+class ObjyLocalArrayListLong extends ObjyArrayList<Long>
+{
+ public ObjyLocalArrayListLong(Class_Object classObject)
+ {
+ super(classObject);
+ }
+
+ ArrayList<Long> arrayList = new ArrayList<Long>();
+
+ long arraySize = 0;
+
+ @Override
+ protected void setValue(long index, Long newValue)
+ {
+ arrayList.set((int)index, newValue);
+ }
+
+ @Override
+ protected Long getValue(long index)
+ {
+ return arrayList.get((int)index);
+ }
+
+ @Override
+ protected long cachedSize()
+ {
+ if (cacheSize == -1)
+ {
+ cacheSize = arraySize;
+ }
+ return cacheSize;
+ }
+
+ @Override
+ protected void update()
+ {
+ // do nothing.
+ }
+
+ @Override
+ protected long getVArraySize()
+ {
+ return arrayList.size();
+ }
+
+ @Override
+ protected void saveSize()
+ {
+ arraySize = cacheSize;
+ cacheSize = -1;
+ }
+
+ @Override
+ protected void grow(int item)
+ {
+ for (int i = 0; i < Math.max(item + 10, 10); i++)
+ {
+ arrayList.add(new Long(0));
+ }
+ }
+
+ @Override
+ public long size()
+ {
+ return arraySize;
+ }
+}
+
+public class ObjyArrayListTest
+{
+ ObjyLocalArrayListLong arrayListLong;
+
+ int numItems = 10;
+
+ @Before
+ public void setUp()
+ {
+ arrayListLong = new ObjyLocalArrayListLong(null);
+ // fill the array.
+ for (int i = 0; i < numItems; i++)
+ {
+ arrayListLong.add(new Long(i));
+ }
+ }
+
+ @Test
+ public void moveItems()
+ {
+ // move elemnt 7 to spot 2.
+ arrayListLong.move(2, 7);
+ assertEquals(numItems, arrayListLong.size());
+ assertEquals(new Long(7), arrayListLong.get(2));
+ }
+
+ @Test
+ public void removeLastItem()
+ {
+ //
+ arrayListLong.remove((int)arrayListLong.size());
+ assertEquals((numItems - 1), arrayListLong.size());
+ }
+
+ @Test
+ public void removeMiddleItem()
+ {
+ //
+ arrayListLong.remove(5);
+ assertEquals((numItems - 1), arrayListLong.size());
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void empty()
+ {
+ new ArrayList<Object>().get(0);
+ }
+
+ @After
+ public void tearDown()
+ {
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyBranchManagementTest.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyBranchManagementTest.java index c450013e53..196c741c43 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyBranchManagementTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyBranchManagementTest.java @@ -1,571 +1,571 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Ibrahim Sallam - initial API and implementation - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.emf.cdo.server.internal.objectivity.db.FdManager; -import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyConnection; -import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjySession; -import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyBranch; -import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyBranchManager; -import org.eclipse.emf.cdo.server.internal.objectivity.utils.ObjyDb; -import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader.BranchInfo; - -import com.objy.db.app.oo; -import com.objy.db.app.ooObj; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -class Temp extends ooObj -{ - protected long lValue = 0; - - protected int revision = 0; - - private int branchId = 0; - - public Temp(long value) - { - lValue = value; - revision = 1; - } - - public void revisionIt() - { - markModified(); - revision++; - } - - public void setBranch(int id) - { - markModified(); - branchId = id; - } - - public int getRevision() - { - fetch(); - return revision; - } - - public int getBranchId() - { - fetch(); - return branchId; - } - - public long getValue() - { - fetch(); - return lValue; - } -} - -/** - * This class will hide access to Objectivity/Db - * - * @author Ibrahim Sallam - */ -class DbStore -{ - - // private final String fdName = "c:\\data\\objyBranchTest.boot"; // TODO - this is windows path style, generalise it. - - private final String repoName = "TestRepo"; - - private FdManager fdManager; - - private ObjyConnection objyConnection; - - private ObjySession objySession; - - public DbStore() - { - fdManager = new FdManager(); - objyConnection = ObjyConnection.INSTANCE; - } - - public void startup() - { - fdManager.setFdDirPath("\\temp"); - fdManager.configure("objyBrnachTest"); - objyConnection.connect(fdManager.getFd(), oo.LogNone); - objySession = objyConnection.getWriteSessionFromPool("TestSession"); - } - - public void shutdown() - { - fdManager.removeData(); - objyConnection.disconnect(); - } - - public ObjyBranchManager getBranchManager() - { - return ObjyDb.getOrCreateBranchManager(repoName); - } - - public void begin() - { - objySession.begin(); - } - - public void commit() - { - objySession.commit(); - } - - public Temp newObject() - { - return new Temp(System.currentTimeMillis()); - } - -} - -/** - * @author Ibrahim Sallam - */ -public class ObjyBranchManagementTest -{ - private static final String BRANCH_NAME_A = "MyBranchA"; - - private static final String BRANCH_NAME_B = "MyBranchB"; - - private final int baseBranchId = 0; - - private final long baseBranchTimeStamp = System.currentTimeMillis(); - - DbStore dbStore = null; - - BranchInfo branchInfoA = null; - - BranchInfo branchInfoB = null; - - public static final int NEW_BRANCH = Integer.MAX_VALUE; - - public static final int NEW_LOCAL_BRANCH = Integer.MIN_VALUE; - - @Before - public void setUp() - { - dbStore = new DbStore(); - branchInfoA = new BranchInfo(BRANCH_NAME_A, baseBranchId, baseBranchTimeStamp); - branchInfoB = new BranchInfo(BRANCH_NAME_B, baseBranchId, baseBranchTimeStamp); - dbStore.startup(); - } - - @Test - public void getNextBranchId() - { - dbStore.begin(); - int branchId = dbStore.getBranchManager().nextBranchId(); - dbStore.commit(); - assertEquals(true, branchId > 0); - } - - @Test - public void createBranch() - { - dbStore.begin(); - int nextBranchId = dbStore.getBranchManager().getLastBranchId() + 1; - dbStore.commit(); - - dbStore.begin(); - int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - dbStore.commit(); - assertEquals(branchId, nextBranchId); - } - - @Test - public void getUnavailableBranch() - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(1); - dbStore.commit(); - assertEquals(true, objyBranch == null); - } - - @Test - public void getBranch() - { - dbStore.begin(); - int branchId = dbStore.getBranchManager().createBranch(NEW_LOCAL_BRANCH, branchInfoB).getElement1(); - dbStore.commit(); - // using the branchId we'll get it from the dbStore. - dbStore.begin(); - BranchInfo branchInfo = dbStore.getBranchManager().getBranch(branchId).getBranchInfo(); - dbStore.commit(); - assertEquals(baseBranchId, branchInfo.getBaseBranchID()); - assertEquals(baseBranchTimeStamp, branchInfo.getBaseTimeStamp()); - assertEquals(BRANCH_NAME_B, branchInfo.getName()); - } - - @Test - public void createBranches() - { - // Create a group of branches (no sub-branches) - dbStore.begin(); - int branchIdA = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - int branchIdB = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoB).getElement1(); - dbStore.commit(); - - dbStore.begin(); - int nextBranchId = dbStore.getBranchManager().nextBranchId(); - dbStore.commit(); - assertEquals(true, branchIdA < nextBranchId); - assertEquals(true, branchIdB < nextBranchId); - } - - @Test - public void getBranches() - { - // Get all branches from a created group. - - // Create a group of branches (no sub-branches) - dbStore.begin(); - int branchIdA = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - int branchIdB = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoB).getElement1(); - dbStore.commit(); - - // using the branchId we'll get it from the dbStore. - dbStore.begin(); - BranchInfo branchInfoB = dbStore.getBranchManager().getBranch(branchIdB).getBranchInfo(); - dbStore.commit(); - assertEquals(baseBranchId, branchInfoB.getBaseBranchID()); - assertEquals(baseBranchTimeStamp, branchInfoB.getBaseTimeStamp()); - assertEquals(BRANCH_NAME_B, branchInfoB.getName()); - - // using the branchId we'll get it from the dbStore. - dbStore.begin(); - BranchInfo branchInfoA = dbStore.getBranchManager().getBranch(branchIdA).getBranchInfo(); - dbStore.commit(); - assertEquals(baseBranchId, branchInfoA.getBaseBranchID()); - assertEquals(baseBranchTimeStamp, branchInfoA.getBaseTimeStamp()); - assertEquals(BRANCH_NAME_A, branchInfoA.getName()); - } - - @Test - public void getBrancheRange() - { - // Get a range of branches from a created group. - int thisBaseBranchId = 0; - long thisBaseBranchTimeStamp = System.currentTimeMillis(); - - // Create a group of branches (no sub-branches) - dbStore.begin(); - String prefixString = "Branch_"; - List<Integer> branchList = new ArrayList<Integer>(); - for (int i = 0; i < 20; i++) - { - dbStore.begin(); - BranchInfo branchInfo = new BranchInfo(prefixString + i, thisBaseBranchId, thisBaseBranchTimeStamp); - int id = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfo).getElement1(); - branchList.add(id); - dbStore.commit(); - } - dbStore.commit(); - - // Get range from 5 to 10. - { - dbStore.begin(); - List<ObjyBranch> branchRangeList = dbStore.getBranchManager().getBranches(branchList.get(5), branchList.get(10)); - int index = 5; - for (ObjyBranch objyBranch : branchRangeList) - { - int expectedId = branchList.get(index); - assertEquals(expectedId, objyBranch.getBranchId()); - assertEquals(thisBaseBranchId, objyBranch.getBaseBranchId()); - assertEquals(thisBaseBranchTimeStamp, objyBranch.getBaseBranchTimeStamp()); - assertEquals("Branch_" + index, objyBranch.getBranchName()); - index++; - } - dbStore.commit(); - } - - // Get range from 7 to end. - { - dbStore.begin(); - List<ObjyBranch> branchRangeList = dbStore.getBranchManager().getBranches(branchList.get(7), 0); - assertEquals(13, branchRangeList.size()); - - int index = 7; - for (ObjyBranch objyBranch : branchRangeList) - { - int expectedId = branchList.get(index); - assertEquals(expectedId, objyBranch.getBranchId()); - assertEquals(thisBaseBranchId, objyBranch.getBaseBranchId()); - assertEquals(thisBaseBranchTimeStamp, objyBranch.getBaseBranchTimeStamp()); - assertEquals("Branch_" + index, objyBranch.getBranchName()); - index++; - } - dbStore.commit(); - } - } - - @Test - public void deleteBranch() - { - dbStore.begin(); - int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - dbStore.commit(); - - // delete it. - dbStore.begin(); - assertEquals(true, dbStore.getBranchManager().deleteBranch(branchId)); - dbStore.commit(); - } - - @Test - public void createSubBranches() - { - dbStore.begin(); - int thisBaseBranchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoB); - long thisBaseBranchTimeStamp = System.currentTimeMillis(); - // using the created branch we'll create subBranches. - dbStore.commit(); - - String prefixString = "SubBranch_"; - List<Integer> subBranchList = new ArrayList<Integer>(); - for (int i = 0; i < 10; i++) - { - dbStore.begin(); - BranchInfo branchInfo = new BranchInfo(prefixString + i, thisBaseBranchId, thisBaseBranchTimeStamp); - int id = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfo).getElement1(); - subBranchList.add(id); - dbStore.commit(); - } - // get sub-branches for 0. - List<ObjyBranch> objyBranchList = new ArrayList<ObjyBranch>(); - - dbStore.begin(); - objyBranchList = dbStore.getBranchManager().getSubBranches(0); - assertEquals(2, objyBranchList.size()); - dbStore.commit(); - - dbStore.begin(); - objyBranchList = dbStore.getBranchManager().getSubBranches(thisBaseBranchId); - assertEquals(10, objyBranchList.size()); - dbStore.commit(); - - } - - @Test - public void getSubBranches() - { - dbStore.begin(); - int thisBaseBranchId = dbStore.getBranchManager().createBranch(NEW_LOCAL_BRANCH, branchInfoA).getElement1(); - long thisBaseBranchTimeStamp = System.currentTimeMillis(); - // using the created branch we'll create subBranches. - dbStore.commit(); - - String prefixString = "SubBranch_"; - List<Integer> subBranchList = new ArrayList<Integer>(); - for (int i = 0; i < 10; i++) - { - dbStore.begin(); - BranchInfo branchInfo = new BranchInfo(prefixString + i, thisBaseBranchId, thisBaseBranchTimeStamp); - int id = dbStore.getBranchManager().createBranch(NEW_LOCAL_BRANCH, branchInfo).getElement1(); - subBranchList.add(id); - dbStore.commit(); - } - // verify that we have sub-branches. - dbStore.begin(); - int i = 0; - for (Integer iValue : subBranchList) - { - BranchInfo branchInfo = dbStore.getBranchManager().getBranch(iValue).getBranchInfo(); - assertEquals(thisBaseBranchId, branchInfo.getBaseBranchID()); - assertEquals(thisBaseBranchTimeStamp, branchInfo.getBaseTimeStamp()); - assertEquals(prefixString + i++, branchInfo.getName()); - } - dbStore.commit(); - - } - - @Test - public void addRevisionsToBranch() - { - List<Temp> objectList = new ArrayList<Temp>(); - // create 100 objects in Objy (Main Branch). - dbStore.begin(); - for (int i = 0; i < 100; i++) - { - Temp tempObject = dbStore.newObject(); - if (i % 2 == 0) - { - objectList.add(tempObject); - } - } - dbStore.commit(); - - // create a branch. - dbStore.begin(); - int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - dbStore.commit(); - - // version what we collected in the array, and put them into a new branch. - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - - for (Temp tempObj : objectList) - { - tempObj.setBranch(branchId); - tempObj.revisionIt(); - objyBranch.addRevision(tempObj); - } - dbStore.commit(); - } - // verify that the number of revisions in a branch is the same as what - // we added. - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - assertEquals(objectList.size(), objyBranch.numberOfRevisions()); - dbStore.commit(); - } - } - - @Test - public void getRevisionsFromBranch() - { - List<Temp> objectList = new ArrayList<Temp>(); - // create 100 objects in Objy (Main Branch). - dbStore.begin(); - for (int i = 0; i < 200; i++) - { - Temp tempObject = dbStore.newObject(); - if (i % 2 == 0) - { - objectList.add(tempObject); - } - } - dbStore.commit(); - - // create a branch. - dbStore.begin(); - int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - dbStore.commit(); - - // version what we collected in the array, and put them into a new branch. - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - - for (Temp tempObj : objectList) - { - tempObj.setBranch(branchId); - tempObj.revisionIt(); - objyBranch.addRevision(tempObj); - } - dbStore.commit(); - } - // Get the objects from the branch. - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - Iterator<?> itr = objyBranch.getRevisions().iterator(); - List<Temp> actualList = new ArrayList<Temp>(); - while (itr.hasNext()) - { - Temp tempObj = (Temp)itr.next(); - assertEquals(tempObj.getBranchId(), branchId); - assertEquals(true, tempObj.getRevision() > 1); - actualList.add(tempObj); - } - assertEquals(objectList.size(), actualList.size()); - dbStore.commit(); - } - } - - @Test - public void deleteRevisionsFromBranch() - { - List<Temp> objectList = new ArrayList<Temp>(); - // create 100 objects in Objy (Main Branch). - dbStore.begin(); - for (int i = 0; i < 100; i++) - { - Temp tempObject = dbStore.newObject(); - if (i % 2 == 0) - { - objectList.add(tempObject); - } - } - dbStore.commit(); - - // create a branch. - dbStore.begin(); - int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1(); - dbStore.commit(); - - // version what we collected in the array, and put them into a new branch. - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - - for (Temp tempObj : objectList) - { - tempObj.setBranch(branchId); - tempObj.revisionIt(); - objyBranch.addRevision(tempObj); - } - dbStore.commit(); - } - // verify that the number of revisions in a branch is the same as what - // we added. - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - assertEquals(objectList.size(), objyBranch.numberOfRevisions()); - dbStore.commit(); - } - - // delete revisions - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - for (Temp tempObj : objectList) - { - assertEquals(true, objyBranch.deleteRevision(tempObj)); - } - dbStore.commit(); - } - - // verify that the number of revisions are 0 - { - dbStore.begin(); - ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId); - assertEquals(0, objyBranch.numberOfRevisions()); - dbStore.commit(); - } - } - - @Test(expected = IndexOutOfBoundsException.class) - public void empty() - { - new ArrayList<Object>().get(0); - } - - @After - public void tearDown() - { - dbStore.shutdown(); - } - -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Ibrahim Sallam - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.emf.cdo.server.internal.objectivity.db.FdManager;
+import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyConnection;
+import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjySession;
+import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyBranch;
+import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyBranchManager;
+import org.eclipse.emf.cdo.server.internal.objectivity.utils.ObjyDb;
+import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader.BranchInfo;
+
+import com.objy.db.app.oo;
+import com.objy.db.app.ooObj;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+class Temp extends ooObj
+{
+ protected long lValue = 0;
+
+ protected int revision = 0;
+
+ private int branchId = 0;
+
+ public Temp(long value)
+ {
+ lValue = value;
+ revision = 1;
+ }
+
+ public void revisionIt()
+ {
+ markModified();
+ revision++;
+ }
+
+ public void setBranch(int id)
+ {
+ markModified();
+ branchId = id;
+ }
+
+ public int getRevision()
+ {
+ fetch();
+ return revision;
+ }
+
+ public int getBranchId()
+ {
+ fetch();
+ return branchId;
+ }
+
+ public long getValue()
+ {
+ fetch();
+ return lValue;
+ }
+}
+
+/**
+ * This class will hide access to Objectivity/Db
+ *
+ * @author Ibrahim Sallam
+ */
+class DbStore
+{
+
+ // private final String fdName = "c:\\data\\objyBranchTest.boot"; // TODO - this is windows path style, generalise it.
+
+ private final String repoName = "TestRepo";
+
+ private FdManager fdManager;
+
+ private ObjyConnection objyConnection;
+
+ private ObjySession objySession;
+
+ public DbStore()
+ {
+ fdManager = new FdManager();
+ objyConnection = ObjyConnection.INSTANCE;
+ }
+
+ public void startup()
+ {
+ fdManager.setFdDirPath("\\temp");
+ fdManager.configure("objyBrnachTest");
+ objyConnection.connect(fdManager.getFd(), oo.LogNone);
+ objySession = objyConnection.getWriteSessionFromPool("TestSession");
+ }
+
+ public void shutdown()
+ {
+ fdManager.removeData();
+ objyConnection.disconnect();
+ }
+
+ public ObjyBranchManager getBranchManager()
+ {
+ return ObjyDb.getOrCreateBranchManager(repoName);
+ }
+
+ public void begin()
+ {
+ objySession.begin();
+ }
+
+ public void commit()
+ {
+ objySession.commit();
+ }
+
+ public Temp newObject()
+ {
+ return new Temp(System.currentTimeMillis());
+ }
+
+}
+
+/**
+ * @author Ibrahim Sallam
+ */
+public class ObjyBranchManagementTest
+{
+ private static final String BRANCH_NAME_A = "MyBranchA";
+
+ private static final String BRANCH_NAME_B = "MyBranchB";
+
+ private final int baseBranchId = 0;
+
+ private final long baseBranchTimeStamp = System.currentTimeMillis();
+
+ DbStore dbStore = null;
+
+ BranchInfo branchInfoA = null;
+
+ BranchInfo branchInfoB = null;
+
+ public static final int NEW_BRANCH = Integer.MAX_VALUE;
+
+ public static final int NEW_LOCAL_BRANCH = Integer.MIN_VALUE;
+
+ @Before
+ public void setUp()
+ {
+ dbStore = new DbStore();
+ branchInfoA = new BranchInfo(BRANCH_NAME_A, baseBranchId, baseBranchTimeStamp);
+ branchInfoB = new BranchInfo(BRANCH_NAME_B, baseBranchId, baseBranchTimeStamp);
+ dbStore.startup();
+ }
+
+ @Test
+ public void getNextBranchId()
+ {
+ dbStore.begin();
+ int branchId = dbStore.getBranchManager().nextBranchId();
+ dbStore.commit();
+ assertEquals(true, branchId > 0);
+ }
+
+ @Test
+ public void createBranch()
+ {
+ dbStore.begin();
+ int nextBranchId = dbStore.getBranchManager().getLastBranchId() + 1;
+ dbStore.commit();
+
+ dbStore.begin();
+ int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ dbStore.commit();
+ assertEquals(branchId, nextBranchId);
+ }
+
+ @Test
+ public void getUnavailableBranch()
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(1);
+ dbStore.commit();
+ assertEquals(true, objyBranch == null);
+ }
+
+ @Test
+ public void getBranch()
+ {
+ dbStore.begin();
+ int branchId = dbStore.getBranchManager().createBranch(NEW_LOCAL_BRANCH, branchInfoB).getElement1();
+ dbStore.commit();
+ // using the branchId we'll get it from the dbStore.
+ dbStore.begin();
+ BranchInfo branchInfo = dbStore.getBranchManager().getBranch(branchId).getBranchInfo();
+ dbStore.commit();
+ assertEquals(baseBranchId, branchInfo.getBaseBranchID());
+ assertEquals(baseBranchTimeStamp, branchInfo.getBaseTimeStamp());
+ assertEquals(BRANCH_NAME_B, branchInfo.getName());
+ }
+
+ @Test
+ public void createBranches()
+ {
+ // Create a group of branches (no sub-branches)
+ dbStore.begin();
+ int branchIdA = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ int branchIdB = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoB).getElement1();
+ dbStore.commit();
+
+ dbStore.begin();
+ int nextBranchId = dbStore.getBranchManager().nextBranchId();
+ dbStore.commit();
+ assertEquals(true, branchIdA < nextBranchId);
+ assertEquals(true, branchIdB < nextBranchId);
+ }
+
+ @Test
+ public void getBranches()
+ {
+ // Get all branches from a created group.
+
+ // Create a group of branches (no sub-branches)
+ dbStore.begin();
+ int branchIdA = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ int branchIdB = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoB).getElement1();
+ dbStore.commit();
+
+ // using the branchId we'll get it from the dbStore.
+ dbStore.begin();
+ BranchInfo branchInfoB = dbStore.getBranchManager().getBranch(branchIdB).getBranchInfo();
+ dbStore.commit();
+ assertEquals(baseBranchId, branchInfoB.getBaseBranchID());
+ assertEquals(baseBranchTimeStamp, branchInfoB.getBaseTimeStamp());
+ assertEquals(BRANCH_NAME_B, branchInfoB.getName());
+
+ // using the branchId we'll get it from the dbStore.
+ dbStore.begin();
+ BranchInfo branchInfoA = dbStore.getBranchManager().getBranch(branchIdA).getBranchInfo();
+ dbStore.commit();
+ assertEquals(baseBranchId, branchInfoA.getBaseBranchID());
+ assertEquals(baseBranchTimeStamp, branchInfoA.getBaseTimeStamp());
+ assertEquals(BRANCH_NAME_A, branchInfoA.getName());
+ }
+
+ @Test
+ public void getBrancheRange()
+ {
+ // Get a range of branches from a created group.
+ int thisBaseBranchId = 0;
+ long thisBaseBranchTimeStamp = System.currentTimeMillis();
+
+ // Create a group of branches (no sub-branches)
+ dbStore.begin();
+ String prefixString = "Branch_";
+ List<Integer> branchList = new ArrayList<Integer>();
+ for (int i = 0; i < 20; i++)
+ {
+ dbStore.begin();
+ BranchInfo branchInfo = new BranchInfo(prefixString + i, thisBaseBranchId, thisBaseBranchTimeStamp);
+ int id = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfo).getElement1();
+ branchList.add(id);
+ dbStore.commit();
+ }
+ dbStore.commit();
+
+ // Get range from 5 to 10.
+ {
+ dbStore.begin();
+ List<ObjyBranch> branchRangeList = dbStore.getBranchManager().getBranches(branchList.get(5), branchList.get(10));
+ int index = 5;
+ for (ObjyBranch objyBranch : branchRangeList)
+ {
+ int expectedId = branchList.get(index);
+ assertEquals(expectedId, objyBranch.getBranchId());
+ assertEquals(thisBaseBranchId, objyBranch.getBaseBranchId());
+ assertEquals(thisBaseBranchTimeStamp, objyBranch.getBaseBranchTimeStamp());
+ assertEquals("Branch_" + index, objyBranch.getBranchName());
+ index++;
+ }
+ dbStore.commit();
+ }
+
+ // Get range from 7 to end.
+ {
+ dbStore.begin();
+ List<ObjyBranch> branchRangeList = dbStore.getBranchManager().getBranches(branchList.get(7), 0);
+ assertEquals(13, branchRangeList.size());
+
+ int index = 7;
+ for (ObjyBranch objyBranch : branchRangeList)
+ {
+ int expectedId = branchList.get(index);
+ assertEquals(expectedId, objyBranch.getBranchId());
+ assertEquals(thisBaseBranchId, objyBranch.getBaseBranchId());
+ assertEquals(thisBaseBranchTimeStamp, objyBranch.getBaseBranchTimeStamp());
+ assertEquals("Branch_" + index, objyBranch.getBranchName());
+ index++;
+ }
+ dbStore.commit();
+ }
+ }
+
+ @Test
+ public void deleteBranch()
+ {
+ dbStore.begin();
+ int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ dbStore.commit();
+
+ // delete it.
+ dbStore.begin();
+ assertEquals(true, dbStore.getBranchManager().deleteBranch(branchId));
+ dbStore.commit();
+ }
+
+ @Test
+ public void createSubBranches()
+ {
+ dbStore.begin();
+ int thisBaseBranchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoB);
+ long thisBaseBranchTimeStamp = System.currentTimeMillis();
+ // using the created branch we'll create subBranches.
+ dbStore.commit();
+
+ String prefixString = "SubBranch_";
+ List<Integer> subBranchList = new ArrayList<Integer>();
+ for (int i = 0; i < 10; i++)
+ {
+ dbStore.begin();
+ BranchInfo branchInfo = new BranchInfo(prefixString + i, thisBaseBranchId, thisBaseBranchTimeStamp);
+ int id = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfo).getElement1();
+ subBranchList.add(id);
+ dbStore.commit();
+ }
+ // get sub-branches for 0.
+ List<ObjyBranch> objyBranchList = new ArrayList<ObjyBranch>();
+
+ dbStore.begin();
+ objyBranchList = dbStore.getBranchManager().getSubBranches(0);
+ assertEquals(2, objyBranchList.size());
+ dbStore.commit();
+
+ dbStore.begin();
+ objyBranchList = dbStore.getBranchManager().getSubBranches(thisBaseBranchId);
+ assertEquals(10, objyBranchList.size());
+ dbStore.commit();
+
+ }
+
+ @Test
+ public void getSubBranches()
+ {
+ dbStore.begin();
+ int thisBaseBranchId = dbStore.getBranchManager().createBranch(NEW_LOCAL_BRANCH, branchInfoA).getElement1();
+ long thisBaseBranchTimeStamp = System.currentTimeMillis();
+ // using the created branch we'll create subBranches.
+ dbStore.commit();
+
+ String prefixString = "SubBranch_";
+ List<Integer> subBranchList = new ArrayList<Integer>();
+ for (int i = 0; i < 10; i++)
+ {
+ dbStore.begin();
+ BranchInfo branchInfo = new BranchInfo(prefixString + i, thisBaseBranchId, thisBaseBranchTimeStamp);
+ int id = dbStore.getBranchManager().createBranch(NEW_LOCAL_BRANCH, branchInfo).getElement1();
+ subBranchList.add(id);
+ dbStore.commit();
+ }
+ // verify that we have sub-branches.
+ dbStore.begin();
+ int i = 0;
+ for (Integer iValue : subBranchList)
+ {
+ BranchInfo branchInfo = dbStore.getBranchManager().getBranch(iValue).getBranchInfo();
+ assertEquals(thisBaseBranchId, branchInfo.getBaseBranchID());
+ assertEquals(thisBaseBranchTimeStamp, branchInfo.getBaseTimeStamp());
+ assertEquals(prefixString + i++, branchInfo.getName());
+ }
+ dbStore.commit();
+
+ }
+
+ @Test
+ public void addRevisionsToBranch()
+ {
+ List<Temp> objectList = new ArrayList<Temp>();
+ // create 100 objects in Objy (Main Branch).
+ dbStore.begin();
+ for (int i = 0; i < 100; i++)
+ {
+ Temp tempObject = dbStore.newObject();
+ if (i % 2 == 0)
+ {
+ objectList.add(tempObject);
+ }
+ }
+ dbStore.commit();
+
+ // create a branch.
+ dbStore.begin();
+ int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ dbStore.commit();
+
+ // version what we collected in the array, and put them into a new branch.
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+
+ for (Temp tempObj : objectList)
+ {
+ tempObj.setBranch(branchId);
+ tempObj.revisionIt();
+ objyBranch.addRevision(tempObj);
+ }
+ dbStore.commit();
+ }
+ // verify that the number of revisions in a branch is the same as what
+ // we added.
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+ assertEquals(objectList.size(), objyBranch.numberOfRevisions());
+ dbStore.commit();
+ }
+ }
+
+ @Test
+ public void getRevisionsFromBranch()
+ {
+ List<Temp> objectList = new ArrayList<Temp>();
+ // create 100 objects in Objy (Main Branch).
+ dbStore.begin();
+ for (int i = 0; i < 200; i++)
+ {
+ Temp tempObject = dbStore.newObject();
+ if (i % 2 == 0)
+ {
+ objectList.add(tempObject);
+ }
+ }
+ dbStore.commit();
+
+ // create a branch.
+ dbStore.begin();
+ int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ dbStore.commit();
+
+ // version what we collected in the array, and put them into a new branch.
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+
+ for (Temp tempObj : objectList)
+ {
+ tempObj.setBranch(branchId);
+ tempObj.revisionIt();
+ objyBranch.addRevision(tempObj);
+ }
+ dbStore.commit();
+ }
+ // Get the objects from the branch.
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+ Iterator<?> itr = objyBranch.getRevisions().iterator();
+ List<Temp> actualList = new ArrayList<Temp>();
+ while (itr.hasNext())
+ {
+ Temp tempObj = (Temp)itr.next();
+ assertEquals(tempObj.getBranchId(), branchId);
+ assertEquals(true, tempObj.getRevision() > 1);
+ actualList.add(tempObj);
+ }
+ assertEquals(objectList.size(), actualList.size());
+ dbStore.commit();
+ }
+ }
+
+ @Test
+ public void deleteRevisionsFromBranch()
+ {
+ List<Temp> objectList = new ArrayList<Temp>();
+ // create 100 objects in Objy (Main Branch).
+ dbStore.begin();
+ for (int i = 0; i < 100; i++)
+ {
+ Temp tempObject = dbStore.newObject();
+ if (i % 2 == 0)
+ {
+ objectList.add(tempObject);
+ }
+ }
+ dbStore.commit();
+
+ // create a branch.
+ dbStore.begin();
+ int branchId = dbStore.getBranchManager().createBranch(NEW_BRANCH, branchInfoA).getElement1();
+ dbStore.commit();
+
+ // version what we collected in the array, and put them into a new branch.
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+
+ for (Temp tempObj : objectList)
+ {
+ tempObj.setBranch(branchId);
+ tempObj.revisionIt();
+ objyBranch.addRevision(tempObj);
+ }
+ dbStore.commit();
+ }
+ // verify that the number of revisions in a branch is the same as what
+ // we added.
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+ assertEquals(objectList.size(), objyBranch.numberOfRevisions());
+ dbStore.commit();
+ }
+
+ // delete revisions
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+ for (Temp tempObj : objectList)
+ {
+ assertEquals(true, objyBranch.deleteRevision(tempObj));
+ }
+ dbStore.commit();
+ }
+
+ // verify that the number of revisions are 0
+ {
+ dbStore.begin();
+ ObjyBranch objyBranch = dbStore.getBranchManager().getBranch(branchId);
+ assertEquals(0, objyBranch.numberOfRevisions());
+ dbStore.commit();
+ }
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void empty()
+ {
+ new ArrayList<Object>().get(0);
+ }
+
+ @After
+ public void tearDown()
+ {
+ dbStore.shutdown();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyConfig.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyConfig.java index 6c33eb2f95..1b8bd83cf1 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyConfig.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyConfig.java @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; -import org.eclipse.emf.cdo.server.IStore; -import org.eclipse.emf.cdo.server.internal.objectivity.ObjectivityStoreConfig; -import org.eclipse.emf.cdo.server.objectivity.ObjyStoreUtil; -import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig; - -/** - * @author Eike Stepper - */ -public class ObjyConfig extends RepositoryConfig -{ - public static final String STORE_NAME = "Objy"; - - private static final long serialVersionUID = 1L; - - private static ObjectivityStoreConfig storeConfig = new ObjectivityStoreConfig(); - - public ObjyConfig(boolean supportingAudits, boolean supportingBranches) - { - super(STORE_NAME, supportingAudits, supportingBranches, IDGenerationLocation.STORE); - - org.eclipse.emf.cdo.server.internal.objectivity.bundle.OM.DEBUG.setEnabled(true); - org.eclipse.emf.cdo.server.internal.objectivity.bundle.OM.INFO.setEnabled(true); - } - - @Override - protected String getStoreName() - { - return STORE_NAME; - } - - @Override - protected void deactivateRepositories() - { - super.deactivateRepositories(); - // System.out.println(">>>>IS:<<<< We need to remove all data created here...."); - storeConfig.resetFD(); - } - - public IStore createStore(String repoName) - { - // We might need to use the repoName to our advantage!!! - System.out.println("************* ObjyStore creation ****************\n"); - return ObjyStoreUtil.createStore(storeConfig); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
+import org.eclipse.emf.cdo.server.IStore;
+import org.eclipse.emf.cdo.server.internal.objectivity.ObjectivityStoreConfig;
+import org.eclipse.emf.cdo.server.objectivity.ObjyStoreUtil;
+import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig;
+
+/**
+ * @author Eike Stepper
+ */
+public class ObjyConfig extends RepositoryConfig
+{
+ public static final String STORE_NAME = "Objy";
+
+ private static final long serialVersionUID = 1L;
+
+ private static ObjectivityStoreConfig storeConfig = new ObjectivityStoreConfig();
+
+ public ObjyConfig(boolean supportingAudits, boolean supportingBranches)
+ {
+ super(STORE_NAME, supportingAudits, supportingBranches, IDGenerationLocation.STORE);
+
+ org.eclipse.emf.cdo.server.internal.objectivity.bundle.OM.DEBUG.setEnabled(true);
+ org.eclipse.emf.cdo.server.internal.objectivity.bundle.OM.INFO.setEnabled(true);
+ }
+
+ @Override
+ protected String getStoreName()
+ {
+ return STORE_NAME;
+ }
+
+ @Override
+ protected void deactivateRepositories()
+ {
+ super.deactivateRepositories();
+ // System.out.println(">>>>IS:<<<< We need to remove all data created here....");
+ storeConfig.resetFD();
+ }
+
+ public IStore createStore(String repoName)
+ {
+ // We might need to use the repoName to our advantage!!!
+ System.out.println("************* ObjyStore creation ****************\n");
+ return ObjyStoreUtil.createStore(storeConfig);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyDBConfigs.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyDBConfigs.java index 340853b81f..66be4d3682 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyDBConfigs.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyDBConfigs.java @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import org.eclipse.emf.cdo.tests.AllConfigs; -import org.eclipse.emf.cdo.tests.AuditSameSessionTest; -import org.eclipse.emf.cdo.tests.AuditTest; -import org.eclipse.emf.cdo.tests.BranchingSameSessionTest; -import org.eclipse.emf.cdo.tests.BranchingTest; -import org.eclipse.emf.cdo.tests.MergingTest; -import org.eclipse.emf.cdo.tests.XATransactionTest; -import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_252214_Test; -import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303807_Test; -import org.eclipse.emf.cdo.tests.config.IScenario; -import org.eclipse.emf.cdo.tests.config.impl.ConfigTest; - -import java.util.List; - -/** - * @author Eike Stepper - */ -public abstract class ObjyDBConfigs extends AllConfigs -{ - @Override - protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario) - { - super.initTestClasses(testClasses, scenario); - - // remove BranchingTests because most mappings do not support it - // Subclasses should add Banching tests if supported - if (!scenario.getRepositoryConfig().isSupportingBranches()) - { - testClasses.remove(BranchingTest.class); - testClasses.remove(BranchingSameSessionTest.class); - testClasses.remove(MergingTest.class); - testClasses.remove(Bugzilla_303807_Test.class); - } - - if (!scenario.getRepositoryConfig().isSupportingAudits()) - { - // non-audit mode - remove audit tests - testClasses.remove(AuditTest.class); - testClasses.remove(AuditSameSessionTest.class); - testClasses.remove(Bugzilla_252214_Test.class); - } - - // testClasses.add(DBStoreTest.class); - // testClasses.add(SQLQueryTest.class); - // testClasses.add(DBAnnotationsTest.class); - - // sometime cause a crash (Investigate!!) - testClasses.remove(XATransactionTest.class); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import org.eclipse.emf.cdo.tests.AllConfigs;
+import org.eclipse.emf.cdo.tests.AuditSameSessionTest;
+import org.eclipse.emf.cdo.tests.AuditTest;
+import org.eclipse.emf.cdo.tests.BranchingSameSessionTest;
+import org.eclipse.emf.cdo.tests.BranchingTest;
+import org.eclipse.emf.cdo.tests.MergingTest;
+import org.eclipse.emf.cdo.tests.XATransactionTest;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_252214_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303807_Test;
+import org.eclipse.emf.cdo.tests.config.IScenario;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
+
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class ObjyDBConfigs extends AllConfigs
+{
+ @Override
+ protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario)
+ {
+ super.initTestClasses(testClasses, scenario);
+
+ // remove BranchingTests because most mappings do not support it
+ // Subclasses should add Banching tests if supported
+ if (!scenario.getRepositoryConfig().isSupportingBranches())
+ {
+ testClasses.remove(BranchingTest.class);
+ testClasses.remove(BranchingSameSessionTest.class);
+ testClasses.remove(MergingTest.class);
+ testClasses.remove(Bugzilla_303807_Test.class);
+ }
+
+ if (!scenario.getRepositoryConfig().isSupportingAudits())
+ {
+ // non-audit mode - remove audit tests
+ testClasses.remove(AuditTest.class);
+ testClasses.remove(AuditSameSessionTest.class);
+ testClasses.remove(Bugzilla_252214_Test.class);
+ }
+
+ // testClasses.add(DBStoreTest.class);
+ // testClasses.add(SQLQueryTest.class);
+ // testClasses.add(DBAnnotationsTest.class);
+
+ // sometime cause a crash (Investigate!!)
+ testClasses.remove(XATransactionTest.class);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyExternalReferenceTest.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyExternalReferenceTest.java index 0dd9d32583..78a0d9e25e 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyExternalReferenceTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyExternalReferenceTest.java @@ -1,288 +1,288 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Simon McDuff - initial API and implementation - * Eike Stepper - maintenance - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import org.eclipse.emf.cdo.eresource.CDOResource; -import org.eclipse.emf.cdo.session.CDOSession; -import org.eclipse.emf.cdo.tests.AbstractCDOTest; -import org.eclipse.emf.cdo.tests.model1.PurchaseOrder; -import org.eclipse.emf.cdo.tests.model1.Supplier; -import org.eclipse.emf.cdo.tests.model4.GenRefSingleNonContained; -import org.eclipse.emf.cdo.transaction.CDOTransaction; -import org.eclipse.emf.cdo.util.DanglingReferenceException; - -import org.eclipse.net4j.util.transaction.TransactionException; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EcoreFactory; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; - -/** - * @author Simon McDuff - */ -public class ObjyExternalReferenceTest extends AbstractCDOTest -{ - final static public String REPOSITORY2_NAME = "repo2"; - - public void testExternalWithDynamicEObject() throws Exception - { - { - ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl()); - - CDOSession sessionA = openSession(); - sessionA.getPackageRegistry().putEPackage(getModel4InterfacesPackage()); - sessionA.getPackageRegistry().putEPackage(getModel4Package()); - CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet); - - CDOResource resA = transactionA1.createResource("/resA"); - Resource resD = resourceSet.createResource(URI.createURI("test://1")); - - EPackage schoolPackage = createDynamicEPackage(); - resourceSet.getPackageRegistry().put(schoolPackage.getNsURI(), schoolPackage); - - EClass eClass = (EClass)schoolPackage.getEClassifier("SchoolBook"); - EObject schoolbook = EcoreUtil.create(eClass); - - GenRefSingleNonContained objectFromResA = getModel4Factory().createGenRefSingleNonContained(); - objectFromResA.setElement(schoolbook); - resD.getContents().add(schoolbook); - - resA.getContents().add(objectFromResA); - transactionA1.commit(); - } - } - - public void testExternalWithEClass() throws Exception - { - { - ResourceSet resourceSet = new ResourceSetImpl(); - - CDOSession sessionA = openSession(); - sessionA.getPackageRegistry().putEPackage(getModel4InterfacesPackage()); - sessionA.getPackageRegistry().putEPackage(getModel4Package()); - CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet); - - CDOResource resA = transactionA1.createResource("/resA"); - GenRefSingleNonContained objectFromResA = getModel4Factory().createGenRefSingleNonContained(); - objectFromResA.setElement(getModel1Package().getAddress()); - resA.getContents().add(objectFromResA); - transactionA1.commit(); - } - - clearCache(getRepository().getRevisionManager()); - - { - CDOSession sessionA = openSession(); - ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet.getPackageRegistry().put(getModel1Package().getNsURI(), getModel1Package()); - - CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet); - CDOResource resA = transactionA1.getResource("/resA"); - - GenRefSingleNonContained objectFromResA = (GenRefSingleNonContained)resA.getContents().get(0); - assertEquals(getModel1Package().getAddress(), objectFromResA.getElement()); - transactionA1.commit(); - } - } - - public void testExternalWithEPackage() throws Exception - { - { - CDOSession sessionA = openSession(); - - ResourceSet resourceSet = new ResourceSetImpl(); - - sessionA.getPackageRegistry().putEPackage(getModel4Package()); - sessionA.getPackageRegistry().putEPackage(getModel4InterfacesPackage()); - - CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet); - CDOResource resA = transactionA1.createResource("/resA"); - GenRefSingleNonContained objectFromResA = getModel4Factory().createGenRefSingleNonContained(); - objectFromResA.setElement(getModel1Package()); - resA.getContents().add(objectFromResA); - transactionA1.commit(); - } - - clearCache(getRepository().getRevisionManager()); - { - CDOSession sessionA = openSession(); - - ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet.getPackageRegistry().put(getModel1Package().getNsURI(), getModel1Package()); - - CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet); - CDOResource resA = transactionA1.getResource("/resA"); - - GenRefSingleNonContained objectFromResA = (GenRefSingleNonContained)resA.getContents().get(0); - assertEquals(getModel1Package(), objectFromResA.getElement()); - transactionA1.commit(); - } - } - - public void testOneXMIResourceManyViewsOnOneResourceSet() throws Exception - { - return; - - /* - * byte[] dataOfresD = null; getRepository(REPOSITORY2_NAME); { CDOSession sessionA = openSession(); CDOSession - * sessionB = openSession(REPOSITORY2_NAME); ResourceSet resourceSet = new ResourceSetImpl(); - * resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl()); - * sessionA.getPackageRegistry().putEPackage(getModel1Package()); - * sessionA.getPackageRegistry().putEPackage(Model2Package.eINSTANCE); - * sessionB.getPackageRegistry().putEPackage(getModel1Package()); - * sessionB.getPackageRegistry().putEPackage(Model2Package.eINSTANCE); CDOTransaction transactionA1 = - * sessionA.openTransaction(resourceSet); CDOTransaction transactionB1 = sessionB.openTransaction(resourceSet); - * CDOResource resA = transactionA1.createResource("/resA"); CDOResource resB = - * transactionB1.createResource("/resB"); EList<Resource> resources = resourceSet.getResources(); assertEquals(4, - * resources.size()); CDOResource resC = transactionA1.createResource("/resC"); assertNotNull(resC); assertEquals(5, - * resources.size()); Resource resD = resourceSet.createResource(URI.createURI("test://1")); assertEquals(6, - * resources.size()); assertEquals(false, resD instanceof CDOResource); Company companyA = - * getModel1Factory().createCompany(); companyA.setName("VALUEA"); Company companyB = - * getModel1Factory().createCompany(); companyB.setName("VALUEB"); Company companyD = - * getModel1Factory().createCompany(); companyD.setName("VALUED"); resD.getContents().add(companyD); - * resA.getContents().add(companyA); resB.getContents().add(companyB); Supplier supplier = - * getModel1Factory().createSupplier(); PurchaseOrder purchaseOrder = getModel1Factory().createPurchaseOrder(); - * supplier.getPurchaseOrders().add(purchaseOrder); resD.getContents().add(supplier); - * resA.getContents().add(purchaseOrder); CDOXATransaction transSet = CDOUtil.createXATransaction(); - * transSet.add(CDOUtil.getViewSet(resourceSet)); transactionA1.commit(); ByteArrayOutputStream outputStream = new - * ByteArrayOutputStream(); resD.save(outputStream, null); dataOfresD = outputStream.toByteArray(); } - * clearCache(getRepository().getRevisionManager()); { ResourceSet resourceSet = new ResourceSetImpl(); CDOSession - * session = openSession(); CDOTransaction transaction = session.openTransaction(resourceSet); CDOSession session2 = - * openSession(REPOSITORY2_NAME); CDOTransaction transaction2 = session2.openTransaction(resourceSet); CDOViewSet - * set = CDOUtil.getViewSet(resourceSet); assertNotNull(set); - * resourceSet.getPackageRegistry().put(getModel1Package().getNsURI(), getModel1Package()); - * resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl()); - * Resource resD = resourceSet.createResource(URI.createURI("test://1")); resD.load(new - * ByteArrayInputStream(dataOfresD), null); CDOResource resA = transaction.getResource("/resA"); CDOResource resB = - * transaction2.getResource("/resB"); Company companyA = (Company)resA.getContents().get(0); Company companyB = - * (Company)resB.getContents().get(0); Company companyD = (Company)resD.getContents().get(0); - * assertNotSame(resA.getURI(), resB.getURI()); assertNotSame(resA.getPath(), "/resA"); - * assertNotSame(resB.getPath(), "/resB"); assertNotSame(resA.cdoView(), transaction2); - * assertNotSame(resB.cdoView(), transaction); assertEquals("VALUEA", companyA.getName()); assertEquals("VALUEB", - * companyB.getName()); assertEquals("VALUED", companyD.getName()); Supplier supplierD = - * (Supplier)resD.getContents().get(1); PurchaseOrder pO = supplierD.getPurchaseOrders().get(0); - * assertEquals(transaction, CDOUtil.getCDOObject(pO).cdoView()); assertEquals(supplierD, pO.getSupplier()); } - */ - } - - public void testManyViewsOnOneResourceSet() throws Exception - { - /* - * getRepository(REPOSITORY2_NAME); { CDOSession sessionA = openSession(); - * sessionA.getPackageRegistry().putEPackage(getModel1Package()); CDOSession sessionB = - * openSession(REPOSITORY2_NAME); ResourceSet resourceSet = new ResourceSetImpl(); CDOTransaction transactionA1 = - * sessionA.openTransaction(resourceSet); CDOTransaction transactionB1 = sessionB.openTransaction(resourceSet); - * CDOResource resA = transactionA1.createResource("/resA"); CDOResource resB = - * transactionB1.createResource("/resB"); Supplier supplier = getModel1Factory().createSupplier(); PurchaseOrder - * purchaseOrder = getModel1Factory().createPurchaseOrder(); supplier.getPurchaseOrders().add(purchaseOrder); - * resB.getContents().add(supplier); resA.getContents().add(purchaseOrder); CDOXATransaction transSet = - * CDOUtil.createXATransaction(); transSet.add(CDOUtil.getViewSet(resourceSet)); transactionA1.commit(); } - * clearCache(getRepository().getRevisionManager()); { ResourceSet resourceSet = new ResourceSetImpl(); CDOSession - * sessionA = openSession(); CDOTransaction transactionA = sessionA.openTransaction(resourceSet); CDOSession - * sessionB = openSession(REPOSITORY2_NAME); CDOTransaction transactionB = sessionB.openTransaction(resourceSet); - * CDOResource resA = transactionA.getResource("/resA"); assertNotNull(resA); CDOResource resB = - * transactionB.getResource("/resB"); assertNotNull(resB); Supplier supplierB = (Supplier)resB.getContents().get(0); - * PurchaseOrder pO = supplierB.getPurchaseOrders().get(0); assertEquals(transactionA, - * CDOUtil.getCDOObject(pO).cdoView()); assertEquals(transactionB, CDOUtil.getCDOObject(supplierB).cdoView()); - * assertEquals(supplierB, pO.getSupplier()); assertEquals(supplierB.getPurchaseOrders().get(0), pO); } - */ - } - - public void testObjectNotAttached() throws Exception - { - msg("Opening session"); - CDOSession session = openSession(); - - msg("Opening transaction"); - CDOTransaction transaction = session.openTransaction(); - - msg("Creating resource"); - CDOResource resource1 = transaction.createResource("/test1"); - - msg("Adding company"); - Supplier supplier = getModel1Factory().createSupplier(); - PurchaseOrder purchaseOrder = getModel1Factory().createPurchaseOrder(); - supplier.getPurchaseOrders().add(purchaseOrder); - - resource1.getContents().add(supplier); - - try - { - msg("Committing"); - transaction.commit(); - fail("TransactionException expected"); - } - catch (TransactionException success) - { - assertEquals(true, success.getCause() instanceof DanglingReferenceException); - assertSame(purchaseOrder, ((DanglingReferenceException)success.getCause()).getTarget()); - } - } - - public void testUsingObjectsBetweenSameTransaction() throws Exception - { - msg("Opening session"); - CDOSession session = openSession(); - - msg("Opening transaction"); - CDOTransaction transaction1 = session.openTransaction(); - CDOTransaction transaction2 = session.openTransaction(); - - msg("Creating resource"); - CDOResource resource1 = transaction1.createResource("/test1"); - CDOResource resource2 = transaction2.createResource("/test2"); - - msg("Adding company"); - Supplier supplier = getModel1Factory().createSupplier(); - PurchaseOrder purchaseOrder = getModel1Factory().createPurchaseOrder(); - supplier.getPurchaseOrders().add(purchaseOrder); - - resource1.getContents().add(supplier); - resource2.getContents().add(purchaseOrder); - - msg("Committing"); - transaction1.commit(); - } - - private EPackage createDynamicEPackage() - { - final EcoreFactory efactory = EcoreFactory.eINSTANCE; - final EcorePackage epackage = EcorePackage.eINSTANCE; - - EClass schoolBookEClass = efactory.createEClass(); - schoolBookEClass.setName("SchoolBook"); - - // create a new attribute for this EClass - EAttribute level = efactory.createEAttribute(); - level.setName("level"); - level.setEType(epackage.getEInt()); - schoolBookEClass.getEStructuralFeatures().add(level); - - // Create a new EPackage and add the new EClasses - EPackage schoolPackage = efactory.createEPackage(); - schoolPackage.setName("elv"); - schoolPackage.setNsPrefix("elv"); - schoolPackage.setNsURI("http:///www.elver.org/School"); - schoolPackage.getEClassifiers().add(schoolBookEClass); - return schoolPackage; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+import org.eclipse.emf.cdo.tests.model4.GenRefSingleNonContained;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.DanglingReferenceException;
+
+import org.eclipse.net4j.util.transaction.TransactionException;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+
+/**
+ * @author Simon McDuff
+ */
+public class ObjyExternalReferenceTest extends AbstractCDOTest
+{
+ final static public String REPOSITORY2_NAME = "repo2";
+
+ public void testExternalWithDynamicEObject() throws Exception
+ {
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl());
+
+ CDOSession sessionA = openSession();
+ sessionA.getPackageRegistry().putEPackage(getModel4InterfacesPackage());
+ sessionA.getPackageRegistry().putEPackage(getModel4Package());
+ CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet);
+
+ CDOResource resA = transactionA1.createResource("/resA");
+ Resource resD = resourceSet.createResource(URI.createURI("test://1"));
+
+ EPackage schoolPackage = createDynamicEPackage();
+ resourceSet.getPackageRegistry().put(schoolPackage.getNsURI(), schoolPackage);
+
+ EClass eClass = (EClass)schoolPackage.getEClassifier("SchoolBook");
+ EObject schoolbook = EcoreUtil.create(eClass);
+
+ GenRefSingleNonContained objectFromResA = getModel4Factory().createGenRefSingleNonContained();
+ objectFromResA.setElement(schoolbook);
+ resD.getContents().add(schoolbook);
+
+ resA.getContents().add(objectFromResA);
+ transactionA1.commit();
+ }
+ }
+
+ public void testExternalWithEClass() throws Exception
+ {
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ CDOSession sessionA = openSession();
+ sessionA.getPackageRegistry().putEPackage(getModel4InterfacesPackage());
+ sessionA.getPackageRegistry().putEPackage(getModel4Package());
+ CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet);
+
+ CDOResource resA = transactionA1.createResource("/resA");
+ GenRefSingleNonContained objectFromResA = getModel4Factory().createGenRefSingleNonContained();
+ objectFromResA.setElement(getModel1Package().getAddress());
+ resA.getContents().add(objectFromResA);
+ transactionA1.commit();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+
+ {
+ CDOSession sessionA = openSession();
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getPackageRegistry().put(getModel1Package().getNsURI(), getModel1Package());
+
+ CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet);
+ CDOResource resA = transactionA1.getResource("/resA");
+
+ GenRefSingleNonContained objectFromResA = (GenRefSingleNonContained)resA.getContents().get(0);
+ assertEquals(getModel1Package().getAddress(), objectFromResA.getElement());
+ transactionA1.commit();
+ }
+ }
+
+ public void testExternalWithEPackage() throws Exception
+ {
+ {
+ CDOSession sessionA = openSession();
+
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ sessionA.getPackageRegistry().putEPackage(getModel4Package());
+ sessionA.getPackageRegistry().putEPackage(getModel4InterfacesPackage());
+
+ CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet);
+ CDOResource resA = transactionA1.createResource("/resA");
+ GenRefSingleNonContained objectFromResA = getModel4Factory().createGenRefSingleNonContained();
+ objectFromResA.setElement(getModel1Package());
+ resA.getContents().add(objectFromResA);
+ transactionA1.commit();
+ }
+
+ clearCache(getRepository().getRevisionManager());
+ {
+ CDOSession sessionA = openSession();
+
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getPackageRegistry().put(getModel1Package().getNsURI(), getModel1Package());
+
+ CDOTransaction transactionA1 = sessionA.openTransaction(resourceSet);
+ CDOResource resA = transactionA1.getResource("/resA");
+
+ GenRefSingleNonContained objectFromResA = (GenRefSingleNonContained)resA.getContents().get(0);
+ assertEquals(getModel1Package(), objectFromResA.getElement());
+ transactionA1.commit();
+ }
+ }
+
+ public void testOneXMIResourceManyViewsOnOneResourceSet() throws Exception
+ {
+ return;
+
+ /*
+ * byte[] dataOfresD = null; getRepository(REPOSITORY2_NAME); { CDOSession sessionA = openSession(); CDOSession
+ * sessionB = openSession(REPOSITORY2_NAME); ResourceSet resourceSet = new ResourceSetImpl();
+ * resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl());
+ * sessionA.getPackageRegistry().putEPackage(getModel1Package());
+ * sessionA.getPackageRegistry().putEPackage(Model2Package.eINSTANCE);
+ * sessionB.getPackageRegistry().putEPackage(getModel1Package());
+ * sessionB.getPackageRegistry().putEPackage(Model2Package.eINSTANCE); CDOTransaction transactionA1 =
+ * sessionA.openTransaction(resourceSet); CDOTransaction transactionB1 = sessionB.openTransaction(resourceSet);
+ * CDOResource resA = transactionA1.createResource("/resA"); CDOResource resB =
+ * transactionB1.createResource("/resB"); EList<Resource> resources = resourceSet.getResources(); assertEquals(4,
+ * resources.size()); CDOResource resC = transactionA1.createResource("/resC"); assertNotNull(resC); assertEquals(5,
+ * resources.size()); Resource resD = resourceSet.createResource(URI.createURI("test://1")); assertEquals(6,
+ * resources.size()); assertEquals(false, resD instanceof CDOResource); Company companyA =
+ * getModel1Factory().createCompany(); companyA.setName("VALUEA"); Company companyB =
+ * getModel1Factory().createCompany(); companyB.setName("VALUEB"); Company companyD =
+ * getModel1Factory().createCompany(); companyD.setName("VALUED"); resD.getContents().add(companyD);
+ * resA.getContents().add(companyA); resB.getContents().add(companyB); Supplier supplier =
+ * getModel1Factory().createSupplier(); PurchaseOrder purchaseOrder = getModel1Factory().createPurchaseOrder();
+ * supplier.getPurchaseOrders().add(purchaseOrder); resD.getContents().add(supplier);
+ * resA.getContents().add(purchaseOrder); CDOXATransaction transSet = CDOUtil.createXATransaction();
+ * transSet.add(CDOUtil.getViewSet(resourceSet)); transactionA1.commit(); ByteArrayOutputStream outputStream = new
+ * ByteArrayOutputStream(); resD.save(outputStream, null); dataOfresD = outputStream.toByteArray(); }
+ * clearCache(getRepository().getRevisionManager()); { ResourceSet resourceSet = new ResourceSetImpl(); CDOSession
+ * session = openSession(); CDOTransaction transaction = session.openTransaction(resourceSet); CDOSession session2 =
+ * openSession(REPOSITORY2_NAME); CDOTransaction transaction2 = session2.openTransaction(resourceSet); CDOViewSet
+ * set = CDOUtil.getViewSet(resourceSet); assertNotNull(set);
+ * resourceSet.getPackageRegistry().put(getModel1Package().getNsURI(), getModel1Package());
+ * resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl());
+ * Resource resD = resourceSet.createResource(URI.createURI("test://1")); resD.load(new
+ * ByteArrayInputStream(dataOfresD), null); CDOResource resA = transaction.getResource("/resA"); CDOResource resB =
+ * transaction2.getResource("/resB"); Company companyA = (Company)resA.getContents().get(0); Company companyB =
+ * (Company)resB.getContents().get(0); Company companyD = (Company)resD.getContents().get(0);
+ * assertNotSame(resA.getURI(), resB.getURI()); assertNotSame(resA.getPath(), "/resA");
+ * assertNotSame(resB.getPath(), "/resB"); assertNotSame(resA.cdoView(), transaction2);
+ * assertNotSame(resB.cdoView(), transaction); assertEquals("VALUEA", companyA.getName()); assertEquals("VALUEB",
+ * companyB.getName()); assertEquals("VALUED", companyD.getName()); Supplier supplierD =
+ * (Supplier)resD.getContents().get(1); PurchaseOrder pO = supplierD.getPurchaseOrders().get(0);
+ * assertEquals(transaction, CDOUtil.getCDOObject(pO).cdoView()); assertEquals(supplierD, pO.getSupplier()); }
+ */
+ }
+
+ public void testManyViewsOnOneResourceSet() throws Exception
+ {
+ /*
+ * getRepository(REPOSITORY2_NAME); { CDOSession sessionA = openSession();
+ * sessionA.getPackageRegistry().putEPackage(getModel1Package()); CDOSession sessionB =
+ * openSession(REPOSITORY2_NAME); ResourceSet resourceSet = new ResourceSetImpl(); CDOTransaction transactionA1 =
+ * sessionA.openTransaction(resourceSet); CDOTransaction transactionB1 = sessionB.openTransaction(resourceSet);
+ * CDOResource resA = transactionA1.createResource("/resA"); CDOResource resB =
+ * transactionB1.createResource("/resB"); Supplier supplier = getModel1Factory().createSupplier(); PurchaseOrder
+ * purchaseOrder = getModel1Factory().createPurchaseOrder(); supplier.getPurchaseOrders().add(purchaseOrder);
+ * resB.getContents().add(supplier); resA.getContents().add(purchaseOrder); CDOXATransaction transSet =
+ * CDOUtil.createXATransaction(); transSet.add(CDOUtil.getViewSet(resourceSet)); transactionA1.commit(); }
+ * clearCache(getRepository().getRevisionManager()); { ResourceSet resourceSet = new ResourceSetImpl(); CDOSession
+ * sessionA = openSession(); CDOTransaction transactionA = sessionA.openTransaction(resourceSet); CDOSession
+ * sessionB = openSession(REPOSITORY2_NAME); CDOTransaction transactionB = sessionB.openTransaction(resourceSet);
+ * CDOResource resA = transactionA.getResource("/resA"); assertNotNull(resA); CDOResource resB =
+ * transactionB.getResource("/resB"); assertNotNull(resB); Supplier supplierB = (Supplier)resB.getContents().get(0);
+ * PurchaseOrder pO = supplierB.getPurchaseOrders().get(0); assertEquals(transactionA,
+ * CDOUtil.getCDOObject(pO).cdoView()); assertEquals(transactionB, CDOUtil.getCDOObject(supplierB).cdoView());
+ * assertEquals(supplierB, pO.getSupplier()); assertEquals(supplierB.getPurchaseOrders().get(0), pO); }
+ */
+ }
+
+ public void testObjectNotAttached() throws Exception
+ {
+ msg("Opening session");
+ CDOSession session = openSession();
+
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource1 = transaction.createResource("/test1");
+
+ msg("Adding company");
+ Supplier supplier = getModel1Factory().createSupplier();
+ PurchaseOrder purchaseOrder = getModel1Factory().createPurchaseOrder();
+ supplier.getPurchaseOrders().add(purchaseOrder);
+
+ resource1.getContents().add(supplier);
+
+ try
+ {
+ msg("Committing");
+ transaction.commit();
+ fail("TransactionException expected");
+ }
+ catch (TransactionException success)
+ {
+ assertEquals(true, success.getCause() instanceof DanglingReferenceException);
+ assertSame(purchaseOrder, ((DanglingReferenceException)success.getCause()).getTarget());
+ }
+ }
+
+ public void testUsingObjectsBetweenSameTransaction() throws Exception
+ {
+ msg("Opening session");
+ CDOSession session = openSession();
+
+ msg("Opening transaction");
+ CDOTransaction transaction1 = session.openTransaction();
+ CDOTransaction transaction2 = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource1 = transaction1.createResource("/test1");
+ CDOResource resource2 = transaction2.createResource("/test2");
+
+ msg("Adding company");
+ Supplier supplier = getModel1Factory().createSupplier();
+ PurchaseOrder purchaseOrder = getModel1Factory().createPurchaseOrder();
+ supplier.getPurchaseOrders().add(purchaseOrder);
+
+ resource1.getContents().add(supplier);
+ resource2.getContents().add(purchaseOrder);
+
+ msg("Committing");
+ transaction1.commit();
+ }
+
+ private EPackage createDynamicEPackage()
+ {
+ final EcoreFactory efactory = EcoreFactory.eINSTANCE;
+ final EcorePackage epackage = EcorePackage.eINSTANCE;
+
+ EClass schoolBookEClass = efactory.createEClass();
+ schoolBookEClass.setName("SchoolBook");
+
+ // create a new attribute for this EClass
+ EAttribute level = efactory.createEAttribute();
+ level.setName("level");
+ level.setEType(epackage.getEInt());
+ schoolBookEClass.getEStructuralFeatures().add(level);
+
+ // Create a new EPackage and add the new EClasses
+ EPackage schoolPackage = efactory.createEPackage();
+ schoolPackage.setName("elv");
+ schoolPackage.setNsPrefix("elv");
+ schoolPackage.setNsURI("http:///www.elver.org/School");
+ schoolPackage.getEClassifiers().add(schoolBookEClass);
+ return schoolPackage;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyStoreQueryTest.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyStoreQueryTest.java index cff894312a..3e1656fb40 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyStoreQueryTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/ObjyStoreQueryTest.java @@ -1,225 +1,225 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Simon McDuff - initial API and implementation - * Eike Stepper - maintenance - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import org.eclipse.emf.cdo.eresource.CDOResource; -import org.eclipse.emf.cdo.session.CDOSession; -import org.eclipse.emf.cdo.tests.AbstractCDOTest; -import org.eclipse.emf.cdo.tests.model1.Category; -import org.eclipse.emf.cdo.tests.model1.Company; -import org.eclipse.emf.cdo.transaction.CDOTransaction; -import org.eclipse.emf.cdo.util.CommitException; -import org.eclipse.emf.cdo.view.CDOQuery; - -import org.eclipse.emf.internal.cdo.query.CDOQueryResultIteratorImpl; - -import org.eclipse.net4j.util.collection.CloseableIterator; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * @author Simon McDuff - */ -public class ObjyStoreQueryTest extends AbstractCDOTest -{ - public void testObjyStoreBasicQuery() throws Exception - { - // skipUnlessConfig(MEM); - - Set<Object> objects = new HashSet<Object>(); - CDOSession session = openSession(); - CDOTransaction transaction = session.openTransaction(); - - CDOResource resource1 = transaction.createResource("/test1"); - objects.add(resource1); - Company company1 = getModel1Factory().createCompany(); - Category category1 = getModel1Factory().createCategory(); - - resource1.getContents().add(company1); - company1.getCategories().add(category1); - - objects.add(company1); - objects.add(category1); - objects.add(transaction.getRootResource()); - company1.setName("TEST"); - - transaction.commit(); - - CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING"); - List<Object> result = query.getResult(Object.class); - assertEquals(4, result.size()); - for (Object object : result) - { - assertEquals(true, objects.contains(object)); - } - - transaction.close(); - session.close(); - } - - public void testObjyStoreBasicQuery_EClassParameter() throws Exception - { - // skipUnlessConfig(MEM); - - Set<Object> objects = new HashSet<Object>(); - CDOSession session = openSession(); - CDOTransaction transaction = session.openTransaction(); - - CDOResource resource1 = transaction.createResource("/test1"); - objects.add(resource1); - Company company1 = getModel1Factory().createCompany(); - Category category1 = getModel1Factory().createCategory(); - - resource1.getContents().add(company1); - company1.getCategories().add(category1); - - objects.add(company1); - objects.add(category1); - - company1.setName("TEST"); - - transaction.commit(); - System.out.println(category1.eClass().getEPackage().getNsURI()); - - CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING"); - query.setParameter("context", getModel1Package().getCategory()); - - List<Category> result = query.getResult(Category.class); - assertEquals(1, result.size()); - assertEquals(category1, result.get(0)); - - transaction.close(); - session.close(); - } - - public void testObjyStoreQueryCancel_successful() throws Exception - { - // skipUnlessConfig(MEM); - - CDOTransaction transaction = initialize(500); - CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING"); - query.setParameter("sleep", 1000L); - final CloseableIterator<Object> result = query.getResultAsync(Object.class); - result.close(); - - new PollingTimeOuter() - { - @Override - protected boolean successful() - { - return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID()); - } - }.assertNoTimeOut(); - - CDOSession session = transaction.getSession(); - transaction.close(); - session.close(); - } - - public void testObjyStoreQueryCancel_ViewClose() throws Exception - { - // skipUnlessConfig(MEM); - - CDOTransaction transaction = initialize(500); - CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING"); - query.setParameter("sleep", 1000L); - final CloseableIterator<Object> result = query.getResultAsync(Object.class); - CDOSession session = transaction.getSession(); - transaction.close(); - new PollingTimeOuter() - { - @Override - protected boolean successful() - { - return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID()); - } - }.assertNoTimeOut(); - - session.close(); - } - - public void testObjyStoreQueryCancel_SessionClose() throws Exception - { - // skipUnlessConfig(MEM); - - CDOTransaction transaction = initialize(500); - CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING"); - query.setParameter("sleep", 1000L); - final CloseableIterator<Object> result = query.getResultAsync(Object.class); - transaction.getSession().close(); - - new PollingTimeOuter() - { - @Override - protected boolean successful() - { - return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID()); - } - }.assertNoTimeOut(); - } - - public void testObjyStoreQueryAsync_UnsupportedLanguage() throws Exception - { - CDOTransaction transaction = initialize(100); - CDOQuery query = transaction.createQuery("TESTss", "QUERYSTRING"); - - try - { - CloseableIterator<Object> result = query.getResultAsync(Object.class); - result.hasNext(); - fail("Should throw an exception"); - } - catch (Exception expected) - { - } - } - - public void testObjyStoreQuerySync_UnsupportedLanguage() throws Exception - { - CDOTransaction transaction = initialize(100); - CDOQuery query = transaction.createQuery("TESTss", "QUERYSTRING"); - - try - { - query.getResult(Object.class); - fail("Should throw an exception"); - } - catch (Exception expected) - { - } - } - - private CDOTransaction initialize(int number) - { - CDOSession session = openSession(); - CDOTransaction transaction = session.openTransaction(); - CDOResource resource1 = transaction.createResource("/test1"); - - for (int i = 0; i < number; i++) - { - Category category1 = getModel1Factory().createCategory(); - resource1.getContents().add(category1); - } - - try - { - transaction.commit(); - } - catch (CommitException ex) - { - ex.printStackTrace(); - } - return transaction; - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.view.CDOQuery;
+
+import org.eclipse.emf.internal.cdo.query.CDOQueryResultIteratorImpl;
+
+import org.eclipse.net4j.util.collection.CloseableIterator;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Simon McDuff
+ */
+public class ObjyStoreQueryTest extends AbstractCDOTest
+{
+ public void testObjyStoreBasicQuery() throws Exception
+ {
+ // skipUnlessConfig(MEM);
+
+ Set<Object> objects = new HashSet<Object>();
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource1 = transaction.createResource("/test1");
+ objects.add(resource1);
+ Company company1 = getModel1Factory().createCompany();
+ Category category1 = getModel1Factory().createCategory();
+
+ resource1.getContents().add(company1);
+ company1.getCategories().add(category1);
+
+ objects.add(company1);
+ objects.add(category1);
+ objects.add(transaction.getRootResource());
+ company1.setName("TEST");
+
+ transaction.commit();
+
+ CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING");
+ List<Object> result = query.getResult(Object.class);
+ assertEquals(4, result.size());
+ for (Object object : result)
+ {
+ assertEquals(true, objects.contains(object));
+ }
+
+ transaction.close();
+ session.close();
+ }
+
+ public void testObjyStoreBasicQuery_EClassParameter() throws Exception
+ {
+ // skipUnlessConfig(MEM);
+
+ Set<Object> objects = new HashSet<Object>();
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource1 = transaction.createResource("/test1");
+ objects.add(resource1);
+ Company company1 = getModel1Factory().createCompany();
+ Category category1 = getModel1Factory().createCategory();
+
+ resource1.getContents().add(company1);
+ company1.getCategories().add(category1);
+
+ objects.add(company1);
+ objects.add(category1);
+
+ company1.setName("TEST");
+
+ transaction.commit();
+ System.out.println(category1.eClass().getEPackage().getNsURI());
+
+ CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING");
+ query.setParameter("context", getModel1Package().getCategory());
+
+ List<Category> result = query.getResult(Category.class);
+ assertEquals(1, result.size());
+ assertEquals(category1, result.get(0));
+
+ transaction.close();
+ session.close();
+ }
+
+ public void testObjyStoreQueryCancel_successful() throws Exception
+ {
+ // skipUnlessConfig(MEM);
+
+ CDOTransaction transaction = initialize(500);
+ CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING");
+ query.setParameter("sleep", 1000L);
+ final CloseableIterator<Object> result = query.getResultAsync(Object.class);
+ result.close();
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID());
+ }
+ }.assertNoTimeOut();
+
+ CDOSession session = transaction.getSession();
+ transaction.close();
+ session.close();
+ }
+
+ public void testObjyStoreQueryCancel_ViewClose() throws Exception
+ {
+ // skipUnlessConfig(MEM);
+
+ CDOTransaction transaction = initialize(500);
+ CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING");
+ query.setParameter("sleep", 1000L);
+ final CloseableIterator<Object> result = query.getResultAsync(Object.class);
+ CDOSession session = transaction.getSession();
+ transaction.close();
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID());
+ }
+ }.assertNoTimeOut();
+
+ session.close();
+ }
+
+ public void testObjyStoreQueryCancel_SessionClose() throws Exception
+ {
+ // skipUnlessConfig(MEM);
+
+ CDOTransaction transaction = initialize(500);
+ CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING");
+ query.setParameter("sleep", 1000L);
+ final CloseableIterator<Object> result = query.getResultAsync(Object.class);
+ transaction.getSession().close();
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return !getRepository().getQueryManager().isRunning(((CDOQueryResultIteratorImpl<?>)result).getQueryID());
+ }
+ }.assertNoTimeOut();
+ }
+
+ public void testObjyStoreQueryAsync_UnsupportedLanguage() throws Exception
+ {
+ CDOTransaction transaction = initialize(100);
+ CDOQuery query = transaction.createQuery("TESTss", "QUERYSTRING");
+
+ try
+ {
+ CloseableIterator<Object> result = query.getResultAsync(Object.class);
+ result.hasNext();
+ fail("Should throw an exception");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testObjyStoreQuerySync_UnsupportedLanguage() throws Exception
+ {
+ CDOTransaction transaction = initialize(100);
+ CDOQuery query = transaction.createQuery("TESTss", "QUERYSTRING");
+
+ try
+ {
+ query.getResult(Object.class);
+ fail("Should throw an exception");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ private CDOTransaction initialize(int number)
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource1 = transaction.createResource("/test1");
+
+ for (int i = 0; i < number; i++)
+ {
+ Category category1 = getModel1Factory().createCategory();
+ resource1.getContents().add(category1);
+ }
+
+ try
+ {
+ transaction.commit();
+ }
+ catch (CommitException ex)
+ {
+ ex.printStackTrace();
+ }
+ return transaction;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/SampleTestsObjy.java b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/SampleTestsObjy.java index 779fcd5099..e1d8073bf7 100644 --- a/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/SampleTestsObjy.java +++ b/plugins/org.eclipse.emf.cdo.tests.objectivity/src/org/eclipse/emf/cdo/tests/objectivity/SampleTestsObjy.java @@ -1,108 +1,108 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.emf.cdo.tests.objectivity; - -import org.eclipse.emf.cdo.tests.BranchingWithCacheClearTest; -import org.eclipse.emf.cdo.tests.InitialTest; -import org.eclipse.emf.cdo.tests.MergingTest; -import org.eclipse.emf.cdo.tests.PartialCommitTest; -import org.eclipse.emf.cdo.tests.RevisionDeltaCascadingBranchesTest; -import org.eclipse.emf.cdo.tests.RevisionDeltaInBranchTest; -import org.eclipse.emf.cdo.tests.UnsetTest; -import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_261218_Test; -import org.eclipse.emf.cdo.tests.config.IScenario; -import org.eclipse.emf.cdo.tests.config.impl.ConfigTest; - -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author Eike Stepper - */ -public class SampleTestsObjy extends ObjyDBConfigs -{ - public static Test suite() - { - return new SampleTestsObjy().getTestSuite("CDO Tests (DBStoreRepositoryConfig Objectivity/DB)"); - } - - @Override - protected void initConfigSuites(TestSuite parent) - { - addScenario(parent, COMBINED, new ObjyConfig(false, false), JVM, NATIVE); - } - - @Override - protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario) - { - testClasses.clear(); - - // testClasses.add(ComplexTest.class); - testClasses.add(InitialTest.class); - testClasses.add(UnsetTest.class); - testClasses.add(BranchingWithCacheClearTest.class); - testClasses.add(MergingTest.class); - testClasses.add(PartialCommitTest.class); - testClasses.add(RevisionDeltaInBranchTest.class); - testClasses.add(RevisionDeltaCascadingBranchesTest.class); - // testClasses.add(ExternalReferenceTest.class); - - // testClasses.add(FeatureMapTest.class); - // testClasses.add(ComplexTest.class); - // testClasses.add(AttributeTest.class); - // testClasses.add(UnsetTest.class); // keep - // testClasses.add(BranchingTest.class); - // testClasses.add(BranchingSameSessionTest.class); - // testClasses.add(MergingTest.class); // keep - // testClasses.add(PushTransactionTest.class); - // testClasses.add(CommitInfoTest.class); // keep (testLogThroughClient and some others fail). - // testClasses.add(AuditTest.class); - // testClasses.add(AuditSameSessionTest.class); - // testClasses.add(ResourceTest.class); // keep - // testClasses.add(InvalidationTest.class); - // testClasses.add(ChunkingTest.class); - // testClasses.add(ChunkingWithMEMTest.class); - // testClasses.add(DetachTest.class); - // testClasses.add(ExternalReferenceTest.class); // keep - // // testClasses.add(XATransactionTest.class); - // testClasses.add(RepositoryTest.class); // keep - // testClasses.add(LockingManagerTest.class); // keep - // testClasses.add(MultiValuedOfAttributeTest.class); // keep - // testClasses.add(Bugzilla_248124_Test.class); // keep - // testClasses.add(Bugzilla_258933_Test.class); // keep - // testClasses.add(Bugzilla_259869_Test.class); // analyse?!! (long and hang for XA). - // testClasses.add(Bugzilla_259949_Test.class); - // testClasses.add(Bugzilla_272861_Test.class); - // testClasses.add(Bugzilla_279982_Test.class); - // testClasses.add(Bugzilla_298561_Test.class); - // testClasses.add(Bugzilla_302233_Test.class); - // testClasses.add(Bugzilla_303807_Test.class); - // testClasses.add(Bugzilla_306998_Test.class); - // testClasses.add(Bugzilla_308895_Test.class); - // testClasses.add(Bugzilla_314264_Test.class); - - // testClasses.add(LockingManagerTest.class); - // testClasses.add(MapTest.class); - // testClasses.add(FeatureMapTest.class); - // testClasses.add(AdapterManagerTest.class); - // testClasses.add(ConflictResolverTest.class); - // testClasses.add(DynamicXSDTest.class); - // testClasses.add(SetFeatureTest.class); - // testClasses.add(DynamicPackageTest.class); - // testClasses.add(LegacyTest.class); - // testClasses.add(Bugzilla_250757_Test.class); - // testClasses.add(Bugzilla_252909_Test.class); - // testClasses.add(Bugzilla_259949_Test.class); - testClasses.add(Bugzilla_261218_Test.class); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.objectivity;
+
+import org.eclipse.emf.cdo.tests.BranchingWithCacheClearTest;
+import org.eclipse.emf.cdo.tests.InitialTest;
+import org.eclipse.emf.cdo.tests.MergingTest;
+import org.eclipse.emf.cdo.tests.PartialCommitTest;
+import org.eclipse.emf.cdo.tests.RevisionDeltaCascadingBranchesTest;
+import org.eclipse.emf.cdo.tests.RevisionDeltaInBranchTest;
+import org.eclipse.emf.cdo.tests.UnsetTest;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_261218_Test;
+import org.eclipse.emf.cdo.tests.config.IScenario;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Eike Stepper
+ */
+public class SampleTestsObjy extends ObjyDBConfigs
+{
+ public static Test suite()
+ {
+ return new SampleTestsObjy().getTestSuite("CDO Tests (DBStoreRepositoryConfig Objectivity/DB)");
+ }
+
+ @Override
+ protected void initConfigSuites(TestSuite parent)
+ {
+ addScenario(parent, COMBINED, new ObjyConfig(false, false), JVM, NATIVE);
+ }
+
+ @Override
+ protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario)
+ {
+ testClasses.clear();
+
+ // testClasses.add(ComplexTest.class);
+ testClasses.add(InitialTest.class);
+ testClasses.add(UnsetTest.class);
+ testClasses.add(BranchingWithCacheClearTest.class);
+ testClasses.add(MergingTest.class);
+ testClasses.add(PartialCommitTest.class);
+ testClasses.add(RevisionDeltaInBranchTest.class);
+ testClasses.add(RevisionDeltaCascadingBranchesTest.class);
+ // testClasses.add(ExternalReferenceTest.class);
+
+ // testClasses.add(FeatureMapTest.class);
+ // testClasses.add(ComplexTest.class);
+ // testClasses.add(AttributeTest.class);
+ // testClasses.add(UnsetTest.class); // keep
+ // testClasses.add(BranchingTest.class);
+ // testClasses.add(BranchingSameSessionTest.class);
+ // testClasses.add(MergingTest.class); // keep
+ // testClasses.add(PushTransactionTest.class);
+ // testClasses.add(CommitInfoTest.class); // keep (testLogThroughClient and some others fail).
+ // testClasses.add(AuditTest.class);
+ // testClasses.add(AuditSameSessionTest.class);
+ // testClasses.add(ResourceTest.class); // keep
+ // testClasses.add(InvalidationTest.class);
+ // testClasses.add(ChunkingTest.class);
+ // testClasses.add(ChunkingWithMEMTest.class);
+ // testClasses.add(DetachTest.class);
+ // testClasses.add(ExternalReferenceTest.class); // keep
+ // // testClasses.add(XATransactionTest.class);
+ // testClasses.add(RepositoryTest.class); // keep
+ // testClasses.add(LockingManagerTest.class); // keep
+ // testClasses.add(MultiValuedOfAttributeTest.class); // keep
+ // testClasses.add(Bugzilla_248124_Test.class); // keep
+ // testClasses.add(Bugzilla_258933_Test.class); // keep
+ // testClasses.add(Bugzilla_259869_Test.class); // analyse?!! (long and hang for XA).
+ // testClasses.add(Bugzilla_259949_Test.class);
+ // testClasses.add(Bugzilla_272861_Test.class);
+ // testClasses.add(Bugzilla_279982_Test.class);
+ // testClasses.add(Bugzilla_298561_Test.class);
+ // testClasses.add(Bugzilla_302233_Test.class);
+ // testClasses.add(Bugzilla_303807_Test.class);
+ // testClasses.add(Bugzilla_306998_Test.class);
+ // testClasses.add(Bugzilla_308895_Test.class);
+ // testClasses.add(Bugzilla_314264_Test.class);
+
+ // testClasses.add(LockingManagerTest.class);
+ // testClasses.add(MapTest.class);
+ // testClasses.add(FeatureMapTest.class);
+ // testClasses.add(AdapterManagerTest.class);
+ // testClasses.add(ConflictResolverTest.class);
+ // testClasses.add(DynamicXSDTest.class);
+ // testClasses.add(SetFeatureTest.class);
+ // testClasses.add(DynamicPackageTest.class);
+ // testClasses.add(LegacyTest.class);
+ // testClasses.add(Bugzilla_250757_Test.class);
+ // testClasses.add(Bugzilla_252909_Test.class);
+ // testClasses.add(Bugzilla_259949_Test.class);
+ testClasses.add(Bugzilla_261218_Test.class);
+ }
+}
|