@Test public void testFilter() throws Exception { CopyableFileFilter readyFilter = new ReadyCopyableFileFilter(); List<CopyableFile> copyableFiles = Lists.newArrayList(); copyableFiles.add(CopyableFileUtils.getTestCopyableFile()); copyableFiles.add(CopyableFileUtils.getTestCopyableFile()); copyableFiles.add(CopyableFileUtils.getTestCopyableFile()); FileSystem sourceFs = Mockito.mock(FileSystem.class); Mockito.when(sourceFs.exists(PathUtils.addExtension(copyableFiles.get(0).getOrigin().getPath(), ".ready"))) .thenReturn(false); Mockito.when(sourceFs.exists(PathUtils.addExtension(copyableFiles.get(1).getOrigin().getPath(), ".ready"))) .thenReturn(true); Mockito.when(sourceFs.exists(PathUtils.addExtension(copyableFiles.get(2).getOrigin().getPath(), ".ready"))) .thenReturn(false); Collection<CopyableFile> filtered = readyFilter.filter(sourceFs, null, copyableFiles); Assert.assertEquals(filtered.size(), 1); }
@Override public Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem targetFs, Collection<CopyableFile> copyableFiles) { Iterator<CopyableFile> cfIterator = copyableFiles.iterator(); ImmutableList.Builder<CopyableFile> filtered = ImmutableList.builder(); while (cfIterator.hasNext()) { CopyableFile cf = cfIterator.next(); Path readyFilePath = PathUtils.addExtension(cf.getOrigin().getPath(), READY_EXTENSION); try { if (sourceFs.exists(readyFilePath)) { filtered.add(cf); } else { log.info(String.format("Removing %s as the .ready file is not found", cf.getOrigin().getPath())); } } catch (IOException e) { log.warn(String.format("Removing %s as the .ready file can not be read. Exception %s", cf.getOrigin().getPath(), e.getMessage())); } } return filtered.build(); }
ReadyCopyableFileFilter implements CopyableFileFilter { @Override public Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem targetFs, Collection<CopyableFile> copyableFiles) { Iterator<CopyableFile> cfIterator = copyableFiles.iterator(); ImmutableList.Builder<CopyableFile> filtered = ImmutableList.builder(); while (cfIterator.hasNext()) { CopyableFile cf = cfIterator.next(); Path readyFilePath = PathUtils.addExtension(cf.getOrigin().getPath(), READY_EXTENSION); try { if (sourceFs.exists(readyFilePath)) { filtered.add(cf); } else { log.info(String.format("Removing %s as the .ready file is not found", cf.getOrigin().getPath())); } } catch (IOException e) { log.warn(String.format("Removing %s as the .ready file can not be read. Exception %s", cf.getOrigin().getPath(), e.getMessage())); } } return filtered.build(); } }
ReadyCopyableFileFilter implements CopyableFileFilter { @Override public Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem targetFs, Collection<CopyableFile> copyableFiles) { Iterator<CopyableFile> cfIterator = copyableFiles.iterator(); ImmutableList.Builder<CopyableFile> filtered = ImmutableList.builder(); while (cfIterator.hasNext()) { CopyableFile cf = cfIterator.next(); Path readyFilePath = PathUtils.addExtension(cf.getOrigin().getPath(), READY_EXTENSION); try { if (sourceFs.exists(readyFilePath)) { filtered.add(cf); } else { log.info(String.format("Removing %s as the .ready file is not found", cf.getOrigin().getPath())); } } catch (IOException e) { log.warn(String.format("Removing %s as the .ready file can not be read. Exception %s", cf.getOrigin().getPath(), e.getMessage())); } } return filtered.build(); }  }
ReadyCopyableFileFilter implements CopyableFileFilter { @Override public Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem targetFs, Collection<CopyableFile> copyableFiles) { Iterator<CopyableFile> cfIterator = copyableFiles.iterator(); ImmutableList.Builder<CopyableFile> filtered = ImmutableList.builder(); while (cfIterator.hasNext()) { CopyableFile cf = cfIterator.next(); Path readyFilePath = PathUtils.addExtension(cf.getOrigin().getPath(), READY_EXTENSION); try { if (sourceFs.exists(readyFilePath)) { filtered.add(cf); } else { log.info(String.format("Removing %s as the .ready file is not found", cf.getOrigin().getPath())); } } catch (IOException e) { log.warn(String.format("Removing %s as the .ready file can not be read. Exception %s", cf.getOrigin().getPath(), e.getMessage())); } } return filtered.build(); }  @Override Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem targetFs,
      Collection<CopyableFile> copyableFiles); }
ReadyCopyableFileFilter implements CopyableFileFilter { @Override public Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem targetFs, Collection<CopyableFile> copyableFiles) { Iterator<CopyableFile> cfIterator = copyableFiles.iterator(); ImmutableList.Builder<CopyableFile> filtered = ImmutableList.builder(); while (cfIterator.hasNext()) { CopyableFile cf = cfIterator.next(); Path readyFilePath = PathUtils.addExtension(cf.getOrigin().getPath(), READY_EXTENSION); try { if (sourceFs.exists(readyFilePath)) { filtered.add(cf); } else { log.info(String.format("Removing %s as the .ready file is not found", cf.getOrigin().getPath())); } } catch (IOException e) { log.warn(String.format("Removing %s as the .ready file can not be read. Exception %s", cf.getOrigin().getPath(), e.getMessage())); } } return filtered.build(); }  @Override Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem targetFs,
      Collection<CopyableFile> copyableFiles); static final String READY_EXTENSION; }