You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2015/10/21 08:19:00 UTC
[2/5] incubator-brooklyn git commit: Test class
BailOutJcloudsLocation: improve exceptions
Test class BailOutJcloudsLocation: improve exceptions
Previously it threw an exception defined as a constant, so the
stacktrace was useless. Now it throws an exception that has as
its cause the constant-exception.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ac58462a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ac58462a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ac58462a
Branch: refs/heads/master
Commit: ac58462ac3fa7a48924a81428cccf0bc4569b35f
Parents: dfe78a6
Author: Aled Sage <al...@gmail.com>
Authored: Thu Oct 15 15:30:42 2015 +0200
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Oct 20 16:15:04 2015 +0100
----------------------------------------------------------------------
.../location/jclouds/BailOutJcloudsLocation.java | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac58462a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
index d31d7e5..10a32b4 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BailOutJcloudsLocation.java
@@ -42,6 +42,8 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Iterables;
import com.google.common.reflect.TypeToken;
public class BailOutJcloudsLocation extends JcloudsLocation {
@@ -81,7 +83,7 @@ public class BailOutJcloudsLocation extends JcloudsLocation {
if (Boolean.TRUE.equals(getConfig(BUILD_TEMPLATE))) {
template = super.buildTemplate(computeService, config);
}
- throw BAIL_OUT_FOR_TESTING;
+ throw new RuntimeException(BAIL_OUT_FOR_TESTING);
}
public Template getTemplate() {
@@ -100,8 +102,14 @@ public class BailOutJcloudsLocation extends JcloudsLocation {
try {
obtain(flags);
} catch (Exception e) {
- if (e == BAIL_OUT_FOR_TESTING || e.getCause() == BAIL_OUT_FOR_TESTING
- || (e instanceof CompoundRuntimeException && ((CompoundRuntimeException) e).getAllCauses().contains(BAIL_OUT_FOR_TESTING))) {
+ boolean found = Iterables.tryFind(Throwables.getCausalChain(e), Predicates.<Throwable>equalTo(e)).isPresent();
+ if (!found && e instanceof CompoundRuntimeException) {
+ for (Throwable cause : ((CompoundRuntimeException) e).getAllCauses()) {
+ found = Iterables.tryFind(Throwables.getCausalChain(cause), Predicates.<Throwable>equalTo(e)).isPresent();
+ if (found) break;
+ }
+ }
+ if (found) {
test.apply(lastConfigBag);
} else {
throw Exceptions.propagate(e);