Skip to main content
summaryrefslogtreecommitdiffstats
blob: 887864c5d55527b9b258703e8e1002ab4ea9437a (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
/*
 * Copyright (c) 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:
 *    Caspar De Groot - initial API and implementation
 */

package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CommitException;

/**
 * Bug 315026: Local rollback inadvertently brings in updates from other sessions
 *
 * @author Caspar De Groot
 */
public class Bugzilla_315026_Test extends AbstractCDOTest
{
  private final static String ORIGINAL_NAME = "AAA";

  private final static String DIRTY_NAME = "BBB";

  private final static String OTHER_NAME = "CCC";

  public void test() throws Exception
  {
    CDOSession session = openSession();
    session.options().setPassiveUpdateEnabled(false);
    CDOTransaction tx = session.openTransaction();
    CDOResource r1 = tx.createResource(getResourcePath("/r1")); //$NON-NLS-1$

    // Create clean content
    Company company = Model1Factory.eINSTANCE.createCompany();
    company.setName(ORIGINAL_NAME);
    r1.getContents().add(company);
    tx.commit();

    // Make it dirty in this session
    company.setName(DIRTY_NAME);

    // Update and commit in another session
    doSecondSession();

    // Rollback this session
    tx.rollback();

    // Clear this session's revision cache
    ((InternalCDORevisionManager)session.getRevisionManager()).getCache().clear();

    // Verify that value in this session does *not* match value assigned in 2nd session
    String name = company.getName();
    assertEquals("Should not have the value committed by the other session", false, OTHER_NAME.equals(name));

    // Verify that value in this session still matches value assigned in this session
    assertEquals("Should have the value originally loaded in this session", ORIGINAL_NAME, name);
  }

  private void doSecondSession() throws CommitException
  {
    CDOSession session = openSession();
    CDOTransaction tx = session.openTransaction();
    CDOResource r1 = tx.getResource(getResourcePath("/r1")); //$NON-NLS-1$

    Company company = (Company)r1.getContents().get(0);
    company.setName(OTHER_NAME);
    tx.commit();

    tx.close();
    session.close();
  }
}

Back to the top