Search in sources :

Example 21 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class CacheContinuousQueryRandomOperationsTest method batchOperation.

/**
     * @param ccfg Cache configuration.
     * @throws Exception If failed.
     */
private void batchOperation(CacheConfiguration ccfg) throws Exception {
    IgniteCache<QueryTestKey, QueryTestValue> cache = grid(getClientIndex()).createCache(ccfg);
    try {
        ContinuousQuery<QueryTestKey, QueryTestValue> qry = new ContinuousQuery<>();
        final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts = new CopyOnWriteArrayList<>();
        if (noOpFilterFactory() != null)
            qry.setRemoteFilterFactory(noOpFilterFactory());
        qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {

            @Override
            public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> events) throws CacheEntryListenerException {
                for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events) evts.add(e);
            }
        });
        Map<QueryTestKey, QueryTestValue> map = new TreeMap<>();
        for (int i = 0; i < KEYS; i++) map.put(new QueryTestKey(i), new QueryTestValue(i));
        try (QueryCursor qryCur = cache.query(qry)) {
            for (int i = 0; i < ITERATION_CNT / 2; i++) {
                log.info("Start iteration: " + i);
                // Not events.
                cache.removeAll(map.keySet());
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                // Get events.
                cache.putAll(map);
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == KEYS;
                    }
                }, 5_000);
                checkEvents(evts, CREATED);
                evts.clear();
                // Not events.
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                U.sleep(100);
                assertEquals(0, evts.size());
                // Get events.
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                // Not events.
                cache.removeAll(map.keySet());
                cache.removeAll(map.keySet());
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == KEYS;
                    }
                }, 5_000);
                checkEvents(evts, REMOVED);
                evts.clear();
                log.info("Finish iteration: " + i);
            }
        }
    } finally {
        grid(getClientIndex()).destroyCache(ccfg.getName());
    }
}
Also used : CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) TreeMap(java.util.TreeMap) CacheEntryEvent(javax.cache.event.CacheEntryEvent) PA(org.apache.ignite.internal.util.typedef.PA) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 22 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class CacheContinuousQueryRandomOperationsTest method singleOperation.

/**
     * @param ccfg Cache configuration.
     * @throws Exception If failed.
     */
private void singleOperation(CacheConfiguration ccfg) throws Exception {
    IgniteCache<QueryTestKey, QueryTestValue> cache = grid(getClientIndex()).createCache(ccfg);
    try {
        ContinuousQuery<QueryTestKey, QueryTestValue> qry = new ContinuousQuery<>();
        final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts = new CopyOnWriteArrayList<>();
        if (noOpFilterFactory() != null)
            qry.setRemoteFilterFactory(noOpFilterFactory());
        qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {

            @Override
            public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> events) throws CacheEntryListenerException {
                for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events) evts.add(e);
            }
        });
        QueryTestKey key = new QueryTestKey(1);
        try (QueryCursor qryCur = cache.query(qry)) {
            for (int i = 0; i < ITERATION_CNT; i++) {
                log.info("Start iteration: " + i);
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                // Get events.
                cache.put(key, new QueryTestValue(1));
                cache.remove(key);
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                cache.remove(key);
                // Get events.
                cache.put(key, new QueryTestValue(2));
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                // Get events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                // Not events.
                cache.remove(key);
                // Get events.
                cache.put(key, new QueryTestValue(3));
                cache.put(key, new QueryTestValue(4));
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                cache.putIfAbsent(key, new QueryTestValue(5));
                cache.putIfAbsent(key, new QueryTestValue(5));
                cache.putIfAbsent(key, new QueryTestValue(5));
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                cache.remove(key, new QueryTestValue(5));
                // Get events.
                cache.remove(key, new QueryTestValue(4));
                cache.putIfAbsent(key, new QueryTestValue(5));
                // Not events.
                cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
                cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
                cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
                // Get events.
                cache.replace(key, new QueryTestValue(5), new QueryTestValue(6));
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == 9;
                    }
                }, 5_000);
                checkSingleEvent(evts.get(0), CREATED, new QueryTestValue(1), null);
                checkSingleEvent(evts.get(1), REMOVED, null, new QueryTestValue(1));
                checkSingleEvent(evts.get(2), CREATED, new QueryTestValue(2), null);
                checkSingleEvent(evts.get(3), REMOVED, null, new QueryTestValue(2));
                checkSingleEvent(evts.get(4), CREATED, new QueryTestValue(3), null);
                checkSingleEvent(evts.get(5), EventType.UPDATED, new QueryTestValue(4), new QueryTestValue(3));
                checkSingleEvent(evts.get(6), REMOVED, null, new QueryTestValue(4));
                checkSingleEvent(evts.get(7), CREATED, new QueryTestValue(5), null);
                checkSingleEvent(evts.get(8), EventType.UPDATED, new QueryTestValue(6), new QueryTestValue(5));
                evts.clear();
                cache.remove(key);
                cache.remove(key);
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == 1;
                    }
                }, 5_000);
                evts.clear();
                log.info("Finish iteration: " + i);
            }
        }
    } finally {
        grid(getClientIndex()).destroyCache(ccfg.getName());
    }
}
Also used : CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) PA(org.apache.ignite.internal.util.typedef.PA) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 23 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridTcpCommunicationSpiMultithreadedSelfTest method afterTest.

/**
     * @throws Exception If failed.
     */
@Override
protected void afterTest() throws Exception {
    super.afterTest();
    for (MessageListener lsnr : lsnrs.values()) {
        lsnr.rcvdMsgs.clear();
        lsnr.rmtMsgCnt.set(0);
    }
    for (CommunicationSpi spi : spis.values()) {
        final ConcurrentMap<UUID, GridCommunicationClient[]> clients = U.field(spi, "clients");
        assert GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                for (GridCommunicationClient[] clients0 : clients.values()) {
                    for (GridCommunicationClient client : clients0) {
                        if (client != null)
                            return false;
                    }
                }
                return true;
            }
        }, getTestTimeout()) : "Clients: " + clients;
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) UUID(java.util.UUID) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient)

Example 24 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridServiceProcessorProxySelfTest method testLocalProxyInvocation.

/**
     * @throws Exception If failed.
     */
public void testLocalProxyInvocation() throws Exception {
    final String name = "testLocalProxyInvocation";
    final Ignite ignite = grid(0);
    ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>());
    for (int i = 0; i < nodeCount(); i++) {
        final int idx = i;
        final AtomicReference<MapService<Integer, String>> ref = new AtomicReference<>();
        //wait because after deployNodeSingleton we don't have guarantees what service was deploy.
        boolean wait = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                MapService<Integer, String> svc = grid(idx).services().serviceProxy(name, MapService.class, false);
                ref.set(svc);
                return svc instanceof Service;
            }
        }, 2000);
        // Make sure service is a local instance.
        assertTrue("Invalid service instance [srv=" + ref.get() + ", node=" + i + ']', wait);
        ref.get().put(i, Integer.toString(i));
    }
    MapService<Integer, String> map = ignite.services().serviceProxy(name, MapService.class, false);
    for (int i = 0; i < nodeCount(); i++) assertEquals(1, map.size());
}
Also used : Service(org.apache.ignite.services.Service) AtomicReference(java.util.concurrent.atomic.AtomicReference) PA(org.apache.ignite.internal.util.typedef.PA) Ignite(org.apache.ignite.Ignite)

Example 25 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class IgniteServiceDynamicCachesSelfTest method testDeployCalledAfterCacheStart.

/**
     * @throws Exception If failed.
     */
public void testDeployCalledAfterCacheStart() throws Exception {
    String cacheName = "cache";
    CacheConfiguration ccfg = new CacheConfiguration(cacheName);
    ccfg.setBackups(1);
    Ignite ig = ignite(0);
    ig.createCache(ccfg);
    try {
        final IgniteServices svcs = ig.services();
        final String svcName = "myService";
        svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, primaryKey(ig.cache(cacheName)));
        boolean res = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return svcs.service(svcName) != null;
            }
        }, 10 * 1000);
        assertTrue("Service was not deployed", res);
        ig.destroyCache(cacheName);
        res = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return svcs.service(svcName) == null;
            }
        }, 10 * 1000);
        assertTrue("Service was not undeployed", res);
    } finally {
        ig.services().cancelAll();
        ig.destroyCache(cacheName);
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

PA (org.apache.ignite.internal.util.typedef.PA)48 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 Ignite (org.apache.ignite.Ignite)17 ArrayList (java.util.ArrayList)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 UUID (java.util.UUID)9 CacheEntryEvent (javax.cache.event.CacheEntryEvent)9 IgniteException (org.apache.ignite.IgniteException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IgniteCache (org.apache.ignite.IgniteCache)5 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 T2 (org.apache.ignite.internal.util.typedef.T2)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Transaction (org.apache.ignite.transactions.Transaction)4