Search in sources :

Example 71 with T2

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

the class CacheContinuousQueryConcurrentPartitionUpdateTest method startListener.

/**
 * @param cache Cache.
 * @return Event counter.
 */
private T2<AtomicInteger, QueryCursor> startListener(IgniteCache<Object, Object> cache) {
    final AtomicInteger evtCnt = new AtomicInteger();
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

        @Override
        public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
            for (CacheEntryEvent evt : evts) {
                assertNotNull(evt.getKey());
                assertNotNull(evt.getValue());
                if ((Integer) evt.getValue() >= 0)
                    evtCnt.incrementAndGet();
            }
        }
    });
    QueryCursor cur = cache.query(qry);
    return new T2<>(evtCnt, cur);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheEntryEvent(javax.cache.event.CacheEntryEvent) QueryCursor(org.apache.ignite.cache.query.QueryCursor) T2(org.apache.ignite.internal.util.typedef.T2)

Example 72 with T2

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

the class CacheContinuousQueryCounterAbstractTest method testEntriesByFilter.

/**
 * @throws Exception If failed.
 */
public void testEntriesByFilter() throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(CACHE_NAME);
    ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
    final Map<Integer, List<T2<Integer, Long>>> map = new HashMap<>();
    final CountDownLatch latch = new CountDownLatch(8);
    qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {

        @Override
        public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
            for (CacheEntryEvent<? extends Integer, ? extends Integer> e : evts) {
                synchronized (map) {
                    List<T2<Integer, Long>> vals = map.get(e.getKey());
                    if (vals == null) {
                        vals = new ArrayList<>();
                        map.put(e.getKey(), vals);
                    }
                    vals.add(new T2<>(e.getValue(), e.unwrap(CacheQueryEntryEvent.class).getPartitionUpdateCounter()));
                }
                latch.countDown();
            }
        }
    });
    qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Integer, Integer>() {

        @Override
        public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Integer> evt) {
            return evt.getValue() % 2 == 0;
        }
    });
    try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache.query(qry)) {
        cache.put(1, 1);
        cache.put(1, 2);
        cache.put(1, 3);
        cache.put(1, 4);
        cache.put(2, 1);
        cache.put(2, 2);
        cache.put(2, 3);
        cache.put(2, 4);
        cache.remove(1);
        cache.remove(2);
        cache.put(1, 10);
        cache.put(2, 40);
        assert latch.await(LATCH_TIMEOUT, MILLISECONDS);
        assertEquals(2, map.size());
        List<T2<Integer, Long>> vals = map.get(1);
        assertNotNull(vals);
        assertEquals(4, vals.size());
        assertEquals((int) vals.get(0).get1(), 2);
        assertEquals((long) vals.get(0).get1(), (long) vals.get(0).get2());
        assertEquals((int) vals.get(1).get1(), 4);
        assertEquals((long) vals.get(1).get1(), (long) vals.get(1).get2());
        assertNull(vals.get(2).get1());
        assertEquals(5, (long) vals.get(2).get2());
        assertEquals((int) vals.get(3).get1(), 10);
        assertEquals(6, (long) vals.get(3).get2());
        vals = map.get(2);
        assertNotNull(vals);
        assertEquals(4, vals.size());
        assertEquals((int) vals.get(0).get1(), 2);
        assertEquals((long) vals.get(0).get1(), (long) vals.get(0).get2());
        assertEquals((int) vals.get(1).get1(), 4);
        assertEquals((long) vals.get(1).get1(), (long) vals.get(1).get2());
        assertNull(vals.get(2).get1());
        assertEquals(5, (long) vals.get(2).get2());
        assertEquals((int) vals.get(3).get1(), 40);
        assertEquals(6, (long) vals.get(3).get2());
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) CacheEntryEvent(javax.cache.event.CacheEntryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) ArrayList(java.util.ArrayList) List(java.util.List) T2(org.apache.ignite.internal.util.typedef.T2)

Example 73 with T2

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

the class WalRecoveryTxLogicalRecordsTest method testFreeListRecovery.

/**
 * @throws Exception If failed.
 */
public void testFreeListRecovery() throws Exception {
    try {
        pageSize = 1024;
        extraCcfg = new CacheConfiguration(CACHE2_NAME);
        Ignite ignite = startGrid(0);
        ignite.cluster().active(true);
        IgniteCache<Integer, IndexedValue> cache1 = ignite.cache(CACHE_NAME);
        IgniteCache<Object, Object> cache2 = ignite.cache(CACHE2_NAME);
        final int KEYS1 = 2048;
        for (int i = 0; i < KEYS1; i++) cache1.put(i, new IndexedValue(i));
        for (int i = 0; i < KEYS1; i++) {
            if (i % 2 == 0)
                cache1.remove(i);
        }
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        for (int i = 0; i < KEYS1; i++) {
            cache2.put(i, new byte[rnd.nextInt(512)]);
            if (rnd.nextBoolean())
                cache2.put(i, new byte[rnd.nextInt(512)]);
            if (rnd.nextBoolean())
                cache2.remove(i);
        }
        Map<Integer, T2<Map<Integer, long[]>, int[]>> cache1_1 = getFreeListData(ignite, CACHE_NAME);
        Map<Integer, T2<Map<Integer, long[]>, int[]>> cache2_1 = getFreeListData(ignite, CACHE2_NAME);
        T2<long[], Integer> rl1_1 = getReuseListData(ignite, CACHE_NAME);
        T2<long[], Integer> rl2_1 = getReuseListData(ignite, CACHE2_NAME);
        ignite.close();
        ignite = startGrid(0);
        ignite.cluster().active(true);
        cache1 = ignite.cache(CACHE_NAME);
        cache2 = ignite.cache(CACHE2_NAME);
        for (int i = 0; i < KEYS1; i++) {
            cache1.get(i);
            cache2.get(i);
        }
        Map<Integer, T2<Map<Integer, long[]>, int[]>> cache1_2 = getFreeListData(ignite, CACHE_NAME);
        Map<Integer, T2<Map<Integer, long[]>, int[]>> cache2_2 = getFreeListData(ignite, CACHE2_NAME);
        T2<long[], Integer> rl1_2 = getReuseListData(ignite, CACHE_NAME);
        T2<long[], Integer> rl2_2 = getReuseListData(ignite, CACHE2_NAME);
        checkEquals(cache1_1, cache1_2);
        checkEquals(cache2_1, cache2_2);
        checkEquals(rl1_1, rl1_2);
        checkEquals(rl2_1, rl2_2);
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) T2(org.apache.ignite.internal.util.typedef.T2)

Example 74 with T2

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

the class HadoopMapReduceCounters method findCounter.

/**
 * Find a counter in the group.
 *
 * @param grpName The name of the counter group.
 * @param cntrName The name of the counter.
 * @param create Create the counter if not found if true.
 * @return The counter that was found or added or {@code null} if create is false.
 */
public Counter findCounter(String grpName, String cntrName, boolean create) {
    T2<String, String> key = new T2<>(grpName, cntrName);
    HadoopLongCounter internalCntr = cntrs.get(key);
    if (internalCntr == null & create) {
        internalCntr = new HadoopLongCounter(grpName, cntrName);
        cntrs.put(key, new HadoopLongCounter(grpName, cntrName));
    }
    return internalCntr == null ? null : new HadoopV2Counter(internalCntr);
}
Also used : HadoopLongCounter(org.apache.ignite.internal.processors.hadoop.counter.HadoopLongCounter) HadoopV2Counter(org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopV2Counter) T2(org.apache.ignite.internal.util.typedef.T2)

Example 75 with T2

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

the class WalRecoveryTxLogicalRecordsTest method getFreeListData.

/**
 * @param ignite Node.
 * @param cacheName Cache name.
 * @return Cache free lists data.
 */
private Map<Integer, T2<Map<Integer, long[]>, int[]>> getFreeListData(Ignite ignite, String cacheName) {
    GridCacheContext ctx = ((IgniteEx) ignite).context().cache().cache(cacheName).context();
    List<GridDhtLocalPartition> parts = ctx.topology().localPartitions();
    assertTrue(!parts.isEmpty());
    assertEquals(ctx.affinity().partitions(), parts.size());
    Map<Integer, T2<Map<Integer, long[]>, int[]>> res = new HashMap<>();
    boolean foundNonEmpty = false;
    boolean foundTails = false;
    for (GridDhtLocalPartition part : parts) {
        CacheFreeListImpl freeList = GridTestUtils.getFieldValue(part.dataStore(), "freeList");
        if (freeList == null)
            // Lazy store.
            continue;
        AtomicReferenceArray<PagesList.Stripe[]> buckets = GridTestUtils.getFieldValue(freeList, AbstractFreeList.class, "buckets");
        // AtomicIntegerArray cnts = GridTestUtils.getFieldValue(freeList, PagesList.class, "cnts");
        assertNotNull(buckets);
        // assertNotNull(cnts);
        assertTrue(buckets.length() > 0);
        // assertEquals(cnts.length(), buckets.length());
        Map<Integer, long[]> tailsPerBucket = new HashMap<>();
        for (int i = 0; i < buckets.length(); i++) {
            PagesList.Stripe[] tails = buckets.get(i);
            long[] ids = null;
            if (tails != null) {
                ids = new long[tails.length];
                for (int j = 0; j < tails.length; j++) ids[j] = tails[j].tailId;
            }
            tailsPerBucket.put(i, ids);
            if (tails != null) {
                assertTrue(tails.length > 0);
                foundTails = true;
            }
        }
        // int[] cntsPerBucket = new int[cnts.length()];
        // 
        // for (int i = 0; i < cnts.length(); i++) {
        // cntsPerBucket[i] = cnts.get(i);
        // 
        // if (cntsPerBucket[i] > 0)
        // foundNonEmpty = true;
        // }
        res.put(part.id(), new T2<>(tailsPerBucket, (int[]) null));
    }
    // assertTrue(foundNonEmpty);
    assertTrue(foundTails);
    return res;
}
Also used : CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) HashMap(java.util.HashMap) PagesList(org.apache.ignite.internal.processors.cache.persistence.freelist.PagesList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) T2(org.apache.ignite.internal.util.typedef.T2)

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