public static void assertHttpStatusCodeEventuallyEquals(Map<String,?> flags, final String url, final int expectedCode) { Asserts.succeedsEventually(flags, new Runnable() { @Override public void run() { assertHttpStatusCodeEquals(url, expectedCode); } }); }
public static void assertErrorContentContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String contents = HttpTool.getErrorContent(url); Asserts.assertTrue(contents != null && contents.length() > 0); for (String text: Lists.asList(phrase, additionalPhrases)) { if (!contents.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" MISSING TEXT: "+text+"\n"+contents); Asserts.fail("URL "+url+" does not contain text: "+text); } } } catch (Exception e) { throw propagateAsAssertionError(e); } }
public static <T> void assertAttributeEqualsContinually(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute, final T expected) { Asserts.succeedsContinually(flags, new Runnable() { @Override public void run() { assertAttributeEquals(entity, attribute, expected); }}); }
/** @deprecated since 0.9.0 use {@link #eventually(Supplier, Predicate, Duration, Duration, String)} */ @Deprecated public static <T> void eventually(Map<String,?> flags, Supplier<? extends T> supplier, Predicate<T> predicate, String errMsg) { eventually(supplier, predicate, toDuration(flags.get("timeout"), null), toDuration(flags.get("period"), null), errMsg); }
public static void assertContentMatches(String url, String regex) { String contents = HttpTool.getContent(url); Asserts.assertNotNull(contents); Asserts.assertTrue(contents.matches(regex), "Contents does not match expected regex ("+regex+"): "+contents); }
public static void assertStringMatchesRegex(String input, String regex1ToMatch, String ...optionalOtherRegexesToMatch) { if (input==null) fail("Input is null."); if (regex1ToMatch!=null) { assertThat(input, StringPredicates.matchesRegex(regex1ToMatch)); } for (String otherRegex: optionalOtherRegexesToMatch) { if (otherRegex!=null) { assertThat(input, StringPredicates.matchesRegex(otherRegex)); } } }
private void startAndAssertException(TestApplication app, Collection<? extends Location> locs) { try { app.start(locs); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContains(e, "Error invoking start"); } }
@Test public void testDecrementsSizeIffLowerBoundExceeded() { tc.resize(2); tc.policies().add(AutoScalerPolicy.builder() .metric(MY_ATTRIBUTE) .metricLowerBound(50) .metricUpperBound(100) .buildSpec()); tc.sensors().set(MY_ATTRIBUTE, 50); Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc, 2)); tc.sensors().set(MY_ATTRIBUTE, 49); Asserts.succeedsEventually(currentSizeAsserter(tc, 1)); }
/** Asserts that two iterables return iterators with the same elements in the same order. If they do not, * an AssertionError is thrown. * @param actual the actual value * @param expected the expected value */ static public void assertEquals(Iterable<?> actual, Iterable<?> expected) { assertEquals(actual, expected, null); }
@Test public void testScheduledEffectorFiresImmediately() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(ScheduledEffectorPolicy.class) .configure(ScheduledEffectorPolicy.EFFECTOR, "myEffector") .configure(ScheduledEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(ScheduledEffectorPolicy.TIME, "immediately") .configure(PeriodicEffectorPolicy.START_SENSOR, START))); Policy policy = Iterables.tryFind(entity.policies(), Predicates.instanceOf(ScheduledEffectorPolicy.class)).orNull(); Asserts.assertNotNull(policy); Asserts.assertTrue(entity.getCallHistory().isEmpty()); Asserts.assertFalse(policy.config().get(ScheduledEffectorPolicy.RUNNING)); entity.sensors().set(START, Boolean.TRUE); assertConfigEqualsEventually(policy, ScheduledEffectorPolicy.RUNNING, true); assertCallHistoryContainsEventually(entity, "myEffector"); }
@Override public void run() { Asserts.assertTrue(changed.get(), entity + " -> " + attribute + " not changed from "+origValue); }}); } finally {
/** * Assert that an object reference is not null. * * @param object The object reference. * * @throws AssertionError if the assertion fails. */ static public void assertNotNull(final Object object) { assertNotNull(object, null); }
public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3, e)); assertAttributeEquals(e, SequenceGroup.SEQUENCE_VALUE, 4); assertAttributeEquals(group, SequenceGroup.SEQUENCE_CURRENT, e); AtomicInteger state = group.sensors().get(SequenceGroup.SEQUENCE_STATE); assertEquals(state.get(), 5); }}); }
public void run() { Asserts.assertEquals(outerTasks.size(), NUM_CALLS); for (Task<?> task : outerTasks) { Asserts.assertTrue(task.isDone()); Asserts.assertTrue(task.isCancelled()); } } });
/** As {@link #eventually(Supplier, Predicate, Duration, Duration, String)} with default. */ public static <T> void eventually(Supplier<? extends T> supplier, Predicate<T> predicate, Duration timeout) { eventually(supplier, predicate, timeout, null, null); }
public void assertClosedEquals(Iterable<? extends HostAndPort> expected) { List<HostAndPort> closed = Lists.newArrayList(); for (List<Object> call : calls) { if ("close".equals(call.get(0))) closed.add((HostAndPort) call.get(4)); } Asserts.assertEqualsIgnoringOrder(closed, expected); } }
/** * Asserts that a condition is true. If it isn't, * an AssertionError, with the given message, is thrown. * @param condition the condition to evaluate * @param message the assertion error message */ public static void assertTrue(boolean condition, String message) { if (!condition) fail(message); }
@Test public void testExpectedFailures() { Asserts.expectedFailureOfType(new IllegalStateException(), NoSuchElementException.class, IllegalStateException.class); Asserts.expectedFailureOfType(new IllegalStateException(), NoSuchElementException.class, Object.class); try { Asserts.expectedFailureOfType(new IllegalStateException(), NoSuchElementException.class, Error.class); Asserts.shouldHaveFailedPreviously(); } catch (Throwable e) { Asserts.expectedFailure(e); } }
@Test public void testJsonyaDeepSimpleFailure() { try { Jsonya.of(europeMap()).atExisting("euroope"); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "euroope", "no", "found"); } }
private Exception assertStartMethodFails(FailingEntity entity) { try { entity.start(locs); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailure(e); return e; } return null; }