use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.
the class GridTcpCommunicationSpiRecoveryAckSelfTest method communicationSession.
/**
* @param spi SPI.
* @return Session.
* @throws Exception If failed.
*/
private GridNioSession communicationSession(TcpCommunicationSpi spi) throws Exception {
final GridNioServer<?> srv = ((GridNioServerWrapper) U.field(spi, "nioSrvWrapper")).nio();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
return !sessions.isEmpty();
}
}, 5000);
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
assertEquals(1, sessions.size());
return sessions.iterator().next();
}
use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.
the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method checkOverflow.
/**
* @throws Exception If failed.
*/
private void checkOverflow() throws Exception {
TcpCommunicationSpi spi0 = spis.get(0);
TcpCommunicationSpi spi1 = spis.get(1);
ClusterNode node0 = nodes.get(0);
ClusterNode node1 = nodes.get(1);
// Await time to close the session by queue overflow.
final int awaitTime = 5_000;
// Check that session will not be closed by idle timeout because expected close by queue overflow.
assertTrue(spi0.getIdleConnectionTimeout() > awaitTime);
final GridNioServer<?> srv1 = ((GridNioServerWrapper) U.field(spi1, "nioSrvWrapper")).nio();
// For prevent session close by write timeout.
srv1.writeTimeout(60_000);
final AtomicInteger ackMsgs = new AtomicInteger(0);
IgniteInClosure<IgniteException> ackC = new CI1<IgniteException>() {
@Override
public void apply(IgniteException o) {
assert o == null;
ackMsgs.incrementAndGet();
}
};
int msgId = 0;
// Send message to establish connection.
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
int sentMsgs = 1;
// Prevent node1 from send
GridTestUtils.setFieldValue(srv1, "skipWrite", true);
final GridNioSession ses0 = communicationSession(spi0);
int queueLimit = ses0.outRecoveryDescriptor().queueLimit();
for (int i = sentMsgs; i < queueLimit; i++) {
try {
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
sentMsgs++;
} catch (IgniteSpiException e) {
log.info("Send error [err=" + e + ", sentMsgs=" + sentMsgs + ']');
break;
}
}
// Wait when session is closed because of queue overflow.
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ses0.closeTime() != 0;
}
}, awaitTime);
assertTrue("Failed to wait for session close", ses0.closeTime() != 0);
GridTestUtils.setFieldValue(srv1, "skipWrite", false);
// It to gain all acks since acks have batch nature.
int cnt = 100 - sentMsgs % spi0.getAckSendThreshold();
for (int i = 0; i < cnt; i++) spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
final int expMsgs = sentMsgs + cnt;
final TestListener lsnr = (TestListener) spi1.getListener();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return lsnr.rcvCnt.get() >= expMsgs;
}
}, 5000);
assertEquals(expMsgs, lsnr.rcvCnt.get());
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return expMsgs == ackMsgs.get();
}
}, 5000);
assertEquals(expMsgs, ackMsgs.get());
}
use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.
the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method checkAck.
/**
* @param ackCnt Recovery acknowledgement count.
* @param idleTimeout Idle connection timeout.
* @param msgPerIter Messages per iteration.
* @throws Exception If failed.
*/
private void checkAck(int ackCnt, int idleTimeout, int msgPerIter) throws Exception {
createSpis(ackCnt, idleTimeout, TcpCommunicationSpi.DFLT_MSG_QUEUE_LIMIT);
try {
TcpCommunicationSpi spi0 = spis.get(0);
TcpCommunicationSpi spi1 = spis.get(1);
ClusterNode node0 = nodes.get(0);
ClusterNode node1 = nodes.get(1);
int msgId = 0;
int expMsgs = 0;
long totAcked = 0;
for (int i = 0; i < 5; i++) {
info("Iteration: " + i);
final AtomicInteger ackMsgs = new AtomicInteger(0);
IgniteInClosure<IgniteException> ackC = new CI1<IgniteException>() {
@Override
public void apply(IgniteException o) {
assert o == null;
ackMsgs.incrementAndGet();
}
};
for (int j = 0; j < msgPerIter; j++) {
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0), ackC);
spi1.sendMessage(node0, new GridTestMessage(node1.id(), ++msgId, 0), ackC);
if (j == 0) {
final TestListener lsnr0 = (TestListener) spi0.getListener();
final TestListener lsnr1 = (TestListener) spi1.getListener();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return lsnr0.rcvCnt.get() >= 1 && lsnr1.rcvCnt.get() >= 1;
}
}, 1000);
}
}
expMsgs += msgPerIter;
final long totAcked0 = totAcked;
for (TcpCommunicationSpi spi : spis) {
GridNioServer<?> srv = ((GridNioServerWrapper) U.field(spi, "nioSrvWrapper")).nio();
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
assertFalse(sessions.isEmpty());
boolean found = false;
for (GridNioSession ses : sessions) {
final GridNioRecoveryDescriptor recoveryDesc = ses.outRecoveryDescriptor();
if (recoveryDesc != null) {
found = true;
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
long acked = GridTestUtils.getFieldValue(recoveryDesc, "acked");
return acked > totAcked0;
}
}, 5000);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return recoveryDesc.messagesRequests().isEmpty();
}
}, 10_000);
assertEquals("Unexpected messages: " + recoveryDesc.messagesRequests(), 0, recoveryDesc.messagesRequests().size());
break;
}
}
assertTrue(found);
}
final int expMsgs0 = expMsgs;
for (TcpCommunicationSpi spi : spis) {
final TestListener lsnr = (TestListener) spi.getListener();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return lsnr.rcvCnt.get() >= expMsgs0;
}
}, 5000);
assertEquals(expMsgs, lsnr.rcvCnt.get());
}
assertEquals(msgPerIter * 2, ackMsgs.get());
totAcked += msgPerIter;
}
} finally {
stopSpis();
}
}
use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.
the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method communicationSession.
/**
* @param spi SPI.
* @return Session.
* @throws Exception If failed.
*/
private GridNioSession communicationSession(TcpCommunicationSpi spi) throws Exception {
final GridNioServer<?> srv = ((GridNioServerWrapper) U.field(spi, "nioSrvWrapper")).nio();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
return !sessions.isEmpty();
}
}, 5000);
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
assertEquals(1, sessions.size());
return sessions.iterator().next();
}
use of org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper in project ignite by apache.
the class GridTcpCommunicationSpiRecoverySelfTest method communicationSession.
/**
* @param spi SPI.
* @param in {@code True} if need find inbound session.
* @return Session.
* @throws Exception If failed.
*/
private GridNioSession communicationSession(TcpCommunicationSpi spi, boolean in) throws Exception {
final GridNioServer<?> srv = ((GridNioServerWrapper) U.field(spi, "nioSrvWrapper")).nio();
GridTestUtils.waitForCondition(() -> {
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
return !sessions.isEmpty();
}, awaitForSocketWriteTimeout());
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
for (GridNioSession ses : sessions) {
if (in == ses.accepted())
return ses;
}
fail("Failed to find session");
return null;
}
Aggregations