@Test(groups = "Integration")
  public void testPollsUrl() throws Exception {
    entity.setAttribute(TestEntity.SERVICE_UP, true);

    entity.addEnricher(
        HttpLatencyDetector.builder()
            .url(baseUrl)
            .rollup(500, TimeUnit.MILLISECONDS)
            .period(100, TimeUnit.MILLISECONDS)
            .build());

    assertLatencyAttributesNonNull(entity);
  }
  @Test(groups = "Integration")
  public void testGetsSensorIfAlredySetThenPolls() throws Exception {
    entity.setAttribute(TEST_URL, baseUrl.toString());

    entity.addEnricher(
        HttpLatencyDetector.builder()
            .url(TEST_URL)
            .noServiceUp()
            .rollup(500, TimeUnit.MILLISECONDS)
            .period(100, TimeUnit.MILLISECONDS)
            .build());

    assertLatencyAttributesNonNull(entity);
  }
  @Test(groups = "Integration")
  public void testWaitsForServiceUp() throws Exception {
    entity.setAttribute(TestEntity.SERVICE_UP, false);

    entity.addEnricher(
        HttpLatencyDetector.builder().url(baseUrl).period(100, TimeUnit.MILLISECONDS).build());

    // nothing until url is set
    EntityTestUtils.assertAttributeEqualsContinually(
        MutableMap.of("timeout", 200),
        entity,
        HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT,
        null);

    // gets value after url is set, and gets rolling average
    entity.setAttribute(TestEntity.SERVICE_UP, true);
    assertLatencyAttributesNonNull(entity);
  }
  @Test
  public void testServiceFailureDetectorWorksAfterRebind() throws Exception {
    origEntity.addEnricher(EnricherSpec.create(ServiceFailureDetector.class));

    // rebind
    TestApplication newApp = rebind();
    final TestEntity newEntity =
        (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class));

    newApp
        .getManagementContext()
        .getSubscriptionManager()
        .subscribe(newEntity, HASensors.ENTITY_FAILED, eventListener);

    newEntity.setAttribute(TestEntity.SERVICE_UP, true);
    ServiceStateLogic.setExpectedState(newEntity, Lifecycle.RUNNING);

    // trigger the failure
    newEntity.setAttribute(TestEntity.SERVICE_UP, false);

    assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(newEntity), null);
    assertEquals(events.size(), 1, "events=" + events);
  }