Search in sources :

Example 1 with TestTcpDiscoverySpi

use of org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi in project ignite by apache.

the class GridCacheRebalancingAsyncSelfTest method testNodeFailedAtRebalancing.

/**
 * @throws Exception Exception.
 */
@Test
public void testNodeFailedAtRebalancing() throws Exception {
    IgniteEx ignite = startGrid(0);
    generateData(ignite, 0, 0);
    log.info("Preloading started.");
    startGrid(1);
    GridDhtPartitionDemander.RebalanceFuture fut = (GridDhtPartitionDemander.RebalanceFuture) grid(1).context().cache().internalCache(CACHE_NAME_DHT_REPLICATED).preloader().rebalanceFuture();
    fut.get();
    U.sleep(10);
    ((TestTcpDiscoverySpi) grid(1).configuration().getDiscoverySpi()).simulateNodeFailure();
    awaitPartitionMapExchange(false, false, Collections.singletonList(ignite.localNode()));
    checkSupplyContextMapIsEmpty();
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) GridDhtPartitionDemander(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander) Test(org.junit.Test)

Example 2 with TestTcpDiscoverySpi

use of org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi in project ignite by apache.

the class GridAbstractTest method getConfiguration.

/**
 * This method should be overridden by subclasses to change configuration parameters.
 *
 * @param igniteInstanceName Ignite instance name.
 * @param rsrcs Resources.
 * @throws Exception If failed.
 * @return Grid configuration used for starting of grid.
 */
@SuppressWarnings("deprecation")
protected IgniteConfiguration getConfiguration(String igniteInstanceName, IgniteTestResources rsrcs) throws Exception {
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setIgniteInstanceName(igniteInstanceName);
    cfg.setGridLogger(rsrcs.getLogger());
    cfg.setMarshaller(rsrcs.getMarshaller());
    cfg.setNodeId(rsrcs.getNodeId());
    cfg.setIgniteHome(rsrcs.getIgniteHome());
    cfg.setMBeanServer(rsrcs.getMBeanServer());
    cfg.setPeerClassLoadingEnabled(true);
    cfg.setMetricsLogFrequency(0);
    cfg.setClientMode(IgnitionEx.isClientMode());
    cfg.setConnectorConfiguration(null);
    TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
    commSpi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));
    commSpi.setTcpNoDelay(true);
    cfg.setCommunicationSpi(commSpi);
    TcpDiscoverySpi discoSpi = new TestTcpDiscoverySpi();
    if (isDebug()) {
        cfg.setFailureDetectionTimeout(getTestTimeout() <= 0 ? getDefaultTestTimeout() : getTestTimeout());
        cfg.setNetworkTimeout(Long.MAX_VALUE / 3);
    } else {
        // Set network timeout to 10 sec to avoid unexpected p2p class loading errors.
        cfg.setNetworkTimeout(10_000);
        cfg.setFailureDetectionTimeout(10_000);
        cfg.setClientFailureDetectionTimeout(10_000);
    }
    // Set metrics update interval to 1 second to speed up tests.
    cfg.setMetricsUpdateFrequency(1000);
    if (!isMultiJvm()) {
        assert sharedStaticIpFinder != null : "Shared static IP finder should be initialized at this point.";
        discoSpi.setIpFinder(sharedStaticIpFinder);
    } else
        discoSpi.setIpFinder(LOCAL_IP_FINDER);
    cfg.setDiscoverySpi(discoSpi);
    SharedFsCheckpointSpi cpSpi = new SharedFsCheckpointSpi();
    Collection<String> paths = new ArrayList<>();
    paths.add(getDefaultCheckpointPath(cfg.getMarshaller()));
    cpSpi.setDirectoryPaths(paths);
    cfg.setCheckpointSpi(cpSpi);
    cfg.setEventStorageSpi(new MemoryEventStorageSpi());
    cfg.setFailureHandler(getFailureHandler(igniteInstanceName));
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) SharedFsCheckpointSpi(org.apache.ignite.spi.checkpoint.sharedfs.SharedFsCheckpointSpi) ArrayList(java.util.ArrayList) MemoryEventStorageSpi(org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 3 with TestTcpDiscoverySpi

use of org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi in project ignite by apache.

the class IgniteContinuousQueryMetadataUpdateTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TestTcpDiscoverySpi) cfg.getDiscoverySpi()).discoveryHook(new DiscoveryHook() {

        @Override
        public void beforeDiscovery(DiscoveryCustomMessage customMsg) {
            if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                try {
                    U.sleep(50);
                } catch (IgniteInterruptedCheckedException e) {
                    fail("Unexpected error:" + e);
                }
            }
        }
    });
    cfg.setPeerClassLoadingEnabled(true);
    return cfg;
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) MetadataUpdateAcceptedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 4 with TestTcpDiscoverySpi

use of org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi in project ignite by apache.

the class CacheContinuousQueryFilterDeploymentFailedTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    // Failure detection timeout > P2P class loading timeout which is set as network timeout.
    cfg.setFailureDetectionTimeout(cfg.getNetworkTimeout() * 2);
    ((TestTcpDiscoverySpi) cfg.getDiscoverySpi()).discoveryHook(new DiscoveryHook() {

        @Override
        public void afterDiscovery(DiscoveryCustomMessage customMsg) {
            if (customMsg instanceof StopRoutineDiscoveryMessage)
                stopRoutineLatch.countDown();
        }
    });
    cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
    return cfg;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) StopRoutineDiscoveryMessage(org.apache.ignite.internal.processors.continuous.StopRoutineDiscoveryMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 5 with TestTcpDiscoverySpi

use of org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi in project ignite by apache.

the class RestProcessorHangTest method testNodeStopOnDiscoverySpiFailTest.

/**
 * Test that node doesn't hang if there are rest requests and discovery SPI failed.
 *
 * Description: Fire up one node that always rejects connections.
 * Fire up another node and without waiting for it to start up publish CACHE_GET request to the rest processor.
 * This request will hang until the node start. As soon as this node fails to connect to the first one it should
 * stop itself causing RestProcessor to wait indefinitely for all rest-workers to finish which leads to node
 * hang on stop process.
 */
@Test
public void testNodeStopOnDiscoverySpiFailTest() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    String rejectorGridName = "rejector";
    IgniteConfiguration regjectorGridCfg = getConfiguration(rejectorGridName);
    // Discovery spi that never allows connecting.
    TestTcpDiscoverySpi discoSpi = new TestTcpDiscoverySpi() {

        @Override
        protected void writeToSocket(TcpDiscoveryAbstractMessage msg, Socket sock, int res, long timeout) throws IOException {
            try {
                // Wait until request is added to rest processor.
                latch.await();
            } catch (InterruptedException ignored) {
            // No-op.
            }
            super.writeToSocket(msg, sock, 255, timeout);
        }
    };
    discoSpi.setIpFinder(sharedStaticIpFinder);
    regjectorGridCfg.setDiscoverySpi(discoSpi);
    startGrid(regjectorGridCfg);
    String hangGridName = "impossibleToJoin";
    IgniteConfiguration hangNodeCfg = getConfiguration(hangGridName);
    GridTestUtils.runAsync(() -> startGrid(hangNodeCfg));
    GridTestUtils.waitForCondition(() -> {
        try {
            IgniteKernal failingGrid = IgnitionEx.gridx(hangGridName);
            return failingGrid != null && failingGrid.context().rest() != null;
        } catch (Exception ignored) {
            return false;
        }
    }, 20_000);
    IgniteEx hangGrid = IgnitionEx.gridx(hangGridName);
    IgniteRestProcessor rest = hangGrid.context().rest();
    new Thread(() -> {
        GridRestProtocolHandler hnd = GridTestUtils.getFieldValue(rest, "protoHnd");
        GridRestCacheRequest req = new GridRestCacheRequest();
        req.cacheName(DEFAULT_CACHE_NAME);
        req.command(GridRestCommand.CACHE_GET);
        req.key("k1");
        latch.countDown();
        try {
            // Submitting cache get request to node that didn't fully start must hang.
            hnd.handle(req);
        } catch (IgniteCheckedException ignored) {
        // No-op.
        }
    }).start();
    latch.await();
    // Node should stop correctly.
    assertTrue(GridTestUtils.waitForCondition(() -> {
        List<Ignite> ignites = IgnitionEx.allGrids();
        return ignites.stream().noneMatch(ignite -> Objects.equals(ignite.name(), hangGridName));
    }, 20_000));
    stopGrid(rejectorGridName);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgnitionEx(org.apache.ignite.internal.IgnitionEx) Socket(java.net.Socket) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) IgniteKernal(org.apache.ignite.internal.IgniteKernal) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) List(java.util.List) Socket(java.net.Socket) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

TestTcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)9 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)4 DiscoveryHook (org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)2 TcpDiscoveryAbstractMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage)2 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Socket (java.net.Socket)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ConnectorConfiguration (org.apache.ignite.configuration.ConnectorConfiguration)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1