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"); }
@Test public void testResizeDown() throws Exception { EntityAsserts.assertAttributeEqualsEventually(cluster, TestCluster.GROUP_SIZE, CLUSTER_INIITIAL_SIZE); cluster.resize(CLUSTER_MAX_SIZE + 2); EntityAsserts.assertAttributeEqualsEventually(cluster, TestSizeRecordingCluster.SIZE_HISTORY_RECORD_COUNT, 3); Assert.assertEquals((int)cluster.getSizeHistory().get(0), CLUSTER_INIITIAL_SIZE); Assert.assertEquals((int)cluster.getSizeHistory().get(1), CLUSTER_MAX_SIZE + 2); Assert.assertEquals((int)cluster.getSizeHistory().get(2), CLUSTER_MAX_SIZE); } }
@Test(groups = {"Integration"}) public void testStartupAndShutdown() { elasticSearchNode = app.createAndManageChild(EntitySpec.create(ElasticSearchNode.class)); app.start(ImmutableList.of(testLocation)); EntityAsserts.assertAttributeEqualsEventually(elasticSearchNode, Startable.SERVICE_UP, true); String url = elasticSearchNode.sensors().get(ElasticSearchNode.DATASTORE_URL); assertNotNull(url); assertTrue(Networking.isReachable(HostAndPort.fromParts(URI.create(url).getHost(), URI.create(url).getPort()))); elasticSearchNode.stop(); EntityAsserts.assertAttributeEqualsEventually(elasticSearchNode, Startable.SERVICE_UP, false); }
private static <T> void assertAttributeEqualsEventually(Entity x, AttributeSensor<T> sensor, T value) { try { EntityAsserts.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(3)), x, sensor, value); } catch (Throwable e) { log.warn("Expected "+x+" eventually to have "+sensor+" = "+value+"; instead:"); Entities.dumpInfo(x); throw Exceptions.propagate(e); } } private static <T> void assertAttributeEqualsContinually(Entity x, AttributeSensor<T> sensor, T value) {
@Test public void testTheTestJavaWebApp() { SoftwareProcess n = app.createAndManageChild(EntitySpec.create(TestJavaWebAppEntity.class)); app.start(locs); EntityAsserts.assertAttributeEqualsEventually(n, AbstractController.SERVICE_UP, true); app.config().set(StartableApplication.DESTROY_ON_STOP, false); app.stop(); EntityAsserts.assertAttributeEqualsEventually(n, AbstractController.SERVICE_UP, false); }
@Test public void testAddsStaticSensorOfTypeInteger() { BasicEntity entity = app.createAndManageChild(EntitySpec.create(BasicEntity.class) .addInitializer(new StaticSensor<Integer>(ConfigBag.newInstance(ImmutableMap.of( StaticSensor.SENSOR_NAME, "myname", StaticSensor.SENSOR_TYPE, Integer.class.getName(), StaticSensor.STATIC_VALUE, "1"))))); EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newSensor(Integer.class, "myname"), 1); } }
@Test public void validThenNull() { addEnricher(); app.sensors().set(currentSensor, 50d); app.sensors().set(totalSensor, 100d); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, 0.5d); app.sensors().set(totalSensor, null); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, 0.5d); }
@Test(groups = {"Integration","Broken"}) public void testCanStartAndStop() throws Exception { RiakNode entity = app.createAndManageChild(EntitySpec.create(RiakNode.class) .configure(RiakNode.SUGGESTED_VERSION, "2.1.1")); app.start(ImmutableList.of(localhostProvisioningLocation)); EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, true); entity.stop(); assertFalse(entity.getAttribute(Startable.SERVICE_UP)); }
@Override protected void doTest(Location loc) throws Exception { RiakNode entity = app.createAndManageChild(EntitySpec.create(RiakNode.class) .configure(RiakNode.SUGGESTED_VERSION, "2.1.1")); app.start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(entity, RiakNode.SERVICE_UP, true); } }
@Test public void testRebindToMachineEntity() throws Exception { MachineEntity entity = origApp.createAndManageChild(EntitySpec.create(MachineEntity.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); origApp.start(ImmutableList.of(origMachine)); EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); rebind(); Entity newEntity = mgmt().getEntityManager().getEntity(entity.getId()); EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); }
@Test public void currentNullTest() { addEnricher(); app.sensors().set(currentSensor, null); app.sensors().set(totalSensor, 100d); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, null); }
@Test public void totalNullTest() { addEnricher(); app.sensors().set(currentSensor, 50d); app.sensors().set(totalSensor, null); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, null); }
@Test public void currentZeroTest() { addEnricher(); app.sensors().set(currentSensor, 0d); app.sensors().set(totalSensor, 100d); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, 0d); }
@Test(groups = "Integration") public void testCanStartAndStop() throws Exception { MongoDBConfigServer entity = app.createAndManageChild(EntitySpec.create(MongoDBConfigServer.class) .configure(MongoDBServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb-configserver.conf")); app.start(ImmutableList.of(localhostProvisioningLocation)); EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, true); Asserts.assertTrue(MongoDBTestHelper.isConfigServer(entity), "Server is not a config server"); entity.stop(); assertFalse(entity.getAttribute(Startable.SERVICE_UP)); } }
@Test public void testGroupWithMatchingFilterReturnsOnlyMatchingMembers() throws Exception { group = app.addChild(EntitySpec.create(SequenceGroup.class) .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.displayNameEqualTo("test-one"))); createTestEntities(); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true); assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1)); assertAttributeEquals(e1, SequenceGroup.SEQUENCE_VALUE, 1); AtomicInteger state = group.sensors().get(SequenceGroup.SEQUENCE_STATE); assertEquals(state.get(), 2); }
@Test public void testSensorPropagatedWhenMappingUsedSameNameButDifferentType() throws Exception { AttributeSensor<String> origSensor = Sensors.newSensor(String.class, "origSensor"); AttributeSensor<Object> sourceSensorFromYaml = Sensors.newSensor(Object.class, "origSensor"); AttributeSensor<Object> targetSensor = Sensors.newSensor(Object.class, "newSensor"); app.enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(sourceSensorFromYaml, targetSensor)) .from(entity) .build()); entity.sensors().set(origSensor, "myval"); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, "myval"); }
@Test public void testPropagatingEnricher() throws Exception { origApp.enrichers().add(Enrichers.builder() .propagating(METRIC1) .from(origEntity) .build()); TestApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newEntity.sensors().set(METRIC1, "myval"); EntityAsserts.assertAttributeEqualsEventually(newApp, METRIC1, "myval"); }
@Test public void testPropagatingAllEnricher() throws Exception { origApp.enrichers().add(Enrichers.builder() .propagatingAll() .from(origEntity) .build()); TestApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newEntity.sensors().set(METRIC1, "myval"); EntityAsserts.assertAttributeEqualsEventually(newApp, METRIC1, "myval"); }
@Test public void testSummingEnricherWithNoProducers() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromChildren() .defaultValueForUnreportedSensors(11) .valueToReportIfNoSensors(40) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, target, 40); }
@Test public void testFromEntity() { entity.enrichers().add(Enrichers.builder() .transforming(NUM1) .publishing(NUM1) .computing(Functions.<Integer>identity()) .from(entity2) .build()); entity2.sensors().set(NUM1, 2); EntityAsserts.assertAttributeEqualsEventually(entity, NUM1, 2); }