use of org.apache.ignite.events.IgfsEvent in project ignite by apache.
the class IgfsEventsAbstractSelfTest method testFileDataEvents.
/**
* Checks events on file data transfer operations.
*
* @throws Exception If failed.
*/
public void testFileDataEvents() throws Exception {
final List<Event> evtList = new ArrayList<>();
final int evtsCnt = 5;
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);
final IgfsPath file = new IgfsPath("/file1");
final int dataSize = 1024;
byte[] buf = new byte[dataSize];
// Will generate IGFS_FILE_CREATED, IGFS_FILE_OPENED_WRITE, IGFS_FILE_CLOSED_WRITE.
try (IgfsOutputStream os = igfs.create(file, false)) {
// Will generate no events.
os.write(buf);
}
// Will generate EVT_IGFS_FILE_OPENED_READ, IGFS_FILE_CLOSED_READ.
try (IgfsInputStream is = igfs.open(file, 256)) {
// Will generate no events.
is.readFully(0, buf);
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(evtsCnt, evtList.size());
IgfsEvent evt = (IgfsEvent) evtList.get(0);
assertEquals(EVT_IGFS_FILE_CREATED, evt.type());
assertEquals(new IgfsPath("/file1"), evt.path());
evt = (IgfsEvent) evtList.get(1);
assertEquals(EVT_IGFS_FILE_OPENED_WRITE, evt.type());
assertEquals(new IgfsPath("/file1"), evt.path());
evt = (IgfsEvent) evtList.get(2);
assertEquals(EVT_IGFS_FILE_CLOSED_WRITE, evt.type());
assertEquals(new IgfsPath("/file1"), evt.path());
assertEquals((long) dataSize, evt.dataSize());
evt = (IgfsEvent) evtList.get(3);
assertEquals(EVT_IGFS_FILE_OPENED_READ, evt.type());
assertEquals(new IgfsPath("/file1"), evt.path());
evt = (IgfsEvent) evtList.get(4);
assertEquals(EVT_IGFS_FILE_CLOSED_READ, evt.type());
assertEquals(new IgfsPath("/file1"), evt.path());
assertEquals((long) dataSize, evt.dataSize());
}
use of org.apache.ignite.events.IgfsEvent in project ignite by apache.
the class IgfsEventsAbstractSelfTest method testTwoFiles.
/**
* Checks events on CRUD operations on 2 files.
*
* @throws Exception If failed.
*/
public void testTwoFiles() throws Exception {
final List<Event> evtList = new ArrayList<>();
final int evtsCnt = 4 + 3 + 2 + 2;
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");
// Will generate EVT_IGFS_FILE_CREATED event + EVT_IGFS_DIR_CREATED event + OPEN + CLOSE.
igfs.create(file1, true).close();
IgfsPath file2 = new IgfsPath(dir, "file2");
// Will generate 1 EVT_IGFS_FILE_CREATED event + OPEN + CLOSE.
igfs.create(file2, true).close();
assertTrue(igfs.exists(dir));
assertTrue(igfs.exists(file1));
assertTrue(igfs.exists(file2));
// Will generate 1 EVT_IGFS_FILE_DELETED and 1 EVT_IGFS_FILE_PURGED.
assertTrue(igfs.delete(file1, false));
// Same.
assertTrue(igfs.delete(file2, false));
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());
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());
assertEquals(0, evt.dataSize());
evt = (IgfsEvent) evtList.get(4);
assertEquals(EVT_IGFS_FILE_CREATED, evt.type());
assertEquals(new IgfsPath("/dir1/file2"), evt.path());
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());
assertEquals(0, evt.dataSize());
assertOneToOne(evtList.subList(7, 11), new EventPredicate(EVT_IGFS_FILE_DELETED, new IgfsPath("/dir1/file1")), new EventPredicate(EVT_IGFS_FILE_PURGED, new IgfsPath("/dir1/file1")), new EventPredicate(EVT_IGFS_FILE_DELETED, new IgfsPath("/dir1/file2")), new EventPredicate(EVT_IGFS_FILE_PURGED, new IgfsPath("/dir1/file2")));
}
use of org.apache.ignite.events.IgfsEvent in project ignite by apache.
the class IgfsEventsAbstractSelfTest method testSingleFileNestedDirs.
/**
* Checks events on CRUD operations on a single file in nested directories.
*
* @throws Exception If failed.
*/
public void testSingleFileNestedDirs() throws Exception {
final List<Event> evtList = new ArrayList<>();
final int evtsCnt = 6 + 1 + 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/dir2/dir3");
IgfsPath file = new IgfsPath(dir, "file1");
// Will generate 3 EVT_IGFS_DIR_CREATED + EVT_IGFS_FILE_CREATED + EVT_IGFS_FILE_OPENED_WRITE +
// EVT_IGFS_FILE_CLOSED and a number of EVT_IGFS_META_UPDATED.
igfs.create(file, true).close();
IgfsPath mvFile = new IgfsPath(dir, "mvFile1");
// Will generate EVT_IGFS_FILE_RENAMED.
igfs.rename(file, mvFile);
// Will generate EVT_IGFS_DIR_DELETED event.
assertTrue(igfs.delete(dir.parent(), 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_DIR_CREATED, evt.type());
assertEquals(new IgfsPath("/dir1/dir2"), evt.path());
evt = (IgfsEvent) evtList.get(2);
assertEquals(EVT_IGFS_DIR_CREATED, evt.type());
assertEquals(new IgfsPath("/dir1/dir2/dir3"), evt.path());
evt = (IgfsEvent) evtList.get(3);
assertEquals(EVT_IGFS_FILE_CREATED, evt.type());
assertEquals(new IgfsPath("/dir1/dir2/dir3/file1"), evt.path());
assertFalse(evt.isDirectory());
evt = (IgfsEvent) evtList.get(4);
assertEquals(EVT_IGFS_FILE_OPENED_WRITE, evt.type());
assertEquals(new IgfsPath("/dir1/dir2/dir3/file1"), evt.path());
evt = (IgfsEvent) evtList.get(5);
assertEquals(EVT_IGFS_FILE_CLOSED_WRITE, evt.type());
assertEquals(new IgfsPath("/dir1/dir2/dir3/file1"), evt.path());
assertEquals(0, evt.dataSize());
evt = (IgfsEvent) evtList.get(6);
assertEquals(EVT_IGFS_FILE_RENAMED, evt.type());
assertEquals(new IgfsPath("/dir1/dir2/dir3/file1"), evt.path());
assertEquals(new IgfsPath("/dir1/dir2/dir3/mvFile1"), evt.newPath());
evt = (IgfsEvent) evtList.get(7);
assertEquals(EVT_IGFS_DIR_DELETED, evt.type());
assertEquals(new IgfsPath("/dir1/dir2"), evt.path());
}
use of org.apache.ignite.events.IgfsEvent in project ignite by apache.
the class IgfsUtils method sendEvents.
/**
* Sends a series of event.
*
* @param kernalCtx Kernal context.
* @param path The path of the created file.
* @param newPath New path.
* @param type The type of event to send.
*/
public static void sendEvents(GridKernalContext kernalCtx, IgfsPath path, IgfsPath newPath, int type) {
assert kernalCtx != null;
assert path != null;
GridEventStorageManager evts = kernalCtx.event();
ClusterNode locNode = kernalCtx.discovery().localNode();
if (evts.isRecordable(type)) {
if (newPath == null)
evts.record(new IgfsEvent(path, locNode, type));
else
evts.record(new IgfsEvent(path, newPath, locNode, type));
}
}
use of org.apache.ignite.events.IgfsEvent in project ignite by apache.
the class IgfsAbstractOutputStream method updateMetricsOnClose.
/**
* Updates IGFS metrics when the stream is closed.
*/
protected void updateMetricsOnClose() {
IgfsLocalMetrics metrics = igfsCtx.metrics();
metrics.addWrittenBytesTime(bytes, time);
metrics.decrementFilesOpenedForWrite();
GridEventStorageManager evts = igfsCtx.kernalContext().event();
if (evts.isRecordable(EVT_IGFS_FILE_CLOSED_WRITE))
evts.record(new IgfsEvent(path, igfsCtx.localNode(), EVT_IGFS_FILE_CLOSED_WRITE, bytes));
}
Aggregations