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());
}
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);
}
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"));
}
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);
}
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);
}
Aggregations