private void checkChildComesUpSoon() { Stopwatch stopwatch = Stopwatch.createStarted(); EntityAsserts.assertAttributeEqualsEventually(p2, Attributes.SERVICE_UP, true); log.info("Took "+Time.makeTimeStringRounded(stopwatch)+" for child-process to be service-up"); }
public static <T> T assertAttributeEventuallyNonNull(final Entity entity, final AttributeSensor<T> attribute) { return assertAttributeEventuallyNonNull(Maps.newLinkedHashMap(), entity, attribute); }
@Override public void run() { assertAttributeEquals(entity, attribute, expected); }}); }
/** * Asserts sensors {@code service.isUp} is true, and that {@code service.state} is "running". * Setting these sensors is common behaviour for entities, but depends on the particular entity * implementation. */ @Beta public static void assertEntityHealthy(Entity entity) { assertAttributeEquals(entity, SERVICE_UP, true); assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); assertAttribute(entity, Attributes.SERVICE_STATE_EXPECTED, new Predicate<Lifecycle.Transition>() { @Override public boolean apply(Lifecycle.Transition transition) { assertNotNull(transition); return Lifecycle.RUNNING.equals(transition.getState()); } }); }
protected void checkStartsRunning(Entity mysql) { // should be starting within a few seconds (and almost certainly won't complete in that time) EntityAsserts.assertAttributeEventually( mysql, Attributes.SERVICE_STATE_ACTUAL, Predicates.or(Predicates.equalTo(Lifecycle.STARTING), Predicates.equalTo(Lifecycle.RUNNING))); // should be up and running within 5m EntityAsserts.assertAttributeEqualsEventually(MutableMap.of("timeout", Duration.FIVE_MINUTES), mysql, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); }
@Test(dataProvider = "specProvider", groups={"Broken"}) public void testFeedContinuesWhenPollerThrows(EntitySpec<FeedExceptionEntity> spec) { Map<?, ?> timeoutFlags = ImmutableMap.of("timeout", "100ms"); FeedExceptionEntity fee = app.createAndManageChild(spec); app.start(ImmutableList.of(app.newSimulatedLocation())); EntityAsserts.assertAttributeEqualsEventually(timeoutFlags, fee, FeedExceptionEntity.FLAG, true); fee.startThrowingPollExceptions(); EntityAsserts.assertAttributeEqualsEventually(timeoutFlags, fee, FeedExceptionEntity.FLAG, false); EntityAsserts.assertAttributeEqualsContinually(timeoutFlags, fee, FeedExceptionEntity.FLAG, false); fee.stopThrowingPollExceptions(); EntityAsserts.assertAttributeEqualsEventually(timeoutFlags, fee, FeedExceptionEntity.FLAG, true); EntityAsserts.assertAttributeEqualsContinually(timeoutFlags, fee, FeedExceptionEntity.FLAG, true); }
@Test public void testSequenceInitial() throws Exception { sequence = app.addChild(EntitySpec.create(SequenceEntity.class) .configure(SequenceEntity.SEQUENCE_START, 0)); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true); assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 0); }
@Test(groups = "Integration") public void testCanStartAndStop() throws Exception { CrateNode entity = app.createAndManageChild(EntitySpec.create(CrateNode.class)); app.start(ImmutableList.of(localhostProvisioningLocation)); EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, true); EntityAsserts.assertAttributeEventuallyNonNull(entity, CrateNode.SERVER_NAME); entity.stop(); assertFalse(entity.getAttribute(Startable.SERVICE_UP)); } }
@Test public void testWaitForServiceSucceedsEventually() throws Exception { Map<?,?> veryShortWait = ImmutableMap.of("timeout", Duration.millis(50)); DynamicCluster cluster = app.addChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.START_TIMEOUT, Asserts.DEFAULT_LONG_TIMEOUT.multiply(2)) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)) .configure("initialSize", 1)); // Indicate that the cluster is not healthy ServiceStateLogic.updateMapSensorEntry(cluster, ServiceStateLogic.SERVICE_NOT_UP_INDICATORS, "simulateNotUpKey", "myVal"); // Start in a background thread Task<Void> task = app.invoke(Startable.START, ImmutableMap.of("locations", ImmutableList.of())); // The member should start, but we should still be waiting for the cluster's service.isUp EntityAsserts.assertGroupSizeEqualsEventually(cluster, 1); TestEntity member = (TestEntity) Iterables.find(cluster.getChildren(), Predicates.instanceOf(TestEntity.class)); EntityAsserts.assertAttributeEqualsEventually(member, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); EntityAsserts.assertAttributeEqualsContinually(veryShortWait, cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING); EntityAsserts.assertAttributeEqualsContinually(veryShortWait, cluster, Attributes.SERVICE_UP, false); assertFalse(task.isDone()); // Clearing the not-up-indicator will allow it to return successfully ServiceStateLogic.updateMapSensorEntry(cluster, ServiceStateLogic.SERVICE_NOT_UP_INDICATORS, "simulateNotUpKey", Entities.REMOVE); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); task.get(Asserts.DEFAULT_LONG_TIMEOUT); }
@Test public void testReducingBuilderWithConcatenator() { entity.enrichers().add(Enrichers.builder() .reducing(Reducer.class, ImmutableList.<AttributeSensor<?>>of(STR1, STR2)) .from(entity) .computing(new Concatenator()) .publishing(STR3) .build() ); EntityAsserts.assertAttributeEquals(entity, STR3, null); entity.sensors().set(STR1, "foo"); EntityAsserts.assertAttributeEqualsContinually(entity, STR3, null); entity.sensors().set(STR2, "bar"); EntityAsserts.assertAttributeEqualsEventually(entity, STR3, "foobar"); }
public static <T> T assertAttributeEventually(final Entity entity, final AttributeSensor<T> attribute, Predicate<? super T> predicate) { return assertAttributeEventually(ImmutableMap.of(), entity, attribute, predicate); }
@Override public void run() { EntityAsserts.assertAttributeEqualsContinually(entity, TestEntity.NAME, myName); } });
@Test public void testGroupDefaults() throws Exception { group = app.addChild(EntitySpec.create(SequenceGroup.class)); createTestEntities(); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true); assertAttribute(group, SequenceGroup.SEQUENCE_VALUE, Predicates.isNull()); assertTrue(group.getMembers().isEmpty()); }
.build(); EntityAsserts.assertAttributeEventuallyNonNull(entity2, SENSOR_STRING); final String val1 = assertDifferentOneInOutput(entity2); EntityAsserts.assertAttributeEventually(entity2, SENSOR_STRING, Predicates.not(Predicates.equalTo(val1))); final String val2 = assertDifferentOneInOutput(entity2); log.info("vals from dynamic sensors are: "+val1.trim()+" and "+val2.trim());
@Test(groups="Integration") public void testDisableRetrievalOfUsageMetrics() throws Exception { LocalhostMachineProvisioningLocation loc = app.newLocalhostProvisioningLocation(); final TomcatServer tc1 = app.createAndManageChild(EntitySpec.create(TomcatServer.class) .configure(SoftwareProcess.RETRIEVE_USAGE_METRICS, false)); final TomcatServer tc2 = app.createAndManageChild(EntitySpec.create(TomcatServer.class)); tc1.start(ImmutableList.of(loc)); tc2.start(ImmutableList.of(loc)); // tc2 uses defaults, so will include usage metrics Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(tc2.getAttribute(TomcatServer.CONNECTOR_STATUS)); assertNotNull(tc2.getAttribute(TomcatServer.ERROR_COUNT)); assertNotNull(tc2.getAttribute(TomcatServer.REQUEST_COUNT)); assertNotNull(tc2.getAttribute(TomcatServer.TOTAL_PROCESSING_TIME)); }}); // tc1 should have status info, but not usage metrics EntityAsserts.assertAttributeEventuallyNonNull(tc1, TomcatServer.CONNECTOR_STATUS); EntityAsserts.assertAttributeEqualsContinually(tc1, TomcatServer.ERROR_COUNT, null); assertNull(tc1.getAttribute(TomcatServer.REQUEST_COUNT)); assertNull(tc1.getAttribute(TomcatServer.TOTAL_PROCESSING_TIME)); } }
@Test public void testCanDisableFilterForRunningEntities() throws Exception { geoDns.config().set(AbstractGeoDnsService.FILTER_FOR_RUNNING, false); app.start(ImmutableList.of(westChildWithLocation, eastChildWithLocationAndWithPrivateHostname)); publishSensors(2, true, true, true); assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2)); final Map<String, String> targets = ImmutableMap.copyOf(geoDns.sensors().get(AbstractGeoDnsService.TARGETS)); TestEntity problemChild = Iterables.get(Entities.descendantsAndSelf(app, TestEntity.class), 0); problemChild.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); assertAttributeEqualsContinually(geoDns, AbstractGeoDnsService.TARGETS, targets); }
@Test(groups="Integration") public void testEnrichersOnRebindJavaApp() throws Exception { VanillaJavaApp javaProcess = app.addChild(EntitySpec.create(VanillaJavaApp.class, EnrichedVanillaJavaAppImpl.class) .configure("main", MAIN_CLASS.getCanonicalName()).configure("classpath", ImmutableList.of(BROOKLYN_THIS_CLASSPATH))); app.start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEventuallyNonNull(javaProcess, EnrichedVanillaJavaAppImpl.AVG1); EntityAsserts.assertAttributeEventuallyNonNull(javaProcess, EnrichedVanillaJavaAppImpl.AVG2); LOG.info("Got avg "+javaProcess.getAttribute(EnrichedVanillaJavaAppImpl.AVG1)); rebind(); VanillaJavaApp javaProcess2 = (VanillaJavaApp) Iterables.find(app.getChildren(), Predicates.instanceOf(VanillaJavaApp.class)); // check sensors working EntityAsserts.assertAttributeChangesEventually(javaProcess2, EnrichedVanillaJavaAppImpl.PROCESS_CPU_TIME); LOG.info("Avg now "+javaProcess2.getAttribute(EnrichedVanillaJavaAppImpl.AVG1)); // check enrichers are functioning EntityAsserts.assertAttributeChangesEventually(javaProcess2, EnrichedVanillaJavaAppImpl.AVG1); EntityAsserts.assertAttributeChangesEventually(javaProcess2, EnrichedVanillaJavaAppImpl.AVG2); LOG.info("Avg now "+javaProcess2.getAttribute(EnrichedVanillaJavaAppImpl.AVG1)); // and check we don't have too many Assert.assertEquals(javaProcess2.getEnrichers().size(), javaProcess.getEnrichers().size()); }
t.start(); try { EntityAsserts.assertGroupSizeEqualsEventually(fabric, 2); CassandraDatacenter d1 = (CassandraDatacenter) Iterables.get(fabric.getMembers(), 0); CassandraDatacenter d2 = (CassandraDatacenter) Iterables.get(fabric.getMembers(), 1); EntityAsserts.assertGroupSizeEqualsEventually(d1, 2); final DummyCassandraNode d1a = (DummyCassandraNode) Iterables.get(d1.getMembers(), 0); final DummyCassandraNode d1b = (DummyCassandraNode) Iterables.get(d1.getMembers(), 1); EntityAsserts.assertGroupSizeEqualsEventually(d2, 2); final DummyCassandraNode d2a = (DummyCassandraNode) Iterables.get(d2.getMembers(), 0); final DummyCassandraNode d2b = (DummyCassandraNode) Iterables.get(d2.getMembers(), 1); EntityAsserts.assertAttributeEventually(fabric, CassandraFabric.CURRENT_SEEDS, predicate); EntityAsserts.assertAttributeEventually(d1, CassandraDatacenter.CURRENT_SEEDS, predicate); EntityAsserts.assertAttributeEventually(d2, CassandraDatacenter.CURRENT_SEEDS, predicate);
public static void assertGroupSizeEqualsEventually(final Group group, int expected) { assertGroupSizeEqualsEventually(ImmutableMap.of(), group, expected); }
@Override public void run() { T val = assertAttribute(entity, attribute, predicate); result.set(val); }}); return result.get();