Skip to main content
summaryrefslogtreecommitdiffstats
blob: 83b2ecffbb73c194ce9f60f5dfd5d98e1433049e (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
/*
 * Copyright (c) 2004 - 2012 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:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.db;

import org.eclipse.emf.cdo.common.CDOCommonRepository;
import org.eclipse.emf.cdo.common.id.CDOID;
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.config.impl.RepositoryConfig;
import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.OfflineConfig;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model3.Class1;
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.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.io.IOUtil;

import java.util.Map;

/**
 * @author Stefan Winkler
 */
public class Bugzilla_377727_Test extends AbstractCDOTest
{
  @Override
  public synchronized Map<String, Object> getTestProperties()
  {
    Map<String, Object> testProperties = super.getTestProperties();
    testProperties.put(OfflineConfig.PROP_TEST_RAW_REPLICATION, Boolean.TRUE);
    return testProperties;
  }

  @Requires(RepositoryConfig.CAPABILITY_OFFLINE)
  @CleanRepositoriesBefore
  public void testAsyncPackages() throws Exception
  {
    CDOID id1;
    CDOID id2;

    IOUtil.OUT().println("=== Disconnect clone ===");

    // disconnect clone from master
    ((OfflineConfig)getRepositoryConfig()).stopMasterTransport();
    ConcurrencyUtil.sleep(1000L);
    while (getRepository().getState() == CDOCommonRepository.State.ONLINE)
    {
      ConcurrencyUtil.sleep(250L);
    }

    IOUtil.OUT().println("=== Clone is disconnected ===");

    {
      // on disconnected master
      CDOSession session = openSession("master");
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource(getResourcePath("test"));

      Class1 c1 = getModel3Factory().createClass1();
      resource.getContents().add(c1);
      id1 = CDOUtil.getCDOObject(c1).cdoID();

      Category cat1 = getModel1Factory().createCategory();
      cat1.setName("Test");
      resource.getContents().add(cat1);
      id2 = CDOUtil.getCDOObject(cat1).cdoID();

      transaction.commit();
      transaction.close();
      session.close();
    }

    // reconnect clone and let sync
    IOUtil.OUT().println("=== reconnect clone ===");

    ((OfflineConfig)getRepositoryConfig()).startMasterTransport();
    while (getRepository().getState() != CDOCommonRepository.State.ONLINE)
    {
      ConcurrencyUtil.sleep(250L);
    }

    IOUtil.OUT().println("=== Clone is reconnected ===");

    CDOSession session = openSession();
    CDOView view = session.openView();
    CDOResource resource = view.getResource(getResourcePath("test"));

    Class1 c1 = (Class1)resource.getContents().get(0);
    assertEquals(id1, CDOUtil.getCDOObject(c1).cdoID());

    Category cat = (Category)resource.getContents().get(1);
    assertEquals(id2, CDOUtil.getCDOObject(cat).cdoID());
  }
}

Back to the top