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();
}
}
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 TcpDiscoveryMultiThreadedTest method getConfiguration.
/** {@inheritDoc} */
@SuppressWarnings({ "IfMayBeConditional" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
UUID id = nodeId.get();
if (id != null) {
cfg.setNodeId(id);
nodeId.set(null);
}
if (client())
cfg.setClientMode(true);
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder).setJoinTimeout(60_000).setNetworkTimeout(10_000));
int[] evts = { EVT_NODE_FAILED, EVT_NODE_LEFT };
Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
lsnrs.put(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
DiscoveryEvent discoveryEvt = (DiscoveryEvent) evt;
failedNodes.add(discoveryEvt.eventNode().id());
return true;
}
}, evts);
cfg.setLocalEventListeners(lsnrs);
cfg.setCacheConfiguration();
cfg.setIncludeEventTypes(EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
cfg.setIncludeProperties();
((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
return cfg;
}
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 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();
}
}
Aggregations