use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class AdapterManagerTest method testInitialise_WithTimeout.
@Test
public void testInitialise_WithTimeout() throws Exception {
TimeInterval standardTimeout = new TimeInterval(2L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockConnection conn = new MockConnection(getName(), new TimeInterval(250L, TimeUnit.MILLISECONDS).toMilliseconds());
adapter.getSharedComponents().addConnection(conn);
AdapterManager adapterManager = new AdapterManager(adapter);
try {
adapterManager.registerMBean();
ObjectName adapterObj = createAdapterObjectName(adapterName);
AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
try {
manager.requestInit(-1);
fail();
} catch (IllegalArgumentException expected) {
}
manager.requestInit(standardTimeout.toMilliseconds());
assertEquals(InitialisedState.getInstance(), manager.getComponentState());
adapterManager.requestClose();
try {
manager.requestInit(new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
fail();
} catch (TimeoutException expected) {
}
} finally {
adapterManager.requestClose();
adapterManager.unregisterMBean();
}
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class DefaultFailedMessageRetrierJmxTest method testMBean_RetryWhen_Retrier_Closed.
@Test
public void testMBean_RetryWhen_Retrier_Closed() throws Exception {
Adapter adapter = createAdapter(getName());
Channel channel = createChannel(getName());
StandardWorkflow wf = createWorkflow(getName());
MockMessageProducer mock = new MockMessageProducer();
wf.setProducer(mock);
channel.getWorkflowList().add(wf);
adapter.getChannelList().add(channel);
DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
retrier.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS));
adapter.setFailedMessageRetrier(retrier);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@" + getName());
SerializableMessage serialized = new DefaultSerializableMessageTranslator().translate(msg);
AdapterManager adapterManager = new AdapterManager(adapter);
try {
adapterManager.registerMBean();
adapterManager.requestStart();
// Close the workflow directly
LifecycleHelper.stop(retrier);
LifecycleHelper.close(retrier);
ObjectName retrierObjName = createRetrierObjectName(adapterManager);
DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
assertFalse(jmxBean.retryMessage(serialized));
assertEquals(0, mock.messageCount());
} finally {
adapterManager.requestClose();
adapterManager.unregisterMBean();
}
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class AddValueToCacheTest method testDoService_NoExpiryMetadata.
@Test
public void testDoService_NoExpiryMetadata() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
ExpiringMapCache cache = createCacheInstanceForTests().withExpiration(new TimeInterval(1L, TimeUnit.SECONDS));
MyCacheEventListener listener = new MyCacheEventListener();
cache.getEventListener().addEventListener(listener);
AddValueToCache service = new AddValueToCache().withExpiry("%message{expiry}").withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
try {
start(service);
// msg.addMetadata("expiry", "a"); // empty expiry should not expire.
service.doService(msg);
Object value = cache.get(msg.getUniqueId());
assertEquals("Hello World", value);
await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(listener::expiredCount, greaterThanOrEqualTo(1));
assertEquals(0, cache.size());
} finally {
stop(service);
}
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class AddValueToCacheTest method testDoService_Expiry_Unsupported.
@Test
public void testDoService_Expiry_Unsupported() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
ExpiringMapCache cache = createCacheInstanceForTests().withExpiration(new TimeInterval(1L, TimeUnit.SECONDS));
MyCacheEventListener listener = new MyCacheEventListener();
cache.getEventListener().addEventListener(listener);
AddValueToCache service = new AddValueToCache().withExpiry("%message{expiry}").withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
try {
start(service);
// unparseable expiry should not expire.
msg.addMetadata("expiry", "a");
service.doService(msg);
Object value = cache.get(msg.getUniqueId());
assertEquals("Hello World", value);
await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(listener::expiredCount, greaterThanOrEqualTo(1));
assertEquals(0, cache.size());
} finally {
stop(service);
}
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class CheckCacheServiceTest method testDoService_Error.
@Test
public void testDoService_Error() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
ExpiringMapCache cache = new KeysSizeUnsupportedCache().withMaxEntries(10).withExpiration(new TimeInterval(10L, TimeUnit.SECONDS));
CheckCacheService service = new CheckCacheService() {
@Override
protected boolean eval(AdaptrisMessage msg, FoundInCache callback) throws CoreException {
throw new CoreException();
}
};
try {
service.withConnection(new CacheConnection().withCacheInstance(cache));
service.setKeysFoundServiceId(FOUND);
service.setKeysNotFoundServiceId(NOT_FOUND);
start(service);
cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
service.doService(msg);
fail();
} catch (ServiceException expected) {
} finally {
stop(service);
}
}
Aggregations