use of org.apache.ignite.testframework.TestDependencyResolver in project ignite by apache.
the class PartitionEvictionOrderTest method testSyncCachesEvictedAtFirst.
/**
* Tests that {@link CacheRebalanceMode#SYNC} caches are evicted at first.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_EVICTION_PERMITS, value = "1")
@WithSystemProperty(key = IGNITE_PDS_WAL_REBALANCE_THRESHOLD, value = "500_000")
public void testSyncCachesEvictedAtFirst() throws Exception {
IgniteEx node0 = startGrid(0);
node0.cluster().state(ACTIVE);
IgniteEx node1 = startGrid(1);
node0.cluster().setBaselineTopology(node1.cluster().topologyVersion());
GridCacheAdapter<Object, Object> utilCache0 = grid(0).context().cache().internalCache(CU.UTILITY_CACHE_NAME);
IgniteCache<Object, Object> cache = node0.getOrCreateCache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 1000; i++) {
utilCache0.put(i, i);
cache.put(i, i);
}
awaitPartitionMapExchange();
stopGrid(0);
GridCacheAdapter<Object, Object> utilCache1 = grid(1).context().cache().internalCache(CU.UTILITY_CACHE_NAME);
IgniteInternalCache<Object, Object> cache2 = grid(1).context().cache().cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 2000; i++) {
try {
cache2.put(i, i + 1);
utilCache1.put(i, i + 1);
} catch (IgniteCheckedException e) {
e.printStackTrace();
}
}
List<T2<Integer, Integer>> evictionOrder = Collections.synchronizedList(new ArrayList<>());
TestDependencyResolver rslvr = new TestDependencyResolver(new DependencyResolver() {
@Override
public <T> T resolve(T instance) {
if (instance instanceof GridDhtPartitionTopologyImpl) {
GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) instance;
top.partitionFactory((ctx, grp, id, recovery) -> new GridDhtLocalPartition(ctx, grp, id, recovery) {
@Override
public long clearAll(EvictionContext evictionCtx) throws NodeStoppingException {
evictionOrder.add(new T2<>(grp.groupId(), id));
return super.clearAll(evictionCtx);
}
});
}
return instance;
}
});
startGrid(0, rslvr);
awaitPartitionMapExchange(true, true, null);
assertEquals(utilCache0.affinity().partitions() + grid(0).cachex(DEFAULT_CACHE_NAME).affinity().partitions(), evictionOrder.size());
for (int i = 0; i < utilCache0.affinity().partitions(); i++) assertEquals(CU.UTILITY_CACHE_GROUP_ID, evictionOrder.get(i).get1().intValue());
}
use of org.apache.ignite.testframework.TestDependencyResolver in project ignite by apache.
the class TxDeadlockOnEntryToStringTest method testDeadlockOnTimeoutWorkerAndToString.
/**
* We removed locks from toString on Entry. The case, a thread X lock entry, after that trying to do a handshake
* with connecting node. But, handshake fails on the first attempt. Between these events, timeout worked trying to
* print this entry, but I locked. The thread X can't reconnect, because timeout worker hangs.
*/
@Test
public void testDeadlockOnTimeoutWorkerAndToString() throws Exception {
// Setup
TestDependencyResolver nearDepRslvr = new TestDependencyResolver();
IgniteEx nearNode = startGrid(0, nearDepRslvr);
TestDependencyResolver incomingDepRslvr = new TestDependencyResolver(this::resolve);
IgniteEx incomingNode = startGrid(1, incomingDepRslvr);
GridTimeoutProcessor tp = nearNode.context().timeout();
ConnectionClientPool pool = nearDepRslvr.getDependency(ConnectionClientPool.class);
GridCacheEntryEx ex = getEntry(nearNode, DEFAULT_CACHE_NAME, TEST_KEY);
// Act
try {
// Lock entry in current thread
ex.lockEntry();
// Print the entry from another thread via timeObject.
CountDownLatch entryPrinted = new CountDownLatch(1);
CountDownLatch entryReadyToPrint = new CountDownLatch(1);
tp.addTimeoutObject(new EntryPrinterTimeoutObject(ex, entryPrinted, entryReadyToPrint));
entryReadyToPrint.await();
// Try to do first handshake with hangs, after reconnect handshake should be passed.
rejectHandshake.set(true);
pool.forceCloseConnection(incomingNode.localNode().id());
nearNode.configuration().getCommunicationSpi().sendMessage(incomingNode.localNode(), UUIDCollectionMessage.of(UUID.randomUUID()));
// Check
assertTrue(GridTestUtils.waitForCondition(() -> entryPrinted.getCount() == 0, 5_000));
} finally {
ex.unlockEntry();
}
}
Aggregations