Java Code Examples for org.apache.brooklyn.core.sensor.Sensors#newIntegerSensor()

The following examples show how to use org.apache.brooklyn.core.sensor.Sensors#newIntegerSensor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InitSlaveTaskBody.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
/**
 * Rebind backwards compatibility
 * @deprecated since 0.9.0
 */
@Deprecated
private ReplicationSnapshot getReplicationInfoMasterConfig() {
    Entity master = getMaster();
    AttributeSensor<String> MASTER_LOG_FILE = Sensors.newStringSensor(
            "mysql.master.log_file", "The binary log file master is writing to");
    AttributeSensor<Integer> MASTER_LOG_POSITION = Sensors.newIntegerSensor(
            "mysql.master.log_position", "The position in the log file to start replication");

    String logFile = master.sensors().get(MASTER_LOG_FILE);
    Integer logPos = master.sensors().get(MASTER_LOG_POSITION);
    if(logFile != null && logPos != null) {
        ReplicationSnapshot replicationSnapshot = new ReplicationSnapshot(null, null, logFile, logPos);
        cluster.sensors().set(MySqlCluster.REPLICATION_LAST_SLAVE_SNAPSHOT, replicationSnapshot);
        master.sensors().set(MASTER_LOG_FILE, null);
        master.sensors().set(MASTER_LOG_POSITION, null);
        return replicationSnapshot;
    }
    return null;
}
 
Example 2
Source File: SequenceGroupTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testAlternateGroupConfiguration() throws Exception {
    AttributeSensor<Integer> value = Sensors.newIntegerSensor("test.value");
    AttributeSensor<String> string = Sensors.newStringSensor("test.string");
    group = app.addChild(EntitySpec.create(SequenceGroup.class)
            .configure(SequenceGroup.SEQUENCE_START, 12345)
            .configure(SequenceGroup.SEQUENCE_INCREMENT, 678)
            .configure(SequenceGroup.SEQUENCE_VALUE_SENSOR, value)
            .configure(SequenceGroup.SEQUENCE_STRING_SENSOR, string)
            .configure(SequenceGroup.SEQUENCE_FORMAT, "0x%04X")
            .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.hasInterfaceMatching(".*TestEntity")));
    createTestEntities();
    app.start(ImmutableList.of(loc1));

    assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);

    assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3));
    assertAttributeEquals(e1, value, 12345);
    assertAttributeEquals(e1, string, "0x3039");
    assertAttributeEquals(e2, value, 13023);
    assertAttributeEquals(e2, string, "0x32DF");
    assertAttributeEquals(e3, value, 13701);
    assertAttributeEquals(e3, string, "0x3585");
}
 
Example 3
Source File: OnPublicNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public <T> void testIgnoresNonMatchingSensors() throws Exception {
    AttributeSensor<URI> sensor1 = Sensors.newSensor(URI.class, "my.different");
    AttributeSensor<URL> sensor2 = Sensors.newSensor(URL.class, "my.different2");
    AttributeSensor<String> sensor3 = Sensors.newStringSensor("my.different3");
    AttributeSensor<Integer> sensor4 = Sensors.newIntegerSensor("my.different4");
    AttributeSensor<HostAndPort> sensor5 = Sensors.newSensor(HostAndPort.class, "my.different5");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1");
    entity.sensors().set(sensor1, URI.create("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(sensor2, new URL("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(sensor3, "http://127.0.0.1:1234/my/path");
    entity.sensors().set(sensor4, 1234);
    entity.sensors().set(sensor5, HostAndPort.fromParts("127.0.0.1", 1234));
    portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234);
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class));

    Map<AttributeSensor<?>, Object> allSensors = entity.sensors().getAll();
    String errMsg = "sensors="+allSensors;
    for (AttributeSensor<?> sensor : allSensors.keySet()) {
        String name = sensor.getName();
        assertFalse(name.startsWith("my.different") && sensor.getName().contains("public"), errMsg);
    }
}
 
Example 4
Source File: OnPublicNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public <T> void testDoesNotDoRegexMatchingWhenSensorsSpecified() throws Exception {
    AttributeSensor<String> sensor = Sensors.newStringSensor("mysensor");
    AttributeSensor<Integer> intPort = Sensors.newIntegerSensor("int.port");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1");
    entity.sensors().set(intPort, 1234);
    entity.sensors().set(sensor, "127.0.0.1:1234");
    portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234);
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
            .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(sensor)));

    assertAttributeEqualsEventually("mysensor.mapped.public", "mypublichost:5678");
    assertAttributeEqualsContinually("int.endpoint.mapped.public", null, VERY_SHORT_WAIT);
}
 
Example 5
Source File: EffectorExceptionLoggedTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testResizeFailsWhenEntitlementThrowsShouldLogException() throws Exception {
    final AttributeSensor<Integer> scalingMetric = Sensors.newIntegerSensor("scalingMetric");
    
    ControlledDynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)
            .configure("initialSize", 1)
            .configure(ControlledDynamicWebAppCluster.CONTROLLER_SPEC, EntitySpec.create(TrackingAbstractController.class))
            .configure(ControlledDynamicWebAppCluster.MEMBER_SPEC, EntitySpec.create(TestJavaWebAppEntity.class))
            .policy(PolicySpec.create(AutoScalerPolicy.class)
                    .configure(AutoScalerPolicy.METRIC, scalingMetric)
                    .configure(AutoScalerPolicy.MIN_POOL_SIZE, 1)
                    .configure(AutoScalerPolicy.MAX_POOL_SIZE, 2)
                    .configure(AutoScalerPolicy.METRIC_LOWER_BOUND, 1)
                    .configure(AutoScalerPolicy.METRIC_UPPER_BOUND, 10)));
    
    Entitlements.setEntitlementContext(new EntitlementContext() {
            @Override
            public String user() {
                return "myuser";
            }});
    app.start(ImmutableList.of(loc));
    Entitlements.clearEntitlementContext();

    String loggerName = EffectorUtils.class.getName();
    ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG;
    Predicate<ILoggingEvent> filter = Predicates.and(EventPredicates.containsMessage("Error invoking "), 
            EventPredicates.containsExceptionStackLine(ThrowingEntitlementManager.class, "isEntitled"));
    LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter);
            
    watcher.start();
    try {
        // Cause the auto-scaler to resize, which will fail because of the bad entitlement implementation
        cluster.sensors().set(scalingMetric, 50);
        watcher.assertHasEventEventually();
    } finally {
        watcher.close();
    }
}
 
Example 6
Source File: DockerContainerImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
    super.init();

    String imageName = config().get(DockerContainer.IMAGE_NAME);
    if (!Strings.isNullOrEmpty(imageName)) {
        config().set(PROVISIONING_PROPERTIES.subKey("imageId"), imageName);
    }

    if (Boolean.TRUE.equals(config().get(DockerContainer.DISABLE_SSH))) {
        config().set(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true);
        config().set(PROVISIONING_PROPERTIES.subKey("useJcloudsSshInit"), false);
        config().set(PROVISIONING_PROPERTIES.subKey("waitForSshable"), false);
        config().set(PROVISIONING_PROPERTIES.subKey("pollForFirstReachableAddress"), false);
        config().set(EmptySoftwareProcessImpl.USE_SSH_MONITORING, false);
    }

    ImmutableSet.Builder<AttributeSensor<Integer>> builder = ImmutableSet.builder();
    List<String> portRanges = MutableList.copyOf(config().get(DockerContainer.INBOUND_TCP_PORTS));
    for (String portRange : portRanges) {
        Iterator<Integer> iterator = PortRanges.fromString(portRange).iterator();
        while (iterator.hasNext()) {
            Integer port = iterator.next();
            AttributeSensor<Integer> element = Sensors.newIntegerSensor("docker.port." + port);
            sensors().set(element, port);
            builder.add(element);
        }
    }

    enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class).configure(OnPublicNetworkEnricher.SENSORS, builder.build()));
}
 
Example 7
Source File: KubernetesLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void registerPortMappings(KubernetesSshMachineLocation machine, Entity entity, Service service) {
    PortForwardManager portForwardManager = (PortForwardManager) getManagementContext().getLocationRegistry()
            .getLocationManaged(PortForwardManagerLocationResolver.PFM_GLOBAL_SPEC);
    List<ServicePort> ports = service.getSpec().getPorts();
    String publicHostText = machine.getSshHostAndPort().getHostText();
    LOG.debug("Recording port-mappings for container {} of {}: {}", machine, this, ports);

    for (ServicePort port : ports) {
        String protocol = port.getProtocol();
        Integer targetPort = port.getTargetPort().getIntVal();

        if (!"TCP".equalsIgnoreCase(protocol)) {
            LOG.debug("Ignoring port mapping {} for {} because only TCP is currently supported", port, machine);
        } else if (targetPort == null) {
            LOG.debug("Ignoring port mapping {} for {} because targetPort.intValue is null", port, machine);
        } else if (port.getNodePort() == null) {
            LOG.debug("Ignoring port mapping {} to {} because port.getNodePort() is null", targetPort, machine);
        } else {
            portForwardManager.associate(publicHostText, HostAndPort.fromParts(publicHostText, port.getNodePort()), machine, targetPort);
            AttributeSensor<Integer> sensor = Sensors.newIntegerSensor("kubernetes." + Strings.maybeNonBlank(port.getName()).or(targetPort.toString()) + ".port");
            entity.sensors().set(sensor, targetPort);
        }
    }

    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
            .configure(AbstractOnNetworkEnricher.MAP_MATCHING, "kubernetes.[a-zA-Z0-9][a-zA-Z0-9-_]*.port"));
}
 
Example 8
Source File: TransformerEnricherWithDslTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 9
Source File: AutoScalerPolicyNoMoreMachinesTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetricResizingBeyondMaxMachines() throws Exception {
    AttributeSensor<Integer> metric = Sensors.newIntegerSensor("test.aggregatedLoad");
    
    cluster.resize(1);
    policy = cluster.policies().add(PolicySpec.create(AutoScalerPolicy.class)
            .configure(AutoScalerPolicy.METRIC, metric)
            .configure(AutoScalerPolicy.METRIC_LOWER_BOUND, 10)
            .configure(AutoScalerPolicy.METRIC_UPPER_BOUND, 20)
            .configure(AutoScalerPolicy.MIN_PERIOD_BETWEEN_EXECS, Duration.millis(10)));

    // Single node trying to handle a load of 21; too high, so will add one more node.
    // That takes the load back to within acceptable limits
    cluster.sensors().set(metric, 21);
    assertSizeEventually(2);
    cluster.sensors().set(metric, 19);

    // With two nodes, load is now too high, so will try (and fail) to add one more node.
    // Trigger another attempt to resize.
    // Any nodes that fail with NoMachinesAvailableException will be immediately deleted.
    cluster.sensors().set(metric, 22);
    assertSizeEventually(2, 0, 1);
    assertSizeContinually(2, 0, 1);
    
    // Metric is re-published; should not keep retrying
    cluster.sensors().set(metric, 21);
    assertSizeContinually(2, 0, 1);
}
 
Example 10
Source File: WindowsPerformanceCounterFeedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPerfCountersToSensors() {
    AttributeSensor<String> stringSensor = Sensors.newStringSensor("foo.bar");
    AttributeSensor<Integer> integerSensor = Sensors.newIntegerSensor("bar.baz");
    AttributeSensor<Double> doubleSensor = Sensors.newDoubleSensor("baz.quux");

    Collection<WindowsPerformanceCounterPollConfig<?>> polls = ImmutableSet.<WindowsPerformanceCounterPollConfig<?>>of(
            new WindowsPerformanceCounterPollConfig<>(stringSensor).performanceCounterName("\\processor information(_total)\\% processor time"),
            new WindowsPerformanceCounterPollConfig<>(integerSensor).performanceCounterName("\\integer.sensor"),
            new WindowsPerformanceCounterPollConfig<>(doubleSensor).performanceCounterName("\\double\\sensor\\with\\multiple\\sub\\paths")
    );

    WindowsPerformanceCounterFeed.SendPerfCountersToSensors sendPerfCountersToSensors = new WindowsPerformanceCounterFeed.SendPerfCountersToSensors(entity, polls);

    assertNull(entity.getAttribute(stringSensor));

    StringBuilder responseBuilder = new StringBuilder();
    // NOTE: This builds the response in a different order to which they are passed to the SendPerfCountersToSensors constructor
    // this tests that the values are applied correctly even if the (possibly non-deterministic) order in which
    // they are returned by the Get-Counter scriptlet is different
    addMockResponse(responseBuilder, "\\\\machine.name\\double\\sensor\\with\\multiple\\sub\\paths", "3.1415926");
    addMockResponse(responseBuilder, "\\\\win-lge7uj2blau\\processor information(_total)\\% processor time", "99.9");
    addMockResponse(responseBuilder, "\\\\machine.name\\integer.sensor", "15");

    sendPerfCountersToSensors.onSuccess(new WinRmToolResponse(responseBuilder.toString(), "", 0));

    EntityAsserts.assertAttributeEquals(entity, stringSensor, "99.9");
    EntityAsserts.assertAttributeEquals(entity, integerSensor, 15);
    EntityAsserts.assertAttributeEquals(entity, doubleSensor, 3.1415926);
}
 
Example 11
Source File: TimeFractionDeltaEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun=true)
@Override
public void setUp() throws Exception {
    super.setUp();
    producer = app.addChild(EntitySpec.create(TestEntity.class));
    
    intSensor = Sensors.newIntegerSensor("int sensor");
    fractionSensor = Sensors.newDoubleSensor("fraction sensor");
}
 
Example 12
Source File: AttributeMapTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testModifyAttributeReturningAbsentDoesNotEmit() throws Exception {
    AttributeSensor<Integer> sensor = Sensors.newIntegerSensor("a", "");
    AttributeSensor<Integer> childSensor = Sensors.newIntegerSensor("a.b", "");
    
    final RecordingSensorEventListener<Object> listener = new RecordingSensorEventListener<>();
    entityImpl.subscriptions().subscribe(entityImpl, sensor, listener);
    
    map.modify(childSensor, Functions.constant(Maybe.<Integer>absent()));
    
    Asserts.succeedsContinually(new Runnable() {
        @Override public void run() {
            assertTrue(Iterables.isEmpty(listener.getEvents()), "events="+listener.getEvents());
        }});
}
 
Example 13
Source File: OnSubnetNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public <T> void testTransformsAllMatchingSensors() throws Exception {
    AttributeSensor<URI> stronglyTypedUri = Sensors.newSensor(URI.class, "strongly.typed.uri");
    AttributeSensor<String> stringUri = Sensors.newStringSensor("string.uri");
    AttributeSensor<URL> stronglyTypedUrl = Sensors.newSensor(URL.class, "strongly.typed.url");
    AttributeSensor<String> stringUrl = Sensors.newStringSensor("string.url");
    AttributeSensor<Integer> intPort = Sensors.newIntegerSensor("int.port");
    AttributeSensor<String> stringPort = Sensors.newStringSensor("string.port");
    AttributeSensor<HostAndPort> hostAndPort = Sensors.newSensor(HostAndPort.class, "hostAndPort.endpoint");
    AttributeSensor<String> stringHostAndPort = Sensors.newStringSensor("stringHostAndPort.endpoint");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, privateIp);
    entity.sensors().set(stronglyTypedUri, URI.create("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(stringUri, "http://"+publicIp+":1234/my/path");
    entity.sensors().set(stronglyTypedUrl, new URL("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(stringUrl, "http://"+publicIp+":1234/my/path");
    entity.sensors().set(intPort, 1234);
    entity.sensors().set(stringPort, "1234");
    entity.sensors().set(hostAndPort, HostAndPort.fromParts(""+publicIp+"", 1234));
    entity.sensors().set(stringHostAndPort, ""+publicIp+":1234");
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class));

    assertAttributeEqualsEventually("strongly.typed.uri.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("string.uri.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("strongly.typed.url.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("string.url.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("int.endpoint.mapped.subnet", ""+privateIp+":1234");
    assertAttributeEqualsEventually("string.endpoint.mapped.subnet", ""+privateIp+":1234");
    assertAttributeEqualsEventually("hostAndPort.endpoint.mapped.subnet", ""+privateIp+":1234");
    assertAttributeEqualsEventually("stringHostAndPort.endpoint.mapped.subnet", ""+privateIp+":1234");
}
 
Example 14
Source File: OnSubnetNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public <T> void testIgnoresNonMatchingSensors() throws Exception {
    AttributeSensor<URI> sensor1 = Sensors.newSensor(URI.class, "my.different");
    AttributeSensor<URL> sensor2 = Sensors.newSensor(URL.class, "my.different2");
    AttributeSensor<String> sensor3 = Sensors.newStringSensor("my.different3");
    AttributeSensor<Integer> sensor4 = Sensors.newIntegerSensor("my.different4");
    AttributeSensor<HostAndPort> sensor5 = Sensors.newSensor(HostAndPort.class, "my.different5");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, privateIp);
    entity.sensors().set(sensor1, URI.create("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(sensor2, new URL("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(sensor3, "http://"+publicIp+":1234/my/path");
    entity.sensors().set(sensor4, 1234);
    entity.sensors().set(sensor5, HostAndPort.fromParts(publicIp, 1234));
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class));

    Asserts.succeedsContinually(ImmutableMap.of("timeout", VERY_SHORT_WAIT), new Runnable() {
        @Override public void run() {
            Map<AttributeSensor<?>, Object> allSensors = entity.sensors().getAll();
            String errMsg = "sensors="+allSensors;
            for (AttributeSensor<?> sensor : allSensors.keySet()) {
                String name = sensor.getName();
                assertFalse(name.startsWith("my.different") && sensor.getName().contains("subnet"), errMsg);
            }
        }});
}
 
Example 15
Source File: OnPublicNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public <T> void testTransformsAllMatchingSensors() throws Exception {
    AttributeSensor<URI> stronglyTypedUri = Sensors.newSensor(URI.class, "strongly.typed.uri");
    AttributeSensor<String> stringUri = Sensors.newStringSensor("string.uri");
    AttributeSensor<URL> stronglyTypedUrl = Sensors.newSensor(URL.class, "strongly.typed.url");
    AttributeSensor<String> stringUrl = Sensors.newStringSensor("string.url");
    AttributeSensor<Integer> intPort = Sensors.newIntegerSensor("int.port");
    AttributeSensor<String> stringPort = Sensors.newStringSensor("string.port");
    AttributeSensor<Integer> portNoPrefix = Sensors.newIntegerSensor("port");
    AttributeSensor<HostAndPort> endpoint = Sensors.newSensor(HostAndPort.class, "hostAndPort.endpoint");
    AttributeSensor<String> stringEndpoint = Sensors.newStringSensor("string.hostAndPort.endpoint");
    AttributeSensor<HostAndPort> hostAndPort = Sensors.newSensor(HostAndPort.class, "example.hostAndPort");
    AttributeSensor<String> stringHostAndPort = Sensors.newStringSensor("string.hostAndPort");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1");
    entity.sensors().set(stronglyTypedUri, URI.create("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(stringUri, "http://127.0.0.1:1234/my/path");
    entity.sensors().set(stronglyTypedUrl, new URL("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(stringUrl, "http://127.0.0.1:1234/my/path");
    entity.sensors().set(intPort, 1234);
    entity.sensors().set(stringPort, "1234");
    entity.sensors().set(portNoPrefix, 1234);
    entity.sensors().set(endpoint, HostAndPort.fromParts("127.0.0.1", 1234));
    entity.sensors().set(stringEndpoint, "127.0.0.1:1234");
    entity.sensors().set(hostAndPort, HostAndPort.fromParts("127.0.0.1", 1234));
    entity.sensors().set(stringHostAndPort, "127.0.0.1:1234");
    portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234);
    entity.addLocations(ImmutableList.of(machine));

    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class));

    assertAttributeEqualsEventually("strongly.typed.uri.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("string.uri.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("strongly.typed.url.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("string.url.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("int.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("string.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("hostAndPort.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("string.hostAndPort.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("example.hostAndPort.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("string.hostAndPort.mapped.public", "mypublichost:5678");
}