protected void createApps() { for (EntitySpec<? extends Application> spec : appSpecsToManage) { Application app = managementContext.getEntityManager().createEntity(spec); apps.add(app); } for (String blueprint : yamlAppsToManage) { Application app = EntityManagementUtils.createUnstarted(managementContext, blueprint); // Note: BrooklynAssemblyTemplateInstantiator automatically puts applications under management. apps.add(app); } }
@Test public void testLoadEntityFromClasspath() throws Exception { String entityName = ExampleEntity.class.getName(); Object appSpec = loadApplicationFromClasspathOrParse(entityName); assertTrue(appSpec instanceof EntitySpec, "app="+appSpec); mgmt = LocalManagementContextForTests.newInstance(); app = (Application) mgmt.getEntityManager().createEntity((EntitySpec<?>)appSpec); Collection<Entity> entities = app.getChildren(); assertEquals(entities.size(), 1, "entities="+entities); assertTrue(Iterables.getOnlyElement(entities) instanceof ExampleEntity, "entities="+entities+"; ifs="+Iterables.getOnlyElement(entities).getClass().getInterfaces()); assertTrue(Iterables.getOnlyElement(entities) instanceof EntityProxy, "entities="+entities); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); app = mgmt.getEntityManager().createEntity(EntitySpec.create(AsyncApplication.class)); }
@Test public void testStartManagementFailsIfAppDeleted() throws Exception { TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); Entities.unmanage(app2); try { Entities.startManagement(app2, mgmt); fail("Managed deleted app "+app2+" in "+mgmt); } catch (IllegalStateException e) { if (!(e.toString().contains("No concrete entity known"))) throw e; } }
public void testHappyPathEmptyApp() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); app.start(ImmutableList.<Location>of()); assertUpAndRunningEventually(app); }
public void testAppFailsCausesAppToFail() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class, TestApplicationDoStartFailing.class)); startAndAssertException(app, ImmutableList.<Location>of()); assertHealthEventually(app, Lifecycle.ON_FIRE, false); }
@Test public void testSpecDeclaresParent() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app)); assertEquals(e.getParent(), app); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e)); }
@Test public void testNewOrphanedEntityCanBeAddedToChild() throws Exception { TestEntity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class)); app.addChild(e); assertTrue(Entities.isManaged(e)); listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, e))); }
@Test public void testSetParentInSetterMethod() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class)); e.setParent(app); assertEquals(e.getParent(), app); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e)); assertEquals(e.getApplication(), app); }
@Test public void testChildInheritsFromParent() throws Exception { EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure("myentity.myconfig", "myval1")); EntityInternal child = mgmt.getEntityManager().createEntity(EntitySpec.create(MyChildEntity.class) .parent(entity)); assertEquals(child.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyEntity.MY_CONFIG, "myval1")); assertEquals(child.config().getBag().getAllConfig(), ImmutableMap.of("myentity.myconfig", "myval1")); assertEquals(child.config().getLocalBag().getAllConfig(), ImmutableMap.of()); }
@Test public void testManageIsNoop() throws Exception { TestEntity child = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class) .parent(app)); Entities.manage(child); assertTrue(Entities.isManaged(child)); listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, child))); }
@Test public void testConfigBagContainsMatchesForFlagName() throws Exception { // Prefers flag-name, over config-key's name EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure("myconfigflagname", "myval")); assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyEntity.MY_CONFIG_WITH_FLAGNAME, "myval")); assertEquals(entity.config().getBag().getAllConfig(), ImmutableMap.of("myentity.myconfigwithflagname", "myval")); assertEquals(entity.config().getLocalBag().getAllConfig(), ImmutableMap.of("myentity.myconfigwithflagname", "myval")); }
@Test public void testConfigBagContainsUnmatched() throws Exception { EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure("notThere", "notThereVal")); assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(ConfigKeys.newConfigKey(Object.class, "notThere"), "notThereVal")); assertEquals(entity.config().getBag().getAllConfig(), ImmutableMap.of("notThere", "notThereVal")); assertEquals(entity.config().getLocalBag().getAllConfig(), ImmutableMap.of("notThere", "notThereVal")); }
@Override protected void setUpApp() { EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class, TestApplicationNoEnrichersImpl.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, shouldSkipOnBoxBaseDirResolution()); app = mgmt.getEntityManager().createEntity(appSpec); }
@Test public void testGetConfigMapWithSubKeys() throws Exception { TestEntity entity = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class) .configure(TestEntity.CONF_MAP_THING.subKey("mysub"), "myval")); assertEquals(entity.config().get(TestEntity.CONF_MAP_THING), ImmutableMap.of("mysub", "myval")); assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_THING).get(), ImmutableMap.of("mysub", "myval")); assertEquals(entity.config().get(TestEntity.CONF_MAP_THING.subKey("mysub")), "myval"); assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_THING.subKey("mysub")).get(), "myval"); }
public void testHappyPathWithChild() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .child(EntitySpec.create(TestEntity.class))); app.start(ImmutableList.<Location>of()); assertUpAndRunningEventually(app); }
public void testOnlyChildFailsToStartCausesAppToFail() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .child(EntitySpec.create(FailingEntity.class) .configure(FailingEntity.FAIL_ON_START, true))); FailingEntity child = (FailingEntity) Iterables.get(app.getChildren(), 0); startAndAssertException(app, ImmutableList.<Location>of()); assertHealthEventually(child, Lifecycle.ON_FIRE, false); assertHealthEventually(app, Lifecycle.ON_FIRE, false); }
public void testStartsThenSomeChildFailsCausesAppToFail() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .child(EntitySpec.create(TestEntity.class)) .child(EntitySpec.create(TestEntity.class))); TestEntity child = (TestEntity) Iterables.get(app.getChildren(), 0); app.start(ImmutableList.<Location>of()); assertUpAndRunningEventually(app); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child"); assertHealthEventually(app, Lifecycle.ON_FIRE, false); }
@DataProvider(name = "brooklynObjects") public Object[][] createBrooklynObjects() throws Exception { EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, shouldSkipOnBoxBaseDirResolution()); setUp(); TestApplication app = mgmt.getEntityManager().createEntity(appSpec); EntityRequiringConfigKeyInRange entity = app.createAndManageChild(EntitySpec.create(EntityRequiringConfigKeyInRange.class) .configure(EntityRequiringConfigKeyInRange.RANGE, 5)); Policy policy = entity.policies().add(PolicySpec.create(TestPolicy.class)); Location location = app.newSimulatedLocation(); return new Object[][]{{entity}, {policy}, {location}}; }
public void testSomeChildFailsToStartThenRecoversCausesAppToRecover() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .child(EntitySpec.create(TestEntity.class)) .child(EntitySpec.create(FailingEntity.class) .configure(FailingEntity.FAIL_ON_START, true))); FailingEntity child = (FailingEntity) Iterables.find(app.getChildren(), Predicates.instanceOf(FailingEntity.class)); startAndAssertException(app, ImmutableList.<Location>of()); assertHealthEventually(app, Lifecycle.ON_FIRE, false); child.sensors().set(Attributes.SERVICE_UP, true); child.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); assertUpAndRunningEventually(app); }