use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class RetryingServiceWrapperTest method testFailsOnceNoRestarts.
@Test
public void testFailsOnceNoRestarts() throws Exception {
// Fail once, then pass
doThrow(new ServiceException("Expected fail.")).doNothing().when(wrappedService).doService(any(AdaptrisMessage.class));
// now setup the retrying service wrapper;
retryingServiceWrapper.setDelayBetweenRetries(new TimeInterval(1L, TimeUnit.SECONDS));
retryingServiceWrapper.setNumRetries(3);
retryingServiceWrapper.setService(wrappedService);
retryingServiceWrapper.setRestartOnFailure(false);
LifecycleHelper.init(retryingServiceWrapper);
LifecycleHelper.start(retryingServiceWrapper);
retryingServiceWrapper.doService(DefaultMessageFactory.getDefaultInstance().newMessage());
verify(wrappedService, times(2)).doService(any(AdaptrisMessage.class));
// init and start will be called once at RetryServiceWrapper init and start and then again on the restart.
verify(wrappedService, times(1)).requestInit();
verify(wrappedService, times(1)).requestStart();
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class TimedInactivityRestartStrategyTest method testExceedsTimeoutNoMessage.
@Test
public void testExceedsTimeoutNoMessage() throws Exception {
restartStrategy.setInactivityPeriod(new TimeInterval(1L, "SECONDS"));
assertFalse(restartStrategy.requiresRestart());
LifecycleHelper.waitQuietly(1500);
assertTrue(restartStrategy.requiresRestart());
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class TimedInactivityRestartStrategyTest method testDoesNotExceedsTimeoutSteadyStreamOfMessage.
@Test
public void testDoesNotExceedsTimeoutSteadyStreamOfMessage() throws Exception {
restartStrategy.setInactivityPeriod(new TimeInterval(1L, "SECONDS"));
assertFalse(restartStrategy.requiresRestart());
// Test will last 2 seconds
for (int counter = 0; counter < 10; counter++) {
restartStrategy.messageProcessed(messageFactory.newMessage());
assertFalse(restartStrategy.requiresRestart());
try {
Thread.sleep(200);
} catch (Exception ex) {
}
}
assertFalse(restartStrategy.requiresRestart());
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class WaitServiceTest method testDoService.
@Test
public void testDoService() throws Exception {
long now = System.currentTimeMillis();
WaitService srv = new WaitService(new TimeInterval(10L, TimeUnit.MILLISECONDS));
execute(srv, AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello"));
assertTrue(now < System.currentTimeMillis());
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class MetadataIdentitySequenceNumberServiceTest method retrieveObjectForSampleConfig.
@Override
protected MetadataIdentitySequenceNumberService retrieveObjectForSampleConfig() {
JdbcConnection connection = new JdbcConnection();
connection.setConnectUrl("jdbc:mysql://localhost:3306/mydatabase");
connection.setConnectionAttempts(2);
connection.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
MetadataIdentitySequenceNumberService service = new MetadataIdentitySequenceNumberService();
service.setMetadataKey("sequence_no");
service.setNumberFormat(DEFAULT_NUMBER_FORMAT);
service.setConnection(connection);
service.setIdentityMetadataKey(DEFAULT_IDENTITY_METADATA_KEY);
service.setOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour.Continue);
return service;
}
Aggregations