Search in sources :

Example 26 with ParallelTestContainer

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

the class DataContextSharedCacheIT method testSnapshotDeletePropagationToDeleted.

/**
 * 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 DELETED objects will be changed to TRANSIENT.
 */
@Test
public void testSnapshotDeletePropagationToDeleted() throws Exception {
    // make sure we have a fully resolved copy of an artist object
    // in the second context
    final Artist altArtist = context1.localObject(artist);
    altArtist.getArtistName();
    assertNotNull(altArtist);
    assertFalse(altArtist == artist);
    // delete peer
    context1.deleteObjects(altArtist);
    // 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);
    assertFalse(context1.hasChanges());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 27 with ParallelTestContainer

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

the class DataContextSharedCacheIT method testSnapshotChangePropagation.

/**
 * Test case to prove that changes made to an object in one ObjectStore and committed
 * to the database will be reflected in the peer ObjectStore using the same
 * DataRowCache.
 */
@Test
public void testSnapshotChangePropagation() throws Exception {
    String originalName = artist.getArtistName();
    final String newName = "version2";
    // make sure we have a fully resolved copy of an artist object
    // in the second context
    final Artist altArtist = context1.localObject(artist);
    assertFalse(altArtist == artist);
    assertEquals(originalName, altArtist.getArtistName());
    assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
    // Update Artist
    artist.setArtistName(newName);
    // no changes propagated till commit...
    assertEquals(originalName, altArtist.getArtistName());
    context.commitChanges();
    // check underlying cache
    DataRow freshSnapshot = context.getObjectStore().getDataRowCache().getCachedSnapshot(altArtist.getObjectId());
    assertEquals(newName, freshSnapshot.get("ARTIST_NAME"));
    // check peer artist
    ParallelTestContainer helper = new ParallelTestContainer() {

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

Example 28 with ParallelTestContainer

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

the class DataContextSharedCacheIT method testSnapshotEvictedAndObjectsHollowedForInvalidate.

@Test
public void testSnapshotEvictedAndObjectsHollowedForInvalidate() throws Exception {
    String originalName = artist.getArtistName();
    // make sure we have a fully resolved copy of an artist object
    // in the second context
    final Artist altArtist = context1.localObject(artist);
    context1.prepareForAccess(altArtist, null, false);
    assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
    context.invalidateObjects(artist);
    // original context
    assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
    assertNull(context.getObjectStore().getDataRowCache().getCachedSnapshot(artist.getObjectId()));
    // alternate context
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertEquals(PersistenceState.HOLLOW, altArtist.getPersistenceState());
            assertNull(context1.getObjectStore().getDataRowCache().getCachedSnapshot(altArtist.getObjectId()));
        }
    }.runTest(5000);
    // resolve object
    assertEquals(originalName, altArtist.getArtistName());
    DataRow altFreshSnapshot = context1.getObjectStore().getDataRowCache().getCachedSnapshot(altArtist.getObjectId());
    assertNotNull(altFreshSnapshot);
    assertEquals(originalName, altFreshSnapshot.get("ARTIST_NAME"));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 29 with ParallelTestContainer

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

the class NestedDataContextParentEventsIT method testParentUpdatedId.

@Test
public void testParentUpdatedId() throws Exception {
    ObjectContext child1 = runtime.newContext(context);
    final Artist ac = child1.newObject(Artist.class);
    ac.setArtistName("X");
    child1.commitChangesToParent();
    final Artist ap = (Artist) context.getGraphManager().getNode(ac.getObjectId());
    assertNotNull(ap);
    assertTrue(ap.getObjectId().isTemporary());
    context.commitChanges();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertFalse(ap.getObjectId().isTemporary());
            assertEquals(ap.getObjectId(), ac.getObjectId());
        }
    }.runTest(1000);
}
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 30 with ParallelTestContainer

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

the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedToOneRelationship.

@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
    Artist a = context.newObject(Artist.class);
    Artist altA = context.newObject(Artist.class);
    Painting p = context.newObject(Painting.class);
    p.setToArtist(a);
    p.setPaintingTitle("PPP");
    a.setArtistName("X");
    altA.setArtistName("Y");
    context.commitChanges();
    ObjectContext peer1 = runtime.newContext(context);
    Painting p1 = peer1.localObject(p);
    Artist altA1 = peer1.localObject(altA);
    final ObjectContext peer2 = runtime.newContext(context);
    final Painting p2 = peer2.localObject(p);
    final Artist altA2 = peer2.localObject(altA);
    Artist a2 = peer2.localObject(a);
    p1.setToArtist(altA1);
    assertSame(a2, p2.getToArtist());
    peer1.commitChangesToParent();
    // pause to let the context events propagate
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertEquals(altA2, p2.getToArtist());
            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) Painting(org.apache.cayenne.testdo.testmap.Painting) 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