use of org.apache.ignite.events.Event 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.Event in project ignite by apache.
the class TcpDiscoverySelfTest method testCoordinatorNodeFailure.
/**
* @throws Exception If any error occurs.
*/
public void testCoordinatorNodeFailure() throws Exception {
try {
Ignite g1 = startGrid(1);
Ignite g2 = startGrid(2);
final CountDownLatch cnt = new CountDownLatch(1);
g2.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
cnt.countDown();
return true;
}
}, EventType.EVT_NODE_FAILED);
info("Nodes were started");
discoMap.get(g1.name()).simulateNodeFailure();
assert cnt.await(20, SECONDS);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.Event 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.Event in project ignite by apache.
the class TcpDiscoveryRestartTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(spi);
int[] evts = { EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT };
cfg.setIncludeEventTypes(evts);
Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
lsnrs.put(new TestEventListener(), evts);
cfg.setLocalEventListeners(lsnrs);
return cfg;
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class IgniteSinkConnectorTest method testSinkPuts.
/**
* Tests the whole data flow from injecting data to Kafka to transferring it to the grid. It reads from two
* specified Kafka topics, because a sink task can read from multiple topics.
*
* @param sinkProps Sink properties.
* @param keyless Tests on Kafka stream with null keys if true.
* @throws Exception Thrown in case of the failure.
*/
private void testSinkPuts(Map<String, String> sinkProps, boolean keyless) throws Exception {
FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>(new Callback<Herder.Created<ConnectorInfo>>() {
@Override
public void onCompletion(Throwable error, Herder.Created<ConnectorInfo> info) {
if (error != null)
throw new RuntimeException("Failed to create a job!");
}
});
herder.putConnectorConfig(sinkProps.get(ConnectorConfig.NAME_CONFIG), sinkProps, false, cb);
cb.get();
final CountDownLatch latch = new CountDownLatch(EVENT_CNT * TOPICS.length);
final IgnitePredicate<Event> putLsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt != null;
latch.countDown();
return true;
}
};
grid.events(grid.cluster().forCacheNodes(CACHE_NAME)).localListen(putLsnr, EVT_CACHE_OBJECT_PUT);
IgniteCache<String, String> cache = grid.cache(CACHE_NAME);
assertEquals(0, cache.size(CachePeekMode.PRIMARY));
Map<String, String> keyValMap = new HashMap<>(EVENT_CNT * TOPICS.length);
// Produces events for the specified number of topics
for (String topic : TOPICS) keyValMap.putAll(produceStream(topic, keyless));
// Checks all events successfully processed in 10 seconds.
assertTrue(latch.await(10, TimeUnit.SECONDS));
grid.events(grid.cluster().forCacheNodes(CACHE_NAME)).stopLocalListen(putLsnr);
// Checks that each event was processed properly.
for (Map.Entry<String, String> entry : keyValMap.entrySet()) assertEquals(entry.getValue(), cache.get(entry.getKey()));
assertEquals(EVENT_CNT * TOPICS.length, cache.size(CachePeekMode.PRIMARY));
}
Aggregations