@Test public void testAttributeSupplier() throws Exception { entity.sensors().set(TestEntity.NAME, "myname"); assertEquals(Entities.attributeSupplier(entity, TestEntity.NAME).get(), "myname"); }
@Test public void testAttributeSupplierUsingTuple() throws Exception { entity.sensors().set(TestEntity.NAME, "myname"); assertEquals(Entities.attributeSupplier(EntityAndAttribute.supplier(entity, TestEntity.NAME)).get(), "myname"); }
@Test public void testPropagatingEnricher() throws Exception { Entity app = createAndStartApplication(loadYaml("test-propagating-enricher.yaml")); waitForApplicationTasks(app); Assert.assertEquals(app.getDisplayName(), "test-propagating-enricher"); log.info("App started:"); Entities.dumpInfo(app); TestEntity entity = (TestEntity)app.getChildren().iterator().next(); entity.sensors().set(TestEntity.NAME, "New Name"); Asserts.eventually(Entities.attributeSupplier(app, TestEntity.NAME), Predicates.<String>equalTo("New Name")); }
@Test public void testSupplierIsPolled() throws Exception { entity = app.createAndManageChild(EntitySpec.create(DataEntity.class) .configure(DataEntity.POLL_PERIOD, 50L) .configure(DataEntity.SENSOR_SUPPLIER_MAP, MutableMap.<AttributeSensor<?>, Supplier<?>>of(longSensor, currentTimeMillis))); app.start(ImmutableList.of(loc)); Asserts.eventually(Entities.attributeSupplier(entity, longSensor), Predicates.notNull()); final Long first = entity.getAttribute(longSensor); assertNotNull(first); Asserts.succeedsEventually(new Runnable() { @Override public void run() { Long second = entity.getAttribute(longSensor); assertNotNull(second); assertTrue(second.longValue() > first.longValue()); } }); }
@Test public void testWithEntityEnricherAndParameters() throws Exception { Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", " id: parentId", " brooklyn.parameters:", " - name: test.fqdn", " type: string", " default: \"www.example.org\"", " brooklyn.enrichers:", " - enricherType: org.apache.brooklyn.enricher.stock.Transformer", " brooklyn.config:", " enricher.triggerSensors:", " - $brooklyn:sensor(\"test.sequence\")", " enricher.targetSensor: $brooklyn:sensor(\"main.uri\")", " enricher.targetValue:", " $brooklyn:formatString:", " - \"http://%s:%d/\"", " - $brooklyn:config(\"test.fqdn\")", " - $brooklyn:attributeWhenReady(\"test.sequence\")")); waitForApplicationTasks(app); log.info("App started:"); final Entity parentEntity = app.getChildren().iterator().next(); Entities.dumpInfo(app); Assert.assertTrue(parentEntity instanceof TestEntity, "Expected parent entity to be TestEntity, found:" + parentEntity); parentEntity.sensors().set(TestEntity.SEQUENCE, 1234); Asserts.eventually(Entities.attributeSupplier(parentEntity, Sensors.newStringSensor("main.uri")), Predicates.<String>equalTo("http://www.example.org:1234/")); }
Asserts.assertTrue(Boolean.valueOf(propagator.getConfig(Propagator.PROPAGATING_ALL)), "Expected Propagator.PROPAGATING_ALL to be true"); ((TestEntity)childEntity).sensors().set(TestEntity.NAME, "New Name"); Asserts.eventually(Entities.attributeSupplier(parentEntity, TestEntity.NAME), Predicates.<String>equalTo("New Name"));
@Test(groups="Integration") // marked integration as it takes a wee while public void testStartSuspended() throws Exception { feed = HttpFeed.builder() .entity(entity) .baseUrl(baseUrl) .poll(HttpPollConfig.forSensor(SENSOR_INT) .period(100) .onSuccess(HttpValueFunctions.responseCode())) .poll(HttpPollConfig.forSensor(SENSOR_STRING) .period(100) .onSuccess(HttpValueFunctions.stringContentsFunction())) .suspended() .build(); Asserts.continually(MutableMap.of("timeout", 500), Entities.attributeSupplier(entity, SENSOR_INT), Predicates.<Integer>equalTo(null)); int countWhenSuspended = server.getRequestCount(); feed.resume(); Asserts.eventually(Entities.attributeSupplier(entity, SENSOR_INT), Predicates.<Integer>equalTo(200)); if (server.getRequestCount() <= countWhenSuspended) Assert.fail("Request count failed to increment when feed was resumed, from "+countWhenSuspended+", still at "+server.getRequestCount()); log.info("RUN: "+countWhenSuspended+" - "+server.getRequestCount()); }