Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e1ea1d9d60fdf47e122fe3d857f5e005dc20b823 (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
/**
 * Copyright (c) 2004 - 2011 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:
 *    Simon McDuff - 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.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

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

/**
 * @author Simon McDuff
 */
public class Bugzilla_273233_Test extends AbstractCDOTest
{
  public void test_Bugzilla_273233_Simple() throws Exception
  {
    CDOSession session = openSession();
    session.options().setPassiveUpdateEnabled(false);

    CDOTransaction trans = session.openTransaction();
    CDOResource res = trans.createResource(getResourcePath("/test/1"));

    trans.commit();
    Company company = getModel1Factory().createCompany();
    res.getContents().add(company);
    session.refresh();
    trans.commit();
    trans.close();
    session.close();
  }

  public void test_Bugzilla_273233_TwoSessions() throws Exception
  {
    CDOSession session = openSession();
    session.options().setPassiveUpdateEnabled(false);

    CDOTransaction trans = session.openTransaction();
    CDOResource res = trans.createResource(getResourcePath("/test/1"));

    trans.commit();

    CDOSession session2 = openSession();
    session2.options().setPassiveUpdateEnabled(false);
    CDOTransaction trans2 = session2.openTransaction();
    CDOResource res2 = trans2.getResource(getResourcePath("/test/1"));

    // Add company in sess/tx #1
    Company company = getModel1Factory().createCompany();
    res.getContents().add(company);

    // Add company in sess/tx #2
    Company company2 = getModel1Factory().createCompany();
    res2.getContents().add(company2);

    // Commit tx #1
    trans.commit();

    assertEquals(false, FSMUtil.isConflict(res2));

    session2.refresh();
    assertEquals(true, FSMUtil.isConflict(res2));

    try
    {
      trans2.commit();
      fail("Should have a conflict exception");
    }
    catch (Exception ex)
    {
      //
    }

    trans.close();
    session.close();
  }

  public void test_Bugzilla_273233_TwoSessionsWithClearCache() throws Exception
  {
    CDOSession session = openSession();
    session.options().setPassiveUpdateEnabled(false);

    CDOTransaction trans = session.openTransaction();
    CDOResource res = trans.createResource(getResourcePath("/test/1"));

    trans.commit();

    CDOSession session2 = openSession();
    session2.options().setPassiveUpdateEnabled(false);
    CDOTransaction trans2 = session2.openTransaction();
    CDOResource res2 = trans2.getResource(getResourcePath("/test/1"));

    // Add company in sess/tx #1
    Company company = getModel1Factory().createCompany();
    res.getContents().add(company);

    // Add company in sess/tx #2
    Company company2 = getModel1Factory().createCompany();
    res2.getContents().add(company2);

    // Commit tx #1
    trans.commit();

    clearCache(session2.getRevisionManager());
    assertEquals(false, FSMUtil.isConflict(res2));

    session2.refresh();
    assertEquals(true, FSMUtil.isConflict(res2));

    try
    {
      trans2.commit();
      fail("Should have a conflict exception");
    }
    catch (Exception ex)
    {
      //
    }

    trans.close();
    session.close();
  }
}

Back to the top