Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c02837030badba80a01cb1188421e50cb797d0f3 (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
/*
 * Copyright (c) 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.common.CDOCommonSession.Options.PassiveUpdateMode;
import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.internal.net4j.protocol.ChangeSubscriptionRequest;
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.tests.util.RequestCallCounter;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

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

/**
 * Bug 458279 about {@link CDOMergingConflictResolver} without {@link ChangeSubscriptionRequest} sent to the server.
 *
 * @author Esteban Dugueperoux
 */
public class Bugzilla_458279_Test extends AbstractCDOTest
{
  private static final String RESOURCE_NAME = "test1.model1";

  /**
   * Test {@link CDOMergingConflictResolver} without {@link ChangeSubscriptionRequest} sent to the server and using {@link PassiveUpdateMode#ADDITIONS}.
   */
  public void testCDOMergingConflictResolverWithoutChangeSubscriptionRequestWithAdditionsPassiveUpdateMode()
      throws Exception
  {
    testCDOMergingConflictResolverWithoutChangeSubscriptionRequest(PassiveUpdateMode.ADDITIONS);
  }

  /**
   * Test {@link CDOMergingConflictResolver} without {@link ChangeSubscriptionRequest} sent to the server and using {@link PassiveUpdateMode#ADDITIONS}.
   */
  public void testCDOMergingConflictResolverWithoutChangeSubscriptionRequestWithChangesPassiveUpdateMode()
      throws Exception
  {
    testCDOMergingConflictResolverWithoutChangeSubscriptionRequest(PassiveUpdateMode.CHANGES);
  }

  /**
   * Test {@link CDOMergingConflictResolver} without {@link ChangeSubscriptionRequest} sent to the server and using {@link PassiveUpdateMode#INVALIDATIONS}.
   */
  public void testCDOMergingConflictResolverWithoutChangeSubscriptionRequestWithInvalidationsPassiveUpdateMode()
      throws Exception
  {
    testCDOMergingConflictResolverWithoutChangeSubscriptionRequest(PassiveUpdateMode.INVALIDATIONS);
  }

  private void testCDOMergingConflictResolverWithoutChangeSubscriptionRequest(PassiveUpdateMode mode) throws Exception
  {
    CDOSession session1 = openSession();
    RequestCallCounter requestCallCounter = new RequestCallCounter(session1);
    requestCallCounter.getNBRequestsCalls().put(CDOProtocolConstants.SIGNAL_CHANGE_SUBSCRIPTION, 0);

    session1.options().setPassiveUpdateMode(mode);
    CDOTransaction transaction1 = session1.openTransaction();
    transaction1.options().addConflictResolver(new CDOMergingConflictResolver(false));
    CDOResource resource1 = transaction1.createResource(getResourcePath(RESOURCE_NAME));
    Company company = getModel1Factory().createCompany();
    resource1.getContents().add(company);
    transaction1.commit();

    company.getCategories().add(getModel1Factory().createCategory());

    CDOSession session2 = openSession();
    CDOTransaction transaction2 = session2.openTransaction();
    CDOResource resource2 = transaction2.getResource(getResourcePath(RESOURCE_NAME));
    Company companyFromSession2 = (Company)resource2.getContents().get(0);
    companyFromSession2.getCategories().add(getModel1Factory().createCategory());
    commitAndSync(transaction2, transaction1);

    assertEquals(mode == PassiveUpdateMode.INVALIDATIONS ? 1 : 2, company.getCategories().size());
    int nbCallToChangeSubscriptionRequest = requestCallCounter.getNBRequestsCalls().get(
        CDOProtocolConstants.SIGNAL_CHANGE_SUBSCRIPTION);
    assertEquals("No ChangeSubscriptionRequest should be send to server", 0, nbCallToChangeSubscriptionRequest);
  }
}

Back to the top