@Test public void testConcurrentSetAttribute() throws Exception { final int NUM_TASKS = Math.min(500 * Runtime.getRuntime().availableProcessors(), 1000); List<ListenableFuture<?>> futures = Lists.newArrayList(); for (int i = 0; i < NUM_TASKS; i++) { final AttributeSensor<Integer> nextSensor = Sensors.newIntegerSensor("EntityConcurrencyTest.exampleSensor"+i); final int val = i; ListenableFuture<?> future = executor.submit(new Runnable() { @Override public void run() { entity.sensors().set(nextSensor, val); }}); futures.add(future); } Futures.allAsList(futures).get(); for (int i = 0; i < NUM_TASKS; i++) { AttributeSensor<Integer> nextSensor = Sensors.newIntegerSensor("EntityConcurrencyTest.exampleSensor"+i); assertEquals(entity.sensors().get(nextSensor), (Integer)i, "i="+i); } }
@Test public void testChildUsesDefaultsFromParent() throws Exception { addCatalogItems( "brooklyn.catalog:", " itemType: template", " items:", " - id: template-with-top-level-params", " item:", " brooklyn.parameters:", " - name: test.parameter", " description: myDescription", " type: String", " default: myDefaultParamVal", " services:", " - type: "+TestEntity.class.getName(), " brooklyn.config:", " " + TestEntity.ATTRIBUTE_AND_CONF_STRING.getName() + ": $brooklyn:config(\"test.parameter\")" ); String yaml = Joiner.on("\n").join( "services:", "- type: template-with-top-level-params"); Entity app = createStartWaitAndLogApplication(yaml); TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren()); assertEquals(entity.sensors().get(TestEntity.ATTRIBUTE_AND_CONF_STRING), "myDefaultParamVal"); }
assertEquals(testEntity.sensors().get(MyTestEntity.MY_SENSOR), "myVal");
ProvisioningTaskState provisioningState = entity().sensors().get(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); log.warn("When stopping {}, timed out after {} waiting for the machine to finish provisioning - machine may we left running", entity(), maxWait); machine = Maybe.ofDisallowingNull(entity().sensors().get(INTERNAL_PROVISIONED_MACHINE));
if (lh.isPresent() && entity().sensors().get(Attributes.SUBNET_HOSTNAME) == null) { entity().sensors().set(Attributes.SUBNET_HOSTNAME, lh.get()); if (la.isPresent() && entity().sensors().get(Attributes.SUBNET_ADDRESS) == null) { entity().sensors().set(Attributes.SUBNET_ADDRESS, la.get()); if (entity().sensors().get(Attributes.HOSTNAME) == null) { entity().sensors().set(Attributes.HOSTNAME, machine.getAddress().getHostName()); if (entity().sensors().get(Attributes.ADDRESS) == null) { entity().sensors().set(Attributes.ADDRESS, machine.getAddress().getHostAddress());
Iterable<FailingEntity> children1 = Iterables.filter(cluster.getChildren(), FailingEntity.class); assertEquals(Iterables.size(children1), 1); assertEquals(Iterables.getOnlyElement(children1).sensors().get(TestEntity.SERVICE_UP), Boolean.TRUE);
.from(app) .build()); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, entity.sensors().get(TestEntity.NAME)); entity.sensors().set(TestEntity.NAME, "newName"); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, "newName");
ProvisioningTaskState provisioningState = entity.sensors().get(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); if (machine.isAbsent() && provisioningState == ProvisioningTaskState.RUNNING) { LOG.warn("Entity {} was provisioning; VM may have been left running", entity); ProvisioningTaskState terminationState = entity.sensors().get(AttributesInternal.INTERNAL_TERMINATION_TASK_STATE); if (machine.isAbsent() && terminationState == ProvisioningTaskState.RUNNING) { LOG.warn("Entity {} was terminating; VM may have been left running", entity);
log.info("Starting {}, obtaining a new location instance in {} with ports {}", new Object[]{entity(), location, flags.get("inboundPorts")}); entity().sensors().set(SoftwareProcess.PROVISIONING_LOCATION, location); Transition expectedState = entity().sensors().get(Attributes.SERVICE_STATE_EXPECTED);
private void testTransformerResolvesResolvableValues(int portStart, int portCount) { // Note: The test gets progressively slower with iterations, probably due to the GC triggering much more frequently. // There's no memory leak, but doesn't seem right to be putting so much pressure on the GC with such a simple test. AttributeSensor<Integer> sourceSensor = Sensors.newIntegerSensor("port"); AttributeSensor<String> targetSensor = Sensors.newStringSensor("port.transformed"); app.enrichers().add(EnricherSpec.create(Transformer.class) .configure(Transformer.SOURCE_SENSOR, sourceSensor) .configure(Transformer.TARGET_SENSOR, targetSensor) .configure(Transformer.TARGET_VALUE, // Can only use the inner-most sensor, but including the // wrapping formatStrings amplifies the resolving effort, making // a bug more probable to manifest. BrooklynDslCommon.formatString("%s", BrooklynDslCommon.formatString("%d", BrooklynDslCommon.attributeWhenReady("port"))))); int failures = 0; for (int port = portStart; port < portStart + portCount; port++) { app.sensors().set(sourceSensor, port); try { EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, Integer.toString(port)); } catch (Exception e) { failures++; LOG.warn("Assertion failed, port=" + port + ", transformed sensor is " + app.sensors().get(targetSensor), e); } } assertEquals(failures, 0, failures + " assertion failures while transforming sensor; see logs for detailed errors"); }
assertEquals(newEntity.sensors().get(CreateUserPolicy.VM_USER_CREDENTIALS), creds);
@Override public Void call(ConfigBag parameters) { synchronized (PublishingEffector.class) { Collection<Object> values = entity().sensors().get(REMOVED_EFFECTOR_VALUES); if (values == null) { values = Sets.newHashSet(); } final Object v = parameters.getStringKey("value"); values.add(v); entity().sensors().set(REMOVED_EFFECTOR_VALUES, values); return null; } } }
@Override public Long get() { Integer a = producer.sensors().get(intSensorA); return (a == null ? null : a.longValue()); }}));
@Override public Integer get() { Integer a = producer.sensors().get(intSensorA); return (a == null ? 0 : a+1); }}));
@Override public Boolean call() throws Exception { ProvisioningTaskState state = entity().sensors().get(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); return (state != ProvisioningTaskState.RUNNING); }}) .backoffTo(Duration.FIVE_SECONDS)
@Test(timeOut = Asserts.THIRTY_SECONDS_TIMEOUT_MS) public void testRebindResetsPermits() throws Exception { final AttributeSensor<ReleaseableLatch> latchSensor = Sensors.newSensor(ReleaseableLatch.class, "latch"); final ReleaseableLatch latchSemaphore = ReleaseableLatch.Factory.newMaxConcurrencyLatch(1); origApp.sensors().set(latchSensor, latchSemaphore); latchSemaphore.acquire(origApp); rebind(); ReleaseableLatch newSemaphore = newApp.sensors().get(latchSensor); // makes sure permits are reset and we can acquire the semaphore again newSemaphore.acquire(origApp); }
@Override public Void call() throws Exception { TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class)); entity.sensors().set(TestEntity.SERVICE_UP, true); entity.sensors().set(TestEntity.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); Thread.sleep(10); assertEquals(entity.sensors().get(TestEntity.SERVICE_UP), Boolean.TRUE); assertEquals(entity.sensors().get(TestEntity.SERVICE_STATE_ACTUAL), Lifecycle.RUNNING); Entities.unmanage(entity); return null; }}); futures.add(future);