Search in sources :

Example 81 with T2

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

the class CacheContinuousQueryFailoverAbstractSelfTest method checkEvents.

/**
 * @param logAll If {@code true} logs all unexpected values.
 * @param expEvts Expected values.
 * @param lsnr Listener.
 * @return Check status.
 */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private boolean checkEvents(boolean logAll, Map<Integer, List<T2<Integer, Integer>>> expEvts, CacheEventListener2 lsnr) {
    assertTrue(!expEvts.isEmpty());
    boolean pass = true;
    for (Map.Entry<Integer, List<T2<Integer, Integer>>> e : expEvts.entrySet()) {
        Integer key = e.getKey();
        List<T2<Integer, Integer>> exp = e.getValue();
        List<CacheEntryEvent<?, ?>> rcvdEvts = lsnr.evts.get(key);
        if (rcvdEvts == null) {
            pass = false;
            log.info("No events for key [key=" + key + ", exp=" + e.getValue() + ']');
            if (!logAll)
                return false;
        } else {
            synchronized (rcvdEvts) {
                if (rcvdEvts.size() != exp.size()) {
                    pass = false;
                    log.info("Missed or extra events for key [key=" + key + ", exp=" + e.getValue() + ", rcvd=" + rcvdEvts + ']');
                    if (!logAll)
                        return false;
                }
                int cnt = Math.min(rcvdEvts.size(), exp.size());
                for (int i = 0; i < cnt; i++) {
                    T2<Integer, Integer> expEvt = exp.get(i);
                    CacheEntryEvent<?, ?> rcvdEvt = rcvdEvts.get(i);
                    if (pass) {
                        assertEquals(key, rcvdEvt.getKey());
                        assertEquals(expEvt.get1(), rcvdEvt.getValue());
                    } else {
                        if (!key.equals(rcvdEvt.getKey()) || !expEvt.get1().equals(rcvdEvt.getValue()))
                            log.warning("Missed events. [key=" + key + ", actKey=" + rcvdEvt.getKey() + ", expVal=" + expEvt.get1() + ", actVal=" + rcvdEvt.getValue() + "]");
                    }
                }
                if (!pass) {
                    for (int i = cnt; i < exp.size(); i++) {
                        T2<Integer, Integer> val = exp.get(i);
                        log.warning("Missed events. [key=" + key + ", expVal=" + val.get1() + ", prevVal=" + val.get2() + "]");
                    }
                }
            }
        }
    }
    if (pass) {
        expEvts.clear();
        lsnr.evts.clear();
    }
    return pass;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) CacheEntryEvent(javax.cache.event.CacheEntryEvent) T2(org.apache.ignite.internal.util.typedef.T2)

Example 82 with T2

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

the class IgfsServerManagerIpcEndpointRegistrationAbstractSelfTest method checkRegisteredIpcEndpoints.

/**
 * Counts all registered IPC endpoints.
 *
 * @return Tuple2 where (tcp endpoints count, shmem endpoints count).
 * @throws Exception If failed.
 */
protected T2<Integer, Integer> checkRegisteredIpcEndpoints() throws Exception {
    GridKernalContext ctx = ((IgniteKernal) grid()).context();
    int tcp = 0;
    int shmem = 0;
    for (GridPortRecord record : ctx.ports().records()) {
        if (record.clazz() == IpcSharedMemoryServerEndpoint.class)
            shmem++;
        else if (record.clazz() == IpcServerTcpEndpoint.class)
            tcp++;
    }
    return new T2<>(tcp, shmem);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridPortRecord(org.apache.ignite.internal.processors.port.GridPortRecord) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) T2(org.apache.ignite.internal.util.typedef.T2)

Example 83 with T2

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

the class CacheContinuousQueryFailoverAbstractSelfTest method testRemoteFilter.

/**
 * @throws Exception If failed.
 */
public void testRemoteFilter() throws Exception {
    this.backups = 2;
    final int SRV_NODES = 4;
    startGridsMultiThreaded(SRV_NODES);
    client = true;
    Ignite qryClient = startGrid(SRV_NODES);
    client = false;
    IgniteCache<Object, Object> qryClientCache = qryClient.cache(DEFAULT_CACHE_NAME);
    if (cacheMode() != REPLICATED)
        assertEquals(backups, qryClientCache.getConfiguration(CacheConfiguration.class).getBackups());
    Affinity<Object> aff = qryClient.affinity(DEFAULT_CACHE_NAME);
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    final CacheEventListener3 lsnr = asyncCallback() ? new CacheEventAsyncListener3() : new CacheEventListener3();
    qry.setLocalListener(lsnr);
    qry.setRemoteFilter(lsnr);
    int PARTS = 10;
    QueryCursor<?> cur = qryClientCache.query(qry);
    Map<Object, T2<Object, Object>> updates = new HashMap<>();
    final List<T3<Object, Object, Object>> expEvts = new ArrayList<>();
    for (int i = 0; i < (atomicityMode() == CacheAtomicityMode.ATOMIC ? SRV_NODES - 1 : SRV_NODES - 2); i++) {
        log.info("Stop iteration: " + i);
        TestCommunicationSpi spi = (TestCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
        Ignite ignite = ignite(i);
        IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
        List<Integer> keys = testKeys(cache, PARTS);
        boolean first = true;
        boolean filtered = false;
        for (Integer key : keys) {
            log.info("Put [node=" + ignite.name() + ", key=" + key + ", part=" + aff.partition(key) + ", filtered=" + filtered + ']');
            T2<Object, Object> t = updates.get(key);
            Integer val = filtered ? (key % 2 == 0 ? key + 1 : key) : key * 2;
            if (t == null) {
                updates.put(key, new T2<>((Object) val, null));
                if (!filtered)
                    expEvts.add(new T3<>((Object) key, (Object) val, null));
            } else {
                updates.put(key, new T2<>((Object) val, (Object) key));
                if (!filtered)
                    expEvts.add(new T3<>((Object) key, (Object) val, (Object) key));
            }
            cache.put(key, val);
            if (first) {
                spi.skipMsg = true;
                first = false;
            }
            filtered = !filtered;
        }
        stopGrid(i);
        boolean check = GridTestUtils.waitForCondition(new PAX() {

            @Override
            public boolean applyx() throws IgniteCheckedException {
                return expEvts.size() == lsnr.keys.size();
            }
        }, 5000L);
        if (!check) {
            Set<Integer> keys0 = new HashSet<>(keys);
            keys0.removeAll(lsnr.keys);
            log.info("Missed events for keys: " + keys0);
            fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + keys0.size() + ']');
        }
        checkEvents(expEvts, lsnr, false);
    }
    cur.close();
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PAX(org.apache.ignite.internal.util.typedef.PAX) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) T2(org.apache.ignite.internal.util.typedef.T2) T3(org.apache.ignite.internal.util.typedef.T3) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

T2 (org.apache.ignite.internal.util.typedef.T2)83 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)31 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)22 Map (java.util.Map)17 Ignite (org.apache.ignite.Ignite)15 UUID (java.util.UUID)14 ClusterNode (org.apache.ignite.cluster.ClusterNode)14 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12 HashSet (java.util.HashSet)11 List (java.util.List)11 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)9 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 CacheEntryEvent (javax.cache.event.CacheEntryEvent)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 CacheException (javax.cache.CacheException)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7