Search in sources :

Example 1 with EVT_CACHE_OBJECT_READ

use of org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ in project ignite by apache.

the class CacheEventSecurityContextTest method checkEvents.

/**
 * Executes specified cache operation on each server node and checks events.
 */
private void checkEvents(ConsumerX<Integer> op, boolean withInitVal, Integer... expEvtTypes) throws Exception {
    IgniteEx crd = grid("crd");
    Set<Integer> evts = Arrays.stream(expEvtTypes).collect(Collectors.toSet());
    // TODO Remove the following workaround after resolving IGNITE-13490.
    if (ATOMIC_CACHE.equals(cacheName) && evts.size() > 1)
        evts.remove(EVT_CACHE_OBJECT_READ);
    if (TRANSACTIONAL_CACHE.equals(cacheName) && !(evts.size() == 1 && evts.contains(EVT_CACHE_OBJECT_READ))) {
        evts.add(EVT_CACHE_OBJECT_LOCKED);
        evts.add(EVT_CACHE_OBJECT_UNLOCKED);
    }
    List<Integer> keys = testNodes().stream().map(node -> keyForNode(crd.affinity(cacheName), KEY_COUNTER, node)).collect(Collectors.toList());
    if (withInitVal)
        keys.forEach(key -> crd.cache(cacheName).put(key, "val"));
    checkEvents(() -> keys.forEach(op), evts);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) Arrays(java.util.Arrays) Transaction(org.apache.ignite.transactions.Transaction) ClientTransactions(org.apache.ignite.client.ClientTransactions) IgniteEx(org.apache.ignite.internal.IgniteEx) EVT_CACHE_OBJECT_READ(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ) CACHE_REPLACE(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REPLACE) ClientCache(org.apache.ignite.client.ClientCache) Collections.singletonList(java.util.Collections.singletonList) MutableEntry(javax.cache.processor.MutableEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SecurityCredentials(org.apache.ignite.plugin.security.SecurityCredentials) Arrays.asList(java.util.Arrays.asList) CACHE_APPEND(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_APPEND) CACHE_REMOVE(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REMOVE) Parameterized(org.junit.runners.Parameterized) EVT_CACHE_OBJECT_UNLOCKED(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_UNLOCKED) GridClientFactory(org.apache.ignite.internal.client.GridClientFactory) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) Collectors(java.util.stream.Collectors) CACHE_GET_AND_REMOVE(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_AND_REMOVE) IgniteCache(org.apache.ignite.IgniteCache) CACHE_PREPEND(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PREPEND) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridClientData(org.apache.ignite.internal.client.GridClientData) CacheEntryProcessor(org.apache.ignite.cache.CacheEntryProcessor) CACHE_GET_ALL(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) CACHE_GET_AND_PUT(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_AND_PUT) CACHE_CAS(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_CAS) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) GridRestCommand(org.apache.ignite.internal.processors.rest.GridRestCommand) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CACHE_GET(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET) SecurityCredentialsBasicProvider(org.apache.ignite.plugin.security.SecurityCredentialsBasicProvider) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) RunWith(org.junit.runner.RunWith) CACHE_GET_AND_REPLACE(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_AND_REPLACE) EntryProcessorException(javax.cache.processor.EntryProcessorException) ArrayList(java.util.ArrayList) Config(org.apache.ignite.client.Config) ClientTransaction(org.apache.ignite.client.ClientTransaction) IgniteClient(org.apache.ignite.client.IgniteClient) EVT_CACHE_QUERY_OBJECT_READ(org.apache.ignite.events.EventType.EVT_CACHE_QUERY_OBJECT_READ) Assume(org.junit.Assume) Collections.singletonMap(java.util.Collections.singletonMap) EVT_CACHE_OBJECT_REMOVED(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED) ImmutableSet.of(com.google.common.collect.ImmutableSet.of) CACHE_REMOVE_ALL(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REMOVE_ALL) EVT_CACHE_OBJECT_PUT(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT) GridClient(org.apache.ignite.internal.client.GridClient) CACHE_ADD(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_ADD) CACHE_PUT_ALL(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT_ALL) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) CACHE_PUT_IF_ABSENT(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT_IF_ABSENT) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) CACHE_REMOVE_VALUE(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REMOVE_VALUE) Consumer(java.util.function.Consumer) Lock(java.util.concurrent.locks.Lock) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CACHE_PUT(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT) CACHE_REPLACE_VALUE(org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REPLACE_VALUE) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) EVT_CACHE_OBJECT_LOCKED(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_LOCKED) IgniteTransactions(org.apache.ignite.IgniteTransactions) EVT_CACHE_QUERY_EXECUTED(org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 2 with EVT_CACHE_OBJECT_READ

use of org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ 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)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Ignite (org.apache.ignite.Ignite)2 IgniteException (org.apache.ignite.IgniteException)2 Ignition (org.apache.ignite.Ignition)2 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)2 ScanQuery (org.apache.ignite.cache.query.ScanQuery)2 EVT_CACHE_OBJECT_READ (org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ)2 EVT_CACHE_OBJECT_REMOVED (org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED)2 ImmutableSet.of (com.google.common.collect.ImmutableSet.of)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1