@Test @SuppressWarnings("unchecked") public void testMoveToTrash() throws Exception { DatasetWriter<StandardEvent> writer = null; try { writer = unbounded.newWriter(); writer.write(sepEvent); writer.write(octEvent); writer.write(novEvent); } finally { Closeables.close(writer, false); } final Path root = new Path("target/data/ns/test"); final Path y2013 = new Path("target/data/ns/test/year=2013"); final Path sep = new Path("target/data/ns/test/year=2013/month=09"); final Path sep12 = new Path("target/data/ns/test/year=2013/month=09/day=12"); final Path oct = new Path("target/data/ns/test/year=2013/month=10"); final Path oct12 = new Path("target/data/ns/test/year=2013/month=10/day=12"); final Path nov = new Path("target/data/ns/test/year=2013/month=11"); final Path nov11 = new Path("target/data/ns/test/year=2013/month=11/day=11"); assertDirectoriesExist(fs, root, y2013, sep, sep12, oct, oct12, nov, nov11); long julStart = new DateTime(2013, 6, 1, 0, 0, DateTimeZone.UTC).getMillis(); long sepStart = new DateTime(2013, 9, 1, 0, 0, DateTimeZone.UTC).getMillis(); final long nov11Start = new DateTime(2013, 11, 11, 0, 0, DateTimeZone.UTC).getMillis(); final long nov12Start = new DateTime(2013, 11, 12, 0, 0, DateTimeZone.UTC).getMillis(); long decStart = new DateTime(2013, 12, 1, 0, 0, DateTimeZone.UTC).getMillis(); final long sepInstant = sepEvent.getTimestamp(); final long sep12End = new DateTime(2013, 9, 13, 0, 0, DateTimeZone.UTC).getMillis() - 1; final long octInstant = octEvent.getTimestamp(); final long oct12Start = new DateTime(2013, 10, 12, 0, 0, 0, DateTimeZone.UTC).getMillis(); final long oct12BadStart = new DateTime(2013, 10, 12, 0, 1, 0, DateTimeZone.UTC).getMillis(); final long oct12End = new DateTime(2013, 10, 12, 23, 59, 59, 999, DateTimeZone.UTC).getMillis(); final long oct12BadEnd = new DateTime(2013, 10, 12, 23, 59, 57, 999, DateTimeZone.UTC).getMillis(); Assert.assertFalse("Delete should return false to indicate no changes", unbounded.from("timestamp", decStart).moveToTrash()); Assert.assertFalse("Delete should return false to indicate no changes", unbounded.from("timestamp", julStart).toBefore("timestamp", sepStart).moveToTrash()); TestHelpers.assertThrows( "Delete should fail if not aligned with partition boundary", UnsupportedOperationException.class, new Runnable() { @Override public void run() { unbounded.to("timestamp", sepInstant).deleteAll(); } }); TestHelpers.assertThrows( "Delete should fail if not aligned with partition boundary", UnsupportedOperationException.class, new Runnable() { @Override public void run() { unbounded.toBefore("timestamp", sep12End).moveToTrash(); } }); assertTrue("Delete should return true to indicate FS changed", unbounded.to("timestamp", sep12End).moveToTrash()); assertDirectoriesDoNotExist(fs, sep12, sep); assertDirectoriesInTrash(fs, trashPolicy, sep12, sep); assertDirectoriesExist(fs, root, y2013, oct, oct12, nov, nov11); Assert.assertFalse("Delete should return false to indicate no changes", unbounded.to("timestamp", sep12End).moveToTrash()); assertDirectoriesDoNotExist(fs, sep12, sep); assertDirectoriesExist(fs, root, y2013, oct, oct12, nov, nov11); TestHelpers.assertThrows( "Delete should fail if not aligned with partition boundary", UnsupportedOperationException.class, new Runnable() { @Override public void run() { unbounded.from("timestamp", nov11Start).to("timestamp", nov12Start).moveToTrash(); } }); TestHelpers.assertThrows( "Delete should fail if not aligned with partition boundary", UnsupportedOperationException.class, new Runnable() { @Override public void run() { unbounded.fromAfter("timestamp", nov11Start).toBefore("timestamp", nov12Start).moveToTrash(); } }); assertTrue("Delete should return true to indicate FS changed", unbounded.from("timestamp", nov11Start).toBefore("timestamp", nov12Start).moveToTrash()); assertDirectoriesDoNotExist(fs, sep12, sep, nov11, nov); assertDirectoriesExist(fs, root, y2013, oct, oct12); Assert.assertFalse("Delete should return false to indicate no changes", unbounded.from("timestamp", nov11Start).toBefore("timestamp", nov12Start).moveToTrash()); assertDirectoriesDoNotExist(fs, sep12, sep, nov11, nov); assertDirectoriesInTrash(fs, trashPolicy, sep12, sep, nov11, nov); assertDirectoriesExist(fs, root, y2013, oct, oct12); TestHelpers.assertThrows( "Delete should fail if not aligned with partition boundary", UnsupportedOperationException.class, new Runnable() { @Override public void run() { unbounded.from("timestamp", octInstant).to("timestamp", octInstant).moveToTrash(); } }); TestHelpers.assertThrows( "Delete should fail if not aligned with partition boundary", UnsupportedOperationException.class, new Runnable() { @Override public void run() { unbounded.from("timestamp", oct12BadStart).to("timestamp", oct12End).moveToTrash(); } }); TestHelpers.assertThrows( "Delete should fail if not aligned with partition boundary", UnsupportedOperationException.class, new Runnable() { @Override public void run() { unbounded.from("timestamp", oct12Start).to("timestamp", oct12BadEnd).moveToTrash(); } }); assertTrue("Delete should return true to indicate FS changed", unbounded.from("timestamp", oct12Start).to("timestamp", oct12End).moveToTrash()); assertDirectoriesDoNotExist(fs, y2013, sep12, sep, oct12, oct, nov11, nov); assertDirectoriesInTrash(fs, trashPolicy, y2013, sep12, sep, oct12, oct, nov11, nov); assertDirectoriesExist(fs, root); Assert.assertFalse("Delete should return false to indicate no changes", unbounded.from("timestamp", oct12Start).to("timestamp", oct12End).moveToTrash()); assertDirectoriesDoNotExist(fs, y2013, sep12, sep, oct12, oct, nov11, nov); assertDirectoriesInTrash(fs, trashPolicy, y2013, sep12, sep, oct12, oct, nov11, nov); assertDirectoriesExist(fs, root); Assert.assertFalse("Delete should return false to indicate no changes", unbounded.moveToTrash()); assertDirectoriesDoNotExist(fs, y2013, sep12, sep, oct12, oct, nov11, nov); assertDirectoriesInTrash(fs, trashPolicy, y2013, sep12, sep, oct12, nov11, nov); assertDirectoriesExist(fs, root); }
@Override public boolean moveToTrash() { if (!constraints.alignedWithBoundaries()) { throw new UnsupportedOperationException( "Cannot cleanly move view to trash: " + this); } return deleteAllUnsafe(true); }
FileSystemView extends AbstractRefinableView<E> implements InputFormatAccessor<E>,
    LastModifiedAccessor, SizeAccessor, Signalable<E> { @Override public boolean moveToTrash() { if (!constraints.alignedWithBoundaries()) { throw new UnsupportedOperationException( "Cannot cleanly move view to trash: " + this); } return deleteAllUnsafe(true); } }
FileSystemView extends AbstractRefinableView<E> implements InputFormatAccessor<E>,
    LastModifiedAccessor, SizeAccessor, Signalable<E> { @Override public boolean moveToTrash() { if (!constraints.alignedWithBoundaries()) { throw new UnsupportedOperationException( "Cannot cleanly move view to trash: " + this); } return deleteAllUnsafe(true); } FileSystemView(FileSystemDataset<E> dataset, @Nullable PartitionListener listener, @Nullable SignalManager signalManager, Class<E> type);   FileSystemView(FileSystemView<E> view, Constraints c); private  FileSystemView(FileSystemView<?> view, Schema schema, Class<E> type); }
FileSystemView extends AbstractRefinableView<E> implements InputFormatAccessor<E>,
    LastModifiedAccessor, SizeAccessor, Signalable<E> { @Override public boolean moveToTrash() { if (!constraints.alignedWithBoundaries()) { throw new UnsupportedOperationException( "Cannot cleanly move view to trash: " + this); } return deleteAllUnsafe(true); } FileSystemView(FileSystemDataset<E> dataset, @Nullable PartitionListener listener, @Nullable SignalManager signalManager, Class<E> type);   FileSystemView(FileSystemView<E> view, Constraints c); private  FileSystemView(FileSystemView<?> view, Schema schema, Class<E> type); @Override DatasetReader<E> newReader(); @Override DatasetWriter<E> newWriter(); @Override Iterable<PartitionView<E>> getCoveringPartitions(); @Override boolean deleteAll(); @Override boolean moveToTrash(); @Override InputFormat<E, Void> getInputFormat(Configuration conf); @Override long getSize(); @Override long getLastModified(); @Override void signalReady(); @Override boolean isReady(); }
FileSystemView extends AbstractRefinableView<E> implements InputFormatAccessor<E>,
    LastModifiedAccessor, SizeAccessor, Signalable<E> { @Override public boolean moveToTrash() { if (!constraints.alignedWithBoundaries()) { throw new UnsupportedOperationException( "Cannot cleanly move view to trash: " + this); } return deleteAllUnsafe(true); } FileSystemView(FileSystemDataset<E> dataset, @Nullable PartitionListener listener, @Nullable SignalManager signalManager, Class<E> type);   FileSystemView(FileSystemView<E> view, Constraints c); private  FileSystemView(FileSystemView<?> view, Schema schema, Class<E> type); @Override DatasetReader<E> newReader(); @Override DatasetWriter<E> newWriter(); @Override Iterable<PartitionView<E>> getCoveringPartitions(); @Override boolean deleteAll(); @Override boolean moveToTrash(); @Override InputFormat<E, Void> getInputFormat(Configuration conf); @Override long getSize(); @Override long getLastModified(); @Override void signalReady(); @Override boolean isReady();  }