Search in sources :

Example 1 with ParallelTestContainer

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

the class DataContextDataChannelEventsIT method testRollbackEvent.

@Test
public void testRollbackEvent() throws Exception {
    Artist a = context.newObject(Artist.class);
    a.setArtistName("X");
    context.commitChanges();
    final MockChannelListener listener = new MockChannelListener();
    EventUtil.listenForChannelEvents(context, listener);
    a.setArtistName("Y");
    context.rollbackChanges();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertFalse(listener.graphCommitted);
            assertFalse(listener.graphChanged);
            assertTrue(listener.graphRolledBack);
        }
    }.runTest(10000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 2 with ParallelTestContainer

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

the class DataContextDataChannelEventsIT method testCommitEvent.

@Test
public void testCommitEvent() throws Exception {
    Artist a = context.newObject(Artist.class);
    a.setArtistName("X");
    context.commitChanges();
    final MockChannelListener listener = new MockChannelListener();
    EventUtil.listenForChannelEvents(context, listener);
    a.setArtistName("Y");
    context.commitChanges();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertTrue(listener.graphCommitted);
            assertFalse(listener.graphChanged);
            assertFalse(listener.graphRolledBack);
        }
    }.runTest(10000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 3 with ParallelTestContainer

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

the class DataContextDataChannelEventsIT method testChangeEventOnPeerChange.

@Test
public void testChangeEventOnPeerChange() throws Exception {
    Artist a = context.newObject(Artist.class);
    a.setArtistName("X");
    context.commitChanges();
    final MockChannelListener listener = new MockChannelListener();
    EventUtil.listenForChannelEvents(context, listener);
    Artist a1 = peer.localObject(a);
    a1.setArtistName("Y");
    peer.commitChangesToParent();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertFalse(listener.graphCommitted);
            assertTrue(listener.graphChanged);
            assertFalse(listener.graphRolledBack);
        }
    }.runTest(10000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 4 with ParallelTestContainer

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

the class DataContextDataChannelEventsIT method testChangeEventOnChildChange.

@Test
public void testChangeEventOnChildChange() throws Exception {
    Artist a = context.newObject(Artist.class);
    a.setArtistName("X");
    context.commitChanges();
    final MockChannelListener listener = new MockChannelListener();
    EventUtil.listenForChannelEvents(context, listener);
    ObjectContext childContext = runtime.newContext(context);
    Artist a1 = childContext.localObject(a);
    a1.setArtistName("Y");
    childContext.commitChangesToParent();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertFalse(listener.graphCommitted);
            assertTrue(listener.graphChanged);
            assertFalse(listener.graphRolledBack);
        }
    }.runTest(10000);
}
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 5 with ParallelTestContainer

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

the class DataContextDelegateSharedCacheIT method testShouldMergeChanges.

/**
 * Test case to prove that delegate method is invoked on external change of object in
 * the store.
 */
@Test
public void testShouldMergeChanges() throws Exception {
    final boolean[] methodInvoked = new boolean[1];
    DataContextDelegate delegate = new MockDataContextDelegate() {

        @Override
        public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore) {
            methodInvoked[0] = true;
            return true;
        }
    };
    // make sure we have a fully resolved copy of an artist object
    // in the second context
    Artist altArtist = context1.localObject(artist);
    assertNotNull(altArtist);
    assertNotSame(altArtist, artist);
    assertEquals(artist.getArtistName(), altArtist.getArtistName());
    assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
    context1.setDelegate(delegate);
    // Update and save artist in peer context
    artist.setArtistName("version2");
    context.commitChanges();
    // assert that delegate was consulted when an object store
    // was refreshed
    ParallelTestContainer helper = new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertTrue("Delegate was not consulted", methodInvoked[0]);
        }
    };
    helper.runTest(3000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) DataObject(org.apache.cayenne.DataObject) DataRow(org.apache.cayenne.DataRow) 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