use of org.apache.ignite.failure.TestFailureHandler in project ignite by apache.
the class IgniteWalFormatFileFailoverTest method failureHandler.
/**
* @param gridIdx Grid index.
* @return Failure handler configured for grid with given index.
*/
private TestFailureHandler failureHandler(int gridIdx) {
FailureHandler hnd = grid(gridIdx).configuration().getFailureHandler();
assertTrue(hnd instanceof TestFailureHandler);
return (TestFailureHandler) hnd;
}
use of org.apache.ignite.failure.TestFailureHandler in project ignite by apache.
the class ReservationsOnDoneAfterTopologyUnlockFailTest method testFailureHandlerTriggeredOnTopologyUnlockError.
/**
* @throws Exception If failed.
*/
@Test
public void testFailureHandlerTriggeredOnTopologyUnlockError() throws Exception {
TestFailureHandler hnd = new TestFailureHandler(false);
IgniteEx grid0 = startGrid(getConfiguration(testNodeName(0)).setFailureHandler(hnd));
ExecutorService mockMgmtExecSvc = spy(grid0.context().pools().getManagementExecutorService());
doAnswer(invocationOnMock -> {
Arrays.stream(Thread.currentThread().getStackTrace()).map(StackTraceElement::getMethodName).filter("onDoneAfterTopologyUnlock"::equals).findAny().ifPresent(m -> {
throw new OutOfMemoryError();
});
return invocationOnMock.callRealMethod();
}).when(mockMgmtExecSvc).execute(any(Runnable.class));
GridTestUtils.setFieldValue(grid(0).context().pools(), "mgmtExecSvc", mockMgmtExecSvc);
grid0.getOrCreateCache(new CacheConfiguration<>().setName(DEFAULT_CACHE_NAME)).put(1, 1);
startGrid(getConfiguration(testNodeName(1)).setFailureHandler(hnd));
hnd.awaitFailure(3000);
assertNotNull("Faulire handler hasn't been triggered.", hnd.failureContext());
assertEquals("Failure type must be CRITICAL_ERROR", hnd.failureContext().type(), FailureType.CRITICAL_ERROR);
assertTrue(hnd.failureContext().error() instanceof OutOfMemoryError);
}
Aggregations