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