@Override public void run() { oct.with("timestamp", later); } });
@Override public void run() { withSpecificTimestamp.with("timestamp", later); } });
@Override public void run() { toOct.with("timestamp", later); } });
@Override public void run() { beforeOct.with("timestamp", later); } });
@Override public void run() { oct.with("timestamp", earlier); } });
@Override public void run() { fromOctober.with("timestamp", earlier); } });
@Override public void run() { afterSep.with("timestamp", earlier); } });
@Override public RefinableView<E> with(String name, Object... values) { return asRefinableView().with(name, values); }
@Test(expected = ValidationException.class) public void testNonExistentField() { unbounded.with("nosuchfield"); }
@Test(expected = IllegalArgumentException.class) public void testInconsistentFieldType() { unbounded.with("timestamp", 0); // not '0L' }
@Test @SuppressWarnings("rawtypes") public void testReadySignalMultipleConstraints() { Assume.assumeTrue(unbounded instanceof Signalable); final long instant = new DateTime(2013, 10, 1, 0, 0, DateTimeZone.UTC).getMillis(); final Signalable withTwoConstrainedFields = (Signalable) unbounded.with("timestamp", instant).with("user_id", 0L); Assert.assertFalse("Should not be ready initially", withTwoConstrainedFields.isReady()); withTwoConstrainedFields.signalReady(); Assert.assertTrue("Should be ready after signal", withTwoConstrainedFields.isReady()); }
@Test public void testViewForRelativeUri() { Path path = new Path("/tmp/datasets/ns/test/y=2014/m=03/d=14"); View<GenericRecord> view = FileSystemDatasets.viewForUri( dataset, "y=2014/m=03/d=14"); Assert.assertEquals("Should create correct view", view, dataset.getPartitionView(path)); Constraints expected = ((AbstractRefinableView<GenericRecord>) dataset.with("y", 2014).with("m", 3).with("d", 14)).getConstraints(); Constraints actual = ((AbstractRefinableView<GenericRecord>) view) .getConstraints(); Assert.assertEquals("Constraints should match expected", expected, actual); }
@Test public void testViewForMissingPartitionNames() { Path path = new Path("2014/3/14"); // like PathConversion, this uses names from the partition strategy // and will accept partitions that don't have a "name=" component View<GenericRecord> view = FileSystemDatasets.viewForUri( dataset, path.toString()); Assert.assertEquals("Should create correct view", view, dataset.getPartitionView(path)); Constraints expected = ((AbstractRefinableView<GenericRecord>) dataset.with("y", 2014).with("m", 3).with("d", 14)).getConstraints(); Constraints actual = ((AbstractRefinableView<GenericRecord>) view) .getConstraints(); Assert.assertEquals("Constraints should match expected", expected, actual); }
@Test public void testViewForDifferentPartitionNames() { Path path = new Path("year=2014/month=3/day=14"); // like PathConversion, this uses names from the partition strategy // and will accept partitions that have a different "name=" component View<GenericRecord> view = FileSystemDatasets.viewForUri( dataset, path.toString()); Assert.assertEquals("Should create correct view", view, dataset.getPartitionView(path)); Constraints expected = ((AbstractRefinableView<GenericRecord>) dataset.with("y", 2014).with("m", 3).with("d", 14)).getConstraints(); Constraints actual = ((AbstractRefinableView<GenericRecord>) view) .getConstraints(); Assert.assertEquals("Constraints should match expected", expected, actual); }
@Test public void testIgnoresAuthority() { Path path = new Path("/tmp/datasets/ns/test/y=2014/m=03/d=14"); View<GenericRecord> view = FileSystemDatasets.viewForUri( dataset, "file://127.0.0.1/tmp/datasets/ns/test/y=2014/m=03/d=14"); Assert.assertEquals("Should create correct view", view, dataset.getPartitionView(path)); Constraints expected = ((AbstractRefinableView<GenericRecord>) dataset.with("y", 2014).with("m", 3).with("d", 14)).getConstraints(); Constraints actual = ((AbstractRefinableView<GenericRecord>) view) .getConstraints(); Assert.assertEquals("Constraints should match expected", expected, actual); }
@Test @SuppressWarnings("rawtypes") public void testReadySignalWithConstraint() { Assume.assumeTrue(unbounded instanceof Signalable); final long instant = new DateTime(2013, 10, 1, 0, 0, DateTimeZone.UTC).getMillis(); final Signalable withSpecificTimestamp = (Signalable) unbounded.with("timestamp", instant); Assert.assertFalse("Should not be ready initially", withSpecificTimestamp.isReady()); withSpecificTimestamp.signalReady(); Assert.assertTrue("Should be ready after signal", withSpecificTimestamp.isReady()); Signalable multipleWithView = (Signalable)unbounded.with("timestamp", instant+1, instant+2); Assert.assertFalse("Should not be ready initially", multipleWithView.isReady()); multipleWithView.signalReady(); Assert.assertTrue("Should be ready after signal", multipleWithView.isReady()); }
@Test public void testMixedConstraintViews() { assertViewUriEquivalent("id, color, and time constraints", "view:file:/tmp/test_name?color=,orange&id=exists()×tamp=[0,9)", test.with("color", "", "orange").with("id") .from("timestamp", 0L).toBefore("timestamp", 9L)); }
@Test public void testViewForIncompleteUri() { Path path = new Path("/tmp/datasets/ns/test/y=2014/m=03"); View<GenericRecord> view = FileSystemDatasets.viewForUri( dataset, path.toString()); Assert.assertEquals("Should create correct view", view, dataset.getPartitionView(path)); Constraints expected = ((AbstractRefinableView<GenericRecord>) dataset.with("y", 2014).with("m", 3)).getConstraints(); Constraints actual = ((AbstractRefinableView<GenericRecord>) view) .getConstraints(); Assert.assertEquals("Constraints should match expected", expected, actual); }
@Test public void testViewForUri() { Path path = new Path("/tmp/datasets/ns/test/y=2014/m=03/d=14"); View<GenericRecord> view = FileSystemDatasets.viewForUri( dataset, "file:" + path); Assert.assertEquals("Should create correct view", view, dataset.getPartitionView(path)); view = FileSystemDatasets.viewForUri( dataset, path.toString()); Assert.assertEquals("Should create correct view", view, dataset.getPartitionView(path)); Constraints expected = ((AbstractRefinableView<GenericRecord>) dataset.with("y", 2014).with("m", 3).with("d", 14)).getConstraints(); Constraints actual = ((AbstractRefinableView<GenericRecord>) view) .getConstraints(); Assert.assertEquals("Constraints should match expected", expected, actual); }
@Test public void testEmptyCheck() throws IOException { Assert.assertTrue("New dataset should be empty", unbounded.isEmpty()); // NOTE: this is an un-restricted write so all should succeed DatasetWriter<StandardEvent> writer = null; try { writer = unbounded.newWriter(); writer.write(sepEvent); } finally { Closeables.close(writer, false); } Assert.assertFalse("Should not be empty after write", unbounded.isEmpty()); Assert.assertFalse("Should find event in September", unbounded.with("timestamp", sepEvent.getTimestamp()).isEmpty()); Assert.assertTrue("Should not find event in October", unbounded.with("timestamp", octEvent.getTimestamp()).isEmpty()); }