Search in sources :

Example 1 with EVT_CACHE_OBJECT_REMOVED

use of org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED 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));
    }
}
Also used : IntStream(java.util.stream.IntStream) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) Arrays(java.util.Arrays) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) Random(java.util.Random) EVT_CACHE_OBJECT_READ(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ) ClientServerError(org.apache.ignite.internal.client.thin.ClientServerError) Future(java.util.concurrent.Future) ServiceContext(org.apache.ignite.services.ServiceContext) Map(java.util.Map) Cache(javax.cache.Cache) EVTS_CACHE(org.apache.ignite.events.EventType.EVTS_CACHE) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) EVT_CACHE_OBJECT_REMOVED(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED) ClientOperation(org.apache.ignite.internal.client.thin.ClientOperation) CyclicBarrier(java.util.concurrent.CyclicBarrier) Query(org.apache.ignite.cache.query.Query) Iterator(java.util.Iterator) IgniteException(org.apache.ignite.IgniteException) FailureHandler(org.apache.ignite.failure.FailureHandler) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) AbstractThinClientTest(org.apache.ignite.internal.client.thin.AbstractThinClientTest) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) Ignition(org.apache.ignite.Ignition) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Service(org.apache.ignite.services.Service) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CacheMode(org.apache.ignite.cache.CacheMode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FailureHandler(org.apache.ignite.failure.FailureHandler) ClientServerError(org.apache.ignite.internal.client.thin.ClientServerError) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test) AbstractThinClientTest(org.apache.ignite.internal.client.thin.AbstractThinClientTest)

Aggregations

Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Cache (javax.cache.Cache)1 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 Ignition (org.apache.ignite.Ignition)1 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)1 CacheMode (org.apache.ignite.cache.CacheMode)1 Query (org.apache.ignite.cache.query.Query)1