use of avro.shaded.com.google.common.base.Predicate in project incubator-gobblin by apache.
the class RecursiveCopyableDatasetTest method testCopyWithDeleteTargetAndDeleteParentDirectories.
@Test
public void testCopyWithDeleteTargetAndDeleteParentDirectories() throws Exception {
Path source = new Path("/source");
Path target = new Path("/target");
List<FileStatus> sourceFiles = Lists.newArrayList(createFileStatus(source, "file1"));
List<FileStatus> targetFiles = Lists.newArrayList(createFileStatus(target, "file3"));
Properties properties = new Properties();
properties.setProperty(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, target.toString());
properties.setProperty(RecursiveCopyableDataset.DELETE_EMPTY_DIRECTORIES_KEY, "true");
properties.setProperty(RecursiveCopyableDataset.DELETE_KEY, "true");
RecursiveCopyableDataset dataset = new TestRecursiveCopyableDataset(source, target, sourceFiles, targetFiles, properties);
Collection<? extends CopyEntity> copyableFiles = dataset.getCopyableFiles(FileSystem.getLocal(new Configuration()), CopyConfiguration.builder(FileSystem.getLocal(new Configuration()), properties).build());
Assert.assertEquals(copyableFiles.size(), 2);
ClassifiedFiles classifiedFiles = classifyFiles(copyableFiles);
Assert.assertTrue(classifiedFiles.getPathsToCopy().containsKey(new Path(source, "file1")));
Assert.assertEquals(classifiedFiles.getPathsToCopy().get(new Path(source, "file1")), new Path(target, "file1"));
Assert.assertEquals(classifiedFiles.getPathsToDelete().size(), 1);
Assert.assertTrue(classifiedFiles.getPathsToDelete().contains(new Path(target, "file3")));
CommitStepCopyEntity entity = (CommitStepCopyEntity) Iterables.filter(copyableFiles, new Predicate<CopyEntity>() {
@Override
public boolean apply(@Nullable CopyEntity copyEntity) {
return copyEntity instanceof CommitStepCopyEntity;
}
}).iterator().next();
DeleteFileCommitStep step = (DeleteFileCommitStep) entity.getStep();
Assert.assertTrue(step.getParentDeletionLimit().isPresent());
Assert.assertEquals(step.getParentDeletionLimit().get(), target);
}
use of avro.shaded.com.google.common.base.Predicate in project incubator-gobblin by apache.
the class RecursiveCopyableDatasetTest method testCopyWithDeleteTarget.
@Test
public void testCopyWithDeleteTarget() throws Exception {
Path source = new Path("/source");
Path target = new Path("/target");
List<FileStatus> sourceFiles = Lists.newArrayList(createFileStatus(source, "file1"));
List<FileStatus> targetFiles = Lists.newArrayList(createFileStatus(target, "file3"));
Properties properties = new Properties();
properties.setProperty(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, target.toString());
properties.setProperty(RecursiveCopyableDataset.DELETE_KEY, "true");
RecursiveCopyableDataset dataset = new TestRecursiveCopyableDataset(source, target, sourceFiles, targetFiles, properties);
Collection<? extends CopyEntity> copyableFiles = dataset.getCopyableFiles(FileSystem.getLocal(new Configuration()), CopyConfiguration.builder(FileSystem.getLocal(new Configuration()), properties).build());
Assert.assertEquals(copyableFiles.size(), 2);
ClassifiedFiles classifiedFiles = classifyFiles(copyableFiles);
Assert.assertTrue(classifiedFiles.getPathsToCopy().containsKey(new Path(source, "file1")));
Assert.assertEquals(classifiedFiles.getPathsToCopy().get(new Path(source, "file1")), new Path(target, "file1"));
Assert.assertEquals(classifiedFiles.getPathsToDelete().size(), 1);
Assert.assertTrue(classifiedFiles.getPathsToDelete().contains(new Path(target, "file3")));
CommitStepCopyEntity entity = (CommitStepCopyEntity) Iterables.filter(copyableFiles, new Predicate<CopyEntity>() {
@Override
public boolean apply(@Nullable CopyEntity copyEntity) {
return copyEntity instanceof CommitStepCopyEntity;
}
}).iterator().next();
DeleteFileCommitStep step = (DeleteFileCommitStep) entity.getStep();
Assert.assertFalse(step.getParentDeletionLimit().isPresent());
}
Aggregations