use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class CachePartitionStateTest method checkNodePartitions.
/**
* @param assign Assignments.
* @param clusterNode Node.
* @param cacheName Cache name.
* @param expState Expected partitions state.
*/
private void checkNodePartitions(AffinityAssignment assign, ClusterNode clusterNode, String cacheName, GridDhtPartitionState expState) {
Affinity<Object> aff = ignite(0).affinity(cacheName);
Set<Integer> nodeParts = new HashSet<>();
nodeParts.addAll(assign.primaryPartitions(clusterNode.id()));
nodeParts.addAll(assign.backupPartitions(clusterNode.id()));
log.info("Test state [node=" + clusterNode.id() + ", cache=" + cacheName + ", parts=" + nodeParts.size() + ", state=" + expState + ']');
if (grid(0).context().discovery().cacheAffinityNode(clusterNode, cacheName))
assertFalse(nodeParts.isEmpty());
boolean check = false;
for (Ignite node : G.allGrids()) {
GridCacheAdapter cache = ((IgniteKernal) node).context().cache().internalCache(cacheName);
if (cache != null) {
check = true;
GridDhtPartitionTopology top = cache.context().topology();
GridDhtPartitionMap partsMap = top.partitions(clusterNode.id());
for (int p = 0; p < aff.partitions(); p++) {
if (nodeParts.contains(p)) {
assertNotNull(partsMap);
GridDhtPartitionState state = partsMap.get(p);
assertEquals("Unexpected state [checkNode=" + clusterNode.id() + ", node=" + node.name() + ", state=" + state + ']', expState, partsMap.get(p));
} else {
if (partsMap != null) {
GridDhtPartitionState state = partsMap.get(p);
assertTrue("Unexpected state [checkNode=" + clusterNode.id() + ", node=" + node.name() + ", state=" + state + ']', state == null || state == EVICTED);
}
}
}
} else {
assertEquals(0, aff.primaryPartitions(((IgniteKernal) node).localNode()).length);
assertEquals(0, aff.backupPartitions(((IgniteKernal) node).localNode()).length);
}
}
assertTrue(check);
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class CachePartitionStateTest method checkRebalance.
/**
* @param cacheName Cache name.
* @param expDone Expected rebalance finish flag.
*/
private void checkRebalance(String cacheName, boolean expDone) {
for (Ignite node : G.allGrids()) {
IgniteKernal node0 = (IgniteKernal) node;
GridCacheAdapter cache = node0.context().cache().internalCache(cacheName);
AffinityTopologyVersion topVer = node0.context().cache().context().exchange().readyAffinityVersion();
if (cache != null)
assertEquals(expDone, cache.context().topology().rebalanceFinished(topVer));
else
node0.context().discovery().cacheAffinityNode(node0.localNode(), cacheName);
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class EvictionPolicyFailureHandlerTest method testCacheMapDoesNotContainsWrongEntityAfterTransaction.
/**
* We expect that localPeek produces an exception, but the entry evict returns false because the transaction locks
* this entry. After transaction commit, the entry will be evicted.
*/
@Test
public void testCacheMapDoesNotContainsWrongEntityAfterTransaction() throws Exception {
LogListener lsnr = LogListener.matches(s -> s.contains("The cache entry cannot be touched")).times(1).build();
log.registerListener(lsnr);
IgniteEx node = startGrid(0);
IgniteEx client = startClientGrid(1);
GridCacheAdapter<Object, Object> cache = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
cache.put(1, 1);
CountDownLatch locPeekFinished = new CountDownLatch(1);
CountDownLatch txStarted = new CountDownLatch(1);
CountDownLatch txFinished = new CountDownLatch(1);
GridTestUtils.runAsync(() -> {
IgniteCache<Object, Object> cache1 = client.cache(DEFAULT_CACHE_NAME);
IgniteTransactions transactions = client.transactions();
try (Transaction tx = transactions.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache1.put(2.1, 2.4);
txStarted.countDown();
locPeekFinished.await();
tx.commit();
} catch (Exception ignore) {
}
txFinished.countDown();
}, "tx-thread");
txStarted.await();
try {
cache.localPeek(2.1, new CachePeekMode[] { CachePeekMode.ONHEAP });
} catch (Exception ignore) {
}
locPeekFinished.countDown();
assertTrue(lsnr.check(10_000));
txFinished.await();
assertFalse(cache.map().entrySet(cache.context().cacheId()).stream().anyMatch(e -> new Double(2.1).equals(e.key().value(null, false))));
assertEquals(ACTIVE, node.cluster().state());
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class IgniteCacheClientNearCacheExpiryTest method testExpirationOnClient.
/**
* @throws Exception If failed.
*/
@Test
public void testExpirationOnClient() throws Exception {
Ignite ignite = grid(NODES - 1);
// Check size of near entries via reflection because entries is filtered for size() API call.
IgniteEx igniteEx = (IgniteEx) ignite;
GridCacheAdapter internalCache = igniteEx.context().cache().internalCache(DEFAULT_CACHE_NAME);
GridCacheLocalConcurrentMap map = GridTestUtils.getFieldValue(internalCache, GridCacheAdapter.class, "map");
assertTrue(ignite.configuration().isClientMode());
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertTrue(((IgniteCacheProxy) cache).context().isNear());
for (int i = 0; i < KEYS_COUNT; i++) cache.put(i, i);
CreatedExpiryPolicy plc = new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 500));
IgniteCache<Object, Object> cacheWithExpiry = cache.withExpiryPolicy(plc);
for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) {
cacheWithExpiry.put(i, i);
assertEquals(i, cacheWithExpiry.localPeek(i));
}
assertEquals(KEYS_COUNT * 2, map.publicSize(internalCache.context().cacheId()));
U.sleep(1000);
assertEquals(KEYS_COUNT, map.publicSize(internalCache.context().cacheId()));
assertEquals(KEYS_COUNT, cache.size());
for (int i = 0; i < KEYS_COUNT; i++) assertEquals(i, cacheWithExpiry.localPeek(i));
for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) assertNull(cache.localPeek(i));
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class IgniteStandByClusterTest method testStaticCacheStartAfterActivationWithCacheFilter.
/**
* @throws Exception if fail.
*/
@Test
public void testStaticCacheStartAfterActivationWithCacheFilter() throws Exception {
String cache1 = "cache1";
String cache2 = "cache2";
String cache3 = "cache3";
IgniteConfiguration cfg1 = getConfiguration("node1");
cfg1.setCacheConfiguration(new CacheConfiguration(cache1).setNodeFilter(new NodeFilterIgnoreByName("node2")));
IgniteConfiguration cfg2 = getConfiguration("node2");
cfg2.setCacheConfiguration(new CacheConfiguration(cache2).setNodeFilter(new NodeFilterIgnoreByName("node3")));
IgniteConfiguration cfg3 = getConfiguration("node3");
cfg3.setCacheConfiguration(new CacheConfiguration(cache3).setNodeFilter(new NodeFilterIgnoreByName("node1")));
IgniteEx ig1 = startGrid(cfg1);
IgniteEx ig2 = startGrid(cfg2);
IgniteEx ig3 = startGrid(cfg3);
assertTrue(!ig1.active());
assertTrue(!ig2.active());
assertTrue(!ig3.active());
ig3.active(true);
assertTrue(ig1.active());
assertTrue(ig2.active());
assertTrue(ig3.active());
for (IgniteEx ig : Arrays.asList(ig1, ig2, ig3)) {
Map<String, DynamicCacheDescriptor> desc = U.field((Object) U.field(ig.context().cache(), "cachesInfo"), "registeredCaches");
assertEquals(4, desc.size());
Map<String, GridCacheAdapter<?, ?>> caches = U.field(ig.context().cache(), "caches");
assertEquals(3, caches.keySet().size());
}
Map<String, GridCacheAdapter<?, ?>> caches1 = U.field(ig1.context().cache(), "caches");
Assert.assertNotNull(caches1.get(cache1));
Assert.assertNotNull(caches1.get(cache2));
Assert.assertNull(caches1.get(cache3));
Map<String, GridCacheAdapter<?, ?>> caches2 = U.field(ig2.context().cache(), "caches");
Assert.assertNull(caches2.get(cache1));
Assert.assertNotNull(caches2.get(cache2));
Assert.assertNotNull(caches2.get(cache3));
Map<String, GridCacheAdapter<?, ?>> caches3 = U.field(ig3.context().cache(), "caches");
Assert.assertNotNull(caches3.get(cache1));
Assert.assertNull(caches3.get(cache2));
Assert.assertNotNull(caches3.get(cache3));
}
Aggregations