Search in sources :

Example 6 with FailureHandler

use of org.apache.ignite.failure.FailureHandler 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)

Example 7 with FailureHandler

use of org.apache.ignite.failure.FailureHandler in project ignite by apache.

the class ServiceAuthorizationTest method configuration.

/**
 * @return Ignite node configuration.
 */
private IgniteConfiguration configuration(int idx, SecurityPermission... perms) throws Exception {
    String name = getTestIgniteInstanceName(idx);
    IgniteConfiguration cfg = getConfiguration(name, new TestSecurityPluginProvider(name, "", create().defaultAllowAll(false).appendSystemPermissions(JOIN_AS_SERVER).appendCachePermissions(DEFAULT_CACHE_NAME, CACHE_CREATE).appendTaskPermissions("org.apache.ignite.internal.processors.affinity.GridAffinityUtils$AffinityJob", TASK_EXECUTE, TASK_CANCEL).appendServicePermissions(TEST_SERVICE_NAME, perms).build(), null, false)).setClientMode(isClient);
    if (authErrLatch != null) {
        cfg.setFailureHandler(new FailureHandler() {

            @Override
            public boolean onFailure(Ignite ignite, FailureContext failureCtx) {
                assertTrue(failureCtx.error() instanceof SecurityException);
                assertTrue(failureCtx.error().getMessage().startsWith("Authorization failed [perm=SERVICE_DEPLOY, name=test-service-name"));
                authErrLatch.countDown();
                return true;
            }
        });
    }
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestSecurityPluginProvider(org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider) FailureContext(org.apache.ignite.failure.FailureContext) FailureHandler(org.apache.ignite.failure.FailureHandler) Ignite(org.apache.ignite.Ignite) SecurityException(org.apache.ignite.plugin.security.SecurityException)

Aggregations

FailureHandler (org.apache.ignite.failure.FailureHandler)7 Ignite (org.apache.ignite.Ignite)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FailureContext (org.apache.ignite.failure.FailureContext)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Random (java.util.Random)1 UUID (java.util.UUID)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