/** * @throws AssertionError if any failures were collected. */ public void validate() { if (0 < failures.size()) { if (1 == failures.size()) { throw failures.get(0); } StringBuilder builder = new StringBuilder(); for (AssertionError assertionError : failures) { builder.append(assertionError.getMessage()).append("\n"); } throw new AssertionError("Assertions failed:\n" + builder, new CompoundRuntimeException("Assertions", failures)); } } }
/** creates the given exception, but without propagating it, for use when caller will be wrapping */ public static RuntimeException create(@Nullable String prefix, Iterable<? extends Throwable> exceptions) { if (Iterables.size(exceptions)==1) { Throwable e = exceptions.iterator().next(); if (Strings.isBlank(prefix)) return new PropagatedRuntimeException(e); return new PropagatedRuntimeException(prefix + ": " + Exceptions.collapseText(e), e); } if (Iterables.isEmpty(exceptions)) { if (Strings.isBlank(prefix)) return new CompoundRuntimeException("(empty compound exception)", exceptions); return new CompoundRuntimeException(prefix, exceptions); } if (Strings.isBlank(prefix)) return new CompoundRuntimeException(Iterables.size(exceptions)+" errors, including: " + Exceptions.collapseText(exceptions.iterator().next()), exceptions); return new CompoundRuntimeException(prefix+"; "+Iterables.size(exceptions)+" errors including: " + Exceptions.collapseText(exceptions.iterator().next()), exceptions); }
public static void stopSequentially(Iterable<? extends Startable> entities) { List<Exception> exceptions = Lists.newArrayList(); List<Startable> failedEntities = Lists.newArrayList(); for (final Startable entity : entities) { if (!Entities.isManaged((Entity)entity)) { log.debug("Not stopping {} because it is not managed; continuing", entity); continue; } try { TaskAdaptable<Void> task = TaskTags.markInessential(Effectors.invocation((Entity)entity, Startable.STOP, Collections.emptyMap())); DynamicTasks.submit(task, (Entity)entity).getUnchecked(); } catch (Exception e) { log.warn("Error stopping "+entity+"; continuing with shutdown", e); exceptions.add(e); failedEntities.add(entity); } } if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error stopping "+(failedEntities.size() > 1 ? "entities" : "entity")+": "+failedEntities, exceptions); } }
@Override @SuppressWarnings("unchecked") public <T> Maybe<T> tryCoerce(Object input, TypeToken<T> targetType) { Class<? super T> rawTargetType = targetType.getRawType(); List<ClassCoercionException> exceptions = Lists.newArrayList(); //now look for static TargetType.fromType(Type t) where value instanceof Type for (Method m: rawTargetType.getMethods()) { if (((m.getModifiers()&Modifier.STATIC)==Modifier.STATIC) && m.getName().startsWith("from") && m.getParameterTypes().length==1 && m.getParameterTypes()[0].isInstance(input)) { if (m.getName().equals("from"+JavaClassNames.verySimpleClassName(m.getParameterTypes()[0]))) { try { return Maybe.of((T) m.invoke(null, input)); } catch (Exception e) { exceptions.add(new ClassCoercionException("Cannot coerce type "+input.getClass()+" to "+rawTargetType.getCanonicalName()+" ("+input+"): "+m.getName()+" adapting failed", e)); } } } } if (exceptions.isEmpty()) { return null; } else if (exceptions.size() == 1) { return Maybe.absent(exceptions.get(0)); } else { String errMsg = "Failed coercing type "+input.getClass()+" to "+rawTargetType.getCanonicalName(); return Maybe.absent(new CompoundRuntimeException(errMsg, exceptions)); } } }
String msg; if (errors.size()>1) { wrapped = new CompoundRuntimeException(errors.size()+" sublocation exceptions, including: "+ Exceptions.collapseText(errors.get(0)), errors); msg = Exceptions.collapseText(wrapped);
} else { throw new CompoundRuntimeException("Problem loading mementos ("+phase+")", exceptions);
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { List<Exception> exceptions = Lists.newArrayList(); try { exceptions.addAll(releaseMachineSafely(machines)); machines.clear(); } finally { super.tearDown(); } if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error in tearDown of "+getClass(), exceptions); } }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { List<Exception> exceptions = Lists.newArrayList(); try { if (machines != null) { exceptions.addAll(releaseMachineSafely(machines)); machines.clear(); } } finally { try { if (managementContext != null) Entities.destroyAll(managementContext); } catch (Exception e) { LOG.warn("Error destroying management context", e); exceptions.add(e); } managementContext = null; } // TODO Debate about whether to: // - use destroyAllCatching (i.e. not propagating exception) // Benefit is that other tests in class will subsequently be run, rather than bailing out. // - propagate exceptions from tearDown // Benefit is that we don't hide errors; release(...) etc should not be throwing exceptions. if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error in tearDown of "+getClass(), exceptions); } }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { List<Exception> exceptions = Lists.newArrayList(); for (ManagementContext mgmt : mgmts) { try { if (mgmt.isRunning()) Entities.destroyAll(mgmt); } catch (Exception e) { LOG.warn("Error destroying management context", e); exceptions.add(e); } } mgmts.clear(); origManagementContext = null; newManagementContext = null; origApp = null; newApp = null; super.tearDown(); if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error in tearDown of "+getClass(), exceptions); } }
@Override public void stop() { List<Exception> errors = Lists.newArrayList(); if (getZooKeeper() != null && Objects.equal(this, getZooKeeper().getParent())) { try { getZooKeeper().stop(); } catch (Exception e) { errors.add(e); } } if (getCurrentSize() > 0) { try { getCluster().stop(); } catch (Exception e) { errors.add(e); } } clearLocations(); sensors().set(SERVICE_UP, false); if (errors.size() != 0) { throw new CompoundRuntimeException("Error stopping Kafka cluster", errors); } }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { List<Exception> exceptions = Lists.newArrayList(); try { if (provisioningManagementContext != null && provisionedMachine != null) { provisionedMachine.getParent().release(provisionedMachine); } } finally { Entities.destroyAll(provisioningManagementContext); provisioningManagementContext = null; provisionedMachine = null; super.tearDown(); } if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error in tearDown of "+getClass(), exceptions); } }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { try { List<Exception> exceptions = Lists.newArrayList(); for (ManagementContext mgmt : mgmts) { try { if (mgmt.isRunning()) Entities.destroyAll(mgmt); } catch (Exception e) { LOG.warn("Error destroying management context", e); exceptions.add(e); } } super.tearDown(); if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error in tearDown of "+getClass(), exceptions); } } finally { mgmts.clear(); origManagementContext = null; newManagementContext = null; origApp = null; newApp = null; RecordingSshTool.clear(); RecordingWinRmTool.clear(); } }
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions); throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions); throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);