Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0ba3cded30b444b8c11d064b5f11feb4f6acbb91 (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
/*
 * Copyright (c) 2016 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.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
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.Category;
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.internal.cdo.view.CDOViewImpl.OptionsImpl;

import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import org.junit.Assert;

import java.util.Collections;

/**
 * Bug 467174 to test lock state and revision prefetch.
 *
 * @author Esteban Dugueperoux
 */
public class Bugzilla_467174_Test extends AbstractCDOTest
{
  public void testCDOObject_LockStateAndRevisionPrefetch() throws Exception
  {
    CDOSession session1 = openSession();
    CDOTransaction transaction1 = session1.openTransaction();

    OptionsImpl options = (OptionsImpl)transaction1.options();
    options.setLockNotificationEnabled(true);
    options.setLockStatePrefetchEnabled(true);

    CDOResource resource1 = transaction1.createResource(getResourcePath("test1.model1"));
    Company company = getModel1Factory().createCompany();
    Category category = getModel1Factory().createCategory();
    company.getCategories().add(category);
    resource1.getContents().add(company);
    resource1.save(Collections.emptyMap());

    CDOObject companyCDOObject = CDOUtil.getCDOObject(company);
    CDOID companyCDOID = companyCDOObject.cdoID();
    CDOObject categoryCDOObject = CDOUtil.getCDOObject(category);
    CDOID categoryCDOID = categoryCDOObject.cdoID();

    CDOSession session2 = openSession();
    ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.eAdapters().add(new AdapterImpl()
    {
      @Override
      public void notifyChanged(Notification msg)
      {
        Object newValue = msg.getNewValue();
        if (newValue instanceof CDOResource)
        {
          ((CDOResource)newValue).cdoPrefetch(CDORevision.DEPTH_INFINITE);
        }
      }
    });

    CDOTransaction transaction2 = session2.openTransaction(resourceSet);
    transaction2.options().setLockNotificationEnabled(true);
    ((OptionsImpl)transaction2.options()).setLockStatePrefetchEnabled(true);

    transaction1.lockObjects(Collections.singletonList(categoryCDOObject), LockType.WRITE, 1);
    transaction1.lockObjects(Collections.singletonList(companyCDOObject), LockType.WRITE, 1);

    CDOObject companyCDOObjectFromTx2 = transaction2.getObject(companyCDOID);
    CDOObject categoryCDOObjectFromTx2 = transaction2.getObject(categoryCDOID);
    Assert.assertTrue(companyCDOObjectFromTx2.cdoWriteLock().isLockedByOthers());
    Assert.assertTrue(categoryCDOObjectFromTx2.cdoWriteLock().isLockedByOthers());
  }
}

Back to the top