private void assertHasEvent(
     Sensor<?> sensor,
     Predicate<Object> componentPredicate,
     Predicate<? super CharSequence> descriptionPredicate) {
   for (SensorEvent<FailureDescriptor> event : events) {
     if (event.getSensor().equals(sensor)
         && (componentPredicate == null
             || componentPredicate.apply(event.getValue().getComponent()))
         && (descriptionPredicate == null
             || descriptionPredicate.apply(event.getValue().getDescription()))) {
       return;
     }
   }
   fail("No matching " + sensor + " event found; events=" + events);
 }
Пример #2
0
  @Override
  public void onEvent(SensorEvent<Object> event) {
    if (firstUpTime == null) {
      if (event != null
          && Attributes.SERVICE_UP.equals(event.getSensor())
          && Boolean.TRUE.equals(event.getValue())) {
        firstUpTime = event.getTimestamp();
      } else if (event == null && Boolean.TRUE.equals(entity.getAttribute(Attributes.SERVICE_UP))) {
        // If this enricher is registered after the entity is up, then we'll get a "synthetic"
        // onEvent(null)
        firstUpTime = System.currentTimeMillis();
      }
    }

    super.onEvent(event);
  }