Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import static org.apache.beam.runners.dataflow.DataflowRunner.getContainerImageForJob;
import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.io.Files.getFileExtension;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -153,7 +153,6 @@
import org.apache.beam.sdk.values.TimestampedValue;
import org.apache.beam.sdk.values.WindowingStrategy;
import org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.InvalidProtocolBufferException;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Throwables;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -351,14 +350,9 @@ public void testPathValidation() {
"--credentialFactoryClass=" + NoopCredentialFactory.class.getName(),
};

try {
Pipeline.create(PipelineOptionsFactory.fromArgs(args).create()).run();
fail();
} catch (RuntimeException e) {
assertThat(
Throwables.getStackTraceAsString(e),
containsString("DataflowRunner requires gcpTempLocation"));
}
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("DataflowRunner requires gcpTempLocation");
Pipeline.create(PipelineOptionsFactory.fromArgs(args).create()).run();
}

@Test
Expand All @@ -372,15 +366,10 @@ public void testPathExistsValidation() {
"--credentialFactoryClass=" + NoopCredentialFactory.class.getName(),
};

try {
Pipeline.create(PipelineOptionsFactory.fromArgs(args).create()).run();
fail();
} catch (RuntimeException e) {
assertThat(
Throwables.getStackTraceAsString(e),
both(containsString("gs://does/not/exist"))
.and(containsString("Unable to verify that GCS bucket gs://does exists")));
}
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("gcpTempLocation");
thrown.expectCause(hasProperty("message", containsString("gs://does/not/exist")));
Pipeline.create(PipelineOptionsFactory.fromArgs(args).create()).run();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,20 @@ private T buildFromMethod(Class<?>[] types) {
String.format(
"Unable to find factory method %s#%s(%s)",
factoryClass.getSimpleName(), methodName, Joiner.on(", ").join(types)));

} catch (IllegalAccessException | InvocationTargetException e) {
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof RuntimeException) {
// If underlying exception is unchecked re-raise it as-is
throw (RuntimeException) e.getTargetException();
}
throw new RuntimeException(
String.format(
"Encountered checked exception when constructing an instance from factory method %s#%s(%s)",
factoryClass.getSimpleName(), methodName, Joiner.on(", ").join(types)),
e.getTargetException());
} catch (IllegalAccessException e) {
throw new RuntimeException(
String.format(
"Failed to construct instance from factory method %s#%s(%s)",
"Failed to construct instance from factory method %s#%s(%s) due to access restriction",
factoryClass.getSimpleName(), methodName, Joiner.on(", ").join(types)),
e);
}
Expand Down