@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); } }}); }
protected void assertAttributeEqualsEventually(String sensorName, String expectedVal) throws Exception { try { EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newStringSensor(sensorName), expectedVal); } catch (Exception e) { throw new Exception("Failed assertion for sensor '"+sensorName+"'; attributes are "+entity.sensors().getAll(), e); } }
@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); } }
protected void assertAttributeEqualsContinually(String sensorName, String expectedVal, Duration duration) throws Exception { try { // EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", duration), entity, Sensors.newStringSensor(sensorName), expectedVal); // TODO "continually" not actually asserted here because these aren't integration tests; // ideally would have two variants of such tests EntityAsserts.assertAttributeEquals(entity, Sensors.newStringSensor(sensorName), expectedVal); } catch (Exception e) { throw new Exception("Failed assertion for sensor '"+sensorName+"'; attributes are "+entity.sensors().getAll(), e); } } }
protected void assertAttributeEqualsEventually(String sensorName, String expectedVal) throws Exception { try { EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newStringSensor(sensorName), expectedVal); } catch (Exception e) { throw new Exception("Failed assertion for sensor '"+sensorName+"'; attributes are "+entity.sensors().getAll(), e); } }