Search in sources :

Example 26 with TimeInterval

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

the class MetadataCountInterceptorTest method testCreatesNewTimeSliceAfterTimeDelay.

@Test
public void testCreatesNewTimeSliceAfterTimeDelay() throws Exception {
    LifecycleHelper.init(metricsInterceptor);
    LifecycleHelper.start(metricsInterceptor);
    // a negative number will expire the timeslice immediately after the first message
    metricsInterceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS));
    AdaptrisMessage message = createMessage(COUNTER_1);
    assertEquals(0, metricsInterceptor.getStats().size());
    submitMessage(message);
    assertEquals(1, metricsInterceptor.getStats().size());
    assertEquals(1, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_1));
    assertEquals(0, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_2));
    metricsInterceptor.setTimesliceDuration(new TimeInterval(1L, TimeUnit.SECONDS));
    submitMessage(message);
    submitMessage(message);
    assertEquals(2, metricsInterceptor.getStats().size());
    assertEquals(1, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_1));
    assertEquals(0, ((MetadataStatistic) metricsInterceptor.getStats().get(0)).getValue(COUNTER_2));
    assertEquals(2, ((MetadataStatistic) metricsInterceptor.getStats().get(1)).getValue(COUNTER_1));
    assertEquals(0, ((MetadataStatistic) metricsInterceptor.getStats().get(1)).getValue(COUNTER_2));
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 27 with TimeInterval

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

the class MetadataCountInterceptorTest 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 28 with TimeInterval

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

the class MetadataCountWorkflowTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    Channel c = new Channel();
    StandardWorkflow wf = new StandardWorkflow();
    wf.setUniqueId("MyWorkflowName");
    MetadataCountInterceptor ti = new MetadataCountInterceptor("metadatakey1");
    ti.setUniqueId("Metrics_For_MyWorkflowName");
    ti.setTimesliceDuration(new TimeInterval(60L, TimeUnit.SECONDS));
    wf.addInterceptor(ti);
    c.setUniqueId(UUID.randomUUID().toString());
    wf.setUniqueId(UUID.randomUUID().toString());
    c.getWorkflowList().add(wf);
    return c;
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) Channel(com.adaptris.core.Channel)

Example 29 with TimeInterval

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

the class DebugPoolFactoryTest method testPoolBuilder.

@Test
public void testPoolBuilder() throws Exception {
    DebugPoolFactory factory = new DebugPoolFactory().withDebugUnreturnedConnectionStackTraces(true).withUnreturnedConnectionTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
    ;
    PluggableJdbcPooledConnection con = createConnection();
    C3P0PooledDataSource pooledDs = factory.build(con);
    ComboPooledDataSource wrapped = pooledDs.wrapped();
    assertEquals(con.getConnectUrl(), wrapped.getJdbcUrl());
    assertTrue(wrapped.isDebugUnreturnedConnectionStackTraces());
    assertEquals(10, wrapped.getUnreturnedConnectionTimeout());
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 30 with TimeInterval

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

the class DefaultPoolFactoryTest method createConnection.

public static PluggableJdbcPooledConnection createConnection() throws Exception {
    String url = "jdbc:derby:memory:" + GUID.safeUUID() + ";create=true";
    PluggableJdbcPooledConnection con = new PluggableJdbcPooledConnection();
    con.setConnectUrl(url);
    con.setDriverImp(DRIVER_IMP);
    con.setConnectionAttempts(1);
    con.setConnectionRetryInterval(new TimeInterval(10L, TimeUnit.MILLISECONDS.name()));
    return con;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval)

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