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