use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class NestedDataContextParentPeerEventsIT method testPeerObjectUpdatedToManyRelationship.
@Test
public void testPeerObjectUpdatedToManyRelationship() throws Exception {
Master a = parentContext1.newObject(Master.class);
a.setName("X");
Child px = parentContext1.newObject(Child.class);
px.setMaster(a);
Child py = parentContext1.newObject(Child.class);
parentContext1.commitChanges();
Child py1 = parentContext2.localObject(py);
Master a1 = parentContext2.localObject(a);
final ObjectContext peer2 = runtime.newContext(parentContext1);
final Child py2 = peer2.localObject(py);
final Master a2 = peer2.localObject(a);
a1.addToChildren(py1);
assertEquals(1, a2.getChildren().size());
assertFalse(a2.getChildren().contains(py2));
parentContext2.commitChangesToParent();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals(2, a2.getChildren().size());
assertTrue(a2.getChildren().contains(py2));
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
}.runTest(2000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class NestedDataContext_DeadlockIT method testDeadlock.
@Test
public void testDeadlock() throws Exception {
createArtists();
final Thread[] threads = new Thread[2];
Random rnd = new Random(System.currentTimeMillis());
for (int i = 0; i < threads.length; i++) {
threads[i] = new UpdateThread("UpdateThread-" + i, runtime.newContext(parent), rnd);
}
for (Thread thread : threads) {
thread.start();
}
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
for (Thread thread : threads) {
// unfortunately here we'll have to leave some dead threads
// behind... Of course if there's no deadlock, there won't
// be a leak either
assertFalse("Deadlocked thread", thread.isAlive());
}
}
}.runTest(40000);
}
Aggregations