Skip to main content
summaryrefslogtreecommitdiffstats
blob: ee030fa7fdd6eedcd4f85a18952a5465a7781d7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * 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.eresource.CDOResource;
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.Requires;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;

/**
 * Test calling to {@link CDOTransaction#setBranch(CDOBranch)} twice. It causes "IllegalStateException : Already in cache".
 *
 * @author Esteban Dugueperoux
 */
@Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
public class Bugzilla_447593_Test extends AbstractCDOTest
{

  public void testTwiceCDOTransactionSetBranch() throws Exception
  {
    CDOSession session = openSession();

    CDOTransaction transaction = session.openTransaction();
    String resourcePath = getResourcePath("test1.model1");
    CDOResource resource = transaction.createResource(resourcePath);
    Category category = getModel1Factory().createCategory();
    category.setName("categoryFromMainBranch");
    resource.getContents().add(category);
    transaction.commit();

    CDOBranch mainBranch = session.getBranchManager().getMainBranch();
    CDOBranch b1ParentBranch = mainBranch.createBranch("b1Parent");
    CDOBranch b1 = b1ParentBranch.createBranch("b1");

    transaction.enableDurableLocking();
    CDOUtil.getCDOObject(category).cdoWriteLock().lock();
    transaction.setBranch(b1);
    resource = transaction.getResource(resourcePath);
    category = (Category)resource.getContents().get(0);
    category.setName("categoryFromB1Branch");
    resource.getContents().add(getModel1Factory().createCategory());
    transaction.commit();

    CDOBranch b11 = b1.createBranch("b11");

    CDOUtil.getCDOObject(category).cdoWriteLock().lock();
    transaction.setBranch(b11);
    resource = transaction.getResource(resourcePath);
    category = (Category)resource.getContents().get(0);
    category.setName("categoryFromB11Branch");
    resource.getContents().add(getModel1Factory().createCategory());
    transaction.commit();
  }

}

Back to the top