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);
}
Aggregations