use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testJoinExchangeBecomeCoordinator.
/**
* @throws Exception If failed.
*/
public void testJoinExchangeBecomeCoordinator() throws Exception {
long topVer = 0;
final int NODES = 3;
for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
checkAffinity(NODES, topVer(topVer, 1), true);
for (int i = 0; i < NODES; i++) {
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg.getClass().equals(GridDhtPartitionsSingleMessage.class) || msg.getClass().equals(GridDhtPartitionsFullMessage.class);
}
});
}
final CountDownLatch latch = new CountDownLatch(1);
IgniteInternalFuture<?> stopFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
latch.await();
U.sleep(5000);
for (int i = 0; i < NODES; i++) stopGrid(getTestIgniteInstanceName(i), false, false);
return null;
}
}, "stop-thread");
latch.countDown();
Ignite node = startGrid(NODES);
assertEquals(NODES + 1, node.cluster().localNode().order());
stopFut.get();
for (int i = 0; i < NODES + 1; i++) calculateAffinity(++topVer);
checkAffinity(1, topVer(topVer, 0), true);
for (int i = 0; i < NODES; i++) startServer(i, ++topVer);
checkAffinity(NODES + 1, topVer(topVer, 1), true);
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testNoForceKeysRequests.
/**
* @throws Exception If failed.
*/
public void testNoForceKeysRequests() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-5510");
cacheC = new IgniteClosure<String, CacheConfiguration[]>() {
@Override
public CacheConfiguration[] apply(String s) {
return null;
}
};
final AtomicBoolean fail = new AtomicBoolean();
spiC = new IgniteClosure<String, TestRecordingCommunicationSpi>() {
@Override
public TestRecordingCommunicationSpi apply(String s) {
TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtForceKeysRequest || msg instanceof GridDhtForceKeysResponse) {
fail.set(true);
U.dumpStack(log, "Unexpected message: " + msg);
}
return false;
}
});
return spi;
}
};
final int SRVS = 3;
for (int i = 0; i < SRVS; i++) startGrid(i);
client = true;
startGrid(SRVS);
client = false;
final List<CacheConfiguration> ccfgs = new ArrayList<>();
ccfgs.add(cacheConfiguration("tc1", TRANSACTIONAL, 0));
ccfgs.add(cacheConfiguration("tc2", TRANSACTIONAL, 1));
ccfgs.add(cacheConfiguration("tc3", TRANSACTIONAL, 2));
for (CacheConfiguration ccfg : ccfgs) ignite(0).createCache(ccfg);
final int NODES = SRVS + 1;
final AtomicInteger nodeIdx = new AtomicInteger();
final long stopTime = System.currentTimeMillis() + 60_000;
IgniteInternalFuture<?> updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = nodeIdx.getAndIncrement();
Ignite node = grid(idx);
List<IgniteCache<Object, Object>> caches = new ArrayList<>();
for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
while (!fail.get() && System.currentTimeMillis() < stopTime) {
for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
}
return null;
}
}, NODES, "update-thread");
IgniteInternalFuture<?> srvRestartFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!fail.get() && System.currentTimeMillis() < stopTime) {
Ignite node = startGrid(NODES);
List<IgniteCache<Object, Object>> caches = new ArrayList<>();
for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
for (int i = 0; i < 2; i++) {
for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
}
U.sleep(500);
stopGrid(NODES);
U.sleep(500);
}
return null;
}
}, "srv-restart");
srvRestartFut.get();
updateFut.get();
assertFalse("Unexpected messages.", fail.get());
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteClientCacheStartFailoverTest method testRebalanceState.
/**
* @throws Exception If failed.
*/
public void testRebalanceState() throws Exception {
final int SRVS = 3;
startGrids(SRVS);
List<String> cacheNames = startCaches(ignite(0), 100);
client = true;
Ignite c = startGrid(SRVS);
assertTrue(c.configuration().isClientMode());
awaitPartitionMapExchange();
client = false;
TestRecordingCommunicationSpi.spi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode clusterNode, Message msg) {
return msg instanceof GridDhtPartitionsFullMessage && ((GridDhtPartitionsFullMessage) msg).exchangeId() == null;
}
});
startGrid(SRVS + 1);
for (String cacheName : cacheNames) c.cache(cacheName);
U.sleep(1000);
for (int i = 0; i < SRVS + 1; i++) {
AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS + 2);
IgniteKernal node = (IgniteKernal) ignite(i);
for (String cacheName : cacheNames) {
GridDhtPartitionTopology top = node.context().cache().internalCache(cacheName).context().topology();
waitForReadyTopology(top, topVer);
assertEquals(topVer, top.readyTopologyVersion());
assertFalse(top.rebalanceFinished(topVer));
}
}
TestRecordingCommunicationSpi.spi(ignite(0)).stopBlock();
for (int i = 0; i < SRVS + 1; i++) {
final AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS + 2, 1);
final IgniteKernal node = (IgniteKernal) ignite(i);
for (String cacheName : cacheNames) {
final GridDhtPartitionTopology top = node.context().cache().internalCache(cacheName).context().topology();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return top.rebalanceFinished(topVer);
}
}, 5000);
assertTrue(top.rebalanceFinished(topVer));
}
}
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteOnePhaseCommitInvokeTest method onePhaseInvoke.
/**
* @param withOldVal If {@code true}
* @param setVal Flag whether set value from entry processor.
* @param retPrev Flag whether entry processor should return previous value.
* @throws Exception If failed.
*/
private void onePhaseInvoke(final boolean withOldVal, final boolean setVal, final boolean retPrev) throws Exception {
log.info("Test onePhaseInvoke [withOldVal=" + withOldVal + ", setVal=" + setVal + ", retPrev=" + retPrev + ']');
Ignite srv0 = startGrid(0);
if (withOldVal)
srv0.cache(CACHE_NAME).put(1, 1);
client = true;
final Ignite clientNode = startGrid(1);
final int grpId = groupIdForCache(srv0, CACHE_NAME);
TestRecordingCommunicationSpi.spi(srv0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtPartitionSupplyMessage && ((GridDhtPartitionSupplyMessage) msg).groupId() == grpId;
}
});
client = false;
Ignite srv1 = startGrid(2);
TestRecordingCommunicationSpi.spi(srv1).blockMessages(GridDhtTxPrepareResponse.class, srv0.name());
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Object res = clientNode.cache(CACHE_NAME).invoke(1, new TestEntryProcessor(setVal, retPrev));
Object expRes;
if (retPrev)
expRes = withOldVal ? 1 : null;
else
expRes = null;
assertEquals(expRes, res);
return null;
}
});
U.sleep(1000);
stopGrid(0);
fut.get();
if (!setVal)
checkCacheData(F.asMap(1, null), CACHE_NAME);
else {
Object expVal;
if (setVal)
expVal = 2;
else
expVal = withOldVal ? 1 : null;
checkCacheData(F.asMap(1, expVal), CACHE_NAME);
}
checkOnePhaseCommitReturnValuesCleaned(-1);
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteTxOriginatingNodeFailureAbstractSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setCommunicationSpi(new TcpCommunicationSpi() {
@Override
public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
if (!F.eq(ignoreMsgNodeId, node.id()) || !ignoredMessage((GridIoMessage) msg))
super.sendMessage(node, msg, ackClosure);
}
});
cfg.getTransactionConfiguration().setDefaultTxConcurrency(OPTIMISTIC);
return cfg;
}
Aggregations