Skip to main content
summaryrefslogtreecommitdiffstats
blob: e05474a83b8fe8bc055d7013cd5dfa6f47cd89f6 (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
/*
 * Copyright (c) 2011, 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.offline;

import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
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.session.CDOSession;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.tests.AbstractSyncingTest;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Customer;
import org.eclipse.emf.cdo.transaction.CDOMerger.ConflictException;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;

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

/**
 * Revision not revised on rawImport for deleted objects.
 * <p>
 * See bug 326047
 *
 * @author Pascal Lehmann
 * @since 4.0
 */
public class Bugzilla_326047_Test extends AbstractSyncingTest
{
  public void test() throws Exception
  {
    InternalRepository clone = getRepository();
    waitForOnline(clone);

    CDOSession masterSession = openSession("master");
    CDOTransaction masterTransaction = masterSession.openTransaction();

    CDOSession session = openSession();

    // Doing this that client notifications are built upon RevisionDeltas instead of RevisionKeys.
    session.options().setPassiveUpdateMode(PassiveUpdateMode.CHANGES);

    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));

    Company company = getModel1Factory().createCompany();
    Customer customer = getModel1Factory().createCustomer();
    company.getCustomers().add(customer);
    resource.getContents().add(company);
    transaction.setCommitComment("resource with one company created on clone");
    transaction.commit();

    // setup another branch.
    final CDOBranch otherBranch = transaction.getBranch().createBranch("other");
    final CDOTransaction otherTransaction = session.openTransaction(otherBranch);

    Customer branchCustomer = otherTransaction.getObject(customer);
    assertNotSame(null, branchCustomer);

    getOfflineConfig().stopMasterTransport();
    waitForOffline(clone);

    // change the name of the customer on branch offline.
    branchCustomer.setName("branch-offline");
    otherTransaction.commit();

    // delete the customer on the online transaction.
    Company masterCompany = (Company)masterTransaction.getObject(CDOUtil.getCDOObject(company).cdoID());
    masterCompany.getCustomers().remove(0);
    masterTransaction.commit();

    // go online again.
    getOfflineConfig().startMasterTransport();
    waitForOnline(clone);

    Exception exception = null;

    try
    {
      // merge branch.
      CDOBranchPoint source = otherTransaction.getBranch().getHead();
      DefaultCDOMerger.PerFeature.ManyValued merger = new DefaultCDOMerger.PerFeature.ManyValued();
      transaction.merge(source, merger); // <-- this merge should generate a conflict.
      transaction.commit(); // <-- commit will fail, because no conflict thrown.
    }
    catch (Exception e)
    {
      exception = e;
    }

    assertInstanceOf(ConflictException.class, exception);
  }
}

Back to the top