public static void dumpInfo(Entity e, Writer out) throws IOException { dumpInfo(e, out, "", " "); } public static void dumpInfo(Entity e, String currentIndentation, String tab) throws IOException {
public static void dumpInfo(Location loc, String currentIndentation, String tab) throws IOException { dumpInfo(loc, new PrintWriter(System.out), currentIndentation, tab); } @SuppressWarnings("rawtypes")
public static void dumpInfo(Location loc) { try { dumpInfo(loc, new PrintWriter(System.out), "", " "); } catch (IOException exc) { // system.out throwing an exception is odd, so don't have IOException on signature throw new RuntimeException(exc); } } public static void dumpInfo(Location loc, Writer out) throws IOException {
public static void dumpInfo(Policy pol) { try { dumpInfo(pol, new PrintWriter(System.out), "", " "); } catch (IOException exc) { // system.out throwing an exception is odd, so don't have IOException on signature throw new RuntimeException(exc); } } public static void dumpInfo(Policy pol, Writer out) throws IOException {
protected void assertCannotFindMessages(Entity entity) { ResourceUtils ru = ResourceUtils.create(entity); Iterable<URL> files = ru.getResources("org/apache/brooklyn/test/osgi/resources/message.txt"); if (files.iterator().hasNext()) { Entities.dumpInfo(entity); Assert.fail("Expected NOT to find 'messages.txt'"); } }
protected void assertCanFindMessages(Entity entity) { ResourceUtils ru = ResourceUtils.create(entity); Iterable<URL> files = ru.getResources("org/apache/brooklyn/test/osgi/resources/message.txt"); if (!files.iterator().hasNext()) { Entities.dumpInfo(entity); Assert.fail("Expected to find 'messages.txt'"); } }
protected Entity setupAndCheckTestEntityInBasicYamlWith(String ...extras) throws Exception { Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", extras)); waitForApplicationTasks(app); Entities.dumpInfo(app); Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); log.info("App started:"); Entities.dumpInfo(app); Assert.assertTrue(app.getChildren().iterator().hasNext(), "Expected app to have child entity"); Entity entity = app.getChildren().iterator().next(); Assert.assertTrue(entity instanceof TestEntity, "Expected TestEntity, found " + entity.getClass()); return entity; }
private static <T> void assertAttributeEquals(Entity x, AttributeSensor<T> sensor, T value) { try { EntityAsserts.assertAttributeEquals(x, sensor, value); } catch (Throwable e) { log.warn("Expected "+x+" to have "+sensor+" = "+value+"; instead:"); Entities.dumpInfo(x); throw Exceptions.propagate(e); } }
protected Entity setupAndCheckTestEntityInBasicYamlWith(String ...extras) throws Exception { managementContextInjected.set(false); configKeys.clear(); Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", extras)); waitForApplicationTasks(app); Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); log.info("App started:"); Entities.dumpInfo(app); Assert.assertTrue(app.getChildren().iterator().hasNext(), "Expected app to have child entity"); Entity entity = app.getChildren().iterator().next(); Assert.assertTrue(entity instanceof TestEntity, "Expected TestEntity, found " + entity.getClass()); return entity; }
protected Entity setupAndCheckTestEntityInBasicYamlWith(String... extras) throws Exception { Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", extras)); waitForApplicationTasks(app); Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); log.info("App started:"); Entities.dumpInfo(app); Assert.assertTrue(app.getChildren().iterator().hasNext(), "Expected app to have child entity"); Entity entity = app.getChildren().iterator().next(); Assert.assertTrue(entity instanceof TestEntity, "Expected TestEntity, found " + entity.getClass()); return entity; }
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) {
private static <T> void assertAttributeEqualsContinually(Entity x, AttributeSensor<T> sensor, T value) { try { EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", Duration.millis(25)), x, sensor, value); } catch (Throwable e) { log.warn("Expected "+x+" continually to have "+sensor+" = "+value+"; instead:"); Entities.dumpInfo(x); throw Exceptions.propagate(e); } } private static <T> void assertAttributeEquals(Entity x, AttributeSensor<T> sensor, T value) {
@Test public void testSensorOnArbitraryClass() throws Exception { Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", " brooklyn.config:", " test.confObject: $brooklyn:sensor(\""+EntitiesYamlTest.class.getName()+"$ArbitraryClassWithSensor\", \"mysensor\")")); waitForApplicationTasks(app); log.info("App started:"); Entities.dumpInfo(app); TestEntity entity = (TestEntity) app.getChildren().iterator().next(); Object object = entity.getConfig(TestEntity.CONF_OBJECT); Assert.assertEquals(object, ArbitraryClassWithSensor.MY_SENSOR); } public static class ArbitraryClassWithSensor {
@Test public void testCatalogParameterFromSuperYamlType() throws Exception { addCatalogItems( loadYaml("config-nested-test.bom") ); Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter } ]", false); Entities.dumpInfo(ent); }
@Test public void testCatalogParameterFromSuperYamlTypeAsSoftware() throws Exception { addCatalogItems( loadYaml("config-nested-test.bom") ); Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter-software } ]", false); Entities.dumpInfo(ent); }
@Test public void testAppSpecXmlPlanParse() { EntitySpec<? extends Application> appSpec = EntityManagementUtils.createEntitySpecForApplication(mgmt, "<root><a_kid foo=\"bar\"/></root>"); Application app = EntityManagementUtils.createStarting(mgmt, appSpec).get(); Entities.dumpInfo(app); Assert.assertEquals(app.getDisplayName(), "root"); Entity child = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(child.getDisplayName(), "a_kid"); Assert.assertEquals(child.config().get(ConfigKeys.newStringConfigKey("foo")), "bar"); }
@Test public void testSimpleXmlPlanParse() { EntitySpec<? extends Application> appSpec = EntityManagementUtils.createEntitySpecForApplication(mgmt, "<root><a_kid foo=\"bar\"/></root>"); Application app = EntityManagementUtils.createStarting(mgmt, appSpec).get(); Entities.dumpInfo(app); Assert.assertEquals(app.getDisplayName(), "root"); Entity child = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(child.getDisplayName(), "a_kid"); Assert.assertEquals(child.config().get(ConfigKeys.newStringConfigKey("foo")), "bar"); }
@Test public void testCatalogParameterFromSuperYamlTypeInCluster() throws Exception { addCatalogItems( loadYaml("config-nested-test.bom") ); Entity cluster = makeBlueprint("services: [ { type: test-cluster-with-map-parameter } ]"); Entities.dumpInfo(cluster.getApplication()); Entity parentInCluster = Iterables.getOnlyElement( ((DynamicCluster)cluster).getMembers() ); Entity target = Iterables.getOnlyElement(parentInCluster.getChildren()); checkEntity( target, false ); }
/** * Test that a node starts and sets SERVICE_UP correctly. */ @Test(groups = "Integration") public void canStartupAndShutdown() { solr = app.createAndManageChild(EntitySpec.create(SolrServer.class)); app.start(ImmutableList.of(testLocation)); EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, true); Entities.dumpInfo(app); solr.stop(); EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, false); }
@Test(groups={"Integration", "WIP", "Broken"}) public void testJavaWebWithMemberSpecRebind() throws Exception { Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-java-web-app-spec-and-db-with-function.yaml")); AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId()); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); for (Task<?> t: tasks) t.blockUntilEnded(); Entities.dumpInfo(app); Application app2 = rebind(app); Assert.assertEquals(app2.getChildren().size(), 2); }