@Override @Deprecated public <T> T setConfig(ConfigKey<T> key, T value) { return config().set(key, value); }
@Test public void testPicksCorrectNamedSubLocations() throws Exception { cluster.config().set(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone2", "zone4")); cluster.start(ImmutableList.of(loc)); List<Location> subLocations = cluster.getAttribute(DynamicCluster.SUB_LOCATIONS); List<String> subLocationNames = getLocationNames(subLocations); assertEquals(subLocationNames, ImmutableList.of("zone2", "zone4")); }
@Test public void testPicksCorrectNumSubLocations() throws Exception { cluster.config().set(DynamicCluster.NUM_AVAILABILITY_ZONES, 2); cluster.start(ImmutableList.of(loc)); List<Location> subLocations = cluster.getAttribute(DynamicCluster.SUB_LOCATIONS); List<String> subLocationNames = getLocationNames(subLocations); assertEquals(subLocationNames, ImmutableList.of("zone1", "zone2")); }
@Override public void apply(EntityLocal entity) { entity.config().set(KEY_1, key1); } }
@Test public void testPersistsOnExplicitCheckpointOfEntity() throws Exception { origE.config().set(MyEntity.MY_CONFIG, "mynewval"); origE.sensors().set(MyEntity.MY_SENSOR, "mysensorval"); // Assert persisted the modified config/attributes newApp = rebind(); MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class)); assertEquals(newE.getConfig(MyEntity.MY_CONFIG), "mynewval"); assertEquals(newE.getAttribute(MyEntity.MY_SENSOR), "mysensorval"); }
@Test public void testSubscribesToHostname() { geoDns.config().set(GeoDnsTestServiceImpl.ADD_ANYTHING, false); app.start( ImmutableList.of(westChild, eastChildWithLocationAndWithPrivateHostname) ); Assert.assertEquals(geoDns.getTargetHostsByName().size(), 0); publishSensors(2, true, true, true); assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2)); Assert.assertEquals(geoDns.getTargetHostsByName().size(), 2); assertIsTarget("West child"); assertIsTarget("East child with location"); }
@Test public void testDeferredDslChainingOnConfig() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.config:", " dest: $brooklyn:config(\"targetValue\").isSupplierEvaluated()"); app.config().set(ConfigKeys.newConfigKey(TestDslSupplierValue.class, "targetValue"), new TestDslSupplierValue()); assertEquals(getConfigEventually(app, DEST), Boolean.TRUE); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test(expectedExceptions=IllegalArgumentException.class) public void testFailFastOnInvalidConfigKeyCoercion() throws Exception { MyOtherEntity entity = app.addChild(EntitySpec.create(MyOtherEntity.class)); ConfigKey<Integer> key = MyOtherEntity.INT_KEY; entity.config().set((ConfigKey)key, "thisisnotanint"); }
@Test public void testCanDisableFilterForRunningEntities() throws Exception { geoDns.config().set(AbstractGeoDnsService.FILTER_FOR_RUNNING, false); app.start(ImmutableList.of(westChildWithLocation, eastChildWithLocationAndWithPrivateHostname)); publishSensors(2, true, true, true); assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2)); final Map<String, String> targets = ImmutableMap.copyOf(geoDns.sensors().get(AbstractGeoDnsService.TARGETS)); TestEntity problemChild = Iterables.get(Entities.descendantsAndSelf(app, TestEntity.class), 0); problemChild.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); assertAttributeEqualsContinually(geoDns, AbstractGeoDnsService.TARGETS, targets); }
@Test(groups={"Integration"}) public void testRoutesToExpectedLocation() { // Without this config, running on a home network (i.e. no public IP) the entity will have a private IP and will be ignored geoDns.config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true); target.sensors().set(Attributes.HOSTNAME,addrWithGeo.getHostName()); app.start(ImmutableList.of(locWithGeo)); LOG.info("geo-scaling test, using {}.{}; expect to be wired to {}", new Object[] {subDomain, primaryDomain, addrWithGeo}); assertTargetHostsEventually(geoDns, 1); }
@Test public void testDeferredDslChainingWithCustomCallable() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.config:", " dest: $brooklyn:config(\"customCallableWrapper\").getSupplier().isSupplierCallable()"); ConfigKey<DslTestSupplierWrapper> customCallableWrapperKey = ConfigKeys.newConfigKey(DslTestSupplierWrapper.class, "customCallableWrapper"); app.config().set(customCallableWrapperKey, new DslTestSupplierWrapper(new DslTestCallable())); assertEquals(getConfigEventually(app, DEST), Boolean.TRUE); }
@Test public void testDeferredDslUserSuppliedPackage() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.config:", " dest: $brooklyn:config(\"targetValue\").isEvaluated()"); app.config().set(ConfigKeys.newConfigKey(UserSuppliedPackageType.class, "targetValue"), new UserSuppliedPackageType()); assertEquals(getConfigEventually(app, DEST), Boolean.TRUE); }
@Test public void testDeferredDslWhiteListPackage() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.config:", " dest: $brooklyn:config(\"targetValue\").isSupplierEvaluated()"); app.config().set(ConfigKeys.newConfigKey(TestDslSupplierValue.class, "targetValue"), new TestDslSupplierValue()); assertEquals(getConfigEventually(app, DEST), Boolean.TRUE); }
@Test(dataProvider = "brooklynObjects") public void testCannotUpdateConfigToInvalidValue(BrooklynObject object) { try { object.config().set(EntityRequiringConfigKeyInRange.RANGE, -1); fail("Expected exception when calling config().set with invalid value on " + object); } catch (Exception e) { Throwable t = Exceptions.getFirstThrowableOfType(e, ConstraintViolationException.class); assertNotNull(t, "Original exception was: " + Exceptions.collapseText(e)); } }
@Override public void run() { for (TestEntity entity : entities) { entity.sensors().set(TestEntity.SEQUENCE, i++); Policy policy = Iterables.find(entity.policies(), Predicates.instanceOf(TestPolicy.class)); policy.config().set(TestPolicy.CONF_NAME, "name-"+i); } }}) .limitTimeTo(testLength)
@Test(groups={"Integration"}) public void testIncludesAddressWithoutGeography() { System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), StubHostGeoLookup.class.getName()); geoDns.config().set(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true); app.start(ImmutableList.of(locWithoutGeo)); target.sensors().set(Attributes.HOSTNAME, StubHostGeoLookup.HOMELESS_IP); LOG.info("geo-scaling test, using {}.{}; expect to be wired to {}", new Object[] {subDomain, primaryDomain, addrWithoutGeo}); assertTargetHostsEventually(geoDns, 1); }
static void addToWarsByContext(Entity entity, String url, String targetName) { targetName = FILENAME_TO_WEB_CONTEXT_MAPPER.convertDeploymentTargetNameToContext(targetName); // TODO a better way to do atomic updates, see comment above synchronized (entity) { Map<String,String> newWarsMap = MutableMap.copyOf(entity.getConfig(WARS_BY_CONTEXT)); newWarsMap.put(targetName, url); entity.config().set(WARS_BY_CONTEXT, newWarsMap); } }
@Test public void testDeferredDslChainingWithCustomSupplier() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.config:", " dest: $brooklyn:config(\"customSupplierWrapper\").getSupplier().isSupplierEvaluated()"); ConfigKey<DslTestSupplierWrapper> customSupplierWrapperKey = ConfigKeys.newConfigKey(DslTestSupplierWrapper.class, "customSupplierWrapper"); app.config().set(customSupplierWrapperKey, new DslTestSupplierWrapper(new TestDslSupplier(new TestDslSupplierValue()))); assertEquals(getConfigEventually(app, DEST), Boolean.TRUE); }
@Test(groups={"WIP", "Integration"}) public void testJavaSystemProperties() throws Exception { final VanillaJavaApp javaProcess = app.createAndManageChild(EntitySpec.create(VanillaJavaApp.class) .configure("main", "my.Main").configure("classpath", ImmutableList.of("c1", "c2")) .configure("args", ImmutableList.of("a1", "a2"))); javaProcess.config().set(UsesJava.JAVA_SYSPROPS, ImmutableMap.of("fooKey", "fooValue", "barKey", "barValue")); // TODO: how to test: launch standalone app that outputs system properties to stdout? Probe via JMX? }
@Test public void testTurnOffIncludeInitialChildren() throws Exception { // Turning off "include initial children" means they will be ignored in the member-count. fabric.config().set(DynamicFabric.INCLUDE_INITIAL_CHILDREN, false); TestEntity existingChild = fabric.addChild(EntitySpec.create(TestEntity.class)); app.start(ImmutableList.of(loc1, loc2)); assertFabricMembers(fabric, 2, ImmutableList.of(loc1, loc2)); assertFalse(fabric.getMembers().contains(existingChild)); assertEqualsIgnoringOrder(existingChild.getLocations(), ImmutableList.of(loc1)); }