use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridTcpCommunicationSpiRecoveryAckSelfTest method checkOverflow.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
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);
final GridNioServer srv1 = U.field(spi1, "nioSrvr");
int msgId = 0;
// Send message to establish connection.
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
// Prevent node1 from send
GridTestUtils.setFieldValue(srv1, "skipWrite", true);
final GridNioSession ses0 = communicationSession(spi0);
int sentMsgs = 1;
for (int i = 0; i < 1280; i++) {
try {
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
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;
}
}, 5000);
assertTrue("Failed to wait for session close", ses0.closeTime() != 0);
GridTestUtils.setFieldValue(srv1, "skipWrite", false);
for (int i = 0; i < 100; i++) spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
final int expMsgs = sentMsgs + 100;
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());
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridTcpCommunicationSpiRecoveryAckSelfTest method checkAck.
/**
* @param ackCnt Recovery acknowledgement count.
* @param idleTimeout Idle connection timeout.
* @param msgPerIter Messages per iteration.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
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);
for (int j = 0; j < msgPerIter; j++) {
spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
spi1.sendMessage(node0, new GridTestMessage(node1.id(), ++msgId, 0));
}
U.sleep(500);
expMsgs += msgPerIter;
final long totAcked0 = totAcked;
for (TcpCommunicationSpi spi : spis) {
GridNioServer srv = U.field(spi, "nioSrvr");
final Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return !sessions.isEmpty();
}
}, 5_000);
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());
}
totAcked += msgPerIter;
}
} finally {
stopSpis();
}
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class ComputeUtilsTest method testGetData.
/**
* Tests {@code getData()} method.
*/
public void testGetData() {
ClusterNode node = grid(1).cluster().localNode();
String upstreamCacheName = "CACHE_1_" + UUID.randomUUID();
String datasetCacheName = "CACHE_2_" + UUID.randomUUID();
CacheConfiguration<Integer, Integer> upstreamCacheConfiguration = new CacheConfiguration<>();
upstreamCacheConfiguration.setName(upstreamCacheName);
upstreamCacheConfiguration.setAffinity(new TestAffinityFunction(node));
IgniteCache<Integer, Integer> upstreamCache = ignite.createCache(upstreamCacheConfiguration);
CacheConfiguration<Integer, Integer> datasetCacheConfiguration = new CacheConfiguration<>();
datasetCacheConfiguration.setName(datasetCacheName);
datasetCacheConfiguration.setAffinity(new TestAffinityFunction(node));
IgniteCache<Integer, Integer> datasetCache = ignite.createCache(datasetCacheConfiguration);
upstreamCache.put(42, 42);
datasetCache.put(0, 0);
UUID datasetId = UUID.randomUUID();
IgniteAtomicLong cnt = ignite.atomicLong("CNT_" + datasetId, 0, true);
for (int i = 0; i < 10; i++) {
Collection<TestPartitionData> data = ComputeUtils.affinityCallWithRetries(ignite, Arrays.asList(datasetCacheName, upstreamCacheName), part -> ComputeUtils.<Integer, Integer, Serializable, TestPartitionData>getData(ignite, upstreamCacheName, datasetCacheName, datasetId, 0, (upstream, upstreamSize, ctx) -> {
cnt.incrementAndGet();
assertEquals(1, upstreamSize);
UpstreamEntry<Integer, Integer> e = upstream.next();
return new TestPartitionData(e.getKey() + e.getValue());
}), 0);
assertEquals(1, data.size());
TestPartitionData dataElement = data.iterator().next();
assertEquals(84, dataElement.val.intValue());
}
assertEquals(1, cnt.get());
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class ComputeUtilsTest method testAffinityCallWithRetriesNegative.
/**
* Tests that in case two caches maintain their partitions on different nodes, affinity call won't be completed.
*/
public void testAffinityCallWithRetriesNegative() {
ClusterNode node1 = grid(1).cluster().localNode();
ClusterNode node2 = grid(2).cluster().localNode();
String firstCacheName = "CACHE_1_" + UUID.randomUUID();
String secondCacheName = "CACHE_2_" + UUID.randomUUID();
CacheConfiguration<Integer, Integer> cacheConfiguration1 = new CacheConfiguration<>();
cacheConfiguration1.setName(firstCacheName);
cacheConfiguration1.setAffinity(new TestAffinityFunction(node1));
IgniteCache<Integer, Integer> cache1 = ignite.createCache(cacheConfiguration1);
CacheConfiguration<Integer, Integer> cacheConfiguration2 = new CacheConfiguration<>();
cacheConfiguration2.setName(secondCacheName);
cacheConfiguration2.setAffinity(new TestAffinityFunction(node2));
IgniteCache<Integer, Integer> cache2 = ignite.createCache(cacheConfiguration2);
try {
try {
ComputeUtils.affinityCallWithRetries(ignite, Arrays.asList(firstCacheName, secondCacheName), part -> part, 0);
} catch (IllegalStateException expectedException) {
return;
}
fail("Missing IllegalStateException");
} finally {
cache1.destroy();
cache2.destroy();
}
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridMarshallerAbstractTest method testMarshallingAnonymousClassInstance.
/**
* Tests marshal anonymous class instance.
*
* @throws Exception If test failed.
*/
public void testMarshallingAnonymousClassInstance() throws Exception {
final Ignite g = grid();
GridMarshallerTestBean inBean = newTestBean(new IgniteClosure() {
/**
*/
private Iterable<ClusterNode> nodes = g.cluster().nodes();
/**
* {@inheritDoc}
*/
@Override
public Object apply(Object o) {
return nodes;
}
});
byte[] buf = marshal(inBean);
GridMarshallerTestBean outBean = unmarshal(buf);
assert inBean.getObjectField() != null;
assert outBean.getObjectField() != null;
assert IgniteClosure.class.isAssignableFrom(inBean.getObjectField().getClass());
assert IgniteClosure.class.isAssignableFrom(outBean.getObjectField().getClass());
assert inBean.getObjectField() != outBean.getObjectField();
assert inBean != outBean;
assert inBean.equals(outBean);
outBean.checkNullResources();
}
Aggregations