Package com.opengamma.engine.calcnode

Examples of com.opengamma.engine.calcnode.MaximumJobItemExecutionWatchdog


      Collections.<ValueSpecification>emptySet(), Collections.<ValueSpecification>emptySet(), ExecutionLogMode.INDICATORS);

  public void testNoAlert() throws Exception {
    final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    try {
      final MaximumJobItemExecutionWatchdog watchdog = new MaximumJobItemExecutionWatchdog();
      watchdog.setMaxJobItemExecutionTime(Timeout.standardTimeoutMillis() / 2);
      watchdog.setScheduler(scheduler);
      final CyclicBarrier barrier = new CyclicBarrier(2);
      (new Thread() {
        @Override
        public void run() {
          try {
            barrier.await(Timeout.standardTimeoutMillis(), TimeUnit.MILLISECONDS);
            barrier.reset();
            watchdog.jobExecutionStarted(JOB);
            watchdog.jobExecutionStopped();
            barrier.await(Timeout.standardTimeoutMillis() * 2, TimeUnit.MILLISECONDS);
            watchdog.jobExecutionStarted(JOB);
            watchdog.jobExecutionStopped();
          } catch (final Exception e) {
            throw new OpenGammaRuntimeException("exception", e);
          }
        }
      }).start();
      barrier.await(Timeout.standardTimeoutMillis(), TimeUnit.MILLISECONDS);
      Thread.sleep(Timeout.standardTimeoutMillis());
      // Watchdog should have run while the thread is alive, but not executing anything
      assertTrue(watchdog.areThreadsAlive());
      barrier.await(Timeout.standardTimeoutMillis(), TimeUnit.MILLISECONDS);
      Thread.sleep(Timeout.standardTimeoutMillis());
      // Watchdog should have run with the thread dead
      assertFalse(watchdog.areThreadsAlive());
    } finally {
      scheduler.shutdown();
    }
  }
View Full Code Here


  }

  public void testAlert() throws Exception {
    final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    try {
      final MaximumJobItemExecutionWatchdog watchdog = new MaximumJobItemExecutionWatchdog();
      watchdog.setMaxJobItemExecutionTime(Timeout.standardTimeoutMillis() / 2);
      watchdog.setScheduler(scheduler);
      final AtomicReference<InterruptedException> caught = new AtomicReference<InterruptedException>();
      final CyclicBarrier barrier = new CyclicBarrier(2);
      (new Thread() {
        @Override
        public void run() {
          try {
            watchdog.jobExecutionStarted(JOB);
            barrier.await(Timeout.standardTimeoutMillis(), TimeUnit.MILLISECONDS);
            Thread.sleep(Timeout.standardTimeoutMillis() * 3);
          } catch (final InterruptedException e) {
            caught.set(e);
          } catch (final Exception e) {
            throw new OpenGammaRuntimeException("exception", e);
          }
        }
      }).start();
      barrier.await(Timeout.standardTimeoutMillis(), TimeUnit.MILLISECONDS);
      assertTrue(watchdog.areThreadsAlive());
      Thread.sleep(Timeout.standardTimeoutMillis());
      // Watchdog will have fired and the default action will have interrupted the thread
      assertFalse(watchdog.areThreadsAlive());
      assertNotNull(caught.get());
    } finally {
      scheduler.shutdown();
    }
  }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.calcnode.MaximumJobItemExecutionWatchdog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.