@Test(groups = "Integration") // Because slow
  public void testRecoversThenDownUpResetsStabilisationCount() throws Exception {
    final long stabilisationDelay = 1000;

    app.addPolicy(
        PolicySpec.create(ConnectionFailureDetector.class)
            .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)
            .configure(
                ConnectionFailureDetector.CONNECTION_RECOVERED_STABILIZATION_DELAY,
                Duration.of(stabilisationDelay)));

    stopServerSocket();
    assertHasEventEventually(HASensors.CONNECTION_FAILED, Predicates.<Object>equalTo(app), null);
    events.clear();

    startServerSocket();
    assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD));

    stopServerSocket();
    Thread.sleep(POLL_PERIOD + OVERHEAD);
    startServerSocket();
    assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD));

    assertHasEventEventually(HASensors.CONNECTION_RECOVERED, Predicates.<Object>equalTo(app), null);
  }
  @Test(groups = "Integration") // Because slow
  public void testNotifiedOfFailureAfterStabilisationDelay() throws Exception {
    final int stabilisationDelay = 1000;

    app.addPolicy(
        PolicySpec.create(ConnectionFailureDetector.class)
            .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)
            .configure(
                ConnectionFailureDetector.CONNECTION_FAILED_STABILIZATION_DELAY,
                Duration.of(stabilisationDelay)));

    stopServerSocket();

    assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD));
    assertHasEventEventually(HASensors.CONNECTION_FAILED, Predicates.<Object>equalTo(app), null);
  }
Esempio n. 3
0
 private String getFailureDescription(long now) {
   String description = null;
   Map<String, Object> serviceProblems = entity.getAttribute(Attributes.SERVICE_PROBLEMS);
   if (serviceProblems != null && !serviceProblems.isEmpty()) {
     Entry<String, Object> problem = serviceProblems.entrySet().iterator().next();
     description = problem.getKey() + ": " + problem.getValue();
     if (serviceProblems.size() > 1) {
       description = serviceProblems.size() + " service problems, including " + description;
     } else {
       description = "service problem: " + description;
     }
   } else if (Boolean.FALSE.equals(entity.getAttribute(Attributes.SERVICE_UP))) {
     description = "service not up";
   } else {
     description = "service failure detected";
   }
   if (publishEntityFailedTime != null
       && currentFailureStartTime != null
       && publishEntityFailedTime > currentFailureStartTime)
     description =
         " (stabilized for "
             + Duration.of(now - currentFailureStartTime, TimeUnit.MILLISECONDS)
             + ")";
   return description;
 }
  @Test
  public void testInvokeStopEntityTimesOutOnShutdown() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    BlockingEntity blockingEntity =
        app.createAndManageChild(
            EntitySpec.create(BlockingEntity.class)
                .configure(BlockingEntity.SHUTDOWN_LATCH, latch));

    // It will timeout after shutdown-timeout
    BrooklynShutdownHooks.setShutdownTimeout(Duration.of(100, TimeUnit.MILLISECONDS));
    BrooklynShutdownHooks.invokeStopOnShutdown(blockingEntity);
    BrooklynShutdownHooks.BrooklynShutdownHookJob job =
        BrooklynShutdownHookJob.newInstanceForTesting();
    job.run();

    latch.countDown();
  }
Esempio n. 5
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  protected void recomputeAfterDelay(long delay) {
    if (isRunning() && executorQueued.compareAndSet(false, true)) {
      long now = System.currentTimeMillis();
      delay = Math.max(0, Math.max(delay, (executorTime + MIN_PERIOD_BETWEEN_EXECS_MILLIS) - now));
      if (LOG.isTraceEnabled()) LOG.trace("{} scheduling publish in {}ms", this, delay);

      Runnable job =
          new Runnable() {
            @Override
            public void run() {
              try {
                executorTime = System.currentTimeMillis();
                executorQueued.set(false);

                onEvent(null);

              } catch (Exception e) {
                if (isRunning()) {
                  LOG.error("Error in enricher " + this + ": " + e, e);
                } else {
                  if (LOG.isDebugEnabled())
                    LOG.debug("Error in enricher " + this + " (but no longer running): " + e, e);
                }
              } catch (Throwable t) {
                LOG.error("Error in enricher " + this + ": " + t, t);
                throw Exceptions.propagate(t);
              }
            }
          };

      ScheduledTask task =
          new ScheduledTask(
              MutableMap.of("delay", Duration.of(delay, TimeUnit.MILLISECONDS)),
              new BasicTask(job));
      ((EntityInternal) entity).getExecutionContext().submit(task);
    }
  }
  protected void schedulePublish(long delay) {
    if (isRunning() && executorQueued.compareAndSet(false, true)) {
      long now = System.currentTimeMillis();
      delay = Math.max(0, Math.max(delay, (executorTime + MIN_PERIOD_BETWEEN_EXECS_MILLIS) - now));
      if (LOG.isTraceEnabled()) LOG.trace("{} scheduling publish in {}ms", this, delay);

      Runnable job =
          new Runnable() {
            @Override
            public void run() {
              try {
                executorTime = System.currentTimeMillis();
                executorQueued.set(false);

                publishNow();

              } catch (Exception e) {
                if (isRunning()) {
                  LOG.error("Problem resizing: " + e, e);
                } else {
                  if (LOG.isDebugEnabled())
                    LOG.debug("Problem resizing, but no longer running: " + e, e);
                }
              } catch (Throwable t) {
                LOG.error("Problem in service-failure-detector: " + t, t);
                throw Exceptions.propagate(t);
              }
            }
          };

      ScheduledTask task =
          new ScheduledTask(
              MutableMap.of("delay", Duration.of(delay, TimeUnit.MILLISECONDS)),
              new BasicTask(job));
      ((EntityInternal) entity).getExecutionContext().submit(task);
    }
  }
Esempio n. 7
0
 public Builder period(long val, TimeUnit units) {
   return period(Duration.of(val, units));
 }