use of com.adaptris.core.stubs.MockFailingConnection in project interlok by adaptris.
the class AdapterManagerTest method testInitialise_WithTimeout_InitFailure.
@Test
public void testInitialise_WithTimeout_InitFailure() throws Exception {
TimeInterval standardTimeout = new TimeInterval(2L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockFailingConnection conn = new MockFailingConnection(getName(), "Init");
conn.setConnectionAttempts(3);
conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
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(standardTimeout.toMilliseconds());
fail();
} catch (CoreException expected) {
}
} finally {
adapterManager.requestClose();
adapterManager.unregisterMBean();
}
}
use of com.adaptris.core.stubs.MockFailingConnection in project interlok by adaptris.
the class AdapterManagerTest method testForceClose_ErrorOnInit_RequestStart.
@Test
public void testForceClose_ErrorOnInit_RequestStart() throws Exception {
final TimeInterval waitTime = new TimeInterval(5L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockFailingConnection conn = new MockFailingConnection(getName(), "Init");
conn.setConnectionAttempts(-1);
conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
adapter.getSharedComponents().addConnection(conn);
List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
try {
register(mBeans);
ObjectName adapterObj = createAdapterObjectName(adapterName);
final AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
// Create a cyclic barrier to wait for init/start operation to finish
final CyclicBarrier gate = new CyclicBarrier(3);
MyExceptionHandler exceptionHandler = new MyExceptionHandler();
ManagedThreadFactory threadFactory = new ManagedThreadFactory();
Thread initThread = threadFactory.newThread(new Runnable() {
@Override
public void run() {
try {
manager.requestInit();
} catch (CoreException e) {
throw new RuntimeException(e);
}
// This code is likely to never trigger, because of the throw above...
try {
gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS);
} catch (Exception gateException) {
}
}
});
initThread.setUncaughtExceptionHandler(exceptionHandler);
initThread.start();
Thread startThread = threadFactory.newThread(new Runnable() {
@Override
public void run() {
try {
manager.requestStart();
} catch (CoreException e) {
throw new RuntimeException(e);
}
// This code is likely to never trigger, because of the throw above...
try {
gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS);
} catch (Exception gateException) {
}
}
});
startThread.setUncaughtExceptionHandler(exceptionHandler);
startThread.start();
try {
gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS);
fail("Adapter init success, when not expected");
} catch (Exception gateException) {
// Expected now force close it, because it took too long.
manager.forceClose();
}
assertEquals(ClosedState.getInstance(), manager.getComponentState());
assertEquals(0, conn.getInitCount());
assertEquals(0, conn.getCloseCount());
} finally {
adapter.requestClose();
}
}
use of com.adaptris.core.stubs.MockFailingConnection in project interlok by adaptris.
the class AdapterManagerTest method testForceClose_ErrorOnStart_RequestStart.
@Test
public void testForceClose_ErrorOnStart_RequestStart() throws Exception {
final TimeInterval waitTime = new TimeInterval(5L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockFailingConnection conn = new MockFailingConnection(getName(), "Start");
conn.setConnectionAttempts(-1);
conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
adapter.getSharedComponents().addConnection(conn);
List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
try {
register(mBeans);
ObjectName adapterObj = createAdapterObjectName(adapterName);
final AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
// Create a cyclic barrier to wait for init operation to finish
final CyclicBarrier gate = new CyclicBarrier(2);
MyExceptionHandler exceptionHandler = new MyExceptionHandler();
Thread startThread = new ManagedThreadFactory().newThread(new Runnable() {
@Override
public void run() {
try {
manager.requestStart();
} catch (CoreException e) {
throw new RuntimeException(e);
}
// This code is likely to never trigger, because of the throw above...
try {
gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS);
} catch (Exception gateException) {
}
}
});
startThread.setUncaughtExceptionHandler(exceptionHandler);
startThread.start();
try {
gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS);
fail("Adapter Start success, when not expected");
} catch (Exception gateException) {
// Expected now force close it, because it took too long.
manager.forceClose();
}
assertEquals(ClosedState.getInstance(), manager.getComponentState());
assertEquals(1, conn.getInitCount());
assertEquals(0, conn.getStartCount());
assertEquals(1, conn.getCloseCount());
} finally {
adapter.requestClose();
}
}
use of com.adaptris.core.stubs.MockFailingConnection in project interlok by adaptris.
the class AdapterManagerTest method testStart_WithTimeout_StartFailure.
@Test
public void testStart_WithTimeout_StartFailure() throws Exception {
TimeInterval standardTimeout = new TimeInterval(3L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockFailingConnection conn = new MockFailingConnection(getName(), "Start");
conn.setConnectionAttempts(3);
conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
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.requestStart(standardTimeout.toMilliseconds());
fail();
} catch (CoreException expected) {
}
} finally {
adapterManager.requestClose();
adapterManager.unregisterMBean();
}
}
use of com.adaptris.core.stubs.MockFailingConnection in project interlok by adaptris.
the class AdapterManagerTest method testForceClose_ErrorOnInit_RequestInit.
@Test
public void testForceClose_ErrorOnInit_RequestInit() throws Exception {
final TimeInterval waitTime = new TimeInterval(5L, TimeUnit.SECONDS);
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockFailingConnection conn = new MockFailingConnection(getName(), "Init");
conn.setConnectionAttempts(-1);
conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
adapter.getSharedComponents().addConnection(conn);
List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
try {
register(mBeans);
ObjectName adapterObj = createAdapterObjectName(adapterName);
final AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
// Create a cyclic barrier to wait for init operation to finish
final CyclicBarrier gate = new CyclicBarrier(2);
MyExceptionHandler exceptionHandler = new MyExceptionHandler();
Thread initThread = new ManagedThreadFactory().newThread(new Runnable() {
@Override
public void run() {
try {
manager.requestInit();
} catch (CoreException e) {
throw new RuntimeException(e);
}
// This code is likely to never trigger, because of the throw above...
try {
gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS);
} catch (Exception gateException) {
}
}
});
initThread.setUncaughtExceptionHandler(exceptionHandler);
initThread.start();
try {
gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS);
fail("Adapter init success, when not expected");
} catch (Exception gateException) {
// Expected now force close it, because it took too long.
manager.forceClose();
}
assertEquals(ClosedState.getInstance(), manager.getComponentState());
assertEquals(0, conn.getInitCount());
assertEquals(0, conn.getCloseCount());
} finally {
adapter.requestClose();
}
}
Aggregations