Search in sources :

Example 11 with ParallelTestContainer

use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.

the class DataContextSharedCacheIT method testSnapshotDeletePropagationToCommitted.

/**
 * Test case to prove that deleting an object in one ObjectStore and committing to the
 * database will be reflected in the peer ObjectStore using the same DataRowCache. By
 * default COMMITTED objects will be changed to TRANSIENT.
 */
@Test
public void testSnapshotDeletePropagationToCommitted() throws Exception {
    // make sure we have a fully resolved copy of an artist object
    // in the second context
    final Artist altArtist = context1.localObject(artist);
    assertNotNull(altArtist);
    assertFalse(altArtist == artist);
    assertEquals(artist.getArtistName(), altArtist.getArtistName());
    assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
    // Update Artist
    context.deleteObjects(artist);
    context.commitChanges();
    // check underlying cache
    assertNull(context.getObjectStore().getDataRowCache().getCachedSnapshot(altArtist.getObjectId()));
    // check peer artist
    ParallelTestContainer helper = new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertEquals(PersistenceState.TRANSIENT, altArtist.getPersistenceState());
            assertNull(altArtist.getObjectContext());
        }
    };
    helper.runTest(3000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 12 with ParallelTestContainer

use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.

the class DataContextSharedCacheIT method testSnapshotInsertPropagationToManyRefresh.

/**
 * Test case to prove that inserting an object in one ObjectStore and committing to
 * the database will be reflected in the peer ObjectStore using the same DataRowCache.
 * This would mean refreshing to-many collections.
 */
@Test
public void testSnapshotInsertPropagationToManyRefresh() throws Exception {
    Painting painting1 = (Painting) context.newObject("Painting");
    painting1.setPaintingTitle("p1");
    painting1.setToArtist(artist);
    context.commitChanges();
    // make sure we have a fully resolved copy of an artist and painting
    // objects
    // in the second context
    final Artist altArtist = context1.localObject(artist);
    final Painting altPainting1 = context1.localObject(painting1);
    assertEquals(artist.getArtistName(), altArtist.getArtistName());
    assertEquals(painting1.getPaintingTitle(), altPainting1.getPaintingTitle());
    assertEquals(1, altArtist.getPaintingArray().size());
    assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
    assertEquals(PersistenceState.COMMITTED, altPainting1.getPersistenceState());
    // insert new painting and add to artist
    Painting painting2 = (Painting) context.newObject("Painting");
    painting2.setPaintingTitle("p2");
    painting2.setToArtist(artist);
    context.commitChanges();
    // check peer artist
    // use threaded helper as a barrier, to avoid triggering faults earlier than
    // needed
    ParallelTestContainer helper = new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            Object value = altArtist.readPropertyDirectly("paintingArray");
            assertTrue("Unexpected: " + value, value instanceof ToManyList);
            assertTrue(((ToManyList) value).isFault());
        }
    };
    helper.runTest(2000);
    List<Painting> list = altArtist.getPaintingArray();
    assertEquals(2, list.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 13 with ParallelTestContainer

use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.

the class NestedDataContextParentPeerEventsIT method testPeerObjectUpdatedSimpleProperty.

@Test
public void testPeerObjectUpdatedSimpleProperty() throws Exception {
    Master a = parentContext1.newObject(Master.class);
    a.setName("X");
    parentContext1.commitChanges();
    Master a1 = parentContext2.localObject(a);
    final ObjectContext child = runtime.newContext(parentContext1);
    final Master a2 = child.localObject(a);
    a1.setName("Y");
    assertEquals("X", a2.getName());
    parentContext2.commitChangesToParent();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertEquals("Y", a2.getName());
            assertFalse("Peer data context became dirty on event processing", child.hasChanges());
        }
    }.runTest(2000);
}
Also used : Master(org.apache.cayenne.testdo.relationships_child_master.Master) ObjectContext(org.apache.cayenne.ObjectContext) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 14 with ParallelTestContainer

use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.

the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedSimpleProperty.

@Test
public void testPeerObjectUpdatedSimpleProperty() throws Exception {
    Artist a = context.newObject(Artist.class);
    a.setArtistName("X");
    context.commitChanges();
    ObjectContext peer1 = runtime.newContext(context);
    Artist a1 = peer1.localObject(a);
    final ObjectContext peer2 = runtime.newContext(context);
    final Artist a2 = peer2.localObject(a);
    a1.setArtistName("Y");
    assertEquals("X", a2.getArtistName());
    peer1.commitChangesToParent();
    // pause to let the context events propagate
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertEquals("Y", a2.getArtistName());
            assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
        }
    }.runTest(2000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectContext(org.apache.cayenne.ObjectContext) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 15 with ParallelTestContainer

use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.

the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedTempOID.

@Test
public void testPeerObjectUpdatedTempOID() throws Exception {
    ObjectContext peer1 = runtime.newContext(context);
    final Artist a1 = peer1.newObject(Artist.class);
    a1.setArtistName("Y");
    ObjectId a1TempId = a1.getObjectId();
    assertTrue(a1TempId.isTemporary());
    ObjectContext peer2 = runtime.newContext(context);
    final Artist a2 = peer2.localObject(a1);
    assertEquals(a1TempId, a2.getObjectId());
    peer1.commitChanges();
    // pause to let the context events propagate
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertFalse(a1.getObjectId().isTemporary());
            assertFalse(a2.getObjectId().isTemporary());
            assertEquals(a2.getObjectId(), a1.getObjectId());
        }
    }.runTest(2000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectId(org.apache.cayenne.ObjectId) ObjectContext(org.apache.cayenne.ObjectContext) 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