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();
}
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;
}
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;
}
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;
}
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);
}
Aggregations