Skip to main content
summaryrefslogtreecommitdiffstats
blob: 58384897bc9484573145d72d1d8172e3ed676130 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * 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.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.server.IRepository;
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.RepositoryConfig;
import org.eclipse.emf.cdo.tests.model4.GenRefMultiContained;
import org.eclipse.emf.cdo.transaction.CDOMerger;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOAdapterPolicy;

import org.eclipse.emf.spi.cdo.DefaultCDOMerger;

import java.util.Map;

/**
 * IllegalStateException when committing a reattached containment of a detached container after branch merge with XRef
 * enabled.
 * <p>
 * See bug 325866
 *
 * @author Pascal Lehmann
 */
public class Bugzilla_325866_Test extends AbstractCDOTest
{
  @Override
  public synchronized Map<String, Object> getTestProperties()
  {
    Map<String, Object> map = super.getTestProperties();
    map.put(IRepository.Props.ENSURE_REFERENTIAL_INTEGRITY, "true");
    return map;
  }

  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  @CleanRepositoriesBefore
  public void testXRefReattachBranch() throws Exception
  {
    skipStoreWithoutQueryXRefs();

    // setup transaction.
    final CDOSession session1 = openSession();
    final CDOTransaction s1Tr1 = session1.openTransaction();
    s1Tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    // create resource, and container tree using transaction 1.
    final CDOResource resource = s1Tr1.createResource(getResourcePath("/test1"));
    GenRefMultiContained container1 = getModel4Factory().createGenRefMultiContained();
    GenRefMultiContained container2 = getModel4Factory().createGenRefMultiContained();
    GenRefMultiContained container3 = getModel4Factory().createGenRefMultiContained();
    resource.getContents().add(container1);
    container1.getElements().add(container2);
    container2.getElements().add(container3);

    s1Tr1.commit();
    sleep(1000L);

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

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

    GenRefMultiContained otherContainer1 = (GenRefMultiContained)branchResource.getContents().get(0);
    assertNotSame(null, otherContainer1);

    GenRefMultiContained otherContainer2 = (GenRefMultiContained)otherContainer1.getElements().get(0);
    assertNotSame(null, otherContainer2);

    GenRefMultiContained otherContainer3 = (GenRefMultiContained)otherContainer2.getElements().get(0);
    assertNotSame(null, otherContainer3);

    // detach the middle container on branch.
    otherContainer1.getElements().remove(otherContainer2);

    // re-attach detached's child container.
    otherContainer1.getElements().add(otherContainer3);

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

    // merge the other branch to main.
    sleep(1000L);
    s1Tr1.merge(s1Tr3.getBranch().getHead(), new DefaultCDOMerger.PerFeature.ManyValued());

    s1Tr1.commit();
    assertEquals(false, s1Tr1.isDirty());
  }

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

    // create resource, and container tree using transaction 1.
    final CDOResource resource = s1Tr1.createResource(getResourcePath("/test1"));
    GenRefMultiContained container1 = getModel4Factory().createGenRefMultiContained();
    GenRefMultiContained container2 = getModel4Factory().createGenRefMultiContained();
    GenRefMultiContained container3 = getModel4Factory().createGenRefMultiContained();
    GenRefMultiContained container4 = getModel4Factory().createGenRefMultiContained();
    GenRefMultiContained container5 = getModel4Factory().createGenRefMultiContained();
    resource.getContents().add(container1);
    resource.getContents().add(container2);
    resource.getContents().add(container3);
    container1.getElements().add(container4);
    container4.getElements().add(container5);

    s1Tr1.commit();
    sleep(1000L);

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

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

    GenRefMultiContained otherContainer1 = (GenRefMultiContained)branchResource.getContents().get(0);
    assertNotSame(null, otherContainer1);
    GenRefMultiContained otherContainer2 = (GenRefMultiContained)branchResource.getContents().get(1);
    assertNotSame(null, otherContainer2);
    GenRefMultiContained otherContainer3 = (GenRefMultiContained)branchResource.getContents().get(2);
    assertNotSame(null, otherContainer3);
    GenRefMultiContained otherContainer4 = (GenRefMultiContained)otherContainer1.getElements().get(0);
    assertNotSame(null, otherContainer4);
    GenRefMultiContained otherContainer5 = (GenRefMultiContained)otherContainer4.getElements().get(0);
    assertNotSame(null, otherContainer5);

    // detach the container1 on branch.
    branchResource.getContents().remove(otherContainer1);

    // re-attach container1 child.
    otherContainer2.getElements().add(otherContainer4);

    // re-attach container1 child.
    otherContainer3.getElements().add(otherContainer5);

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

    sleep(1000L);

    // merge the other branch to main.
    CDOBranchPoint head = s1Tr3.getBranch().getHead();
    CDOMerger merger = new DefaultCDOMerger.PerFeature.ManyValued();
    s1Tr1.merge(head, merger);

    s1Tr1.commit();
    assertEquals(false, s1Tr1.isDirty());
  }
}

Back to the top