Search in sources :

Example 36 with ParallelTestContainer

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);
}
Also used : Master(org.apache.cayenne.testdo.relationships_child_master.Master) ObjectContext(org.apache.cayenne.ObjectContext) Child(org.apache.cayenne.testdo.relationships_child_master.Child) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 37 with ParallelTestContainer

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);
}
Also used : Random(java.util.Random) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Aggregations

ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)37 Test (org.junit.Test)34 Artist (org.apache.cayenne.testdo.testmap.Artist)26 ObjectContext (org.apache.cayenne.ObjectContext)10 DataRow (org.apache.cayenne.DataRow)6 SQLTemplate (org.apache.cayenne.query.SQLTemplate)5 Painting (org.apache.cayenne.testdo.testmap.Painting)4 DataObject (org.apache.cayenne.DataObject)3 Master (org.apache.cayenne.testdo.relationships_child_master.Master)3 ObjectId (org.apache.cayenne.ObjectId)2 Expression (org.apache.cayenne.exp.Expression)2 DbEntity (org.apache.cayenne.map.DbEntity)2 Child (org.apache.cayenne.testdo.relationships_child_master.Child)2 SoftDelete (org.apache.cayenne.testdo.soft_delete.SoftDelete)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 DataContext (org.apache.cayenne.access.DataContext)1 SnapshotEvent (org.apache.cayenne.access.event.SnapshotEvent)1 BatchTranslatorFactory (org.apache.cayenne.access.translator.batch.BatchTranslatorFactory)1