use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class MyCayenneEvent method assertReceivedEventsForClass.
// allows just enough time for the event threads to run
private static void assertReceivedEventsForClass(final int expected) throws Exception {
ParallelTestContainer helper = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals(expected, numberOfReceivedEventsForClass);
}
};
helper.runTest(5000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class MyCayenneEvent method assertReceivedEvents.
// allows just enough time for the event threads to run
private static void assertReceivedEvents(final int expected, final DefaultEventManagerTest listener) throws Exception {
ParallelTestContainer helper = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals(expected, listener.numberOfReceivedEvents);
}
};
helper.runTest(5000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class EventBridgeTest method testSendExternalEvent.
@Test
public void testSendExternalEvent() throws Exception {
final EventSubject local = EventSubject.getSubject(EventBridgeTest.class, "testInstall");
String external = "externalSubject";
final TestBridge bridge = new TestBridge(local, external);
DefaultEventManager manager = new DefaultEventManager(2);
managersToClean.add(manager);
bridge.startup(manager, EventBridge.RECEIVE_LOCAL_EXTERNAL);
final SnapshotEvent eventWithNoSubject = new SnapshotEvent(this, this, null, null, null, null);
manager.postEvent(eventWithNoSubject, local);
// check that event was received and that subject was injected...
// since bridge is notified asynchronously by default,
// we must wait till notification is received
ParallelTestContainer helper = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertTrue(bridge.lastLocalEvent instanceof SnapshotEvent);
assertEquals(local, bridge.lastLocalEvent.getSubject());
}
};
helper.runTest(5000);
final SnapshotEvent eventWithSubject = new SnapshotEvent(this, this, null, null, null, null);
eventWithSubject.setSubject(local);
manager.postEvent(eventWithNoSubject, local);
// check that event was received and that subject was injected...
// since bridge is notified asynchronously by default,
// we must wait till notification is received
ParallelTestContainer helper1 = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertTrue(bridge.lastLocalEvent instanceof SnapshotEvent);
assertEquals(local, bridge.lastLocalEvent.getSubject());
}
};
helper1.runTest(5000);
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class SoftDeleteBatchTranslatorIT method testUpdate.
@Test
public void testUpdate() throws Exception {
final DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
BatchTranslatorFactory oldFactory = dataNode.getBatchTranslatorFactory();
try {
dataNode.setBatchTranslatorFactory(new SoftDeleteTranslatorFactory());
final SoftDelete test = context.newObject(SoftDelete.class);
test.setName("SoftDeleteBatchQueryBuilderTest");
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() {
Expression exp = ExpressionFactory.matchExp("name", test.getName());
assertEquals(1, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
exp = ExpressionFactory.matchDbExp("DELETED", true);
assertEquals(0, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
}
}.runTest(200);
context.deleteObjects(test);
assertEquals(test.getPersistenceState(), PersistenceState.DELETED);
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() {
Expression exp = ExpressionFactory.matchExp("name", test.getName());
assertEquals(0, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
SQLTemplate template = new SQLTemplate(entity, "SELECT * FROM SOFT_DELETE");
template.setFetchingDataRows(true);
assertEquals(1, context.performQuery(template).size());
}
}.runTest(200);
} finally {
context.performQuery(new SQLTemplate(entity, "DELETE FROM SOFT_DELETE"));
dataNode.setBatchTranslatorFactory(oldFactory);
}
}
use of org.apache.cayenne.test.parallel.ParallelTestContainer in project cayenne by apache.
the class NestedDataContextParentPeerEventsIT method testPeerObjectUpdatedToOneRelationship.
@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
Master a = parentContext1.newObject(Master.class);
Master altA = parentContext1.newObject(Master.class);
Child p = parentContext1.newObject(Child.class);
p.setMaster(a);
a.setName("X");
altA.setName("Y");
parentContext1.commitChanges();
Child p1 = parentContext2.localObject(p);
Master altA1 = parentContext2.localObject(altA);
final ObjectContext childContext1 = runtime.newContext(parentContext1);
final Child p2 = childContext1.localObject(p);
final Master altA2 = childContext1.localObject(altA);
Master a2 = childContext1.localObject(a);
p1.setMaster(altA1);
assertSame(a2, p2.getMaster());
assertNotSame(altA2, p2.getMaster());
parentContext2.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertSame(altA2, p2.getMaster());
assertFalse("Peer data context became dirty on event processing", childContext1.hasChanges());
}
}.runTest(2000);
}
Aggregations