use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class IgfsEventsAbstractSelfTest method testDirWithFiles.
/**
* Checks events on CRUD operations on a single directory
* with some files.
*
* @throws Exception If failed.
*/
public void testDirWithFiles() throws Exception {
final List<Event> evtList = new ArrayList<>();
final int evtsCnt = 4 + 3 + 1;
final CountDownLatch latch = new CountDownLatch(evtsCnt);
grid(1).events().localListen(lsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
log.info("Received event [evt=" + evt + ']');
evtList.add(evt);
latch.countDown();
return true;
}
}, EVTS_IGFS);
IgfsPath dir = new IgfsPath("/dir1");
IgfsPath file1 = new IgfsPath(dir, "file1");
IgfsPath file2 = new IgfsPath(dir, "file2");
// Will generate EVT_IGFS_DIR_CREATED + EVT_IGFS_FILE_CREATED + EVT_IGFS_FILE_OPENED_WRITE +
// EVT_IGFS_FILE_CLOSED_WRITE.
igfs.create(file1, true).close();
// Will generate EVT_IGFS_FILE_CREATED + EVT_IGFS_FILE_OPENED_WRITE +
// EVT_IGFS_FILE_CLOSED.
igfs.create(file2, true).close();
// Will generate EVT_IGFS_DIR_DELETED event.
assertTrue(igfs.delete(dir, true));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(evtsCnt, evtList.size());
IgfsEvent evt = (IgfsEvent) evtList.get(0);
assertEquals(EVT_IGFS_DIR_CREATED, evt.type());
assertEquals(new IgfsPath("/dir1"), evt.path());
assertTrue(evt.isDirectory());
evt = (IgfsEvent) evtList.get(1);
assertEquals(EVT_IGFS_FILE_CREATED, evt.type());
assertEquals(new IgfsPath("/dir1/file1"), evt.path());
assertFalse(evt.isDirectory());
evt = (IgfsEvent) evtList.get(2);
assertEquals(EVT_IGFS_FILE_OPENED_WRITE, evt.type());
assertEquals(new IgfsPath("/dir1/file1"), evt.path());
evt = (IgfsEvent) evtList.get(3);
assertEquals(EVT_IGFS_FILE_CLOSED_WRITE, evt.type());
assertEquals(new IgfsPath("/dir1/file1"), evt.path());
evt = (IgfsEvent) evtList.get(4);
assertEquals(EVT_IGFS_FILE_CREATED, evt.type());
assertEquals(new IgfsPath("/dir1/file2"), evt.path());
assertFalse(evt.isDirectory());
evt = (IgfsEvent) evtList.get(5);
assertEquals(EVT_IGFS_FILE_OPENED_WRITE, evt.type());
assertEquals(new IgfsPath("/dir1/file2"), evt.path());
evt = (IgfsEvent) evtList.get(6);
assertEquals(EVT_IGFS_FILE_CLOSED_WRITE, evt.type());
assertEquals(new IgfsPath("/dir1/file2"), evt.path());
evt = (IgfsEvent) evtList.get(7);
assertEquals(EVT_IGFS_DIR_DELETED, evt.type());
assertEquals(new IgfsPath("/dir1"), evt.path());
}
use of org.apache.ignite.lang.IgnitePredicate 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.lang.IgnitePredicate 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.lang.IgnitePredicate 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.lang.IgnitePredicate in project ignite by apache.
the class IgniteSourceConnectorTest method doTest.
/**
* Tests the source with the specified source configurations.
*
* @param srcProps Source properties.
* @param conditioned Flag indicating whether filtering is enabled.
* @throws Exception Fails if error.
*/
private void doTest(Map<String, String> srcProps, boolean conditioned) 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!", error);
}
});
herder.putConnectorConfig(srcProps.get(ConnectorConfig.NAME_CONFIG), srcProps, true, cb);
cb.get();
// Ugh! To be sure Kafka Connect's worker thread is properly started...
Thread.sleep(5000);
final CountDownLatch latch = new CountDownLatch(EVENT_CNT);
final IgnitePredicate<CacheEvent> locLsnr = new IgnitePredicate<CacheEvent>() {
@Override
public boolean apply(CacheEvent evt) {
assert evt != null;
latch.countDown();
return true;
}
};
grid.events(grid.cluster().forCacheNodes(CACHE_NAME)).localListen(locLsnr, 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);
keyValMap.putAll(sendData());
// Checks all events are processed.
assertTrue(latch.await(10, TimeUnit.SECONDS));
grid.events(grid.cluster().forCacheNodes(CACHE_NAME)).stopLocalListen(locLsnr);
assertEquals(EVENT_CNT, cache.size(CachePeekMode.PRIMARY));
// Checks the events are transferred to Kafka broker.
if (conditioned)
checkDataDelivered(EVENT_CNT * TOPICS.length / 2);
else
checkDataDelivered(EVENT_CNT * TOPICS.length);
}
Aggregations