@Test(expectedExceptions = AssertionError.class) public void shouldFailToAssertConfigEquals() { EntityAsserts.assertConfigEquals(entity, TestEntity.CONF_NAME, "bogus"); }
@Test public void shouldAssertConfigEquals() { EntityAsserts.assertConfigEquals(entity, TestEntity.CONF_NAME, "defaultval"); }
protected void assertEmptySoftwareProcessConfig(Entity entity, Map<String, ?> expectedEnv, Map<String, String> expectedFiles, Map<String, ?> expectedProvisioningProps) { EntityAsserts.assertConfigEquals(entity, EmptySoftwareProcess.SHELL_ENVIRONMENT, MutableMap.<String, Object>copyOf(expectedEnv)); List<MapConfigKey<String>> keys = ImmutableList.of(EmptySoftwareProcess.PRE_INSTALL_TEMPLATES, EmptySoftwareProcess.PRE_INSTALL_FILES, EmptySoftwareProcess.INSTALL_TEMPLATES, EmptySoftwareProcess.INSTALL_FILES, EmptySoftwareProcess.RUNTIME_TEMPLATES, EmptySoftwareProcess.RUNTIME_FILES); for (MapConfigKey<String> key : keys) { EntityAsserts.assertConfigEquals(entity, key, expectedFiles); } EntityAsserts.assertConfigEquals(entity, EmptySoftwareProcess.PROVISIONING_PROPERTIES, MutableMap.<String, Object>copyOf(expectedProvisioningProps)); }
protected void checkNewAppNonInheritingKey1(Application app) { // check key EntityAsserts.assertConfigEquals(app, key1, "1"); // check not inherited TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class)); EntityAsserts.assertConfigEquals(entity, key1, null); }
@Test public void testExtendsSuperTypeConfigSimple() throws Exception { ImmutableMap<String, Object> expectedEnv = ImmutableMap.<String, Object>of("ENV1", "myEnv1", "ENV2", "myEnv2"); // super-type has shell.env; sub-type shell.env String yaml = Joiner.on("\n").join( "location: localhost-stub", "services:", "- type: EmptySoftwareProcess-with-shell.env", " brooklyn.config:", " shell.env:", " ENV2: myEnv2"); Entity app = createStartWaitAndLogApplication(yaml); Entity entity = Iterables.getOnlyElement(app.getChildren()); EntityAsserts.assertConfigEquals(entity, EmptySoftwareProcess.SHELL_ENVIRONMENT, expectedEnv); }
@Test public void testExtendsSuperTypeConfigMixingLongOverridingShortNames() throws Exception { ImmutableMap<String, Object> expectedEnv = ImmutableMap.<String, Object>of("ENV1", "myEnv1", "ENV2", "myEnv2"); // super-type has env; sub-type shell.env String yaml = Joiner.on("\n").join( "location: localhost-stub", "services:", "- type: EmptySoftwareProcess-with-env", " brooklyn.config:", " shell.env:", " ENV2: myEnv2"); Entity app = createStartWaitAndLogApplication(yaml); Entity entity = Iterables.getOnlyElement(app.getChildren()); EntityAsserts.assertConfigEquals(entity, EmptySoftwareProcess.SHELL_ENVIRONMENT, expectedEnv); }
@Test public void testExtendsSuperTypeConfigMixingShortOverridingLongName() throws Exception { ImmutableMap<String, Object> expectedEnv = ImmutableMap.<String, Object>of("ENV1", "myEnv1", "ENV2", "myEnv2"); // super-type has shell.env; sub-type env String yaml = Joiner.on("\n").join( "location: localhost-stub", "services:", "- type: EmptySoftwareProcess-with-shell.env", " brooklyn.config:", " env:", " ENV2: myEnv2"); Entity app = createStartWaitAndLogApplication(yaml); Entity entity = Iterables.getOnlyElement(app.getChildren()); EntityAsserts.assertConfigEquals(entity, EmptySoftwareProcess.SHELL_ENVIRONMENT, expectedEnv); }
@Test public void testExtendsSuperTypeConfigMixingShortOverridingShortName() throws Exception { // fixed Sept 2016 ImmutableMap<String, Object> expectedEnv = ImmutableMap.<String, Object>of("ENV1", "myEnv1", "ENV2", "myEnv2"); // super-type has env; sub-type env String yaml = Joiner.on("\n").join( "location: localhost-stub", "services:", "- type: EmptySoftwareProcess-with-env", " brooklyn.config:", " env:", " ENV2: myEnv2"); Entity app = createStartWaitAndLogApplication(yaml); Entity entity = Iterables.getOnlyElement(app.getChildren()); EntityAsserts.assertConfigEquals(entity, EmptySoftwareProcess.SHELL_ENVIRONMENT, expectedEnv); }
@Override public void run() { Application app2RO = n1.mgmt.lookup(app2.getId(), Application.class); Assert.assertNotNull(app2RO); EntityAsserts.assertConfigEquals(app2RO, TestEntity.CONF_NAME, "second-app"); } });
@Override public void run() { Set<BigInteger> alltokens = Sets.newLinkedHashSet(); for (Entity node : nodes) { EntityAsserts.assertAttributeEquals(node, Startable.SERVICE_UP, true); EntityAsserts.assertAttributeEquals(node, CassandraNode.PEERS, tokensPerNode*numNodes); EntityAsserts.assertConfigEquals(node, CassandraNode.NUM_TOKENS_PER_NODE, 256); Set<BigInteger> tokens = node.getAttribute(CassandraNode.TOKENS); assertNotNull(tokens); assertEquals(tokens.size(), tokensPerNode, "tokens="+tokens); alltokens.addAll(tokens); } assertFalse(alltokens.contains(null)); assertEquals(alltokens.size(), tokensPerNode*numNodes); }}); }
@Override public void run() { Set<BigInteger> alltokens = Sets.newLinkedHashSet(); for (Entity node : nodes) { EntityAsserts.assertAttributeEquals(node, Startable.SERVICE_UP, true); EntityAsserts.assertConfigEquals(node, CassandraNode.NUM_TOKENS_PER_NODE, 1); EntityAsserts.assertAttributeEquals(node, CassandraNode.PEERS, numNodes); Set<BigInteger> tokens = node.getAttribute(CassandraNode.TOKENS); assertNotNull(tokens); alltokens.addAll(tokens); } assertFalse(alltokens.contains(null), "tokens="+alltokens); assertEquals(alltokens.size(), numNodes); }}); }
@Test public void testAddConfigContinue() throws Throwable { RebindOptions rebindOptions = RebindOptions.create().additionalProperties(ImmutableMap.of("rebind.failureMode.addConfig", "continue")); TestApplication rebindedApp = rebind(rebindOptions); EntityAsserts.assertConfigEquals(rebindedApp, TestEntity.CONF_MAP_THING, null); }
@Test public void testLocationEntityConfigurationWithDefault() throws Exception { Map<String, EntitySpec<?>> map = ImmutableMap.<String, EntitySpec<?>>builder() .put("default", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Default")) .build(); entity = app.addChild(EntitySpec.create(LocationEntity.class) .configure(LocationEntity.LOCATION_ENTITY_SPEC_MAP, map)); app.start(ImmutableList.of(loc1)); assertEquals(entity.getChildren().size(), 1); Entity child = Iterables.getOnlyElement(entity.getChildren()); assertTrue(child instanceof TestEntity); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_TYPE, "SimulatedLocation"); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_ENTITY, child); EntityAsserts.assertConfigEquals(child, TestEntity.CONF_NAME, "Default"); EntityAsserts.assertEntityHealthy(child); EntityAsserts.assertEntityHealthy(entity); }
EntityAsserts.assertConfigEquals(entity, EmptySoftwareProcess.SHELL_ENVIRONMENT, ImmutableMap.<String, Object>of("ENV1", "myEnv1", "ENV2", "myEnv2", "ENV3", "myEnv3"));
@Test public void testLocationEntityConfigurationWithWrongTypeAndDefault() throws Exception { Map<String, EntitySpec<?>> map = ImmutableMap.<String, EntitySpec<?>>builder() .put("OtherLocation", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Other")) .put("default", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Default")) .build(); entity = app.addChild(EntitySpec.create(LocationEntity.class) .configure(LocationEntity.LOCATION_ENTITY_SPEC_MAP, map)); app.start(ImmutableList.of(loc1)); assertEquals(entity.getChildren().size(), 1); Entity child = Iterables.getOnlyElement(entity.getChildren()); assertTrue(child instanceof TestEntity); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_TYPE, "SimulatedLocation"); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_ENTITY, child); EntityAsserts.assertConfigEquals(child, TestEntity.CONF_NAME, "Default"); EntityAsserts.assertEntityHealthy(child); EntityAsserts.assertEntityHealthy(entity); }
@Test public void testLocationEntityConfigurationWithType() throws Exception { Map<String, EntitySpec<?>> map = ImmutableMap.<String, EntitySpec<?>>builder() .put("OtherLocation", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Other")) .put("SimulatedLocation", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Simulated")) .put("default", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Default")) .build(); entity = app.addChild(EntitySpec.create(LocationEntity.class) .configure(LocationEntity.LOCATION_ENTITY_SPEC_MAP, map)); app.start(ImmutableList.of(loc1)); assertEquals(entity.getChildren().size(), 1); Entity child = Iterables.getOnlyElement(entity.getChildren()); assertTrue(child instanceof TestEntity); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_TYPE, "SimulatedLocation"); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_ENTITY, child); EntityAsserts.assertConfigEquals(child, TestEntity.CONF_NAME, "Simulated"); EntityAsserts.assertEntityHealthy(child); EntityAsserts.assertEntityHealthy(entity); }
@Test public void testLocationEntityConfigurationWithCountry() throws Exception { Map<String, EntitySpec<?>> map = ImmutableMap.<String, EntitySpec<?>>builder() .put("UK", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "United Kingdom")) .put("DE", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Germany")) .put("default", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "default")) .build(); entity = app.addChild(EntitySpec.create(LocationEntity.class) .configure(LocationEntity.LOCATION_ENTITY_SPEC_MAP, map)); app.start(ImmutableList.of(loc3)); assertEquals(entity.getChildren().size(), 1); Entity child = Iterables.getOnlyElement(entity.getChildren()); assertTrue(child instanceof TestEntity); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_TYPE, "SimulatedLocation"); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_COUNTRY_CODES, ImmutableSet.of("UK", "US")); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_ENTITY, child); EntityAsserts.assertConfigEquals(child, TestEntity.CONF_NAME, "United Kingdom"); EntityAsserts.assertEntityHealthy(child); EntityAsserts.assertEntityHealthy(entity); }
@Test public void testLocationEntityConfigurationWithProvider() throws Exception { Map<String, EntitySpec<?>> map = ImmutableMap.<String, EntitySpec<?>>builder() .put("cloud", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Cloud")) .put("other", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Other")) .put("default", EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "Default")) .build(); entity = app.addChild(EntitySpec.create(LocationEntity.class) .configure(LocationEntity.LOCATION_ENTITY_SPEC_MAP, map)); app.start(ImmutableList.of(loc2)); assertEquals(entity.getChildren().size(), 1); Entity child = Iterables.getOnlyElement(entity.getChildren()); assertTrue(child instanceof TestEntity); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_TYPE, "SimulatedLocation"); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_PROVIDER, "cloud"); EntityAsserts.assertAttributeEqualsEventually(entity, LocationEntity.LOCATION_ENTITY, child); EntityAsserts.assertConfigEquals(child, TestEntity.CONF_NAME, "Cloud"); EntityAsserts.assertEntityHealthy(child); EntityAsserts.assertEntityHealthy(entity); }
@Test public void testHandlesReferencingOtherLocations() throws Exception { MyLocation origLoc = new MyLocation(); MyEntityReffingOthers origE = origApp.createAndManageChild(EntitySpec.create(MyEntityReffingOthers.class) .configure("locationRef", origLoc)); origE.sensors().set(MyEntityReffingOthers.LOCATION_REF_SENSOR, origLoc); origApp.start(ImmutableList.of(origLoc)); newApp = rebind(); MyEntityReffingOthers newE = (MyEntityReffingOthers) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntityReffingOthers.class)); MyLocation newLoc = (MyLocation) Iterables.getOnlyElement(newApp.getLocations()); EntityAsserts.assertAttributeEquals(newE, MyEntityReffingOthers.LOCATION_REF_SENSOR, newLoc); EntityAsserts.assertConfigEquals(newE, MyEntityReffingOthers.LOCATION_REF_CONFIG, newLoc); }
@Test public void testHandlesReferencingOtherEntities() throws Exception { MyEntity origOtherE = origApp.createAndManageChild(EntitySpec.create(MyEntity.class)); MyEntityReffingOthers origE = origApp.createAndManageChild(EntitySpec.create(MyEntityReffingOthers.class) .configure("entityRef", origOtherE)); origE.sensors().set(MyEntityReffingOthers.ENTITY_REF_SENSOR, origOtherE); newApp = rebind(); MyEntityReffingOthers newE = (MyEntityReffingOthers) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntityReffingOthers.class)); MyEntity newOtherE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class)); EntityAsserts.assertAttributeEquals(newE, MyEntityReffingOthers.ENTITY_REF_SENSOR, newOtherE); EntityAsserts.assertConfigEquals(newE, MyEntityReffingOthers.ENTITY_REF_CONFIG, newOtherE); }