Search in sources :

Example 1 with TestDependencyResolver

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());
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) ArrayList(java.util.ArrayList) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) Test(org.junit.Test) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) IgniteCache(org.apache.ignite.IgniteCache) T2(org.apache.ignite.internal.util.typedef.T2) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) T2(org.apache.ignite.internal.util.typedef.T2) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 2 with TestDependencyResolver

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();
    }
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) IgniteEx(org.apache.ignite.internal.IgniteEx) ConnectionClientPool(org.apache.ignite.spi.communication.tcp.internal.ConnectionClientPool) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)2 TestDependencyResolver (org.apache.ignite.testframework.TestDependencyResolver)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteSystemProperties (org.apache.ignite.IgniteSystemProperties)1 IGNITE_PDS_WAL_REBALANCE_THRESHOLD (org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD)1 ATOMIC (org.apache.ignite.cache.CacheAtomicityMode.ATOMIC)1 REPLICATED (org.apache.ignite.cache.CacheMode.REPLICATED)1 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)1 ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1