Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cf30815774e2577938295cdd6a47e45c8a5163d7 (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
/*
 * Copyright (c) 2011, 2012, 2015, 2016, 2022 Eike Stepper (Loehne, 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:
 *    Szabolcs Bardy - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
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.IRepositoryConfig;
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.spi.cdo.DefaultCDOMerger;

/**
 * @author Szabolcs Bardy
 */
public class Bugzilla_337054_Test extends AbstractCDOTest
{
  private static final String RESOURCE_NAME = "/337054";

  private static final int LIST_SIZE = 3;

  @Requires({ IRepositoryConfig.CAPABILITY_BRANCHING, IRepositoryConfig.CAPABILITY_CHUNKING, IRepositoryConfig.CAPABILITY_RESTARTABLE })
  public void testCDOElementProxies() throws Exception
  {
    CDOSession session = openSession();
    session.options().setCollectionLoadingPolicy(CDOUtil.createCollectionLoadingPolicy(0, 300));

    CDOTransaction mainTransaction = session.openTransaction();
    CDOResource resource = mainTransaction.createResource(getResourcePath(RESOURCE_NAME));

    msg("Filling up list...");
    for (int i = 0; i < LIST_SIZE; i++)
    {
      Company company = getModel1Factory().createCompany();
      company.setName("TestCompany_" + i);
      resource.getContents().add(company);
    }

    msg("Committing data...");
    mainTransaction.commit();
    mainTransaction.close();

    msg("Creating a branch with a new element...");
    String branchName = getBranchName(String.valueOf(System.currentTimeMillis()));
    CDOBranch branch = session.getBranchManager().getMainBranch().createBranch(branchName);

    Company branchCompany = getModel1Factory().createCompany();
    branchCompany.setName("TestCompany_" + LIST_SIZE);

    CDOTransaction branchTransaction = session.openTransaction(branch);
    CDOResource branchResource = branchTransaction.getResource(getResourcePath(RESOURCE_NAME));
    branchResource.getContents().add(branchCompany);

    branchTransaction.commit();
    branchTransaction.close();

    // Restart repository.
    restartRepository();

    session = openSession();
    session.options().setCollectionLoadingPolicy(CDOUtil.createCollectionLoadingPolicy(0, 300));

    // Merge.
    mainTransaction = session.openTransaction(session.getBranchManager().getMainBranch());
    branch = session.getBranchManager().getMainBranch().getBranch(branchName);

    resource = mainTransaction.getResource(getResourcePath(RESOURCE_NAME));
    int resourceContentsBeforeMerge = resource.getContents().size();
    msg("Before: " + resourceContentsBeforeMerge);

    mainTransaction.merge(branch.getHead(), new DefaultCDOMerger.PerFeature.ManyValued());
    mainTransaction.commit();

    int resourceContentsAfterMerge = resource.getContents().size();
    msg("After: " + resourceContentsAfterMerge);

    assertEquals(resourceContentsBeforeMerge + 1, resourceContentsAfterMerge);
  }
}

Back to the top