Search in sources :

Example 21 with ParallelTestContainer

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);
}
Also used : DataRow(org.apache.cayenne.DataRow) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer)

Example 22 with ParallelTestContainer

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);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 23 with ParallelTestContainer

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);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 24 with ParallelTestContainer

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);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 25 with ParallelTestContainer

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);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) 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