@Test public void noMetadataContentAllowedAfterFirstLine1() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Instead, found this section in between"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "\n" + "//// METADATA\n" + "//// CHANGE name=chng1\n" + "CREATE TABLE;\n" + "//// METADATA\n" + "//// CHANGE name=chng1\n" + "CREATE TABLE;\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void noMetadataContentAllowedAfterFirstLine3() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Instead, found this section in between"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "\n" + "//// METADATA\n" + "//// METADATA\n" + "//// CHANGE name=chng1\n" + "CREATE TABLE;\n" + "//// METADATA\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
private void testViewUnbounded( Pipeline pipeline, PTransform<PCollection<KV<String, Integer>>, ? extends PCollectionView<?>> view) { thrown.expect(IllegalStateException.class); thrown.expectMessage("Unable to create a side-input view from input"); thrown.expectCause( ThrowableMessageMatcher.hasMessage(Matchers.containsString("non-bounded PCollection"))); pipeline .apply( new PTransform<PBegin, PCollection<KV<String, Integer>>>() { @Override public PCollection<KV<String, Integer>> expand(PBegin input) { return PCollection.createPrimitiveOutputInternal( input.getPipeline(), WindowingStrategy.globalDefault(), PCollection.IsBounded.UNBOUNDED, KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())); } }) .apply(view); }
@Test public void transformDisplayDataExceptionShouldFail() { DoFn<Integer, Integer> brokenDoFn = new DoFn<Integer, Integer>() { @ProcessElement public void processElement(ProcessContext c) throws Exception {} @Override public void populateDisplayData(DisplayData.Builder builder) { throw new RuntimeException("oh noes!"); } }; Pipeline p = getPipeline(); p .apply(Create.of(1, 2, 3)) .apply(ParDo.of(brokenDoFn)); thrown.expectMessage(brokenDoFn.getClass().getName()); thrown.expectCause(ThrowableMessageMatcher.hasMessage(is("oh noes!"))); p.run(); }
@Test public void invalidNoContentAllowedInMetadata() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("First content of the file must be the"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "contentNotAllowedHere\n" + "//// METADATA\n" + "invalid content\n" + "//// CHANGE name=chng1\n" + "CREATE TABLE;\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void invalidNoContentAllowedInPrologue1() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("First content of the file must be the"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "contentNotAllowedHere\n" + "//// METADATA\n" + "//// CHANGE name=chng1\n" + "CREATE TABLE;\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void invalidNoContentAllowedInPrologue2() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("First content of the file must be the"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "contentNotAllowedHere\n" + "//// CHANGE name=chng1\n" + "CREATE TABLE;\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void invalidNoContentAllowedInPrologue3() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("No //// CHANGE sections found"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "contentNotAllowedHere\n" + "CREATE TABLE;\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void noMetadataContentAllowedAfterFirstLine2() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Instead, found this section in between"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "\n" + "//// CHANGE name=chng1\n" + "CREATE TABLE;\n" + "//// METADATA\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void noContentAtAll1() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("No //// " + TextMarkupDocumentReader.TAG_CHANGE + " sections found; at least one is required"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void noContentAtAll2() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("No //// " + TextMarkupDocumentReader.TAG_CHANGE + " sections found; at least one is required"))); TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), fkChangeType, triggerChangeType); String fileContent = "\n" + "//// METADATA\n" + ""; parser.value(tableChangeType, null, fileContent, objectName, "schema", null); }
@Test public void noContentInPrologue() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Improper section ordering: METADATA section must come before the content section"))); RerunnableChangeParser parser = new RerunnableChangeParser(); String fileContent = "\n" + "prologueContentBeforeSections" + "//// METADATA\n" + ""; parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null); }
@Test public void noChangeSectionAllowed1() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these disallowed sections"))); RerunnableChangeParser parser = new RerunnableChangeParser(); String fileContent = "\n" + "//// METADATA\n" + "//// CHANGE name=abc"; parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null); }
@Test public void noChangeSectionAllowed2() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these disallowed sections"))); RerunnableChangeParser parser = new RerunnableChangeParser(); String fileContent = "\n" + "//// CHANGE name=abc"; parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null); }
@Test public void noMultipleMetadataSections1() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these extra sections instances: [METADATA"))); RerunnableChangeParser parser = new RerunnableChangeParser(); String fileContent = "\n" + "//// METADATA\n" + "//// DROP\n" + "//// METADATA\n" + ""; parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null); }
@Test public void noMultipleMetadataSections2() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these extra sections instances: [METADATA"))); RerunnableChangeParser parser = new RerunnableChangeParser(); String fileContent = "\n" + "//// METADATA\n" + "//// METADATA\n" + ""; parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null); }
@Test public void noMultipleDropSections() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these extra sections instances: [DROP_COMMAND"))); RerunnableChangeParser parser = new RerunnableChangeParser(); String fileContent = "\n" + "//// METADATA\n" + "//// DROP_COMMAND\n" + "//// DROP_COMMAND\n" + ""; parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null); }
@Test @Category(NeedsRunner.class) public void testMapSideInputWithNullValuesCatchesDuplicates() { final PCollectionView<Map<String, Integer>> view = pipeline .apply( "CreateSideInput", Create.of(KV.of("a", (Integer) null), KV.of("a", (Integer) null)) .withCoder( KvCoder.of(StringUtf8Coder.of(), NullableCoder.of(VarIntCoder.of())))) .apply(View.<String, Integer>asMap()); PCollection<KV<String, Integer>> output = pipeline.apply("CreateMainInput", Create.of("apple", "banana", "blackberry")) .apply( "OutputSideInputs", ParDo.of(new DoFn<String, KV<String, Integer>>() { @ProcessElement public void processElement(ProcessContext c) { c.output( KV.of(c.element(), c.sideInput(view).get(c.element().substring(0, 1)))); } }).withSideInputs(view)); PAssert.that(output).containsInAnyOrder( KV.of("apple", 1), KV.of("banana", 3), KV.of("blackberry", 3)); // PipelineExecutionException is thrown with cause having a message stating that a // duplicate is not allowed. thrown.expectCause( ThrowableMessageMatcher.hasMessage(Matchers.containsString("Duplicate values for a"))); pipeline.run(); }
private void testViewNonmerging( Pipeline pipeline, PTransform<PCollection<KV<String, Integer>>, ? extends PCollectionView<?>> view) { thrown.expect(IllegalStateException.class); thrown.expectMessage("Unable to create a side-input view from input"); thrown.expectCause( ThrowableMessageMatcher.hasMessage(Matchers.containsString("Consumed by GroupByKey"))); pipeline.apply(Create.<KV<String, Integer>>of(KV.of("hello", 5))) .apply(Window.<KV<String, Integer>>into(new InvalidWindows<>( "Consumed by GroupByKey", FixedWindows.of(Duration.standardHours(1))))) .apply(view); }
@Test public void canNotSuicide() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(containsString("violating a Go rule")); thrown.expectCause(ThrowableMessageMatcher.hasMessage(containsString("You can not kill yourself"))); addTurnsToPlayer(firstPlayer, "a1", "c1", "b2"); addTurnsToPlayer(secondPlayer, "a3", "b3", "b1"); actPlay(); }
@Test public void nonWritableBasedir() throws IOException { String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo"); expected.expectCause(ThrowableMessageMatcher .hasMessage(containsString("Cannot write parent"))); this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false) .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri, "spring.cloud.config.server.git.basedir:/tmp") .run(); }
public static Matcher<Throwable> hasMessageThat(final Matcher<String> messageMatcher) { return new ThrowableMessageMatcher<>(messageMatcher); }