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);
}
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());
}
}
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();
}
}
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);
}
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;
}
Aggregations