Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 146c82d9b9fdd52a90886dd84b13e7241f00d28a (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Copyright (c) 2011-2013 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:
 *    Pascal Lehmann - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.offline;

import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.tests.AbstractSyncingTest;
import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Product1;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.trace.PrintTraceHandler;

import java.text.MessageFormat;

/**
 * CommitNotifications overtaking each other.
 * <p>
 * See bug 328352
 *
 * @author Pascal Lehmann
 * @since 4.0
 */
public class Bugzilla_328352_Test extends AbstractSyncingTest
{
  private final int NUM_PRODUCTS = 200;

  private final int NUM_CLIENT_VIEWS = 10;

  @Requires(IRepositoryConfig.CAPABILITY_OFFLINE)
  @Skips("DB.ranges")
  // Too slow in DB.ranges (11 minutes), see bug 357441
  public void testOfflineCloneSynchronization() throws Exception
  {
    disableConsole();

    // create an offline clone.
    InternalRepository clone = getRepository();
    waitForOnline(clone);

    // create master session & transaction.
    InternalRepository master = getRepository("master");
    CDOSession masterSession = openSession(master.getName());
    CDOTransaction masterTransaction = masterSession.openTransaction();

    // create client session & transaction.
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();

    // doing this that client notifications are built upon RevisionDeltas instead of RevisionKeys.
    session.options().setPassiveUpdateMode(PassiveUpdateMode.CHANGES);

    // create additional client sessions.
    CDOView[] cloneViews = new CDOView[NUM_CLIENT_VIEWS + 1];
    for (int i = 0; i < NUM_CLIENT_VIEWS; i++)
    {
      CDOView view = session.openView();
      cloneViews[i] = view;
    }

    cloneViews[NUM_CLIENT_VIEWS] = transaction;

    // create resource and base model.
    CDOResource resource = masterTransaction.createResource(getResourcePath("/my/resource"));
    Company company = getModel1Factory().createCompany();
    Category catA = getModel1Factory().createCategory();
    catA.setName("CatA");
    company.getCategories().add(catA);
    Category catB = getModel1Factory().createCategory();
    catB.setName("CatB");
    company.getCategories().add(catB);
    resource.getContents().add(company);

    for (int i = 0; i < NUM_PRODUCTS; i++)
    {
      Product1 product = getModel1Factory().createProduct1();
      product.setName("Product" + i);
      catA.getProducts().add(product);
    }

    masterTransaction.commit();
    transaction.waitForUpdate(masterTransaction.getLastCommitTime(), 1000);

    // touch the objects on the views to actually receive updates.
    for (CDOView view : cloneViews)
    {
      Category vCatA = (Category)view.getObject(CDOUtil.getCDOObject(catA).cdoID());
      Category vCatB = (Category)view.getObject(CDOUtil.getCDOObject(catB).cdoID());
      vCatB.getName();
      for (Product1 vProduct : vCatA.getProducts())
      {
        vProduct.getName();
      }
    }

    // do a lot of changes on master session.
    long start = System.currentTimeMillis();
    for (int i = 0; i < NUM_PRODUCTS; i++)
    {
      Product1 p = catA.getProducts().remove(0);
      catB.getProducts().add(p);
      catB.getProducts().move(0, p);

      masterTransaction.commit();
    }

    Thread.sleep(100);
    catA.setName(catA.getName() + " empty");
    masterTransaction.commit();

    System.out.println(MessageFormat.format("## Committing changes on {0} products took: {1}", NUM_PRODUCTS,
        System.currentTimeMillis() - start));

    // session.waitForUpdate(masterTransaction.getLastCommitTime(), 5000);
    for (CDOView view : cloneViews)
    {
      view.waitForUpdate(masterTransaction.getLastCommitTime(), 5000);
    }

    // adding this sleep as the waitForUpdate does not seem to work as expected in case of an error.
    sleep(5000);
    System.out.println("## Started checking....");

    // check if all changes are made.
    Category cloneCatA = (Category)transaction.getObject(CDOUtil.getCDOObject(catA).cdoID());
    Category cloneCatB = (Category)transaction.getObject(CDOUtil.getCDOObject(catB).cdoID());
    System.out.println("CatA IdVersion: " + CDOUtil.getCDOObject(cloneCatA).cdoRevision().toString());
    System.out.println("CatB IdVersion: " + CDOUtil.getCDOObject(cloneCatB).cdoRevision().toString());
    assertEquals(NUM_PRODUCTS, cloneCatB.getProducts().size());
    assertEquals(0, cloneCatA.getProducts().size());
    assertEquals(catA.getName(), cloneCatA.getName());
  }

  @Override
  public void disableConsole()
  {
    OMPlatform.INSTANCE.setDebugging(false);
    OMPlatform.INSTANCE.removeTraceHandler(PrintTraceHandler.CONSOLE);
    // OMPlatform.INSTANCE.removeLogHandler(PrintLogHandler.CONSOLE);
  }
}

Back to the top