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); } }); }
/** * @see #succeedsEventually(Map, Callable) */ public static <T> T succeedsEventually(Callable<T> c) { return succeedsEventually(ImmutableMap.<String,Object>of(), c); }
public void assertHasEventEventually(final Predicate<? super SensorEvent<T>> filter) { Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertHasEvent(filter); }}); }
private void assertStateEventually(Entity entity, Lifecycle expectedState, Lifecycle state, Boolean isUp) { Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertState(entity, expectedState, state, isUp); }}); }
protected void assertTaskCountForEntityEventually(final Entity entity, final int expectedCount) { // Dead task (and initialization task) should have been GC'd on completion. // However, the GC'ing happens in a listener, executed in a different thread - the task.get() // doesn't block for it. Therefore can't always guarantee it will be GC'ed by now. Asserts.succeedsEventually(new Runnable() { @Override public void run() { forceGc(); Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(((EntityInternal)entity).getManagementContext().getExecutionManager(), entity); Assert.assertEquals(tasks.size(), expectedCount, "Tasks were "+tasks); }}); }
private static void assertEventually(Map<String,?> flags, Runnable r) { try { Asserts.succeedsEventually(flags, r); } catch (Exception e) { throw propagateAsAssertionError(e); } }
private void assertOnlyAppEventually(final ManagementContext managementContext, final Class<? extends Application> expectedType) { Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertOnlyApp(managementContext, expectedType); }}); } }
private void assertMgmtStartedEventually(final ManagementContext mgmt) { Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertTrue(mgmt.isStartupComplete()); }}); } });
private void assertStateEventually(Entity entity, Lifecycle expectedState, Lifecycle state, Boolean isUp) { Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertState(entity, expectedState, state, isUp); }}); }
protected void checkPlaneIdPersisted(final ManagementContext mgmt) { final File planeIdFile = new File(mementoDir, BrooklynMementoPersisterToObjectStore.PLANE_ID_FILE_NAME); Asserts.succeedsEventually(new Callable<Void>() { @Override public Void call() throws Exception { String planeId = readFile(planeIdFile); assertEquals(mgmt.getManagementPlaneIdMaybe().get(), planeId); return null; } }); }
private <T> void assertSensorEventually(final AttributeSensor<T> sensor, final T expectedVal, long timeout) { Asserts.succeedsEventually(ImmutableMap.of("timeout", timeout), new Callable<Void>() { @Override public Void call() { assertEquals(entity.getAttribute(sensor), expectedVal); return null; } }); } }
private <T> void assertEqualsEventually(final T actual, final T expected) { Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { assertEquals(actual, expected, "actual="+actual); }}); }
private void assertRecordsEventually(final RecordingMembershipTrackingPolicy policy, final List<Record>... validExpecteds) { Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { for (List<Record> validExpected : validExpecteds) { if (policy.records.equals(validExpected)) return; } fail("actual="+policy.records+"; valid: "+Arrays.toString(validExpecteds)); }}); }
@Test(groups={"Live", "Live-sanity"}) public void testReleasesSshPort() throws Exception { execRelease(loc, pseudoMachine); Asserts.succeedsEventually(new Runnable() { @Override public void run() { portForwarder.assertClosedEquals(ImmutableSet.of(HostAndPort.fromParts("1.1.1.1", 2000))); }}); }
private void assertHasEventEventually(final Sensor<?> sensor, final Predicate<Object> componentPredicate, final Predicate<? super CharSequence> descriptionPredicate) { Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { assertHasEvent(sensor, componentPredicate, descriptionPredicate); }}); }
private void assertItemsEventually(final MockItemEntity... expected) { Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { assertEquals(ImmutableSet.copyOf(itemGroup.getMembers()), ImmutableSet.copyOf(expected)); }}); }
@Test public void testRestartsOnFailure() throws Exception { policy = e1.policies().add(PolicySpec.create(ServiceRestarter.class) .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); e1.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure")); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(e1.getCallHistory(), ImmutableList.of("restart")); }}); }
@Test public void testServiceRestarterWorksAfterRebind() throws Exception { origEntity.policies().add(PolicySpec.create(ServiceRestarter.class) .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); TestApplication newApp = rebind(); final TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newEntity.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(origEntity, "simulate failure")); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(newEntity.getCallHistory(), ImmutableList.of("restart")); }}); }
@Test public void testNeverGrowAboveMaximmum() throws Exception { resizable.policies().remove(policy); policy = resizable.policies().add(AutoScalerPolicy.builder() .maxPoolSize(5) .buildSpec()); resizable.resize(4); resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(4, 1000000L, 4*10L, 4*20L)); // expect pool to grow only to the maximum Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 5)); }
@Test public void testDecreaseMaxPoolSizeCausesImmediateShrink() { tc.resize(6); AutoScalerPolicy policy = tc.policies().add(AutoScalerPolicy.builder().metric(MY_ATTRIBUTE) .metricLowerBound(50).metricUpperBound(100) .maxPoolSize(6) .buildSpec()); policy.config().set(AutoScalerPolicy.MAX_POOL_SIZE, 4); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 4)); }