Skip to main content
summaryrefslogtreecommitdiffstats
blob: a662c0ea574bcb0b09c5ba9074f0473fea63e2e1 (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
133
134
135
136
137
138
/*
 * Copyright (c) 2009-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:
 *    Simon McDuff - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.CDOObject;
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.model1.Customer;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;

/**
 * Bug 267352: NullPointerException on reload
 *
 * @author Simon McDuff
 */
public class Bugzilla_267352_Test extends AbstractCDOTest
{
  public void testReload() throws Exception
  {
    final Customer customer = getModel1Factory().createCustomer();
    customer.setName("customer");

    final boolean[] done = { false };
    final Exception[] exception = { null };

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));
    resource.getContents().add(customer);
    transaction.commit();

    Thread thread = new Thread("ChangeObjects")
    {
      @Override
      public void run()
      {
        CDOSession session = openSession();

        try
        {
          CDOTransaction transaction = session.openTransaction();
          CDOObject customerToLoad = CDOUtil.getCDOObject(transaction.getObject(customer));

          while (!done[0])
          {
            sleep(10);

            // Could fail if the attach is not thread safe
            transaction.reload(customerToLoad);
          }
        }
        catch (Exception ex)
        {
          exception[0] = ex;
        }
        finally
        {
          session.close();
        }
      }
    };

    thread.start();

    for (int i = 0; i < 100 && exception[0] == null; i++)
    {
      synchronized (transaction)
      {
        customer.setName("Ottawa" + i);
        transaction.commit();
      }
    }

    done[0] = true;
    thread.join(DEFAULT_TIMEOUT);

    if (exception[0] != null)
    {
      exception[0].printStackTrace();
      fail(exception[0].getMessage());
    }
  }

  public void test1() throws Exception
  {
    testReload();
  }

  public void test2() throws Exception
  {
    testReload();
  }

  public void test3() throws Exception
  {
    testReload();
  }

  public void test4() throws Exception
  {
    testReload();
  }

  public void test5() throws Exception
  {
    testReload();
  }

  public void test6() throws Exception
  {
    testReload();
  }

  public void test7() throws Exception
  {
    testReload();
  }

  public void test8() throws Exception
  {
    testReload();
  }

  public void test9() throws Exception
  {
    testReload();
  }
}

Back to the top