use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.
the class GridTcpCommunicationSpiLanTest method testRunSender.
/**
* @throws Exception If failed.
*/
public void testRunSender() throws Exception {
reject = true;
info(">>> Starting send to remote node multithreaded test. <<<");
final AtomicInteger cntr = new AtomicInteger();
final int msgCnt = 10000;
long start = System.currentTimeMillis();
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
while (cntr.getAndIncrement() < msgCnt) {
GridTestMessage msg = new GridTestMessage(locNode.id(), msgId.getAndIncrement(), 0);
msg.payload(new byte[13 * 1024]);
spi.sendMessage(remoteNode, msg);
}
} catch (IgniteException e) {
fail("Unable to send message: " + e.getMessage());
}
}
}, THREAD_CNT, "message-sender");
fut.get();
info(">>> Sent all messages in " + (System.currentTimeMillis() - start) + " milliseconds");
assertEquals("Invalid count of messages was sent", msgCnt, msgId.get());
U.sleep(IDLE_CONN_TIMEOUT * 2);
}
use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.
the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method startSpis.
/**
* @param ackCnt Recovery acknowledgement count.
* @param idleTimeout Idle connection timeout.
* @param queueLimit Message queue limit.
* @throws Exception If failed.
*/
private void startSpis(int ackCnt, int idleTimeout, int queueLimit) 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++) {
TcpCommunicationSpi spi = getSpi(ackCnt, idleTimeout, queueLimit);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
GridSpiTestContext ctx = initSpiContext();
MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {
@Override
public void registerAll(IgniteMessageFactory factory) {
factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
}
};
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
spi.setListener(new TestListener());
node.order(i);
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
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.spi.communication.GridTestMessage 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();
MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {
@Override
public void registerAll(IgniteMessageFactory factory) {
factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
}
};
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
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);
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
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.spi.communication.GridTestMessage in project ignite by apache.
the class GridTcpCommunicationSpiMultithreadedSelfTest method testFlowSend.
/**
* @throws Exception If failed.
*/
@Test
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(() -> {
try {
while (run.get() && !Thread.currentThread().isInterrupted()) {
U.sleep(interval * 3 / 2);
((TcpCommunicationSpi) spis.get(from.id())).onNodeLeft(to.consistentId(), 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 = ((GridNioServerWrapper) U.field(spi, "nioSrvWrapper")).nio();
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
for (GridNioSession ses : sessions) {
final GridNioRecoveryDescriptor snd = ses.outRecoveryDescriptor();
if (snd != null) {
GridTestUtils.waitForCondition(() -> snd.messagesRequests().isEmpty(), 10_000);
assertEquals("Unexpected messages: " + snd.messagesRequests(), 0, snd.messagesRequests().size());
}
}
}
}
use of org.apache.ignite.spi.communication.GridTestMessage in project ignite by apache.
the class GridTcpCommunicationSpiRecoverySelfTest method startSpis.
/**
* @throws Exception If failed.
*/
private void startSpis() 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++) {
TcpCommunicationSpi spi = getSpi(i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.order(i);
GridSpiTestContext ctx = initSpiContext();
MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
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(new TestListener());
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
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);
}
}
}
Aggregations