@Test public void testApplier() throws Exception { DFSClient client = Mockito.mock(DFSClient.class); FileInfo root = HadoopUtil.convertFileStatus(getDummyDirStatus("/", 1000), "/"); metaStore.insertFile(root); BackUpInfo backUpInfo = new BackUpInfo(1L, "/file", "remote/dest/", 10); metaStore.insertBackUpInfo(backUpInfo); InotifyEventApplier applier = new InotifyEventApplier(metaStore, client); Event.CreateEvent createEvent = new Event.CreateEvent.Builder() .iNodeType(Event.CreateEvent.INodeType.FILE) .ctime(1) .defaultBlockSize(1024) .groupName("cg1") .overwrite(true) .ownerName("user1") .path("/file") .perms(new FsPermission("777")) .replication(3) .build(); HdfsFileStatus status1 = CompatibilityHelperLoader.getHelper().createHdfsFileStatus( 0, false, 1, 1024, 0, 0, new FsPermission("777"), "owner", "group", new byte[0], new byte[0], 1010, 0, null, (byte) 0); Mockito.when(client.getFileInfo(Matchers.startsWith("/file"))).thenReturn(status1); Mockito.when(client.getFileInfo(Matchers.startsWith("/dir"))).thenReturn(getDummyDirStatus("", 1010)); applier.apply(new Event[] {createEvent}); FileInfo result1 = metaStore.getFile().get(1); Assert.assertEquals(result1.getPath(), "/file"); Assert.assertEquals(result1.getFileId(), 1010L); Assert.assertEquals(result1.getPermission(), 511); Event close = new Event.CloseEvent("/file", 1024, 0); applier.apply(new Event[] {close}); FileInfo result2 = metaStore.getFile().get(1); Assert.assertEquals(result2.getLength(), 1024); Assert.assertEquals(result2.getModificationTime(), 0L); Event meta = new Event.MetadataUpdateEvent.Builder() .path("/file") .metadataType(Event.MetadataUpdateEvent.MetadataType.TIMES) .mtime(2) .atime(3) .replication(4) .ownerName("user2") .groupName("cg2") .build(); applier.apply(new Event[] {meta}); FileInfo result4 = metaStore.getFile().get(1); Assert.assertEquals(result4.getAccessTime(), 3); Assert.assertEquals(result4.getModificationTime(), 2); Event meta1 = new Event.MetadataUpdateEvent.Builder() .path("/file") .metadataType(Event.MetadataUpdateEvent.MetadataType.OWNER) .ownerName("user1") .groupName("cg1") .build(); applier.apply(new Event[] {meta1}); result4 = metaStore.getFile().get(1); Assert.assertEquals(result4.getOwner(), "user1"); Assert.assertEquals(result4.getGroup(), "cg1"); Event.CreateEvent createEvent2 = new Event.CreateEvent.Builder() .iNodeType(Event.CreateEvent.INodeType.DIRECTORY) .ctime(1) .groupName("cg1") .overwrite(true) .ownerName("user1") .path("/dir") .perms(new FsPermission("777")) .replication(3) .build(); Event.CreateEvent createEvent3 = new Event.CreateEvent.Builder() .iNodeType(Event.CreateEvent.INodeType.FILE) .ctime(1) .groupName("cg1") .overwrite(true) .ownerName("user1") .path("/dir/file") .perms(new FsPermission("777")) .replication(3) .build(); Event rename = new Event.RenameEvent.Builder().dstPath("/dir2").srcPath("/dir").timestamp(5).build(); applier.apply(new Event[] {createEvent2, createEvent3, rename}); List<FileInfo> result5 = metaStore.getFile(); List<String> expectedPaths = Arrays.asList("/dir2", "/dir2/file", "/file"); List<String> actualPaths = new ArrayList<>(); for (FileInfo s : result5) { actualPaths.add(s.getPath()); } Collections.sort(actualPaths); Assert.assertTrue(actualPaths.size() == 4); Assert.assertTrue(actualPaths.containsAll(expectedPaths)); Event unlink = new Event.UnlinkEvent.Builder().path("/").timestamp(6).build(); applier.apply(new Event[]{unlink}); Thread.sleep(1200); Assert.assertEquals(metaStore.getFile().size(), 0); System.out.println("Files in table " + metaStore.getFile().size()); List<FileDiff> fileDiffList = metaStore.getPendingDiff(); Assert.assertTrue(fileDiffList.size() == 4); }
public void apply(List<Event> events) throws IOException, MetaStoreException, InterruptedException { List<String> statements = new ArrayList<>(); for (Event event : events) { List<String> gen = getSqlStatement(event); if (gen != null && !gen.isEmpty()) { for (String s : gen) { if (s != null && s.length() > 0) { statements.add(s); } } } } this.metaStore.execute(statements); }
InotifyEventApplier { public void apply(List<Event> events) throws IOException, MetaStoreException, InterruptedException { List<String> statements = new ArrayList<>(); for (Event event : events) { List<String> gen = getSqlStatement(event); if (gen != null && !gen.isEmpty()) { for (String s : gen) { if (s != null && s.length() > 0) { statements.add(s); } } } } this.metaStore.execute(statements); } }
InotifyEventApplier { public void apply(List<Event> events) throws IOException, MetaStoreException, InterruptedException { List<String> statements = new ArrayList<>(); for (Event event : events) { List<String> gen = getSqlStatement(event); if (gen != null && !gen.isEmpty()) { for (String s : gen) { if (s != null && s.length() > 0) { statements.add(s); } } } } this.metaStore.execute(statements); } InotifyEventApplier(MetaStore metaStore, DFSClient client);  InotifyEventApplier(MetaStore metaStore, DFSClient client, NamespaceFetcher namespaceFetcher); }
InotifyEventApplier { public void apply(List<Event> events) throws IOException, MetaStoreException, InterruptedException { List<String> statements = new ArrayList<>(); for (Event event : events) { List<String> gen = getSqlStatement(event); if (gen != null && !gen.isEmpty()) { for (String s : gen) { if (s != null && s.length() > 0) { statements.add(s); } } } } this.metaStore.execute(statements); } InotifyEventApplier(MetaStore metaStore, DFSClient client);  InotifyEventApplier(MetaStore metaStore, DFSClient client, NamespaceFetcher namespaceFetcher); void apply(List<Event> events); void apply(Event[] events); }
InotifyEventApplier { public void apply(List<Event> events) throws IOException, MetaStoreException, InterruptedException { List<String> statements = new ArrayList<>(); for (Event event : events) { List<String> gen = getSqlStatement(event); if (gen != null && !gen.isEmpty()) { for (String s : gen) { if (s != null && s.length() > 0) { statements.add(s); } } } } this.metaStore.execute(statements); } InotifyEventApplier(MetaStore metaStore, DFSClient client);  InotifyEventApplier(MetaStore metaStore, DFSClient client, NamespaceFetcher namespaceFetcher); void apply(List<Event> events); void apply(Event[] events);  }