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