Skip to main content
summaryrefslogtreecommitdiffstats
blob: 02e1f662ab5ad2b5fc0f2774a44be281dc8f98f2 (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
/**
 * 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.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.TestAdapter;
import org.eclipse.emf.cdo.tests.model2.Task;
import org.eclipse.emf.cdo.tests.model2.TaskContainer;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
import org.eclipse.emf.cdo.view.CDOView;

import java.util.ArrayList;
import java.util.List;

/**
 * IndexOutOfBoundsException on View Invalidation.
 * <p>
 * See bug 313913
 */
public class Bugzilla_313913_Test extends AbstractCDOTest
{
  public void testAccessOldValue() throws Exception
  {
    final CDOSession session = openSession();
    final CDOTransaction transaction = session.openTransaction();
    transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    TaskContainer container = getModel2Factory().createTaskContainer();

    for (int i = 0; i < 2; i++)
    {
      Task task = getModel2Factory().createTask();
      container.getTasks().add(task);
    }

    final CDOResource resourceA = transaction.createResource("/test1");
    resourceA.getContents().add(container);
    transaction.commit();

    CDOView view = session.openView();
    view.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
    view.getObject(container).eAdapters().add(new TestAdapter());

    CDOView view2 = session.openView();
    view2.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
    view2.getObject(container).eAdapters().add(new TestAdapter());

    CDOView view3 = session.openView();
    view3.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
    view3.getObject(container).eAdapters().add(new TestAdapter());

    List<Task> tasks = new ArrayList<Task>(container.getTasks());
    container.getTasks().removeAll(tasks);

    container.getTasks().add(getModel2Factory().createTask());
    transaction.commit();

    sleep(100);

    System.out.println(container.getTasks().toString());
    System.out.println(view.getObject(container).getTasks().toString());
    // this will fail...
    System.out.println(view2.getObject(container).getTasks().toString());

  }
}

Back to the top