Search in sources :

Example 6 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class CacheNoAffinityExchangeTest method testNoAffinityOnJoiningClientNode.

/**
 * Tests the "long" joining of the client node to the cluster
 * when the message from the client is handled after affinity assignments are wiped from the history.
 *
 * Expected result: client node should reconnect to the cluster, server nodes should not be affected in any way.
 *
 * @throws Exception If Failed.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_AFFINITY_HISTORY_SIZE, value = "2")
public void testNoAffinityOnJoiningClientNode() throws Exception {
    Ignite ig = startGrids(1);
    ig.cluster().state(ACTIVE);
    clientCommSpi = new TestRecordingCommunicationSpi();
    clientCommSpi.blockMessages(GridDhtPartitionsSingleMessage.class, ig.configuration().getIgniteInstanceName());
    // Start client node and block initial PME in order to guarantee that single message will be processed
    // when affinity history for the corresponding topology version is already cleaned.
    IgniteInternalFuture<?> startClientFut = GridTestUtils.runAsync(() -> {
        try {
            startClientCaches = true;
            startClientGrid(1);
        } catch (Exception e) {
            throw new RuntimeException("Unexpected exception.", e);
        }
    });
    // Wait for initial PME.
    clientCommSpi.waitForBlocked();
    startClientCaches = false;
    // Start new server nodes in order to clean the history of affinity assignments.
    for (int i = 2; i < 5; i++) {
        startGrid(i);
        stopGrid(i, true);
    }
    // Send single message from the client.
    clientCommSpi.stopBlock();
    // Make sure that client node successfully started.
    startClientFut.get(getTestTimeout());
    awaitPartitionMapExchange();
    StringBuilder failures = new StringBuilder();
    errs.forEach((k, v) -> failures.append("nodeId=").append(k).append(", err=").append(v).append(U.nl()));
    assertTrue("Failure handler should not be triggered " + failures.toString(), errs.isEmpty());
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 7 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class CacheNoAffinityExchangeTest method testNoAffinityOnClientCacheStart.

/**
 * Tests getting a cache on the client node when the history of affinity assignments is not enough.
 *
 * Expected result: client request should be rejected with the cause, server nodes should not be affected in any way.
 *
 * @throws Exception If Failed.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_AFFINITY_HISTORY_SIZE, value = "2")
public void testNoAffinityOnClientCacheStart() throws Exception {
    Ignite ig = startGrids(1);
    ig.cluster().state(ACTIVE);
    ig.getOrCreateCache("client-cache");
    startClientCaches = false;
    IgniteEx client = startClientGrid(1);
    TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(client);
    clientSpi.blockMessages((node, msg) -> msg instanceof GridDhtAffinityAssignmentRequest);
    // Block creating client cache in order to guarantee that GridDhtAffinityAssignmentRequest message
    // will be processed when affinity history for the corresponding topology version is already cleaned.
    IgniteInternalFuture<?> startClientCacheFut = GridTestUtils.runAsync(() -> {
        client.cache("client-cache");
    });
    clientSpi.waitForBlocked();
    startClientCaches = false;
    // Start new server nodes in order to clean the history of affinity assignments.
    for (int i = 2; i < 5; i++) {
        startGrid(i);
        stopGrid(i, true);
    }
    // Send GridDhtAffinityAssignmentRequest from the client.
    clientSpi.stopBlock();
    assertThrows(log, () -> startClientCacheFut.get(), IgniteCheckedException.class, null);
    awaitPartitionMapExchange();
    StringBuilder failures = new StringBuilder();
    errs.forEach((k, v) -> failures.append("nodeId=").append(k).append(", err=").append(v).append(U.nl()));
    assertTrue("Failure handler should not be triggered " + failures.toString(), errs.isEmpty());
    // Make sure that the next call is successful.
    assertNotNull(client.cache("client-cache"));
}
Also used : GridDhtAffinityAssignmentRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentRequest) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 8 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class PartitionsExchangeCoordinatorFailoverTest method testChangeCoordinatorToLocallyJoiningNode2.

/**
 * Test checks that changing coordinator to a node that joining to cluster at the moment works correctly
 * in case of completed exchange on client nodes.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK, value = "true")
public void testChangeCoordinatorToLocallyJoiningNode2() throws Exception {
    newCaches = false;
    spiFactory = TestRecordingCommunicationSpi::new;
    IgniteEx crd = startGrid(CRD_NONE);
    // Start several clients.
    IgniteEx clientNode = (IgniteEx) startClientGridsMultiThreaded(2, 2);
    awaitPartitionMapExchange();
    final int newCrdNodeIdx = 1;
    // A full message shouldn't be send to new coordinator.
    blockSendingFullMessage(crd, node -> node.consistentId().equals(getTestIgniteInstanceName(newCrdNodeIdx)));
    IgniteInternalFuture<?> newCrdJoinFut = GridTestUtils.runAsync(() -> startGrid(newCrdNodeIdx));
    // Wait till client node will receive full message and finish exchange on node join.
    GridTestUtils.waitForCondition(() -> {
        GridDhtPartitionsExchangeFuture fut = clientNode.cachex(CACHE_NAME).context().shared().exchange().lastFinishedFuture();
        return fut != null && fut.topologyVersion().equals(new AffinityTopologyVersion(4, 0));
    }, 60_000);
    Assert.assertFalse("New coordinator join shouldn't be happened before stopping old coordinator.", newCrdJoinFut.isDone());
    // Stop coordinator.
    stopGrid(CRD_NONE);
    // New coordinator join process should succeed after that.
    newCrdJoinFut.get();
    awaitPartitionMapExchange();
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 9 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class CdcSelfTest method testMultiNodeConsumption.

/**
 */
@Test
@WithSystemProperty(key = IGNITE_DATA_STORAGE_FOLDER_BY_CONSISTENT_ID, value = "true")
public void testMultiNodeConsumption() throws Exception {
    IgniteEx ign1 = startGrid(0);
    IgniteEx ign2 = startGrid(1);
    ign1.cluster().state(ACTIVE);
    IgniteCache<Integer, User> cache = ign1.getOrCreateCache(DEFAULT_CACHE_NAME);
    // Calculate expected count of key for each node.
    int[] keysCnt = new int[2];
    for (int i = 0; i < KEYS_CNT * 2; i++) {
        Ignite primary = primaryNode(i, DEFAULT_CACHE_NAME);
        assertTrue(primary == ign1 || primary == ign2);
        keysCnt[primary == ign1 ? 0 : 1]++;
    }
    // Adds data concurrently with CDC start.
    IgniteInternalFuture<?> addDataFut = runAsync(() -> addData(cache, 0, KEYS_CNT));
    UserCdcConsumer cnsmr1 = new UserCdcConsumer();
    UserCdcConsumer cnsmr2 = new UserCdcConsumer();
    IgniteConfiguration cfg1 = getConfiguration(ign1.name());
    IgniteConfiguration cfg2 = getConfiguration(ign2.name());
    // Always run CDC with consistent id to ensure instance read data for specific node.
    if (!specificConsistentId) {
        cfg1.setConsistentId((Serializable) ign1.localNode().consistentId());
        cfg2.setConsistentId((Serializable) ign2.localNode().consistentId());
    }
    CountDownLatch latch = new CountDownLatch(2);
    GridAbsPredicate sizePredicate1 = sizePredicate(keysCnt[0], DEFAULT_CACHE_NAME, UPDATE, cnsmr1);
    GridAbsPredicate sizePredicate2 = sizePredicate(keysCnt[1], DEFAULT_CACHE_NAME, UPDATE, cnsmr2);
    CdcMain cdc1 = createCdc(cnsmr1, cfg1, latch, sizePredicate1);
    CdcMain cdc2 = createCdc(cnsmr2, cfg2, latch, sizePredicate2);
    IgniteInternalFuture<?> fut1 = runAsync(cdc1);
    IgniteInternalFuture<?> fut2 = runAsync(cdc2);
    addDataFut.get(getTestTimeout());
    runAsync(() -> addData(cache, KEYS_CNT, KEYS_CNT * 2)).get(getTestTimeout());
    // Wait while predicate will become true and state saved on the disk for both cdc.
    assertTrue(latch.await(getTestTimeout(), MILLISECONDS));
    checkMetrics(cdc1, keysCnt[0]);
    checkMetrics(cdc2, keysCnt[1]);
    assertFalse(cnsmr1.stopped());
    assertFalse(cnsmr2.stopped());
    fut1.cancel();
    fut2.cancel();
    assertTrue(cnsmr1.stopped());
    assertTrue(cnsmr2.stopped());
    removeData(cache, 0, KEYS_CNT * 2);
    cdc1 = createCdc(cnsmr1, cfg1);
    cdc2 = createCdc(cnsmr2, cfg2);
    IgniteInternalFuture<?> rmvFut1 = runAsync(cdc1);
    IgniteInternalFuture<?> rmvFut2 = runAsync(cdc2);
    waitForSize(KEYS_CNT * 2, DEFAULT_CACHE_NAME, DELETE, cnsmr1, cnsmr2);
    checkMetrics(cdc1, keysCnt[0]);
    checkMetrics(cdc2, keysCnt[1]);
    rmvFut1.cancel();
    rmvFut2.cancel();
    assertTrue(cnsmr1.stopped());
    assertTrue(cnsmr2.stopped());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CdcMain(org.apache.ignite.internal.cdc.CdcMain) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 10 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class GridVersionSelfTest method testVersions.

/**
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = IGNITE_UPDATE_NOTIFIER, value = "true")
public void testVersions() throws Exception {
    try {
        final IgniteEx ignite = (IgniteEx) startGrid();
        IgniteProductVersion currVer = ignite.version();
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return ignite.latestVersion() != null;
            }
        }, 2 * 60_000);
        String newVer = ignite.latestVersion();
        info("Versions [cur=" + currVer + ", latest=" + newVer + ']');
        assertNotNull(newVer);
        assertNotSame(currVer.toString(), newVer);
    } finally {
        stopGrid();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)71 Test (org.junit.Test)71 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)59 IgniteEx (org.apache.ignite.internal.IgniteEx)46 Ignite (org.apache.ignite.Ignite)20 LogListener (org.apache.ignite.testframework.LogListener)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)11 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 File (java.io.File)9 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)8 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)8 List (java.util.List)7 IgniteCache (org.apache.ignite.IgniteCache)7 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)7