@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); } }
private static PCollection<String> pCollection(final Pipeline pipeline) { return pipeline .apply("Create", Create.of(WORDS).withCoder(StringUtf8Coder.of())) .apply( "Map1", MapElements.via( new SimpleFunction<String, String>() { @Override public String apply(final String input) { return WHATEVER; } })); }
private void runTestRead(String[] expected) throws Exception { File tmpFile = tempFolder.newFile(); String filename = tmpFile.getPath(); try (PrintStream writer = new PrintStream(new FileOutputStream(tmpFile))) { for (String elem : expected) { byte[] encodedElem = CoderUtils.encodeToByteArray(StringUtf8Coder.of(), elem); String line = new String(encodedElem, Charsets.UTF_8); writer.println(line); } } TextIO.Read read = TextIO.read().from(filename); PCollection<String> output = p.apply(read); PAssert.that(output).containsInAnyOrder(expected); p.run(); }
@Test @Category(NeedsRunner.class) public void testDistinct() { List<String> strings = Arrays.asList("k1", "k5", "k5", "k2", "k1", "k2", "k3"); PCollection<String> input = p.apply(Create.of(strings).withCoder(StringUtf8Coder.of())); PCollection<String> output = input.apply(Distinct.create()); PAssert.that(output).containsInAnyOrder("k1", "k5", "k2", "k3"); p.run(); }
@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 @Category(NeedsRunner.class) public void testConstantVoidKeys() { PCollection<String> input = p.apply(Create.of(Arrays.asList(COLLECTION)).withCoder(StringUtf8Coder.of())); PCollection<KV<Void, String>> output = input.apply(WithKeys.of((Void) null)); PAssert.that(output).containsInAnyOrder(WITH_CONST_NULL_KEYS); p.run(); }
@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 public void createKeyedBundleKeyed() { StructuralKey<String> key = StructuralKey.of("foo", StringUtf8Coder.of()); CommittedBundle<KV<String, Integer>> keyedBundle = context .<String, KV<String, Integer>>createKeyedBundle(key, downstream) .commit(Instant.now()); assertThat(keyedBundle.getKey(), Matchers.equalTo(key)); }
@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 public void testTimerCoderWithConsistentWithEqualsPayloadCoder() throws Exception { Coder<Timer<String>> coder = Timer.Coder.of(StringUtf8Coder.of()); CoderProperties.coderDecodeEncodeEqual(coder, Timer.of(INSTANT, "ABC")); CoderProperties.coderConsistentWithEquals( coder, Timer.of(INSTANT, "ABC"), Timer.of(INSTANT, "ABC")); CoderProperties.coderDeterministic(coder, Timer.of(INSTANT, "ABC"), Timer.of(INSTANT, "ABC")); }
@Test @Category(NeedsRunner.class) public void testConstantKeys() { PCollection<String> input = p.apply(Create.of(Arrays.asList(COLLECTION)).withCoder(StringUtf8Coder.of())); PCollection<KV<Integer, String>> output = input.apply(WithKeys.of(100)); PAssert.that(output).containsInAnyOrder(WITH_CONST_KEYS); 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 testToStringIterable() { ArrayList<Iterable<String>> iterables = new ArrayList<>(); iterables.add(Arrays.asList(new String[] {"one", "two", "three"})); iterables.add(Arrays.asList(new String[] {"four", "five", "six"})); ArrayList<String> expected = new ArrayList<>(); expected.add("one,two,three"); expected.add("four,five,six"); PCollection<Iterable<String>> input = p.apply(Create.of(iterables).withCoder(IterableCoder.of(StringUtf8Coder.of()))); PCollection<String> output = input.apply(ToString.iterables()); PAssert.that(output).containsInAnyOrder(expected); p.run(); }