private WriteResult writeResult(Pipeline p) { PCollection<TableRow> empty = p.apply("CreateEmptyFailedInserts", Create.empty(TypeDescriptor.of(TableRow.class))); return WriteResult.in(p, new TupleTag<>("failedInserts"), empty); }
@Test public void parDoWithFnTypeNotParDo() { AppliedPTransform<?, ?, ?> notParDo = getAppliedTransform(Create.empty(VoidCoder.of())); PTransformMatcher matcher = PTransformMatchers.parDoWithFnType(doFnWithState.getClass()); assertThat(matcher.matches(notParDo), is(false)); }
@Test(expected = NullPointerException.class) public void testJoinNullValueIsNull() { p.enableAbandonedNodeEnforcement(false); Join.leftOuterJoin( p.apply("CreateLeft", Create.empty(KvCoder.of(StringUtf8Coder.of(), VarLongCoder.of()))), p.apply( "CreateRight", Create.empty(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of()))), null); } }
@Test(expected = NullPointerException.class) public void testJoinNullValueIsNull() { p.enableAbandonedNodeEnforcement(false); Join.rightOuterJoin( p.apply("CreateLeft", Create.empty(KvCoder.of(StringUtf8Coder.of(), VarLongCoder.of()))), p.apply( "CreateRight", Create.empty(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of()))), null); } }
@Test(expected = NullPointerException.class) public void testJoinLeftNullValueIsNull() { p.enableAbandonedNodeEnforcement(false); Join.fullOuterJoin( p.apply("CreateLeft", Create.empty(KvCoder.of(StringUtf8Coder.of(), VarLongCoder.of()))), p.apply( "CreateRight", Create.empty(KvCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of()))), null, ""); }
@Test(expected = IllegalArgumentException.class) public void testSampleAnyNegative() { pipeline.enableAbandonedNodeEnforcement(false); pipeline.apply(Create.empty(BigEndianIntegerCoder.of())).apply(Sample.any(-10)); }
@Test @Category(ValidatesRunner.class) public void testEmpty() { PCollection<Long> vals = pipeline.apply(Create.empty(VarLongCoder.of())); PAssert.that(vals).empty(); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testGloballyEmptyCollection() { PCollection<Long> emptyInput = p.apply(Create.empty(VarLongCoder.of())); PCollection<Long> output = emptyInput.apply(Latest.globally()); PAssert.that(output).containsInAnyOrder((Long) null); p.run(); }
/** Tests that when writing to a non-existent table, the write fails. */ @Test public void testTableCheckIgnoredWhenCanNotAccessConfig() throws Exception { PCollection<KV<ByteString, Iterable<Mutation>>> emptyInput = p.apply( Create.empty( KvCoder.of(ByteStringCoder.of(), IterableCoder.of(ProtoCoder.of(Mutation.class))))); emptyInput.apply("write", defaultWrite.withTableId(NOT_ACCESSIBLE_VALUE)); p.run(); }
@Test @Category(ValidatesRunner.class) public void testCreateEmpty() { PCollection<String> output = p.apply(Create.empty(StringUtf8Coder.of())); PAssert.that(output).containsInAnyOrder(NO_LINES_ARRAY); assertEquals(StringUtf8Coder.of(), output.getCoder()); p.run(); }
@Test public void fnWithSideInputDefault() throws Exception { PCollection<Integer> pCollection = p.apply(Create.empty(VarIntCoder.of())); final PCollectionView<Integer> value = pCollection.apply(View.<Integer>asSingleton().withDefaultValue(0)); try (DoFnTester<Integer, Integer> tester = DoFnTester.of(new SideInputDoFn(value))) { tester.processElement(1); tester.processElement(2); tester.processElement(4); tester.processElement(8); assertThat(tester.peekOutputElements(), containsInAnyOrder(0, 0, 0, 0)); } }
@Test @Category(ValidatesRunner.class) public void testEmpty() { PCollection<KV<Integer, Long>> inputs = p.apply(Create.empty(new TypeDescriptor<KV<Integer, Long>>() {})); PCollection<TableRow> result = inputs.apply(ParDo.of(new FormatCountsFn())); PAssert.that(result).empty(); p.run().waitUntilFinish(); }
@Before public void setup() { created = p.apply(Create.empty(ByteArrayCoder.of())); transformed = created.apply(ParDo.of(new IdentityDoFn<>())); DirectGraphVisitor visitor = new DirectGraphVisitor(); p.traverseTopologically(visitor); factory = ImmutabilityCheckingBundleFactory.create( ImmutableListBundleFactory.create(), visitor.getGraph()); }
@Test public void bundleEncodeFailsAddFails() { PCollection<Record> pc = p.apply(Create.empty(new RecordNoEncodeCoder())); UncommittedBundle<Record> bundle = factory.createBundle(pc); thrown.expect(UserCodeException.class); thrown.expectCause(isA(CoderException.class)); thrown.expectMessage("Encode not allowed"); bundle.add(WindowedValue.valueInGlobalWindow(new Record())); }
@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 public void bundleDecodeFailsAddFails() { PCollection<Record> pc = p.apply(Create.empty(new RecordNoDecodeCoder())); UncommittedBundle<Record> bundle = factory.createBundle(pc); thrown.expect(UserCodeException.class); thrown.expectCause(isA(CoderException.class)); thrown.expectMessage("Decode not allowed"); bundle.add(WindowedValue.valueInGlobalWindow(new Record())); }
@Test public void keyedBundleEncodeFailsAddFails() { PCollection<Record> pc = p.apply(Create.empty(new RecordNoEncodeCoder())); UncommittedBundle<Record> bundle = factory.createKeyedBundle(StructuralKey.of("foo", StringUtf8Coder.of()), pc); thrown.expect(UserCodeException.class); thrown.expectCause(isA(CoderException.class)); thrown.expectMessage("Encode not allowed"); bundle.add(WindowedValue.valueInGlobalWindow(new Record())); }
@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, 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 public void testTopEmptyWithIncompatibleWindows() { p.enableAbandonedNodeEnforcement(false); Window<String> windowingFn = Window.into(FixedWindows.of(Duration.standardDays(10L))); PCollection<String> input = p.apply(Create.empty(StringUtf8Coder.of())).apply(windowingFn); expectedEx.expect(IllegalStateException.class); expectedEx.expectMessage("Top"); expectedEx.expectMessage("GlobalWindows"); expectedEx.expectMessage("withoutDefaults"); expectedEx.expectMessage("asSingletonView"); input.apply(Top.of(1, new OrderByLength())); }