use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class DataContextSharedCacheEmpiricIT method assertOnCommit.
private void assertOnCommit(final Artist a2) throws Exception {
// check underlying cache
final DataRow freshSnapshot = c2.getObjectStore().getDataRowCache().getCachedSnapshot(a2.getObjectId());
assertNotNull("No snapshot for artist", freshSnapshot);
assertEquals(NEW_NAME, freshSnapshot.get("ARTIST_NAME"));
// check peer artist
ParallelTestContainer helper = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals("Snapshot change is not propagated: " + freshSnapshot, NEW_NAME, a2.getArtistName());
}
};
helper.runTest(3000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class ObjectStoreGCIT method testRetainUnreferencedNew.
@Test
public void testRetainUnreferencedNew() throws Exception {
assertEquals(0, context.getObjectStore().registeredObjectsCount());
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
a = null;
assertEquals(1, context.getObjectStore().registeredObjectsCount());
// allow for slow GC
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(1, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
assertEquals(1, context.getObjectStore().registeredObjectsCount());
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(0, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class ObjectStoreGCIT method testRetainUnreferencedModified.
@Test
public void testRetainUnreferencedModified() throws Exception {
context.performGenericQuery(new SQLTemplate(Artist.class, "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
assertEquals(0, context.getObjectStore().registeredObjectsCount());
Artist a = Cayenne.objectForPK(context, Artist.class, 1);
a.setArtistName("Y");
a = null;
assertEquals(1, context.getObjectStore().registeredObjectsCount());
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(1, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(0, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class ObjectStoreGCIT method testReleaseUnreferenced.
@Test
public void testReleaseUnreferenced() throws Exception {
context.performGenericQuery(new SQLTemplate(Artist.class, "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
assertEquals(0, context.getObjectStore().registeredObjectsCount());
ObjectSelect.query(Artist.class).select(context);
assertEquals(1, context.getObjectStore().registeredObjectsCount());
// allow for slow GC
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
System.gc();
assertEquals(0, context.getObjectStore().registeredObjectsCount());
}
}.runTest(2000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class DataContextSharedCacheIT method testSnapshotDeletePropagationToHollow.
/**
* Test case to prove that deleting an object in one ObjectStore and committed to the
* database will be reflected in the peer ObjectStore using the same DataRowCache. By
* default HOLLOW objects will be changed to TRANSIENT.
*/
@Test
public void testSnapshotDeletePropagationToHollow() throws Exception {
final Artist altArtist = context1.localObject(artist);
assertNotNull(altArtist);
assertFalse(altArtist == artist);
assertEquals(PersistenceState.HOLLOW, 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);
}
Aggregations