@Test
 public void testInessentialChildrenFailureDoesNotAbortSecondaryOrFailPrimary() {
   Task<String> t1 = monitorableTask(null, "1", new FailCallable());
   TaskTags.markInessential(t1);
   Task<String> t =
       Tasks.<String>builder()
           .dynamic(true)
           .body(monitorableJob("main"))
           .add(t1)
           .add(monitorableTask("2"))
           .build();
   ec.submit(t);
   releaseAndWaitForMonitorableJob("1");
   Assert.assertFalse(t.blockUntilEnded(TINY_TIME));
   releaseAndWaitForMonitorableJob("2");
   Assert.assertFalse(t.blockUntilEnded(TINY_TIME));
   releaseMonitorableJob("main");
   Assert.assertTrue(t.blockUntilEnded(TIMEOUT));
   Assert.assertEquals(messages, MutableList.of("1", "2", "main"));
   Assert.assertTrue(
       stopwatch.elapsed(TimeUnit.MILLISECONDS) < TIMEOUT.toMilliseconds(),
       "took too long: " + stopwatch);
   Assert.assertFalse(t.isError());
   Assert.assertTrue(t1.isError());
 }
  @Test
  public void testChildrenRunConcurrentlyWithPrimary() {
    Task<String> t =
        Tasks.<String>builder()
            .dynamic(true)
            .body(monitorableJob("main"))
            .add(monitorableTask("1"))
            .add(monitorableTask("2"))
            .build();
    ec.submit(t);
    releaseAndWaitForMonitorableJob("1");
    releaseAndWaitForMonitorableJob("main");
    Assert.assertFalse(t.blockUntilEnded(TINY_TIME));
    releaseMonitorableJob("2");

    Assert.assertTrue(t.blockUntilEnded(TIMEOUT));
    Assert.assertEquals(messages, MutableList.of("1", "main", "2"));
    Assert.assertTrue(
        stopwatch.elapsed(TimeUnit.MILLISECONDS) < TIMEOUT.toMilliseconds(),
        "took too long: " + stopwatch);
    Assert.assertFalse(t.isError());
  }
 protected void logProblem(String type, Object val) {
   if (lastWasProblem && currentProblemLoggedAsWarning) {
     if (log.isDebugEnabled())
       log.debug("Recurring " + type + " reading " + this + " from " + entity + ": " + val);
   } else {
     long nowTime = System.currentTimeMillis();
     // get a non-volatile value
     Long currentProblemStartTimeCache = currentProblemStartTime;
     long expiryTime =
         lastSuccessTime != null
             ? lastSuccessTime + logWarningGraceTime.toMilliseconds()
             : currentProblemStartTimeCache != null
                 ? currentProblemStartTimeCache + logWarningGraceTimeOnStartup.toMilliseconds()
                 : nowTime + logWarningGraceTimeOnStartup.toMilliseconds();
     if (!lastWasProblem) {
       if (expiryTime <= nowTime) {
         currentProblemLoggedAsWarning = true;
         log.warn("Read of " + entity + "->" + sensor + " gave " + type + ": " + val);
         if (log.isDebugEnabled() && val instanceof Throwable)
           log.debug(
               "Trace for " + type + " reading " + entity + "->" + sensor + ": " + val,
               (Throwable) val);
       } else {
         if (log.isDebugEnabled())
           log.debug(
               "Read of "
                   + entity
                   + "->"
                   + sensor
                   + " gave "
                   + type
                   + " (in grace period)"
                   + ": "
                   + val);
       }
       lastWasProblem = true;
       currentProblemStartTime = nowTime;
     } else {
       if (expiryTime <= nowTime) {
         currentProblemLoggedAsWarning = true;
         log.warn(
             "Read of "
                 + entity
                 + "->"
                 + sensor
                 + " gave "
                 + type
                 + " (grace period expired, occurring for "
                 + Duration.millis(nowTime - currentProblemStartTimeCache)
                 + ")"
                 + ": "
                 + val);
         if (log.isDebugEnabled() && val instanceof Throwable)
           log.debug(
               "Trace for " + type + " reading " + entity + "->" + sensor + ": " + val,
               (Throwable) val);
       } else {
         log.debug(
             "Recurring "
                 + type
                 + " reading "
                 + this
                 + " from "
                 + entity
                 + " (still in grace period)"
                 + ": "
                 + val);
       }
     }
   }
 }
 private long tickerAdvance(Duration duration) {
   currentTime.addAndGet(duration.toMilliseconds());
   return tickerCurrentMillis();
 }
示例#5
0
 public Builder period(Duration period) {
   return period(period.toMilliseconds(), TimeUnit.MILLISECONDS);
 }
 protected void logProblem(String type, Object val) {
   if (lastWasProblem && currentProblemLoggedAsWarning) {
     if (log.isTraceEnabled())
       log.trace(
           "Recurring {} reading {} in {}: {}",
           new Object[] {type, this, getBriefDescription(), val});
   } else {
     long nowTime = System.currentTimeMillis();
     // get a non-volatile value
     Long currentProblemStartTimeCache = currentProblemStartTime;
     long expiryTime =
         lastSuccessTime != null
             ? lastSuccessTime + logWarningGraceTime.toMilliseconds()
             : currentProblemStartTimeCache != null
                 ? currentProblemStartTimeCache + logWarningGraceTimeOnStartup.toMilliseconds()
                 : nowTime + logWarningGraceTimeOnStartup.toMilliseconds();
     if (!lastWasProblem) {
       if (expiryTime <= nowTime) {
         currentProblemLoggedAsWarning = true;
         log.warn("Read of " + getBriefDescription() + " gave " + type + ": " + val);
         if (log.isDebugEnabled() && val instanceof Throwable)
           log.debug(
               "Trace for " + type + " reading " + getBriefDescription() + ": " + val,
               (Throwable) val);
       } else {
         if (log.isDebugEnabled())
           log.debug(
               "Read of "
                   + getBriefDescription()
                   + " gave "
                   + type
                   + " (in grace period): "
                   + val);
       }
       lastWasProblem = true;
       currentProblemStartTime = nowTime;
     } else {
       if (expiryTime <= nowTime) {
         currentProblemLoggedAsWarning = true;
         log.warn(
             "Read of "
                 + getBriefDescription()
                 + " gave "
                 + type
                 + " (grace period expired, occurring for "
                 + Duration.millis(nowTime - currentProblemStartTimeCache)
                 + ", "
                 + (config.hasExceptionHandler() ? "" : ", no exception handler set for sensor")
                 + ")"
                 + ": "
                 + val);
         if (log.isDebugEnabled() && val instanceof Throwable)
           log.debug(
               "Trace for " + type + " reading " + getBriefDescription() + ": " + val,
               (Throwable) val);
       } else {
         if (log.isDebugEnabled())
           log.debug(
               "Recurring {} reading {} in {} (still in grace period): {}",
               new Object[] {type, this, getBriefDescription(), val});
       }
     }
   }
 }