use of net.dempsy.container.locking.LockingContainer.InstanceWrapper in project Dempsy by Dempsy.
the class TestInstanceManager method testMultipleInstanceCreation.
@Test
public void testMultipleInstanceCreation() throws Exception {
final CombinedMP prototype = new CombinedMP();
try (final LockingContainer manager = setupContainer(new MessageProcessor<CombinedMP>(prototype))) {
final DummyDispatcher dispatcher = ((DummyDispatcher) manager.getDispatcher());
assertEquals("starts with no instances", 0, manager.getProcessorCount());
final KeyedMessageWithType message1 = km(new MessageOne(123));
final InstanceWrapper wrapper1 = manager.getInstanceForKey(message1.key, message1.message);
manager.dispatch(message1, Operation.handle, true);
final CombinedMP instance1 = (CombinedMP) wrapper1.getInstance();
final KeyedMessageWithType message2 = km(new MessageOne(456));
final InstanceWrapper wrapper2 = manager.getInstanceForKey(message2.key, message2.message);
manager.dispatch(message2, Operation.handle, true);
final CombinedMP instance2 = (CombinedMP) wrapper2.getInstance();
assertEquals("instances were created", 2, manager.getProcessorCount());
assertEquals(new ReturnString("MessageOne"), dispatcher.lastDispatched.message);
assertEquals("message count to instance1", 1, instance1.messages.size());
assertEquals("message count to instance2", 1, instance2.messages.size());
assertSame("message1 went to instance1", message1.message, instance1.messages.get(0));
assertSame("message2 went to instance2", message2.message, instance2.messages.get(0));
assertEquals(new ReturnString("MessageOne"), dispatcher.lastDispatched.message);
}
}
use of net.dempsy.container.locking.LockingContainer.InstanceWrapper in project Dempsy by Dempsy.
the class TestInstanceManager method testSingleInstanceOneMessage.
@Test
public void testSingleInstanceOneMessage() throws Throwable {
final CombinedMP prototype = new CombinedMP();
try (final LockingContainer manager = setupContainer(new MessageProcessor<CombinedMP>(prototype))) {
assertEquals("starts with no instances", 0, manager.getProcessorCount());
final KeyedMessageWithType message = km(new MessageOne(123));
final InstanceWrapper wrapper = manager.getInstanceForKey(message.key, message.message);
assertEquals("instance was created", 1, manager.getProcessorCount());
final CombinedMP instance = (CombinedMP) wrapper.getInstance();
// activation is now inline with insantiation so it's active immediately
// assertEquals("instance not already activated", 0, instance.activationCount);
assertEquals("instance activated", 1, instance.activationCount);
assertEquals("instance has no existing messages", -1, instance.firstMessageTime);
// assertNull("instance has no message list", instance.messages);
assertTrue("real activation time", instance.activationTime > 0);
assertEquals("message count", 0, instance.messages.size());
// dispatch the message
// wrapper.run();
manager.dispatch(message, Operation.handle, true);
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);
// The return value cannot be routed.
assertEquals(new ReturnString("MessageOne"), ((DummyDispatcher) manager.getDispatcher()).lastDispatched.message);
assertEquals("prototype not activated", 0, prototype.activationCount);
assertEquals("prototype did not receive messages", -1, prototype.firstMessageTime);
assertNull("prototype has no message list", prototype.messages);
}
}
use of net.dempsy.container.locking.LockingContainer.InstanceWrapper in project Dempsy by Dempsy.
the class TestInstanceManager method testSingleInstanceTwoMessagesSameClassSeparateExecution.
@Test
public void testSingleInstanceTwoMessagesSameClassSeparateExecution() throws Exception {
final CombinedMP prototype = new CombinedMP();
try (final LockingContainer manager = setupContainer(new MessageProcessor<CombinedMP>(prototype))) {
final DummyDispatcher dispatcher = ((DummyDispatcher) manager.getDispatcher());
assertEquals("starts with no instances", 0, manager.getProcessorCount());
final KeyedMessageWithType message1 = km(new MessageOne(123));
final InstanceWrapper wrapper1 = manager.getInstanceForKey(message1.key, message1.message);
manager.dispatch(message1, Operation.handle, true);
final CombinedMP instance = (CombinedMP) wrapper1.getInstance();
assertEquals("instance was created", 1, manager.getProcessorCount());
assertEquals("instance activated", 1, instance.activationCount);
assertTrue("real activation time", instance.activationTime > 0);
assertSame("instance received message", message1.message, instance.messages.get(0));
assertEquals("message count", 1, instance.messages.size());
assertTrue("activated before first message", instance.activationTime < instance.firstMessageTime);
assertEquals(new ReturnString("MessageOne"), dispatcher.lastDispatched.message);
final KeyedMessageWithType message2 = km(new MessageOne(123));
final InstanceWrapper wrapper2 = manager.getInstanceForKey(message2.key, message2.message);
manager.dispatch(message2, Operation.handle, true);
assertSame("same wrapper returned for second message", wrapper1, wrapper2);
assertEquals("no other instance was created", 1, manager.getProcessorCount());
assertEquals("no second activation", 1, instance.activationCount);
assertEquals("both messages delivered", 2, instance.messages.size());
assertSame("message1 delivered first", message1.message, instance.messages.get(0));
assertSame("message2 delivered second", message2.message, instance.messages.get(1));
assertEquals(new ReturnString("MessageOne"), dispatcher.lastDispatched.message);
}
}
use of net.dempsy.container.locking.LockingContainer.InstanceWrapper in project Dempsy by Dempsy.
the class TestInstanceManager method testSingleInstanceTwoMessagesDifferentClassSeparateExecution.
@Test
public void testSingleInstanceTwoMessagesDifferentClassSeparateExecution() throws Exception {
final CombinedMP prototype = new CombinedMP();
try (final LockingContainer manager = setupContainer(new MessageProcessor<CombinedMP>(prototype))) {
final DummyDispatcher dispatcher = ((DummyDispatcher) manager.getDispatcher());
assertEquals("starts with no instances", 0, manager.getProcessorCount());
final KeyedMessageWithType message1 = km(new MessageOne(123));
final InstanceWrapper wrapper = manager.getInstanceForKey(message1.key, message1.message);
manager.dispatch(message1, Operation.handle, true);
final CombinedMP instance = (CombinedMP) wrapper.getInstance();
assertEquals("instance was created", 1, manager.getProcessorCount());
assertEquals("instance activated", 1, instance.activationCount);
assertTrue("real activation time", instance.activationTime > 0);
assertSame("instance received message", message1.message, instance.messages.get(0));
assertEquals("message count", 1, instance.messages.size());
assertTrue("activated before first message", instance.activationTime < instance.firstMessageTime);
assertEquals(new ReturnString("MessageOne"), dispatcher.lastDispatched.message);
final KeyedMessageWithType message2 = km(new MessageTwo(123));
assertSame("same wrapper returned for second message", wrapper, manager.getInstanceForKey(message2.key, message2.message));
manager.dispatch(message2, Operation.handle, true);
assertEquals("no other instance was created", 1, manager.getProcessorCount());
assertEquals("no second activation", 1, instance.activationCount);
assertEquals("both messages delivered", 2, instance.messages.size());
assertSame("message1 delivered first", message1.message, instance.messages.get(0));
assertSame("message2 delivered second", message2.message, instance.messages.get(1));
assertEquals(new ReturnString("MessageTwo"), dispatcher.lastDispatched.message);
}
}
use of net.dempsy.container.locking.LockingContainer.InstanceWrapper in project Dempsy by Dempsy.
the class TestInstanceManager method testSingleInstanceTwoMessagesSameClassCombinedExecution.
@Test
public void testSingleInstanceTwoMessagesSameClassCombinedExecution() throws Exception {
final CombinedMP prototype = new CombinedMP();
try (final LockingContainer manager = setupContainer(new MessageProcessor<CombinedMP>(prototype))) {
final DummyDispatcher dispatcher = ((DummyDispatcher) manager.getDispatcher());
assertEquals("starts with no instances", 0, manager.getProcessorCount());
final KeyedMessageWithType message1 = km(new MessageOne(123));
final InstanceWrapper wrapper = manager.getInstanceForKey(message1.key, message1.message);
manager.dispatch(message1, Operation.handle, true);
assertEquals("instance was created", 1, manager.getProcessorCount());
final KeyedMessageWithType message2 = km(new MessageOne(123));
assertSame("same wrapper returned for second message", wrapper, manager.getInstanceForKey(message2.key, message2.message));
manager.dispatch(message2, Operation.handle, true);
final CombinedMP instance = (CombinedMP) wrapper.getInstance();
assertEquals("no other instance was created", 1, manager.getProcessorCount());
assertEquals("instance activated", 1, instance.activationCount);
assertTrue("real activation time", instance.activationTime > 0);
assertTrue("activated before first message", instance.activationTime < instance.firstMessageTime);
assertEquals("both messages delivered", 2, instance.messages.size());
assertSame("message1 delivered first", message1.message, instance.messages.get(0));
assertSame("message2 delivered second", message2.message, instance.messages.get(1));
assertEquals(new ReturnString("MessageOne"), dispatcher.lastDispatched.message);
}
}
Aggregations