use of org.apache.ignite.events.EventType.EVTS_CACHE in project ignite by apache.
the class ReliabilityTest method testServerCriticalError.
/**
* Test server-side critical error.
*/
@Test
public void testServerCriticalError() throws Exception {
AtomicBoolean failure = new AtomicBoolean();
FailureHandler hnd = (ignite, ctx) -> failure.compareAndSet(false, true);
try (Ignite ignite = startGrid(getConfiguration().setFailureHandler(hnd).setIncludeEventTypes(EVTS_CACHE));
IgniteClient client = startClient(ignite)) {
ClientCache<Object, Object> cache = client.getOrCreateCache(DEFAULT_CACHE_NAME);
cachePut(cache, 0, 0);
String msg = "critical error message";
ignite.events().localListen(e -> {
throw new Error(msg);
}, EVT_CACHE_OBJECT_READ);
GridTestUtils.assertThrowsAnyCause(log, () -> cache.get(0), ClientServerError.class, msg);
assertFalse(failure.get());
// OutOfMemoryError should also invoke failure handler.
ignite.events().localListen(e -> {
throw new OutOfMemoryError(msg);
}, EVT_CACHE_OBJECT_REMOVED);
GridTestUtils.assertThrowsAnyCause(log, () -> cache.remove(0), ClientServerError.class, msg);
assertTrue(GridTestUtils.waitForCondition(failure::get, 1_000L));
}
}
Aggregations