Search in sources :

Example 21 with Event

use of org.apache.hadoop.hdfs.inotify.Event in project SSM by Intel-bigdata.

the class TestInotifyEventApplier method testApplierRenameEvent.

@Test
public void testApplierRenameEvent() throws Exception {
    DFSClient client = Mockito.mock(DFSClient.class);
    SmartConf conf = new SmartConf();
    NamespaceFetcher namespaceFetcher = new NamespaceFetcher(client, metaStore, null, conf);
    InotifyEventApplier applier = new InotifyEventApplier(metaStore, client, namespaceFetcher);
    FileInfo[] fileInfos = new FileInfo[] { HadoopUtil.convertFileStatus(getDummyFileStatus("/dirfile", 7000), "/dirfile"), HadoopUtil.convertFileStatus(getDummyDirStatus("/dir", 8000), "/dir"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir/file1", 8001), "/dir/file1"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir/file2", 8002), "/dir/file2"), HadoopUtil.convertFileStatus(getDummyDirStatus("/dir2", 8100), "/dir2"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir2/file1", 8101), "/dir2/file1"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir2/file2", 8102), "/dir2/file2"), HadoopUtil.convertFileStatus(getDummyDirStatus("/dir/dir", 8200), "/dir/dir"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir/dir/f1", 8201), "/dir/dir/f1"), HadoopUtil.convertFileStatus(getDummyFileStatus("/file", 2000), "/file") };
    metaStore.insertFiles(fileInfos);
    Mockito.when(client.getFileInfo("/dir1")).thenReturn(getDummyDirStatus("/dir1", 8000));
    Event.RenameEvent dirRenameEvent = new Event.RenameEvent.Builder().srcPath("/dir").dstPath("/dir1").build();
    applier.apply(new Event[] { dirRenameEvent });
    Assert.assertTrue(metaStore.getFile("/dir") == null);
    Assert.assertTrue(metaStore.getFile("/dir/file1") == null);
    Assert.assertTrue(metaStore.getFile("/dirfile") != null);
    Assert.assertTrue(metaStore.getFile("/dir1") != null);
    Assert.assertTrue(metaStore.getFile("/dir1/file1") != null);
    Assert.assertTrue(metaStore.getFile("/dir1/dir/f1") != null);
    Assert.assertTrue(metaStore.getFile("/dir2") != null);
    Assert.assertTrue(metaStore.getFile("/dir2/file1") != null);
    Assert.assertTrue(metaStore.getFile("/file") != null);
    List<Event> events = new ArrayList<>();
    Event.RenameEvent renameEvent = new Event.RenameEvent.Builder().srcPath("/file1").dstPath("/file2").build();
    events.add(renameEvent);
    applier.apply(events);
    Assert.assertTrue(metaStore.getFile("/file2") == null);
    /*
    Mockito.when(client.getFileInfo("/file2")).thenReturn(getDummyFileStatus("/file2", 2000));
    applier.apply(events);
    FileInfo info = metaStore.getFile("/file2");
    Assert.assertTrue(info != null && info.getFileId() == 2000);
    */
    events.clear();
    renameEvent = new Event.RenameEvent.Builder().srcPath("/file").dstPath("/file1").build();
    events.add(renameEvent);
    applier.apply(events);
    FileInfo info2 = metaStore.getFile("/file");
    Assert.assertTrue(info2 == null);
    FileInfo info3 = metaStore.getFile("/file1");
    Assert.assertTrue(info3 != null);
    renameEvent = new Event.RenameEvent.Builder().srcPath("/file1").dstPath("/file2").build();
    events.clear();
    events.add(renameEvent);
    applier.apply(events);
    FileInfo info4 = metaStore.getFile("/file1");
    FileInfo info5 = metaStore.getFile("/file2");
    Assert.assertTrue(info4 == null && info5 != null);
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) ArrayList(java.util.ArrayList) FileInfo(org.smartdata.model.FileInfo) Event(org.apache.hadoop.hdfs.inotify.Event) SmartConf(org.smartdata.conf.SmartConf) Test(org.junit.Test)

Aggregations

Event (org.apache.hadoop.hdfs.inotify.Event)21 Test (org.junit.Test)12 EventBatch (org.apache.hadoop.hdfs.inotify.EventBatch)10 ArrayList (java.util.ArrayList)9 FsPermission (org.apache.hadoop.fs.permission.FsPermission)7 DFSClient (org.apache.hadoop.hdfs.DFSClient)6 IOException (java.io.IOException)5 MockFlowFile (org.apache.nifi.util.MockFlowFile)4 TestRunner (org.apache.nifi.util.TestRunner)4 OutputStream (java.io.OutputStream)3 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)3 AlluxioURI (alluxio.AlluxioURI)2 InvalidPathException (alluxio.exception.InvalidPathException)2 LockResource (alluxio.resource.LockResource)2 Callable (java.util.concurrent.Callable)2 AclEntryProto (org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto)2 FileInfo (org.smartdata.model.FileInfo)2 Constants (alluxio.Constants)1 SyncInfo (alluxio.SyncInfo)1 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)1