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);
}
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);
}
}
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());
}
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());
}
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);
}
Aggregations