use of org.apache.ignite.internal.util.GridConcurrentHashSet in project ignite by apache.
the class TcpDiscoveryPendingMessageDeliveryTest method testDeliveryAllFailedMessagesInCorrectOrder.
/**
* @throws Exception If failed.
*/
@Test
public void testDeliveryAllFailedMessagesInCorrectOrder() throws Exception {
IgniteEx coord = startGrid("coordinator");
TcpDiscoverySpi coordDisco = (TcpDiscoverySpi) coord.configuration().getDiscoverySpi();
Set<TcpDiscoveryAbstractMessage> sentEnsuredMsgs = new GridConcurrentHashSet<>();
coordDisco.addSendMessageListener(msg -> {
if (coordDisco.ensured(msg))
sentEnsuredMsgs.add(msg);
});
// Node which receive message but will not send it further around the ring.
IgniteEx receiver = startGrid("receiver");
// Node which will be failed first.
IgniteEx dummy = startGrid("dummy");
// Node which should received all fail message in any way.
startGrid("listener");
sentEnsuredMsgs.clear();
receivedEnsuredMsgs.clear();
blockMsgs = true;
log.info("Sending fail node messages");
coord.context().discovery().failNode(dummy.localNode().id(), "Dummy node failed");
coord.context().discovery().failNode(receiver.localNode().id(), "Receiver node failed");
boolean delivered = GridTestUtils.waitForCondition(() -> {
log.info("Waiting for messages delivery");
return receivedEnsuredMsgs.equals(sentEnsuredMsgs);
}, 5000);
assertTrue("Sent: " + sentEnsuredMsgs + "; received: " + receivedEnsuredMsgs, delivered);
}
use of org.apache.ignite.internal.util.GridConcurrentHashSet in project ignite by apache.
the class TcpDiscoveryRestartTest method testRestart.
/**
* @throws Exception If failed.
*/
@Test
public void testRestart() throws Exception {
err = new AtomicReference<>();
final int NODE_CNT = 3;
startGrids(NODE_CNT);
final GridConcurrentHashSet<UUID> nodeIds = new GridConcurrentHashSet<>();
final AtomicInteger id = new AtomicInteger(NODE_CNT);
final IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int nodeIdx = id.getAndIncrement();
for (int i = 0; i < 10 && err.get() == null; i++) {
Ignite ignite = startGrid(nodeIdx);
UUID nodeId = ignite.cluster().localNode().id();
if (!nodeIds.add(nodeId))
failed("Duplicated node ID: " + nodeId);
stopGrid(nodeIdx);
}
return null;
}
}, 5, "restart-thread");
IgniteInternalFuture<?> loadFut = GridTestUtils.runMultiThreadedAsync(new Callable<Long>() {
@Override
public Long call() throws Exception {
long dummyRes = 0;
List<String> list = new ArrayList<>();
while (!fut.isDone()) {
for (int i = 0; i < 100; i++) {
String str = new String(new byte[i]);
list.add(str);
dummyRes += str.hashCode();
}
if (list.size() > 1000_000) {
list = new ArrayList<>();
System.gc();
}
}
return dummyRes;
}
}, 2, "test-load");
fut.get();
loadFut.get();
assertNull(err.get());
for (int i = 0; i < NODE_CNT; i++) {
Ignite ignite = ignite(i);
TestEventListener lsnr = (TestEventListener) F.firstKey(ignite.configuration().getLocalEventListeners());
assertNotNull(lsnr);
for (UUID nodeId : nodeIds) lsnr.checkEvents(nodeId);
}
}
Aggregations