Search in sources :

Example 66 with WithSystemProperty

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

the class TcpCommunicationSpiMultiJvmTest method testIPv6NodesSuccessfullyConnectDespiteOfIPv4ExternalAddress.

/**
 * Verifies that even when two nodes explicitely declare preferring IPv6 stack they're still able to connect
 * if one node provides IPv4 address as primary one.
 *
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = "java.net.preferIPv6Stack", value = "true")
public void testIPv6NodesSuccessfullyConnectDespiteOfIPv4ExternalAddress() throws Exception {
    localAddrStr = "127.0.0.1";
    externalAddr = new InetSocketAddress("0:0:0:0:0:0:0:1%lo", 45010);
    IgniteEx ig = startGrid(0);
    remoteNodePrefersIPv6 = true;
    externalAddr = null;
    startGrid(1);
    AtomicBoolean cacheCreatedAndLoaded = createAndLoadCacheAsync(ig);
    assertTrue(GridTestUtils.waitForCondition(cacheCreatedAndLoaded::get, 10_000));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InetSocketAddress(java.net.InetSocketAddress) 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 67 with WithSystemProperty

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

the class IgniteWalRecoveryTest method testRecoveryAfterRestart_Join.

/**
 * Tests a scenario when a coordinator has failed after recovery during node join.
 */
@Test
@WithSystemProperty(key = "IGNITE_DISABLE_WAL_DURING_REBALANCING", value = "false")
public void testRecoveryAfterRestart_Join() throws Exception {
    IgniteEx crd = startGrid(1);
    crd.cluster().active(true);
    for (int i = 0; i < PARTS; i++) {
        crd.cache(CACHE_1).put(i, i);
        crd.cache(CACHE_2).put(i, i);
    }
    TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionSupplyMessage) {
                GridDhtPartitionSupplyMessage msg0 = (GridDhtPartitionSupplyMessage) msg;
                return msg0.groupId() == CU.cacheId(CACHE_2);
            }
            return false;
        }
    });
    IgniteEx g2 = startGrid(2);
    resetBaselineTopology();
    TestRecordingCommunicationSpi.spi(crd).waitForBlocked();
    forceCheckpoint(g2);
    g2.close();
    TestRecordingCommunicationSpi.spi(crd).stopBlock();
    waitForTopology(1);
    CountDownLatch l1 = new CountDownLatch(1);
    CountDownLatch l2 = new CountDownLatch(1);
    GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            startGrid(getPMEBlockingConfiguration(2, l1, l2));
            return null;
        }
    });
    assertTrue(U.await(l1, 10, TimeUnit.SECONDS));
    stopGrid(getTestIgniteInstanceName(1), true, false);
    l2.countDown();
    awaitPartitionMapExchange();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 68 with WithSystemProperty

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

the class IgniteWalRecoveryTest method testRecoveryAfterRestart_Activate.

/**
 * Tests a scenario when a coordinator has failed after recovery during activation.
 */
@Test
@WithSystemProperty(key = IGNITE_DISABLE_WAL_DURING_REBALANCING, value = "false")
public void testRecoveryAfterRestart_Activate() throws Exception {
    IgniteEx crd = startGrid(1);
    crd.cluster().active(true);
    for (int i = 0; i < PARTS; i++) {
        crd.cache(CACHE_1).put(i, i);
        crd.cache(CACHE_2).put(i, i);
    }
    TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionSupplyMessage) {
                GridDhtPartitionSupplyMessage msg0 = (GridDhtPartitionSupplyMessage) msg;
                return msg0.groupId() == CU.cacheId(CACHE_2);
            }
            return false;
        }
    });
    IgniteEx g2 = startGrid(2);
    resetBaselineTopology();
    TestRecordingCommunicationSpi.spi(crd).waitForBlocked();
    forceCheckpoint(g2);
    stopAllGrids();
    waitForTopology(0);
    // Restart and activate.
    CountDownLatch l1 = new CountDownLatch(1);
    CountDownLatch l2 = new CountDownLatch(1);
    crd = startGrid(1);
    startGrid(getPMEBlockingConfiguration(2, l1, l2));
    GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            grid(1).cluster().active(true);
        }
    });
    assertTrue(U.await(l1, 10, TimeUnit.SECONDS));
    stopGrid(getTestIgniteInstanceName(1), true, false);
    l2.countDown();
    awaitPartitionMapExchange();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 69 with WithSystemProperty

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

the class RebuildIndexWithHistoricalRebalanceTest method shouldRebuldIndexForMovingPartitionWithHistoricalRebalance.

/**
 */
@Test
// Use only historical rebalance
@WithSystemProperty(key = IGNITE_PDS_WAL_REBALANCE_THRESHOLD, value = "0")
public void shouldRebuldIndexForMovingPartitionWithHistoricalRebalance() throws Exception {
    IgniteEx node1 = startGrid(0);
    startGrid(1);
    node1.cluster().active(true);
    IgniteCache<UserKey, UserValue> cache = node1.getOrCreateCache(CACHE_NAME);
    cache.put(new UserKey(1), new UserValue(333));
    stopGrid(1);
    cache.put(new UserKey(2), new UserValue(555));
    SUPPLY_MESSAGE_LATCH.set(new CountDownLatch(1));
    removeIndexBin(1);
    LogListener rebuildLsnr = finishIndexRebuildLsnr(CACHE_NAME);
    IgniteEx node2 = startGrid(1);
    assertTrue(GridTestUtils.waitForCondition(rebuildLsnr::check, 10_000));
    SUPPLY_MESSAGE_LATCH.get().countDown();
    awaitPartitionMapExchange();
    ValidateIndexesClosure clo = new ValidateIndexesClosure(() -> false, Collections.singleton(CACHE_NAME), 0, 0, false, true);
    node2.context().resource().injectGeneric(clo);
    VisorValidateIndexesJobResult res = clo.call();
    assertFalse(res.hasIssues());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) ValidateIndexesClosure(org.apache.ignite.internal.visor.verify.ValidateIndexesClosure) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 70 with WithSystemProperty

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

the class TcpDiscoveryNodeJoinAndFailureTest method testConnectingNodesStopIfNoConnectedNodeIsPresented.

/**
 * If whole ring fails but two server nodes both in CONNECTING state remain alive they should not hang
 * indefinitely sending join requests to each other.
 *
 * @see <a href="https://issues.apache.org/jira/browse/IGNITE-11621">IGNITE-11621</a>
 * with comments provides detailed description of this corner case.
 *
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE, value = "false")
public void testConnectingNodesStopIfNoConnectedNodeIsPresented() throws Exception {
    /*
            Test reproduces the needed behavior (two nodes in CONNECTING state) doing the following:
                - it starts two regular nodes, node0 (coordinator) and node1 (just another server) with special
                  discovery SPIs;
                - when node1 receives NodeAddFinished for subsequently started node2, it doesn't send it to the node
                  but closes disco socket to node2 leaving it in CONNECTING state and generating NodeFailed for it.
                  Also at this moment node3 is started;
                - when node0 receives this NodeFailed it fails (because special SPI throws an exception) and stops;
                - when node1 receives another join request from node2 or NodeAdded from node3 reaches it back,
                  node1's special SPI also throws an exception so it goes down as well;
                - as a result, both node2 and node3 get stuck in CONNECTING state and as they use special IpFinders
                  they see each other and are able to send join requests to each other back and forth.

            The whole purpose of the test is to verify that these two nodes won't stuck in CONNECTING state forever
            and will eventually stop.
         */
    usePortFromNodeName = true;
    final AtomicInteger joinReqsCntr = new AtomicInteger(0);
    final AtomicReference<IgniteInternalFuture> futureRef = new AtomicReference();
    final UUID node2Id = UUID.randomUUID();
    final TcpDiscoverySpi node0SpecialSpi = new TcpDiscoverySpi() {

        @Override
        protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
            if (msg instanceof TcpDiscoveryNodeFailedMessage) {
                TcpDiscoveryNodeFailedMessage failedMsg = (TcpDiscoveryNodeFailedMessage) msg;
                UUID failedNodeId = failedMsg.failedNodeId();
                if (failedNodeId.equals(node2Id))
                    throw new RuntimeException("Stop node0 exception");
            }
            if (msg instanceof TcpDiscoveryJoinRequestMessage) {
                TcpDiscoveryJoinRequestMessage joinReq = (TcpDiscoveryJoinRequestMessage) msg;
                if (joinReq.node().id().equals(node2Id))
                    joinReqsCntr.incrementAndGet();
            }
        }
    };
    final TcpDiscoverySpi node1SpecialSpi = new TcpDiscoverySpi() {

        @Override
        protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
            if (msg instanceof TcpDiscoveryNodeAddFinishedMessage) {
                TcpDiscoveryNodeAddFinishedMessage finishedMsg = (TcpDiscoveryNodeAddFinishedMessage) msg;
                UUID nodeId = finishedMsg.nodeId();
                if (nodeId.equals(node2Id)) {
                    Object workerObj = GridTestUtils.getFieldValue(impl, "msgWorker");
                    OutputStream out = GridTestUtils.getFieldValue(workerObj, "out");
                    try {
                        out.close();
                        log.warning("Out to 'sick' node closed");
                    } catch (Exception ignored) {
                    // No-op.
                    }
                    futureRef.set(GridTestUtils.runAsync(() -> {
                        try {
                            startGrid(NODE_WITH_PORT_ID_3);
                        } catch (Exception ignored) {
                        // NO-op.
                        }
                    }));
                }
            }
            if (msg instanceof TcpDiscoveryJoinRequestMessage) {
                TcpDiscoveryJoinRequestMessage joinReq = (TcpDiscoveryJoinRequestMessage) msg;
                int joinReqsCount = joinReqsCntr.get();
                if (joinReq.node().id().equals(node2Id) && joinReqsCount == 1)
                    throw new RuntimeException("Stop node1 exception by subsequent join req");
            }
            if (msg instanceof TcpDiscoveryNodeAddedMessage) {
                TcpDiscoveryNodeAddedMessage addedMsg = (TcpDiscoveryNodeAddedMessage) msg;
                if (addedMsg.node().discoveryPort() == 47503)
                    throw new RuntimeException("Stop node1 exception by new node added msg");
            }
        }
    };
    specialSpi = node0SpecialSpi;
    startGrid(NODE_WITH_PORT_ID_0);
    specialSpi = node1SpecialSpi;
    startGrid(NODE_WITH_PORT_ID_1);
    specialIpFinder0 = new TcpDiscoveryVmIpFinder(false);
    ((TcpDiscoveryVmIpFinder) specialIpFinder0).setAddresses(Arrays.asList("127.0.0.1:47501", "127.0.0.1:47503"));
    specialIpFinder1 = new TcpDiscoveryVmIpFinder(false);
    ((TcpDiscoveryVmIpFinder) specialIpFinder1).setAddresses(Arrays.asList("127.0.0.1:47502"));
    specialSpi = null;
    nodeId = node2Id;
    boolean expectedExceptionThrown = false;
    try {
        startGrid(NODE_WITH_PORT_ID_2);
    } catch (Exception e) {
        Throwable cause0 = e.getCause();
        assertNotNull(cause0);
        Throwable cause1 = cause0.getCause();
        assertNotNull(cause1);
        String errorMsg = cause1.getMessage();
        assertTrue("Expected error message was not found: " + errorMsg, errorMsg.contains("Failed to connect to any address from IP finder"));
        expectedExceptionThrown = true;
    }
    assertTrue("Expected exception was not thrown.", expectedExceptionThrown);
    IgniteInternalFuture startGridFut = futureRef.get();
    if (startGridFut != null)
        startGridFut.get();
}
Also used : TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) OutputStream(java.io.OutputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TcpDiscoveryNodeFailedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage) TcpDiscoveryNodeAddFinishedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddFinishedMessage) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TcpDiscoveryNodeAddedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage) UUID(java.util.UUID) TcpDiscoveryJoinRequestMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryJoinRequestMessage) 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