Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_370105_Test.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java90
3 files changed, 104 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java
index 8a638b5135..2073ef2d14 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java
@@ -182,13 +182,7 @@ public class CDOBranchImpl extends Container<CDOBranch> implements InternalCDOBr
if (branches == null && loadOnDemand)
{
- SubBranchInfo[] infos = branchManager.getBranchLoader().loadSubBranches(id);
- branches = new InternalCDOBranch[infos.length];
- for (int i = 0; i < infos.length; i++)
- {
- SubBranchInfo info = infos[i];
- branches[i] = branchManager.getBranch(info.getID(), info.getName(), this, info.getBaseTimeStamp());
- }
+ loadBranches();
}
return branches;
@@ -281,7 +275,7 @@ public class CDOBranchImpl extends Container<CDOBranch> implements InternalCDOBr
{
if (branches == null)
{
- branches = new InternalCDOBranch[] { branch };
+ loadBranches();
}
else
{
@@ -333,6 +327,17 @@ public class CDOBranchImpl extends Container<CDOBranch> implements InternalCDOBr
base = baseBranch.getPoint(branchInfo.getBaseTimeStamp());
}
+ private synchronized void loadBranches()
+ {
+ SubBranchInfo[] infos = branchManager.getBranchLoader().loadSubBranches(id);
+ branches = new InternalCDOBranch[infos.length];
+ for (int i = 0; i < infos.length; i++)
+ {
+ SubBranchInfo info = infos[i];
+ branches[i] = branchManager.getBranch(info.getID(), info.getName(), this, info.getBaseTimeStamp());
+ }
+ }
+
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_370105_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_370105_Test.java
index c1d0547dd4..a125d43b7a 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_370105_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_370105_Test.java
@@ -29,6 +29,7 @@ import org.eclipse.emf.common.util.EList;
public class Bugzilla_370105_Test extends AbstractCDOTest
{
@Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
+ @CleanRepositoriesBefore(reason = "to not be disturb by branches created by other tests")
public void testInsertInListOf5thSubBranch() throws Throwable
{
Company company = initModel();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java
new file mode 100644
index 0000000000..f1341c87de
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447912_Test.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2004-2014 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:
+ * Esteban Dugueperoux - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.branch.CDOBranchChangedEvent;
+import org.eclipse.emf.cdo.common.branch.CDOBranchChangedEvent.ChangeKind;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+
+/**
+ * Test that when another client creates a branch, and we call {@link CDOBranch#getBranches()} for the first time, it calls all existing branches.
+ *
+ * @author Esteban Dugueperoux
+ */
+@Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
+@CleanRepositoriesBefore(reason = "to have assert works")
+public class Bugzilla_447912_Test extends AbstractCDOTest
+{
+
+ private NewBranchNotificationListener newBranchNotificationListener;
+
+ public void testCDOBranch_getBranches() throws Exception
+ {
+ CDOSession session1 = openSession();
+ CDOView view1 = session1.openView();
+ CDOBranch mainBranchFromView1 = view1.getBranch();
+ String branchB1Name = "b1";
+ String branchB2Name = "b2";
+ mainBranchFromView1.createBranch(branchB1Name);
+
+ CDOSession session2 = openSession();
+ CDOView view2 = session2.openView();
+ CDOBranch mainBranchFromView2 = view2.getBranch();
+
+ newBranchNotificationListener = new NewBranchNotificationListener(session2);
+ synchronized (newBranchNotificationListener)
+ {
+ mainBranchFromView1.createBranch(branchB2Name);
+ newBranchNotificationListener.wait();
+ }
+
+ assertEquals(mainBranchFromView1.getBranches().length, mainBranchFromView2.getBranches().length);
+ assertEquals(session1.getBranchManager().getMainBranch().getBranches().length, session2.getBranchManager()
+ .getMainBranch().getBranches().length);
+ assertEquals(2, mainBranchFromView1.getBranches().length);
+ assertEquals(mainBranchFromView1.getBranches()[0].getID(), mainBranchFromView2.getBranches()[0].getID());
+ assertEquals(mainBranchFromView1.getBranches()[1].getID(), mainBranchFromView2.getBranches()[1].getID());
+ assertEquals(mainBranchFromView1.getBranches()[0].getName(), mainBranchFromView2.getBranches()[0].getName());
+ assertEquals(mainBranchFromView1.getBranches()[1].getName(), mainBranchFromView2.getBranches()[1].getName());
+ assertEquals(branchB1Name, mainBranchFromView2.getBranches()[0].getName());
+ assertEquals(branchB2Name, mainBranchFromView2.getBranches()[1].getName());
+ }
+
+ class NewBranchNotificationListener implements IListener
+ {
+ public NewBranchNotificationListener(CDOSession session)
+ {
+ session.getBranchManager().addListener(this);
+ }
+
+ public synchronized void notifyEvent(IEvent event)
+ {
+ if (event instanceof CDOBranchChangedEvent)
+ {
+ CDOBranchChangedEvent branchChangedEvent = (CDOBranchChangedEvent)event;
+ if (branchChangedEvent.getChangeKind() == ChangeKind.CREATED)
+ {
+ notify();
+ }
+ }
+ }
+ }
+
+}

Back to the top