@Test public void testRestrictedRead() throws IOException { FileSystemPartitionView<TestRecord> partition0 = partitioned.getPartitionView(URI.create("id_hash=0")); FileSystemPartitionView<TestRecord> partition1 = partitioned.getPartitionView(URI.create("id_hash=1")); FileSystemPartitionView<TestRecord> partition2 = partitioned.getPartitionView(URI.create("id_hash=2")); FileSystemPartitionView<TestRecord> partition3 = partitioned.getPartitionView(URI.create("id_hash=3")); int count0 = DatasetTestUtilities.materialize(partition0).size(); int total = DatasetTestUtilities.materialize(partitioned).size(); Assert.assertTrue("Should read some records", count0 > 0); Assert.assertTrue("Should not read the entire dataset", count0 < total); // move other partitions so they match the partition0 constraint FileSystem local = LocalFileSystem.getInstance(); local.rename(new Path(partition1.getLocation()), new Path(partitioned.getDirectory(), "0")); local.rename( new Path(partition2.getLocation()), new Path(partitioned.getDirectory(), "hash=0")); local.rename( new Path(partition3.getLocation()), new Path(partitioned.getDirectory(), "id_hash=00")); int newCount0 = DatasetTestUtilities.materialize(partition0).size(); Assert.assertEquals("Should match original count", count0, newCount0); int countByConstraints = DatasetTestUtilities.materialize(partition0.toConstraintsView()).size(); Assert.assertEquals("Should match total count", total, countByConstraints); }
@Test public void testRestrictedDelete() throws IOException { FileSystemPartitionView<TestRecord> partition0 = partitioned.getPartitionView(URI.create("id_hash=0")); FileSystemPartitionView<TestRecord> partition1 = partitioned.getPartitionView(URI.create("id_hash=1")); FileSystemPartitionView<TestRecord> partition2 = partitioned.getPartitionView(URI.create("id_hash=2")); FileSystemPartitionView<TestRecord> partition3 = partitioned.getPartitionView(URI.create("id_hash=3")); int count0 = DatasetTestUtilities.materialize(partition0).size(); int total = DatasetTestUtilities.materialize(partitioned).size(); Assert.assertTrue("Should read some records", count0 > 0); Assert.assertTrue("Should not read the entire dataset", count0 < total); // move other partitions so they match the partition0 constraint FileSystem local = LocalFileSystem.getInstance(); local.rename(new Path(partition1.getLocation()), new Path(partitioned.getDirectory(), "0")); local.rename( new Path(partition2.getLocation()), new Path(partitioned.getDirectory(), "hash=0")); local.rename( new Path(partition3.getLocation()), new Path(partitioned.getDirectory(), "id_hash=00")); Assert.assertEquals( "Constraints should match all 4 directories", total, DatasetTestUtilities.materialize(partition0.toConstraintsView()).size()); partition0.deleteAll(); int newCount0 = DatasetTestUtilities.materialize(partition0).size(); Assert.assertEquals("Should have removed all records in id_hash=0", 0, newCount0); Assert.assertTrue( "Should not have deleted other directories", local.exists(new Path(partitioned.getDirectory(), "0"))); Assert.assertTrue( "Should not have deleted other directories", local.exists(new Path(partitioned.getDirectory(), "hash=0"))); Assert.assertTrue( "Should not have deleted other directories", local.exists(new Path(partitioned.getDirectory(), "id_hash=00"))); Assert.assertEquals( "Should match total without deleted data", total - count0, DatasetTestUtilities.materialize(partition0.toConstraintsView()).size()); partitioned.unbounded.deleteAll(); Assert.assertFalse( "Should have deleted all other directories", local.exists(new Path(partitioned.getDirectory(), "0"))); Assert.assertFalse( "Should have deleted all other directories", local.exists(new Path(partitioned.getDirectory(), "hash=0"))); Assert.assertFalse( "Should have deleted all other directories", local.exists(new Path(partitioned.getDirectory(), "id_hash=00"))); }