@Test public void testJoinNoneToNoneMapping() { leftListOfKv.add(KV.of("Key2", 4L)); PCollection<KV<String, Long>> leftCollection = p.apply("CreateLeft", Create.of(leftListOfKv)); listRightOfKv.add(KV.of("Key3", "bar")); PCollection<KV<String, String>> rightCollection = p.apply("CreateRight", Create.of(listRightOfKv)); PCollection<KV<String, KV<Long, String>>> output = Join.innerJoin(leftCollection, rightCollection); PAssert.that(output).containsInAnyOrder(expectedResult); p.run(); }
@Test @Category(ValidatesRunner.class) public void testParDoEmpty() { List<Integer> inputs = Arrays.asList(); PCollection<String> output = pipeline .apply(Create.of(inputs).withCoder(VarIntCoder.of())) .apply("TestDoFn", ParDo.of(new TestDoFn())); PAssert.that(output).satisfies(ParDoTest.HasExpectedOutput.forInput(inputs)); pipeline.run(); }
@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, DataflowPortabilityApiUnsupported.class}) public void testWindowedCombineEmpty() { PCollection<Double> mean = pipeline .apply(Create.empty(BigEndianIntegerCoder.of())) .apply(Window.into(FixedWindows.of(Duration.millis(1)))) .apply(Combine.globally(new MeanInts()).withoutDefaults()); PAssert.that(mean).empty(); pipeline.run(); }
@Test @Category(ValidatesRunner.class) public void testEmpty() { PCollection<Long> vals = pipeline.apply(Create.empty(VarLongCoder.of())); PAssert.that(vals).empty(); pipeline.run(); }
@Test @Category(ValidatesRunner.class) public void testGroupByKeyEmpty() { List<KV<String, Integer>> ungroupedPairs = Arrays.asList(); PCollection<KV<String, Integer>> input = p.apply( Create.of(ungroupedPairs) .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); PCollection<KV<String, Iterable<Integer>>> output = input.apply(GroupByKey.create()); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testDistinctEmpty() { List<String> strings = Arrays.asList(); PCollection<String> input = p.apply(Create.of(strings).withCoder(StringUtf8Coder.of())); PCollection<String> output = input.apply(Distinct.create()); PAssert.that(output).empty(); p.run(); }
@Test @Category(NeedsRunner.class) public void testSampleAnyEmpty() { PCollection<Integer> input = pipeline.apply(Create.empty(BigEndianIntegerCoder.of())); PCollection<Integer> output = input .apply(Window.into(FixedWindows.of(Duration.standardSeconds(3)))) .apply(Sample.any(2)); PAssert.that(output).satisfies(new VerifyCorrectSample<>(0, EMPTY)); pipeline.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(); }
@Test public void testAvg() { String sql = "SELECT AVG(f_int1) FROM PCOLLECTION GROUP BY f_int3"; PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(2)); pipeline.run(); }
@Test public void testCountStar() { String sql = "SELECT COUNT(*) FROM PCOLLECTION GROUP BY f_int3"; PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(7L)); pipeline.run(); }
@Test public void testPopulationVarianceInt() { String sql = "SELECT VAR_POP(f_int) FROM PCOLLECTION GROUP BY f_int2"; PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(26)); pipeline.run().waitUntilFinish(); }
@Test public void testPopulationVarianceInt() { String sql = "SELECT COVAR_POP(f_int1, f_int2) FROM PCOLLECTION GROUP BY f_int3"; PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(1)); pipeline.run().waitUntilFinish(); }
/** Tests that {@code containsInAnyOrder} is actually order-independent. */ @Test @Category(ValidatesRunner.class) public void testGlobalWindowContainsInAnyOrder() throws Exception { PCollection<Integer> pcollection = pipeline.apply(Create.of(1, 2, 3, 4)); PAssert.that(pcollection).inWindow(GlobalWindow.INSTANCE).containsInAnyOrder(2, 1, 4, 3); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testSampleMultiplicity() { PCollection<Integer> input = pipeline.apply( Create.of(ImmutableList.copyOf(REPEATED_DATA)).withCoder(BigEndianIntegerCoder.of())); // At least one value must be selected with multiplicity. PCollection<Iterable<Integer>> output = input.apply(Sample.fixedSizeGlobally(6)); PAssert.thatSingletonIterable(output).satisfies(new VerifyCorrectSample<>(6, REPEATED_DATA)); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testSampleInsufficientElements() { PCollection<Integer> input = pipeline.apply( Create.of(ImmutableList.copyOf(DATA)).withCoder(BigEndianIntegerCoder.of())); PCollection<Iterable<Integer>> output = input.apply(Sample.fixedSizeGlobally(10)); PAssert.thatSingletonIterable(output).satisfies(new VerifyCorrectSample<>(5, DATA)); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testSampleEmpty() { PCollection<Integer> input = pipeline.apply(Create.empty(BigEndianIntegerCoder.of())); PCollection<Iterable<Integer>> output = input.apply(Sample.fixedSizeGlobally(3)); PAssert.thatSingletonIterable(output).satisfies(new VerifyCorrectSample<>(0, EMPTY)); pipeline.run(); }