use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpDiscoveryNodeAttributesUpdateOnReconnectTest method testReconnect.
/**
* @throws Exception If failed.
*/
public void testReconnect() throws Exception {
Ignite srv = startGrid("server");
IgniteEvents evts = srv.events();
evts.enableLocal(EventType.EVTS_DISCOVERY_ALL);
evts.localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
ClusterNode node = ((DiscoveryEvent) evt).eventNode();
rejoinAttr = node.attribute("test");
return true;
}
}, EventType.EVT_NODE_JOINED);
Ignite client = startGrid("client");
reconnectClientNode(log, client, srv, null);
assertEquals("2", rejoinAttr);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpDiscoverySelfTest method testPingInterruptedOnNodeFailed.
/**
* @throws Exception If any error occurs.
*/
public void testPingInterruptedOnNodeFailed() throws Exception {
try {
final Ignite pingingNode = startGrid("testPingInterruptedOnNodeFailedPingingNode");
final Ignite failedNode = startGrid("testPingInterruptedOnNodeFailedFailingNode");
startGrid("testPingInterruptedOnNodeFailedSimpleNode");
((TestTcpDiscoverySpi) failedNode.configuration().getDiscoverySpi()).ignorePingResponse = true;
final UUID failedNodeId = failedNode.cluster().localNode().id();
final CountDownLatch pingLatch = new CountDownLatch(1);
final CountDownLatch eventLatch = new CountDownLatch(1);
final AtomicBoolean pingRes = new AtomicBoolean(true);
final AtomicBoolean failRes = new AtomicBoolean(false);
long startTs = System.currentTimeMillis();
pingingNode.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
if (((DiscoveryEvent) event).eventNode().id().equals(failedNodeId)) {
failRes.set(true);
eventLatch.countDown();
}
return true;
}
}, EventType.EVT_NODE_FAILED);
IgniteInternalFuture<?> pingFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
pingLatch.countDown();
pingRes.set(pingingNode.configuration().getDiscoverySpi().pingNode(failedNodeId));
return null;
}
}, 1);
IgniteInternalFuture<?> failingFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
pingLatch.await();
Thread.sleep(3000);
((TestTcpDiscoverySpi) failedNode.configuration().getDiscoverySpi()).simulateNodeFailure();
return null;
}
}, 1);
failingFut.get();
pingFut.get();
assertFalse(pingRes.get());
assertTrue(System.currentTimeMillis() - startTs < pingingNode.configuration().getFailureDetectionTimeout() / 2);
assertTrue(eventLatch.await(7, TimeUnit.SECONDS));
assertTrue(failRes.get());
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpDiscoverySelfTest method testMetricsSending.
/**
* @throws Exception If any error occurs.
*/
public void testMetricsSending() throws Exception {
final AtomicBoolean stopping = new AtomicBoolean();
try {
final CountDownLatch latch1 = new CountDownLatch(1);
final Ignite g1 = startGrid(1);
IgnitePredicate<Event> lsnr1 = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
info(evt.message());
latch1.countDown();
return true;
}
};
g1.events().localListen(lsnr1, EVT_NODE_METRICS_UPDATED);
assert latch1.await(10, SECONDS);
g1.events().stopLocalListen(lsnr1);
final CountDownLatch latch1_1 = new CountDownLatch(1);
final CountDownLatch latch1_2 = new CountDownLatch(1);
final CountDownLatch latch2_1 = new CountDownLatch(1);
final CountDownLatch latch2_2 = new CountDownLatch(1);
final Ignite g2 = startGrid(2);
g2.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (stopping.get())
return true;
info(evt.message());
UUID id = ((DiscoveryEvent) evt).eventNode().id();
if (id.equals(g1.cluster().localNode().id()))
latch2_1.countDown();
else if (id.equals(g2.cluster().localNode().id()))
latch2_2.countDown();
else
assert false : "Event fired for unknown node.";
return true;
}
}, EVT_NODE_METRICS_UPDATED);
g1.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (stopping.get())
return true;
info(evt.message());
UUID id = ((DiscoveryEvent) evt).eventNode().id();
if (id.equals(g1.cluster().localNode().id()))
latch1_1.countDown();
else if (id.equals(g2.cluster().localNode().id()))
latch1_2.countDown();
else
assert false : "Event fired for unknown node.";
return true;
}
}, EVT_NODE_METRICS_UPDATED);
assert latch1_1.await(10, SECONDS);
assert latch1_2.await(10, SECONDS);
assert latch2_1.await(10, SECONDS);
assert latch2_2.await(10, SECONDS);
} finally {
stopping.set(true);
stopAllGrids();
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpDiscoverySelfTest method testNodeAdded.
/**
* @throws Exception If any error occurs.
*/
public void testNodeAdded() throws Exception {
try {
final Ignite g1 = startGrid(1);
final CountDownLatch cnt = new CountDownLatch(2);
g1.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
info("Node joined: " + evt.message());
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
TcpDiscoveryNode node = ((TcpDiscoveryNode) discoMap.get(g1.name()).getNode(discoEvt.eventNode().id()));
assert node != null && node.visible();
cnt.countDown();
return true;
}
}, EventType.EVT_NODE_JOINED);
startGrid(2);
startGrid(3);
info("Nodes were started");
assert cnt.await(1, SECONDS);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpDiscoverySelfTest method testNoRingMessageWorkerAbnormalFailureOnSegmentation.
/**
* @throws Exception If failed
*/
public void testNoRingMessageWorkerAbnormalFailureOnSegmentation() throws Exception {
try {
TestMessageWorkerFailureSpi1 spi1 = new TestMessageWorkerFailureSpi1(TestMessageWorkerFailureSpi1.SEGMENTATION_MODE);
nodeSpi.set(spi1);
Ignite ignite1 = startGrid("testNoRingMessageWorkerAbnormalFailureNormalNode");
nodeSpi.set(new TcpDiscoverySpi());
final Ignite ignite2 = startGrid("testNoRingMessageWorkerAbnormalFailureSegmentedNode");
final AtomicBoolean disconnected = new AtomicBoolean();
final AtomicBoolean segmented = new AtomicBoolean();
final CountDownLatch disLatch = new CountDownLatch(1);
final CountDownLatch segLatch = new CountDownLatch(1);
final UUID failedNodeId = ignite2.cluster().localNode().id();
ignite1.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EventType.EVT_NODE_FAILED && failedNodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
disconnected.set(true);
disLatch.countDown();
return false;
}
}, EventType.EVT_NODE_FAILED);
ignite2.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (!failedNodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
return true;
if (evt.type() == EventType.EVT_NODE_SEGMENTED) {
segmented.set(true);
segLatch.countDown();
}
return true;
}
}, EventType.EVT_NODE_SEGMENTED);
spi1.stop = true;
disLatch.await(15, TimeUnit.SECONDS);
assertTrue(disconnected.get());
spi1.stop = false;
segLatch.await(15, TimeUnit.SECONDS);
assertTrue(segmented.get());
Thread.sleep(10_000);
String result = strLog.toString();
assert result.contains("Local node SEGMENTED") && !result.contains("TcpDiscoverSpi's message worker thread failed abnormally") : result;
} finally {
stopAllGrids();
}
}
Aggregations