Search in sources :

Example 6 with TimeInterval

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

the class GetAndCacheOauthTokenTest method testService_WithError.

@Test(expected = ServiceException.class)
public void testService_WithError() throws Exception {
    ExpiringMapCache cache = new ExpiringMapCache().withExpiration(new TimeInterval(5L, TimeUnit.SECONDS));
    AccessToken t = new AccessToken(getName());
    GetAndCacheOauthToken service = new GetAndCacheOauthToken().withCacheKey("OauthToken").withConnection(new CacheConnection(cache)).withAccessTokenBuilder(new DummyAccessTokenBuilder(t, true));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    execute(service, msg);
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 7 with TimeInterval

use of com.adaptris.util.TimeInterval 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);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Test(org.junit.Test)

Example 8 with TimeInterval

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

the class MessageMetricsInterceptorTest method testDoesNotCreateMoreHistoryThanSpecified.

@Test
public void testDoesNotCreateMoreHistoryThanSpecified() throws Exception {
    LifecycleHelper.init(metricsInterceptor);
    LifecycleHelper.start(metricsInterceptor);
    AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
    // A minus time will expire the time slice immediately after the first message
    metricsInterceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS));
    assertEquals(0, metricsInterceptor.getStats().size());
    submitMessage(message);
    assertEquals(1, metricsInterceptor.getStats().size());
    metricsInterceptor.setTimesliceDuration(new TimeInterval(500L, TimeUnit.MILLISECONDS));
    submitMessage(message);
    submitMessage(message);
    assertEquals(2, metricsInterceptor.getStats().size());
    waitFor(1);
    submitMessage(message);
    submitMessage(message);
    submitMessage(message);
    // Should still only be 2 time slices
    assertEquals(2, metricsInterceptor.getStats().size());
    assertEquals(2, ((MessageStatistic) metricsInterceptor.getStats().get(0)).getTotalMessageCount());
    assertEquals(3, ((MessageStatistic) metricsInterceptor.getStats().get(1)).getTotalMessageCount());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 9 with TimeInterval

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

the class MessageMetricsInterceptorTest method testProduceAfterNewTimeSlice.

@Test
public void testProduceAfterNewTimeSlice() throws Exception {
    ProducingStatisticManager producingStatisticManager = new ProducingStatisticManager();
    producingStatisticManager.setMarshaller(mockMarshaller);
    producingStatisticManager.setProducer(mockStandaloneProducer);
    metricsInterceptor.setStatisticManager(producingStatisticManager);
    LifecycleHelper.init(metricsInterceptor);
    LifecycleHelper.start(metricsInterceptor);
    AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
    // A minus time will expire the time slice immediately after the first message
    metricsInterceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS));
    assertEquals(0, metricsInterceptor.getStats().size());
    submitMessage(message);
    assertEquals(1, metricsInterceptor.getStats().size());
    submitMessage(message);
    verify(mockMarshaller).marshal(any());
    verify(mockStandaloneProducer).produce(any());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 10 with TimeInterval

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

the class MessageMetricsInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    openMocks = MockitoAnnotations.openMocks(this);
    metricsInterceptor = new MessageMetricsInterceptor();
    metricsInterceptor.setTimesliceDuration(new TimeInterval(5L, TimeUnit.SECONDS));
    metricsInterceptor.setTimesliceHistoryCount(2);
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Before(org.junit.Before)

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