|
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011, 2015 Oracle and/or its affiliates. All rights reserved. |
2 |
* Copyright (c) 2010, 2017 Oracle and/or its affiliates. All rights reserved. |
| 3 |
* This program and the accompanying materials are made available under the |
3 |
* This program and the accompanying materials are made available under the |
| 4 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
4 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| 5 |
* which accompanies this distribution. |
5 |
* which accompanies this distribution. |
|
Link Here
|
| 8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
| 9 |
* |
9 |
* |
| 10 |
* Contributors: |
10 |
* Contributors: |
| 11 |
* Oracle - initial API and implementation from Oracle TopLink |
11 |
* 08/17/2010-2.2 Tom Ware |
| 12 |
* Mark Wolochuk - Bug 321041 ConcurrentModificationException on getFromIdentityMap() fix |
12 |
* - 321041 ConcurrentModificationException on getFromIdentityMap() fix |
| 13 |
******************************************************************************/ |
13 |
******************************************************************************/ |
| 14 |
package org.eclipse.persistence.testing.tests.identitymaps; |
14 |
package org.eclipse.persistence.testing.tests.identitymaps; |
| 15 |
|
15 |
|
| 16 |
import java.util.ConcurrentModificationException; |
|
|
| 17 |
|
| 18 |
import org.eclipse.persistence.expressions.Expression; |
16 |
import org.eclipse.persistence.expressions.Expression; |
| 19 |
import org.eclipse.persistence.expressions.ExpressionBuilder; |
17 |
import org.eclipse.persistence.expressions.ExpressionBuilder; |
| 20 |
import org.eclipse.persistence.queries.ReadObjectQuery; |
18 |
import org.eclipse.persistence.queries.ReadObjectQuery; |
| 21 |
import org.eclipse.persistence.sessions.UnitOfWork; |
19 |
import org.eclipse.persistence.sessions.UnitOfWork; |
| 22 |
import org.eclipse.persistence.testing.framework.AutoVerifyTestCase; |
20 |
import org.eclipse.persistence.testing.framework.TestCase; |
| 23 |
import org.eclipse.persistence.testing.framework.TestErrorException; |
|
|
| 24 |
import org.eclipse.persistence.testing.models.employee.domain.Employee; |
21 |
import org.eclipse.persistence.testing.models.employee.domain.Employee; |
| 25 |
|
22 |
|
| 26 |
/** |
23 |
/** |
| 27 |
* Test for bug fix 321041 - EclipseLink throws ConcurrentModificationException when triggering lazy load from conforming query |
24 |
* Bug# 321041 - EclipseLink throws ConcurrentModificationException when triggering lazy load from conforming query |
| 28 |
* @author tware |
|
|
| 29 |
* |
| 30 |
*/ |
25 |
*/ |
| 31 |
public class TriggerValueHoldersSelfReferencingOneToOneTest extends AutoVerifyTestCase{ |
26 |
public class TriggerValueHoldersSelfReferencingOneToOneTest extends TestCase { |
| 32 |
|
27 |
|
|
|
28 |
/** Current transaction. */ |
| 33 |
protected UnitOfWork uow = null; |
29 |
protected UnitOfWork uow = null; |
| 34 |
protected ConcurrentModificationException exception = null; |
|
|
| 35 |
|
30 |
|
| 36 |
public void setup(){ |
31 |
/** |
|
|
32 |
* Test setup. |
| 33 |
* Open transaction, initialize query and initialize cache with 1st query executions. |
| 34 |
*/ |
| 35 |
public void setup() { |
| 37 |
getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); |
36 |
getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); |
| 38 |
uow = getSession().acquireUnitOfWork(); |
37 |
uow = getSession().acquireUnitOfWork(); |
| 39 |
|
38 |
// Preload the UnitOfWork identity map with 2 Employees which have different managers |
| 40 |
|
|
|
| 41 |
// preload the UnitOfWork identity map with 2 Employees which have different managers |
| 42 |
ExpressionBuilder emp = new ExpressionBuilder(); |
39 |
ExpressionBuilder emp = new ExpressionBuilder(); |
| 43 |
Expression queryExp = emp.get("firstName").equal("Charles").and(emp.get("lastName").equal("Chanley")); |
40 |
Expression queryExp = emp.get("firstName").equal("Charles").and(emp.get("lastName").equal("Chanley")); |
| 44 |
uow.readObject(Employee.class, queryExp); |
41 |
uow.readObject(Employee.class, queryExp); |
| 45 |
|
|
|
| 46 |
emp = new ExpressionBuilder(); |
42 |
emp = new ExpressionBuilder(); |
| 47 |
queryExp = emp.get("firstName").equal("Marcus").and(emp.get("lastName").equal("Saunders")); |
43 |
queryExp = emp.get("firstName").equal("Marcus").and(emp.get("lastName").equal("Saunders")); |
| 48 |
uow.readObject(Employee.class, queryExp); |
44 |
uow.readObject(Employee.class, queryExp); |
| 49 |
} |
45 |
} |
| 50 |
|
46 |
|
| 51 |
public void test(){ |
47 |
/** |
|
|
48 |
* Test cleanup. |
| 49 |
* Release transaction and reset cache. |
| 50 |
*/ |
| 51 |
public void reset() { |
| 52 |
uow.release(); |
| 53 |
uow = null; |
| 54 |
getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); |
| 55 |
} |
| 52 |
|
56 |
|
|
|
57 |
/** |
| 58 |
* Test case. |
| 59 |
* Verify that {@code ConcurrentModificationException} is not thrown from {@code IdentityMapManager} |
| 60 |
* during 2nd queries execution when objects are already in the cache. |
| 61 |
*/ |
| 62 |
public void test() { |
| 53 |
// We query for both Employees here because it is impossible to tell which order |
63 |
// We query for both Employees here because it is impossible to tell which order |
| 54 |
// keys will be returned from the identity map in |
64 |
// keys will be returned from the identity map in |
| 55 |
// This bug only occurs when the first key returned is non-conforming and |
65 |
// This bug only occurs when the first key returned is non-conforming and |
|
Link Here
|
| 59 |
ReadObjectQuery query = new ReadObjectQuery(Employee.class, queryExp); |
69 |
ReadObjectQuery query = new ReadObjectQuery(Employee.class, queryExp); |
| 60 |
query.conformResultsInUnitOfWork(); |
70 |
query.conformResultsInUnitOfWork(); |
| 61 |
query.getInMemoryQueryIndirectionPolicy().triggerIndirection(); |
71 |
query.getInMemoryQueryIndirectionPolicy().triggerIndirection(); |
| 62 |
uow.executeQuery(query); |
72 |
Employee bob = (Employee)uow.executeQuery(query); |
| 63 |
|
73 |
assertNotNull(bob); |
|
|
74 |
assertEquals("Bob", bob.getManager().getFirstName()); |
| 64 |
emp = new ExpressionBuilder(); |
75 |
emp = new ExpressionBuilder(); |
| 65 |
queryExp = emp.get("manager").get("firstName").equal("John"); |
76 |
queryExp = emp.get("manager").get("firstName").equal("John"); |
| 66 |
query = new ReadObjectQuery(Employee.class, queryExp); |
77 |
query = new ReadObjectQuery(Employee.class, queryExp); |
| 67 |
query.conformResultsInUnitOfWork(); |
78 |
query.conformResultsInUnitOfWork(); |
| 68 |
query.getInMemoryQueryIndirectionPolicy().triggerIndirection(); |
79 |
query.getInMemoryQueryIndirectionPolicy().triggerIndirection(); |
| 69 |
uow.executeQuery(query); |
80 |
Employee john = (Employee)uow.executeQuery(query); |
| 70 |
} |
81 |
assertNotNull(john); |
| 71 |
|
82 |
assertEquals("John", john.getManager().getFirstName()); |
| 72 |
public void verify(){ |
|
|
| 73 |
if (exception != null){ |
| 74 |
throw new TestErrorException("A ConcurrentModificationException was thrown when using a Self Referencing Relationship and " + |
| 75 |
"a TriggerIndirection query policy."); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
public void reset(){ |
| 80 |
uow = null; |
| 81 |
getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); |
| 82 |
} |
83 |
} |
| 83 |
|
84 |
|
| 84 |
} |
85 |
} |