Search in sources :

Example 31 with ParallelTestContainer

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

Example 32 with ParallelTestContainer

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

Example 33 with ParallelTestContainer

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

Example 34 with ParallelTestContainer

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);
    }
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) DbEntity(org.apache.cayenne.map.DbEntity) SoftDelete(org.apache.cayenne.testdo.soft_delete.SoftDelete) Expression(org.apache.cayenne.exp.Expression) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 35 with ParallelTestContainer

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);
}
Also used : Master(org.apache.cayenne.testdo.relationships_child_master.Master) ObjectContext(org.apache.cayenne.ObjectContext) Child(org.apache.cayenne.testdo.relationships_child_master.Child) 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