use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class InFlightWorkflowInterceptorTest method testInterceptor.
@Test
public void testInterceptor() throws Exception {
InFlightWorkflowInterceptor interceptor = new InFlightWorkflowInterceptor("testInterceptor");
final PoolingWorkflow wf = createPoolingWorkflow("workflow", interceptor);
wf.setPoolSize(1);
wf.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS));
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new WaitService(new TimeInterval(2L, TimeUnit.SECONDS)));
MockChannel c = new MockChannel();
c.getWorkflowList().add(wf);
try {
LifecycleHelper.initAndStart(c);
wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
assertEquals(1, interceptor.messagesInFlightCount());
assertEquals(0, interceptor.messagesPendingCount());
new Thread(new Runnable() {
@Override
public void run() {
wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
}
}).start();
LifecycleHelper.waitQuietly(100);
assertEquals(1, interceptor.messagesInFlightCount());
assertEquals(1, interceptor.messagesPendingCount());
ExampleServiceCase.waitForMessages(prod, 2, 10000);
} finally {
LifecycleHelper.stopAndClose(c);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_Defaults_NotAsObjectMetadata.
@Test
public void testInterceptor_Defaults_NotAsObjectMetadata() throws Exception {
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertEquals("channelName", metadata.get(CoreConstants.CHANNEL_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertEquals("workflowName", metadata.get(CoreConstants.WORKFLOW_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertEquals(msg.getUniqueId(), metadata.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertFalse(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertFalse(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertFalse(object.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_NoDefaults.
@Test
public void testInterceptor_NoDefaults() throws Exception {
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setUseDefaultKeys(false);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
assertFalse(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertFalse(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertFalse(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertFalse(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertFalse(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertFalse(object.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_Defaults.
@Test
public void testInterceptor_Defaults() throws Exception {
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setAddDefaultKeysAsObjectMetadata(true);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertEquals("channelName", metadata.get(CoreConstants.CHANNEL_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertEquals("workflowName", metadata.get(CoreConstants.WORKFLOW_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertEquals(msg.getUniqueId(), metadata.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertTrue(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertEquals("channelName", object.get(CoreConstants.CHANNEL_ID_KEY));
assertTrue(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertEquals("workflowName", object.get(CoreConstants.WORKFLOW_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertEquals(msg.getUniqueId(), object.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_KVP_Expression.
@Test
public void testInterceptor_KVP_Expression() throws Exception {
KeyValuePairList kvp = new KeyValuePairList();
kvp.add(new KeyValuePair("key1", "%message{mk1}"));
kvp.add(new KeyValuePair("key2", "%message{mk2}"));
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setValuesToSet(kvp);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.addMetadata("mk1", "mv1");
msg.addMetadata("mk2", "mv2");
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
assertTrue(metadata.containsKey("key1"));
assertEquals("mv1", metadata.get("key1"));
assertTrue(metadata.containsKey("key2"));
assertEquals("mv2", metadata.get("key2"));
} finally {
BaseCase.stop(c);
}
}
Aggregations