Search in sources :

Example 6 with TestFailureHandler

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;
}
Also used : TestFailureHandler(org.apache.ignite.failure.TestFailureHandler) FailureHandler(org.apache.ignite.failure.FailureHandler) TestFailureHandler(org.apache.ignite.failure.TestFailureHandler)

Example 7 with TestFailureHandler

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);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) ExecutorService(java.util.concurrent.ExecutorService) TestFailureHandler(org.apache.ignite.failure.TestFailureHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

TestFailureHandler (org.apache.ignite.failure.TestFailureHandler)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 Test (org.junit.Test)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Ignite (org.apache.ignite.Ignite)2 FailureHandler (org.apache.ignite.failure.FailureHandler)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 IgniteSpiOperationTimeoutException (org.apache.ignite.spi.IgniteSpiOperationTimeoutException)1