@Test @Category({ValidatesRunner.class, UsesFailureMessage.class}) public void testEmptyFalse() throws Exception { PCollection<Long> vals = pipeline.apply(GenerateSequence.from(0).to(5)); PAssert.that("Vals should have been empty", vals).empty(); Throwable thrown = runExpectingAssertionFailure(pipeline); String message = thrown.getMessage(); assertThat(message, containsString("Vals should have been empty")); assertThat(message, containsString("Expected: iterable over [] in any order")); }
@Test @Category({ValidatesRunner.class, UsesFailureMessage.class}) public void testEmptyFalseDefaultReasonString() throws Exception { PCollection<Long> vals = pipeline.apply(GenerateSequence.from(0).to(5)); PAssert.that(vals).empty(); Throwable thrown = runExpectingAssertionFailure(pipeline); String message = thrown.getMessage(); assertThat(message, containsString("GenerateSequence/Read(BoundedCountingSource).out")); assertThat(message, containsString("Expected: iterable over [] in any order")); }
@Test @Category(ValidatesRunner.class) public void testParDoEmptyOutputs() { List<Integer> inputs = Arrays.asList(); PCollection<String> output = pipeline .apply(Create.of(inputs).withCoder(VarIntCoder.of())) .apply("TestDoFn", ParDo.of(new TestNoOutputDoFn())); PAssert.that(output).empty(); pipeline.run(); }
@Test @Category(ValidatesRunner.class) public void testNoTornadoes() { TableRow row = new TableRow().set("month", 6).set("tornado", false); PCollection<TableRow> inputs = p.apply(Create.of(ImmutableList.of(row))); PCollection<Integer> result = inputs.apply(ParDo.of(new ExtractTornadoesFn())); PAssert.that(result).empty(); p.run().waitUntilFinish(); }
@Test @Category(NeedsRunner.class) public void testKVMatchesNameNone() { PCollection<KV<String, String>> output = p.apply(Create.of("x y z")) .apply(Regex.findKV("a (?<keyname>b) (?<valuename>c)", "keyname", "valuename")); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testKVMatchesNone() { PCollection<KV<String, String>> output = p.apply(Create.of("x y z")).apply(Regex.matchesKV("a (b) (c)", 1, 2)); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testMatchesNameNone() { PCollection<String> output = p.apply(Create.of("a", "b", "c", "d")) .apply(Regex.matches("x (?<namedgroup>[xyz]*)", "namedgroup")); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testMatchesNone() { PCollection<String> output = p.apply(Create.of("a", "b", "c", "d")).apply(Regex.matches("[xyz]")); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testKVFindNameNone() { PCollection<KV<String, String>> output = p.apply(Create.of("x y z")) .apply(Regex.findKV("a (?<keyname>b) (?<valuename>c)", "keyname", "valuename")); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) @SuppressWarnings("unchecked") public void testCountPerElementEmpty() { PCollection<String> input = p.apply(Create.of(NO_LINES).withCoder(StringUtf8Coder.of())); PCollection<KV<String, Long>> output = input.apply(Count.perElement()); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testEmptyBoundedSource() { PCollection<Long> input = p.apply(Read.from(CountingSource.upTo(0))); PAssert.that(input).empty(); p.run(); }
@Test @Category(ValidatesRunner.class) public void testFlattenPCollectionsEmptyThenParDo() { PCollection<String> output = PCollectionList.<String>empty(p) .apply(Flatten.pCollections()) .setCoder(StringUtf8Coder.of()) .apply(ParDo.of(new IdentityFn<>())); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testNoFilterByPredicateWithLambda() { PCollection<Integer> output = p.apply(Create.of(1, 2, 4, 5)).apply(Filter.by(i -> false)); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testModPartition() { PCollectionList<Integer> outputs = pipeline.apply(Create.of(1, 2, 4, 5)).apply(Partition.of(3, new ModFn())); assertTrue(outputs.size() == 3); PAssert.that(outputs.get(0)).empty(); PAssert.that(outputs.get(1)).containsInAnyOrder(1, 4); PAssert.that(outputs.get(2)).containsInAnyOrder(2, 5); pipeline.run(); }
@Test @Category(ValidatesRunner.class) public void testKeysEmpty() { PCollection<KV<String, Integer>> input = p.apply( Create.of(Arrays.asList(EMPTY_TABLE)) .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); PCollection<String> output = input.apply(Keys.create()); PAssert.that(output).empty(); p.run(); } }
@Test @Category(NeedsRunner.class) public void testPerKeyEmptyCollection() { PCollection<KV<String, String>> output = p.apply(Create.empty(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of()))) .apply(Latest.perKey()); PAssert.that(output).empty(); p.run(); }
@Test @Category(ValidatesRunner.class) public void testFlattenPCollectionsEmpty() { PCollection<String> output = PCollectionList.<String>empty(p) .apply(Flatten.pCollections()) .setCoder(StringUtf8Coder.of()); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testKVFindNone() { PCollection<KV<String, String>> output = p.apply(Create.of("x y z")).apply(Regex.findKV("a (b) (c)", 1, 2)); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testFindNone() { PCollection<String> output = p.apply(Create.of("a", "b", "c", "d")).apply(Regex.find("[xyz]")); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testNoFilterByPredicate() { PCollection<Integer> output = p.apply(Create.of(1, 2, 4, 5)).apply(Filter.by(new TrivialFn(false))); PAssert.that(output).empty(); p.run(); }