use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class CacheExchangeMergeTest method blockExchangeFinish.
/**
* @param crd Exchange coordinator.
* @param topVer Exchange topology version.
*/
private void blockExchangeFinish(Ignite crd, long topVer) {
final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer);
TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsFullMessage) {
GridDhtPartitionsFullMessage msg0 = (GridDhtPartitionsFullMessage) msg;
return msg0.exchangeId() != null && msg0.exchangeId().topologyVersion().equals(topVer0);
}
return false;
}
});
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class CacheExchangeMergeTest method blockExchangeFinish.
/**
* @param crd Exchange coordinator.
* @param topVer Exchange topology version.
* @param blockNodes Nodes which do not receive messages.
* @param waitMsgNodes Nodes which should receive messages.
* @return Awaited state latch.
*/
private CountDownLatch blockExchangeFinish(Ignite crd, long topVer, final List<Integer> blockNodes, final List<Integer> waitMsgNodes) {
log.info("blockExchangeFinish [crd=" + crd.cluster().localNode().id() + ", block=" + blockNodes + ", wait=" + waitMsgNodes + ']');
final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer);
final CountDownLatch latch = new CountDownLatch(waitMsgNodes.size());
TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsFullMessage) {
GridDhtPartitionsFullMessage msg0 = (GridDhtPartitionsFullMessage) msg;
if (msg0.exchangeId() == null || msg0.exchangeId().topologyVersion().compareTo(topVer0) < 0)
return false;
String name = node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME);
assert name != null : node;
for (Integer idx : blockNodes) {
if (name.equals(getTestIgniteInstanceName(idx)))
return true;
}
for (Integer idx : waitMsgNodes) {
if (name.equals(getTestIgniteInstanceName(idx))) {
log.info("Coordinators sends awaited message [node=" + node.id() + ']');
latch.countDown();
}
}
}
return false;
}
});
return latch;
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class GridIoManagerBenchmark0 method testLatency.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("deprecation")
public void testLatency() throws Exception {
final IgniteKernal sndKernal = (IgniteKernal) grid(0);
final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
final ClusterNode sndNode = sndKernal.localNode();
final ClusterNode rcvNode = rcvKernal.localNode();
final GridIoManager snd = sndKernal.context().io();
final GridIoManager rcv = rcvKernal.context().io();
final LongAdder msgCntr = new LongAdder();
final Integer topic = 1;
final Map<IgniteUuid, CountDownLatch> map = new ConcurrentHashMap<>();
rcv.addMessageListener(topic, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
try {
rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
} catch (IgniteCheckedException e) {
error("Failed to send message.", e);
}
}
});
snd.addMessageListener(topic, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
map.get(((GridTestMessage) msg).id()).countDown();
}
});
Timer t = new Timer("results-reporter");
t.schedule(new TimerTask() {
private long ts = System.currentTimeMillis();
@Override
public void run() {
long newTs = System.currentTimeMillis();
long qrys = msgCntr.sumThenReset();
long time = newTs - ts;
X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
ts = newTs;
}
}, 10000, 10000);
final AtomicBoolean finish = new AtomicBoolean();
IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
IgniteUuid msgId = IgniteUuid.randomUuid();
while (!finish.get()) {
CountDownLatch latch = new CountDownLatch(1);
map.put(msgId, latch);
snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
latch.await();
msgCntr.increment();
}
} catch (IgniteCheckedException e) {
X.println("Message send failed", e);
} catch (InterruptedException ignored) {
// No-op.
}
return null;
}
}, 1, "send-thread");
Thread.sleep(TEST_TIMEOUT);
finish.set(true);
t.cancel();
f.get();
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class GridTcpCommunicationSpiConcurrentConnectSelfTest method startSpis.
/**
* @param lsnr Message listener.
* @throws Exception If failed.
*/
private void startSpis(MessageListener lsnr) throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
for (int i = 0; i < SPI_CNT; i++) {
CommunicationSpi<Message> spi = createSpi();
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.setAttribute(IgniteNodeAttributes.ATTR_CLIENT_MODE, false);
node.order(i + 1);
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
if (useSsl) {
IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
ignite.setStaticCfg(cfg);
}
spi.setListener(lsnr);
node.setAttributes(spi.getNodeAttributes());
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
spis.add(spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
for (ClusterNode n : nodes) {
if (!n.equals(e.getKey()))
e.getValue().remoteNodes().add(n);
}
}
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class GridTcpCommunicationSpiMultithreadedSelfTest method testFlowSend.
/**
* @throws Exception If failed.
*/
public void testFlowSend() throws Exception {
reject = true;
final CyclicBarrier barrier = new CyclicBarrier(THREAD_CNT);
final Random rnd = new Random();
final ClusterNode from = randomNode(rnd);
ClusterNode tmp;
do {
tmp = randomNode(rnd);
} while (tmp.id().equals(from.id()));
final ClusterNode to = tmp;
final int iterationCnt = 1000;
final AtomicInteger threadId = new AtomicInteger();
final int interval = 50;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
try {
// Only first thread will print messages.
int id = threadId.getAndIncrement();
for (int i = 0; i < iterationCnt; i++) {
if (id == 0 && (i % 50) == 0)
info(">>> Running iteration " + i);
try {
for (ClusterNode node : nodes) {
Message msg = new GridTestMessage(from.id(), msgId.getAndIncrement(), 0);
spis.get(from.id()).sendMessage(node, msg);
}
} catch (IgniteException e) {
log.warning(">>> Oops, unable to send message (safe to ignore).", e);
}
barrier.await();
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (BrokenBarrierException e) {
info("Wait on barrier failed: " + e);
Thread.currentThread().interrupt();
}
}
}, THREAD_CNT, "message-sender");
final AtomicBoolean run = new AtomicBoolean(true);
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
while (run.get() && !Thread.currentThread().isInterrupted()) {
U.sleep(interval * 3 / 2);
((TcpCommunicationSpi) spis.get(from.id())).onNodeLeft(to.id());
}
} catch (IgniteInterruptedCheckedException ignored) {
Thread.currentThread().interrupt();
}
}
}, 1);
fut.get();
run.set(false);
fut2.get();
// Wait when all messages are acknowledged to do not break next tests' logic.
for (CommunicationSpi<Message> spi : spis.values()) {
GridNioServer srv = U.field(spi, "nioSrvr");
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
for (GridNioSession ses : sessions) {
final GridNioRecoveryDescriptor snd = ses.outRecoveryDescriptor();
if (snd != null) {
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return snd.messagesRequests().isEmpty();
}
}, 10_000);
assertEquals("Unexpected messages: " + snd.messagesRequests(), 0, snd.messagesRequests().size());
}
}
}
}
Aggregations