Skip to main content
summaryrefslogtreecommitdiffstats
blob: b83eb8d975e7a5abd3ef17be40b5524468be7930 (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
/*
 * Copyright (c) 2004 - 2011 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:
 *    Stefan Winkler - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.performance;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.performance.framework.PerformanceTest;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;

import java.util.Random;

/**
 * @author Stefan Winkler
 */
public class DeleteRandomTest extends PerformanceTest
{
  private static final int AMOUNT_ELEMENTS = 10000;

  private Random random = new Random();

  private Company initModel() throws CommitException
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("res"));

    Company company = getModel1Factory().createCompany();

    for (int i = 0; i < AMOUNT_ELEMENTS; i++)
    {
      Category cat = getModel1Factory().createCategory();
      cat.setName(Integer.toString(i));
      company.getCategories().add(cat);
    }

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

    return company;
  }

  public void test() throws Exception
  {
    Company company = initModel();
    CDOTransaction transaction = (CDOTransaction)CDOUtil.getCDOObject(company).cdoView();

    for (int i = 0; i < AMOUNT_ELEMENTS / 2; i++)
    {
      int currentSize = AMOUNT_ELEMENTS - i;
      int indexToRemove = random.nextInt(currentSize);

      company.getCategories().remove(indexToRemove);

      startProbing();
      transaction.commit();
      stopProbing();
    }
  }
}

Back to the top