use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteClusterActivateDeactivateTest method clientReconnectClusterDeactivated.
/**
* @param transition If {@code true} client reconnects while cluster state transition is in progress.
* @throws Exception If failed.
*/
private void clientReconnectClusterDeactivated(final boolean transition) throws Exception {
testReconnectSpi = true;
testSpi = transition;
final int SRVS = 3;
final int CLIENTS = 3;
startWithCaches1(SRVS, CLIENTS);
final Ignite srv = ignite(0);
IgniteEx client = grid(SRVS);
if (persistenceEnabled())
ignite(0).cluster().active(true);
checkCache(client, CU.UTILITY_CACHE_NAME, true);
checkCaches1(SRVS + CLIENTS);
// Wait for late affinity assignment to finish.
grid(0).context().cache().context().exchange().affinityReadyFuture(new AffinityTopologyVersion(SRVS + CLIENTS, 1)).get();
final AffinityTopologyVersion STATE_CHANGE_TOP_VER = new AffinityTopologyVersion(SRVS + CLIENTS + 1, 1);
final TestRecordingCommunicationSpi spi1 = transition ? TestRecordingCommunicationSpi.spi(ignite(1)) : null;
final AtomicReference<IgniteInternalFuture> stateFut = new AtomicReference<>();
IgniteClientReconnectAbstractTest.reconnectClientNode(log, client, srv, () -> {
if (transition) {
blockExchangeSingleMessage(spi1, STATE_CHANGE_TOP_VER);
stateFut.set(GridTestUtils.runAsync(() -> srv.cluster().active(false), "deactivate"));
try {
U.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
} else
srv.cluster().active(false);
});
if (transition) {
assertFalse(stateFut.get().isDone());
// Public API method would block forever because we blocked the exchange message.
assertFalse(client.context().state().publicApiActiveState(false));
spi1.waitForBlocked();
spi1.stopBlock();
stateFut.get().get();
}
checkNoCaches(SRVS + CLIENTS);
ignite(0).cluster().active(true);
checkCache(client, CU.UTILITY_CACHE_NAME, true);
assertTrue(client.cluster().active());
checkCaches1(SRVS + CLIENTS);
checkCache(client, CACHE_NAME_PREFIX + 0, true);
this.client = false;
startGrid(SRVS + CLIENTS);
this.client = true;
startGrid(SRVS + CLIENTS + 1);
checkCaches1(SRVS + CLIENTS + 2);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteClusterActivateDeactivateTest method clientReconnectClusterActivated.
/**
* @param transition If {@code true} client reconnects while cluster state transition is in progress.
* @throws Exception If failed.
*/
private void clientReconnectClusterActivated(final boolean transition) throws Exception {
testReconnectSpi = true;
testSpi = transition;
active = false;
final int SRVS = 3;
final int CLIENTS = 3;
startWithCaches1(SRVS, CLIENTS);
final Ignite srv = ignite(0);
IgniteEx client = grid(SRVS);
checkNoCaches(SRVS + CLIENTS);
final AffinityTopologyVersion STATE_CHANGE_TOP_VER = new AffinityTopologyVersion(SRVS + CLIENTS + 1, 1);
final TestRecordingCommunicationSpi spi1 = transition ? TestRecordingCommunicationSpi.spi(ignite(1)) : null;
final AtomicReference<IgniteInternalFuture> stateFut = new AtomicReference<>();
IgniteClientReconnectAbstractTest.reconnectClientNode(log, client, srv, () -> {
if (transition) {
blockExchangeSingleMessage(spi1, STATE_CHANGE_TOP_VER);
stateFut.set(GridTestUtils.runAsync(() -> srv.cluster().active(true), "activate"));
try {
U.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
} else
srv.cluster().active(true);
});
if (transition) {
assertFalse(stateFut.get().isDone());
assertTrue(client.context().state().clusterState().transition());
spi1.waitForBlocked();
spi1.stopBlock();
stateFut.get().get();
}
checkCache(client, CU.UTILITY_CACHE_NAME, true);
checkCaches1(SRVS + CLIENTS);
checkCache(client, CACHE_NAME_PREFIX + 0, true);
this.client = false;
startGrid(SRVS + CLIENTS);
this.client = true;
startGrid(SRVS + CLIENTS + 1);
checkCaches1(SRVS + CLIENTS + 2);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteClusterActivateDeactivateTest method joinWhileActivate1.
/**
* @param startClient If {@code true} joins client node, otherwise server.
* @param withNewCache If {@code true} joining node has new cache in configuration.
* @throws Exception If failed.
*/
private void joinWhileActivate1(final boolean startClient, final boolean withNewCache) throws Exception {
IgniteInternalFuture<?> activeFut = startNodesAndBlockStatusChange(2, 0, 0, false);
IgniteInternalFuture<?> startFut = GridTestUtils.runAsync((Callable<Void>) () -> {
client = startClient;
ccfgs = withNewCache ? cacheConfigurations2() : cacheConfigurations1();
startGrid(2);
return null;
});
TestRecordingCommunicationSpi spi1 = TestRecordingCommunicationSpi.spi(ignite(1));
spi1.stopBlock();
activeFut.get();
startFut.get();
for (int c = 0; c < 2; c++) checkCache(ignite(2), CACHE_NAME_PREFIX + c, true);
if (withNewCache) {
for (int i = 0; i < 3; i++) {
for (int c = 0; c < 4; c++) checkCache(ignite(i), CACHE_NAME_PREFIX + c, true);
}
}
awaitPartitionMapExchange();
checkCaches(3, withNewCache ? 4 : 2);
client = false;
startGrid(3);
checkCaches(4, withNewCache ? 4 : 2);
client = true;
startGrid(4);
checkCaches(5, withNewCache ? 4 : 2);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteOnePhaseCommitInvokeTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
cfg.setCommunicationSpi(commSpi);
cfg.setClientMode(client);
CacheConfiguration ccfg = new CacheConfiguration();
ccfg.setName(CACHE_NAME);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setBackups(1);
ccfg.setRebalanceMode(ASYNC);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteOnePhaseCommitNearReadersTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
cfg.setClientMode(client);
if (testSpi) {
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
cfg.setCommunicationSpi(commSpi);
}
return cfg;
}
Aggregations