Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4ddabcd64a693178673abd52a7e8d829976b7edf (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
/**
 * Copyright (c) 2004 - 2010 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.bugzilla;

import org.eclipse.emf.cdo.common.CDOCommonRepository;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.server.InternalSynchronizableRepository;
import org.eclipse.emf.cdo.tests.AbstractSyncingTest;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.net4j.acceptor.IAcceptor;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;

/**
 * @author Eike Stepper
 */
public class Bugzilla_325097_Test extends AbstractSyncingTest
{
  @Override
  protected boolean isRawReplication()
  {
    return true;
  }

  @Override
  protected boolean isFailover()
  {
    return true;
  }

  private IAcceptor backupAcceptor;

  @Override
  public void tearDown() throws Exception
  {
    super.tearDown();
    stopBackupTransport();
  }

  protected void startBackupTransport()
  {
    if (backupAcceptor == null)
    {
      IOUtil.OUT().println();
      IOUtil.OUT().println("startBackupTransport()");
      IOUtil.OUT().println();
      IManagedContainer container = getServerContainer();
      backupAcceptor = (IAcceptor)container.getElement("org.eclipse.net4j.acceptors", "jvm", "backup");
    }
  }

  protected void stopBackupTransport()
  {
    if (backupAcceptor != null)
    {
      IOUtil.OUT().println();
      IOUtil.OUT().println("stopBackupTransport()");
      IOUtil.OUT().println();
      backupAcceptor.close();
      backupAcceptor = null;
    }
  }

  public void testNewObjectAfterSwitch() throws Exception
  {
    InternalSynchronizableRepository repo1_master = (InternalSynchronizableRepository)getRepository(getRepository()
        .getName() + "_master");
    InternalSynchronizableRepository repo1 = getRepository();

    InternalSynchronizableRepository master = repo1_master;
    InternalSynchronizableRepository backup = repo1;

    CDOSession session = openSession(master.getName());
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource("/my/resource");

    Company company = getModel1Factory().createCompany();
    company.setName("Test");

    resource.getContents().add(company);
    transaction.setCommitComment("Company created");
    transaction.commit();

    sleep(1000);

    startBackupTransport();
    repo1.setType(CDOCommonRepository.Type.MASTER);
    repo1_master.setType(CDOCommonRepository.Type.BACKUP);

    master = repo1;
    backup = repo1_master;

    assertEquals(CDOCommonRepository.Type.MASTER, master.getType());
    assertEquals(CDOCommonRepository.Type.BACKUP, backup.getType());

    // make sure the backup repository is in sync
    waitForOnline(backup);

    session.close();
    session = openSession(master.getName());

    // make sure we are running the session on the master
    assertEquals(CDOCommonRepository.Type.MASTER, session.getRepositoryInfo().getType());
    transaction = session.openTransaction();

    resource = transaction.getResource("/my/resource");
    company = (Company)resource.getContents().get(0);

    // Create a new company
    company = getModel1Factory().createCompany();
    company.setName("Test2");

    resource.getContents().add(company);
    transaction.commit();

    session.close();
    LifecycleUtil.deactivate(backup);
    LifecycleUtil.deactivate(master);
  }
}

Back to the top