blob: 9da26d7430febadc6eb600d4a35502f8fa39b311 (
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
|
/*
* Copyright (c) 2014, 2015 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:
* Esteban Dugueperoux - initial API and implementation
*/
package org.eclipse.emf.cdo.tests.bugzilla;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.lock.CDOLockState;
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.cdo.util.CDOUtil;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.junit.Assert;
/**
* Bug 449665 about {@link CDOLockState} on {@link CDOResource} in {@link CDOState#PROXY} state.
*
* @author Esteban Dugueperoux
*/
public class Bugzilla_449665_Test extends AbstractCDOTest
{
private static final String RESOURCE_NAME = "test1.model1";
/**
* Test {@link CDOObject#cdoLockState()} on a simple {@link CDOObject} in {@link CDOState#PROXY} state.
*/
public void testCDOObject_GetLockState() throws Exception
{
CDOSession session1 = openSession();
CDOTransaction transaction1 = session1.openTransaction();
CDOResource resource1 = transaction1.createResource(getResourcePath(RESOURCE_NAME));
Company company = getModel1Factory().createCompany();
resource1.getContents().add(company);
transaction1.commit();
CDOSession session2 = openSession();
CDOTransaction transaction2 = session2.openTransaction();
transaction2.getResourceSet().eAdapters().add(new EContentAdapterQueringCDOLockState());
CDOResource resource2 = transaction2.getResource(getResourcePath(RESOURCE_NAME));
// Make company in CDOState.PROXY by remote change
company.setName("oneChange");
resource1.getContents().add(getModel1Factory().createCategory());
commitAndSync(transaction1, transaction2);
company = (Company)resource2.getContents().get(0);
CDOObject companyCDOObject = CDOUtil.getCDOObject(company);
CDOLockState lockState = companyCDOObject.cdoLockState();
Object expectedLockedObject = companyCDOObject.cdoID();
if (session1.getRepositoryInfo().isSupportingBranches())
{
expectedLockedObject = CDOIDUtil.createIDAndBranch(companyCDOObject.cdoID(), transaction2.getBranch());
}
assertEquals(expectedLockedObject, lockState.getLockedObject());
Assert.assertTrue(lockState.getReadLockOwners().isEmpty());
assertNull(lockState.getWriteLockOwner());
assertNull(lockState.getWriteOptionOwner());
}
/**
* Test {@link CDOObject#cdoLockState()} on a {@link CDOResource} in {@link CDOState#PROXY} state.
*/
public void testCDOResource_GetLockState() throws Exception
{
CDOSession session1 = openSession();
CDOTransaction transaction1 = session1.openTransaction();
CDOResource resource1 = transaction1.createResource(getResourcePath(RESOURCE_NAME));
transaction1.commit();
CDOSession session2 = openSession();
CDOTransaction transaction2 = session2.openTransaction();
transaction2.getResourceSet().eAdapters().add(new EContentAdapterQueringCDOLockState());
CDOResource resource2 = transaction2.getResource(getResourcePath(RESOURCE_NAME));
// Make CDOResouce in CDOState.PROXY by remote change
resource1.getContents().add(getModel1Factory().createCategory());
commitAndSync(transaction1, transaction2);
CDOLockState lockState = resource2.cdoLockState();
Object expectedLockedObject = resource2.cdoID();
if (session1.getRepositoryInfo().isSupportingBranches())
{
expectedLockedObject = CDOIDUtil.createIDAndBranch(resource2.cdoID(), transaction2.getBranch());
}
assertEquals(expectedLockedObject, lockState.getLockedObject());
Assert.assertTrue(lockState.getReadLockOwners().isEmpty());
assertNull(lockState.getWriteLockOwner());
assertNull(lockState.getWriteOptionOwner());
}
/**
* A {@link EContentAdapter} to get {@link CDOLockState} for each loaded object.
*/
private static class EContentAdapterQueringCDOLockState extends EContentAdapter
{
@Override
protected void addAdapter(Notifier notifier)
{
if (notifier instanceof EObject)
{
EObject eObject = (EObject)notifier;
CDOObject cdoObject = CDOUtil.getCDOObject(eObject);
if (cdoObject != null)
{
cdoObject.cdoLockState();
}
}
super.addAdapter(notifier);
}
}
}
|