Search in sources :

Example 76 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class JmxWaitServiceTest method testWaitNegation.

@Test
public void testWaitNegation() throws Exception {
    JmxWaitService service = new JmxWaitService();
    service.setOperationName(getName());
    service.setObjectName("com.adaptris:type=JMX,id=" + getName());
    when(mockInvoker.invoke((MBeanServerConnection) any(), (ObjectName) any(), anyString(), any(Object[].class), any(String[].class))).thenReturn(true, false);
    service.setInvoker(mockInvoker);
    service.setNegate(true);
    service.setRetryInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    try {
        start(service);
        service.doService(AdaptrisMessageFactory.getDefaultInstance().newMessage());
    } finally {
        stop(service);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 77 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class PooledSplitJoinServiceTest method testService_DidNoWork.

@Test(expected = ServiceException.class)
public void testService_DidNoWork() throws Exception {
    PooledSplitJoinService service = new PooledSplitJoinService();
    service.setServiceErrorHandler(new NoExceptionIfWorkDone().withMetadataKey(NoExceptionIfWorkDone.DEFAULT_METADATA_KEY));
    service.setSplitter(new LineCountSplitter(1));
    service.setService(asCollection(new MockExceptionStrategyService(MockExceptionStrategyService.MODE.ERROR)));
    service.setPoolsize(10);
    service.setTimeout(new TimeInterval(5L, TimeUnit.SECONDS));
    service.setAggregator(new AppendingMessageAggregator());
    service.registerEventHandler(LifecycleHelper.initAndStart(new DefaultEventHandler()));
    AdaptrisMessage msg = createLineCountMessageInput(50);
    execute(service, msg);
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) Test(org.junit.Test)

Example 78 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class PooledSplitJoinServiceTest method testService.

@Test
public void testService() throws Exception {
    PooledSplitJoinService service = new PooledSplitJoinService();
    service.setAggregator(new AppendingMessageAggregator());
    service.setSplitter(new LineCountSplitter(1));
    service.setPoolsize(10);
    service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
    service.setService(new WaitService(new TimeInterval(100L, TimeUnit.MILLISECONDS), true));
    AdaptrisMessage msg = createLineCountMessageInput(50);
    ExampleServiceCase.execute(service, msg);
    List<String> result = IOUtils.readLines(msg.getReader());
    // Using an appending message aggregator just means that we double up on the original message...
    assertEquals(50 * 2, result.size());
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) Test(org.junit.Test)

Example 79 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class PooledSplitJoinServiceTest method testService_DidWorkSuccessfully.

@Test
public void testService_DidWorkSuccessfully() throws Exception {
    PooledSplitJoinService service = new PooledSplitJoinService();
    service.setServiceErrorHandler(new NoExceptionIfWorkDone().withMetadataKey(NoExceptionIfWorkDone.DEFAULT_METADATA_KEY));
    service.setSplitter(new LineCountSplitter(1));
    service.setService(asCollection(new WaitService(new TimeInterval(10L, TimeUnit.MILLISECONDS), false), new MockExceptionStrategyService(MockExceptionStrategyService.MODE.NEUTRAL)));
    service.setPoolsize(10);
    service.setTimeout(new TimeInterval(5L, TimeUnit.SECONDS));
    service.setAggregator(new AppendingMessageAggregator());
    service.registerEventHandler(LifecycleHelper.initAndStart(new DefaultEventHandler()));
    AdaptrisMessage msg = createLineCountMessageInput(50);
    execute(service, msg);
    List<String> result = IOUtils.readLines(msg.getReader());
    // Using an appending message aggregator just means that we double up on the original message...
    // Since we aren't doing any filtering... then we will always get 100 msgs.
    assertEquals(50 * 2, result.size());
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) Test(org.junit.Test)

Example 80 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class PoolingMessageSplitterServiceTest method testServiceWithXmlSplitter_WarmStart_WaitWhileBusy.

@Test
public void testServiceWithXmlSplitter_WarmStart_WaitWhileBusy() throws Exception {
    MockMessageProducer producer = createMockProducer();
    PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)), new StandaloneProducer(producer)).withWarmStart(true).withMaxThreads(1).withWaitWhileBusy(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
    XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
    execute(service, msg);
    assertEquals("Number of messages", 3, producer.getMessages().size());
}
Also used : WaitService(com.adaptris.core.services.WaitService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

TimeInterval (com.adaptris.util.TimeInterval)310 Test (org.junit.Test)249 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)86 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)49 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)42 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)40 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)38 Channel (com.adaptris.core.Channel)36 MockChannel (com.adaptris.core.stubs.MockChannel)32 File (java.io.File)28 StandardWorkflow (com.adaptris.core.StandardWorkflow)27 Adapter (com.adaptris.core.Adapter)26 GuidGenerator (com.adaptris.util.GuidGenerator)25 FilenameFilter (java.io.FilenameFilter)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 StandaloneProducer (com.adaptris.core.StandaloneProducer)23 CoreException (com.adaptris.core.CoreException)22 WaitService (com.adaptris.core.services.WaitService)22 RandomAccessFile (java.io.RandomAccessFile)21 ObjectName (javax.management.ObjectName)21