Search in sources :

Example 66 with TimeInterval

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();
}
Also used : ServiceException(com.adaptris.core.ServiceException) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 67 with TimeInterval

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());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 68 with TimeInterval

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());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 69 with TimeInterval

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());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 70 with TimeInterval

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;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection)

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