Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8f7ca121f676e0d5398552afec01deead8f6a286 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * Copyright (c) 2010-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:
 *    Pascal Lehmann - initial API and implementation
 *    Eike Stepper - maintenance
 */
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.model4.ContainedElementNoOpposite;
import org.eclipse.emf.cdo.tests.model4.MultiContainedElement;
import org.eclipse.emf.cdo.tests.model4.RefMultiContained;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOAdapterPolicy;

/**
 * NPE in TransactionCommitContext with re-attached object on branch.
 * <p>
 * See bug 324756
 * 
 * @author Pascal Lehmann
 */
public class Bugzilla_324756_Test extends AbstractCDOTest
{
  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  public void testReattachBranchVersion() throws Exception
  {
    // setup transaction.
    final CDOSession session1 = openSession();
    final CDOTransaction s1Tr1 = session1.openTransaction();
    s1Tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    // create resource, container using transaction 1.
    final CDOResource resource = s1Tr1.createResource(getResourcePath("/test1"));
    RefMultiContained container = getModel4Factory().createRefMultiContained();
    resource.getContents().add(container);

    s1Tr1.commit();

    // do a couple of changes to have the version increase.
    MultiContainedElement element1 = getModel4Factory().createMultiContainedElement();
    container.getElements().add(element1);

    s1Tr1.commit();

    container.getElements().remove(0);

    s1Tr1.commit();

    // setup another branch.
    final CDOBranch otherBranch = s1Tr1.getBranch().createBranch("other");
    final CDOTransaction s1Tr3 = session1.openTransaction(otherBranch);

    CDOResource branchResource = s1Tr3.getObject(resource);
    assertNotSame(null, branchResource);

    // detach container on branch.
    RefMultiContained otherContainer = (RefMultiContained)branchResource.getContents().remove(0);
    assertNotSame(null, otherContainer);

    // re-attach container.

    branchResource.getContents().add(otherContainer);

    s1Tr3.commit(); // <--- This will store the revision with the wrong version.

    // do a change to create a RevisionDelta with wrong version.
    MultiContainedElement element2 = getModel4Factory().createMultiContainedElement();
    otherContainer.getElements().add(element2);

    s1Tr3.commit(); // <--- This will throw the exception:
    // java.lang.NullPointerException at
    // org.eclipse.emf.cdo.internal.server.TransactionCommitContext.isContainerLocked(TransactionCommitContext.java:712)

    assertEquals(false, s1Tr3.isDirty());
  }

  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  public void testReattachBranchVersion2() throws Exception
  {
    // setup transaction.
    final CDOSession session1 = openSession();
    final CDOTransaction s1Tr1 = session1.openTransaction();
    s1Tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    // create resource, element using transaction 1.
    final CDOResource resource = s1Tr1.createResource(getResourcePath("/test1"));
    ContainedElementNoOpposite element = getModel4Factory().createContainedElementNoOpposite();
    element.setName("Version1");
    resource.getContents().add(element);

    s1Tr1.commit();

    // do a couple of changes to have the version increase.
    element.setName("Version2");

    s1Tr1.commit();

    element.setName("Version3");

    s1Tr1.commit();

    // setup another branch.
    final CDOBranch otherBranch = s1Tr1.getBranch().createBranch("other");
    final CDOTransaction s1Tr3 = session1.openTransaction(otherBranch);

    CDOResource branchResource = s1Tr3.getObject(resource);
    assertNotSame(null, branchResource);

    // detach container on branch.
    ContainedElementNoOpposite otherElement = (ContainedElementNoOpposite)branchResource.getContents().remove(0);
    assertNotSame(null, otherElement);

    // re-attach container.

    branchResource.getContents().add(otherElement);

    s1Tr3.commit(); // <--- This will store the revision with the wrong version.

    // do a change to create a RevisionDelta with wrong version.
    otherElement.setName("BranchVersion2");

    s1Tr3.commit(); // <--- This will throw the exception:
    // java.lang.IllegalStateException: Origin revision not found for
    // CDORevisionDelta[ContainedElementNoOpposite@OID2:1v4 --> [CDOFeatureDelta[name, SET, value=BranchVersion2]]]

    assertEquals(false, s1Tr3.isDirty());
  }
}

Back to the top