Search in sources :

Example 6 with InstanceWrapper

use of net.dempsy.container.locking.LockingContainer.InstanceWrapper in project Dempsy by Dempsy.

the class TestInstanceManager method testQueueIsClearedAfterExecution.

// This test no longer really matters since there is no queue but we might as well leave it
// since it exercises the container.
@Test
public void testQueueIsClearedAfterExecution() throws Exception {
    final CombinedMP prototype = new CombinedMP();
    try (final LockingContainer manager = setupContainer(new MessageProcessor<CombinedMP>(prototype))) {
        final KeyedMessageWithType message = km(new MessageOne(123));
        final InstanceWrapper wrapper = manager.getInstanceForKey(message.key, message.message);
        manager.dispatch(message, Operation.handle, true);
        assertEquals("instance was created", 1, manager.getProcessorCount());
        final CombinedMP instance = (CombinedMP) wrapper.getInstance();
        assertEquals("instance activated", 1, instance.activationCount);
        assertTrue("real activation time", instance.activationTime > 0);
        assertSame("instance received message", message.message, instance.messages.get(0));
        assertEquals("message count", 1, instance.messages.size());
        assertTrue("activated before first message", instance.activationTime < instance.firstMessageTime);
        final long activationTime = instance.activationTime;
        final long firstMessageTime = instance.firstMessageTime;
        // here is where the queue would have been advanced again ... but there is no queue anymore.
        assertTrue("activation time didn't change", activationTime == instance.activationTime);
        assertTrue("message time didn't change", firstMessageTime == instance.firstMessageTime);
        assertEquals("message count didn't change", 1, instance.messages.size());
    }
}
Also used : InstanceWrapper(net.dempsy.container.locking.LockingContainer.InstanceWrapper) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) Test(org.junit.Test)

Example 7 with InstanceWrapper

use of net.dempsy.container.locking.LockingContainer.InstanceWrapper in project Dempsy by Dempsy.

the class TestInstanceManager method testOutput.

@Test
public void testOutput() throws Exception {
    final OutputTestMP prototype = new OutputTestMP();
    try (final LockingContainer manager = setupContainer(new MessageProcessor<OutputTestMP>(prototype))) {
        final DummyDispatcher dispatcher = ((DummyDispatcher) manager.getDispatcher());
        // we need to dispatch messages to create MP instances
        final KeyedMessageWithType message1 = km(new MessageOne(1));
        final InstanceWrapper wrapper1 = manager.getInstanceForKey(message1.key, message1.message);
        manager.dispatch(message1, Operation.handle, true);
        final KeyedMessageWithType message2 = km(new MessageOne(2));
        final InstanceWrapper wrapper2 = manager.getInstanceForKey(message2.key, message2.message);
        manager.dispatch(message2, Operation.handle, true);
        assertEquals(new ReturnString("MessageOne"), dispatcher.lastDispatched.message);
        manager.outputPass();
        final OutputTestMP mp1 = (OutputTestMP) wrapper1.getInstance();
        assertTrue("MP1 output did not occur after activation", mp1.activationTime < mp1.outputTime);
        final OutputTestMP mp2 = (OutputTestMP) wrapper2.getInstance();
        assertTrue("MP2 output did not occur after activation", mp2.activationTime < mp2.outputTime);
        assertTrue(mp1 != mp2);
        assertEquals(new ReturnInt(42), dispatcher.lastDispatched.message);
    }
}
Also used : InstanceWrapper(net.dempsy.container.locking.LockingContainer.InstanceWrapper) KeyedMessageWithType(net.dempsy.messages.KeyedMessageWithType) Test(org.junit.Test)

Aggregations

InstanceWrapper (net.dempsy.container.locking.LockingContainer.InstanceWrapper)7 KeyedMessageWithType (net.dempsy.messages.KeyedMessageWithType)7 Test (org.junit.Test)7