@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { em = new BasicExecutionManager("mycontext"); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { em = new BasicExecutionManager("mycontext"); data = Collections.synchronizedMap(new HashMap<Integer,String>()); }
@BeforeMethod(alwaysRun=true) public void setUp() { em = new BasicExecutionManager("mycontext"); data = Collections.synchronizedMap(new HashMap<Object, Object>()); data.clear(); }
@BeforeClass public void setup() { em = new BasicExecutionManager("mycontext"); ec = new BasicExecutionContext(em); }
@BeforeMethod(alwaysRun=true) public void setUp() { em = new BasicExecutionManager("mycontext"); ec = new BasicExecutionContext(em); ex = Executors.newCachedThreadPool(); data = Collections.synchronizedMap(new LinkedHashMap<Object,Object>()); started = new Semaphore(0); waitInTask = new Semaphore(0); cancelledWhileSleeping = new Semaphore(0); }
@BeforeMethod public void setUp() { em = new BasicExecutionManager("mycontextid"); em.setTaskSchedulerForTag("category1", SingleThreadedScheduler.class); }
@Override public synchronized ExecutionManager getExecutionManager() { if (!isRunning()) throw new IllegalStateException("Management context no longer running"); if (execution == null) { execution = new BasicExecutionManager(getManagementNodeId()); gc = new BrooklynGarbageCollector(configMap, execution, getStorage()); } return execution; }
@BeforeMethod(alwaysRun=true) public void setUp() { em = new BasicExecutionManager("mycontext"); ec = new BasicExecutionContext(em); cancellations = new Semaphore(0); messages = new ArrayList<String>(); monitorableJobSemaphoreMap = MutableMap.of(); monitorableTasksMap = MutableMap.of(); monitorableTasksMap.clear(); stopwatch = Stopwatch.createStarted(); }
@Test public void testScheduledTaskResubmittedIfExceptionThrownAndCancelOnExceptionFalse() { BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final AtomicInteger calls = new AtomicInteger(0); ScheduledTask t = new ScheduledTask(MutableMap.of("period", Duration.ONE_MILLISECOND, "maxIterations", 5, "cancelOnException", false), new Callable<Task<?>>() { @Override public Task<?> call() throws Exception { return new BasicTask<>(new Callable<Integer>() { @Override public Integer call() { calls.incrementAndGet(); throw new RuntimeException("boo"); }}); }}); m.submit(t); t.blockUntilEnded(); assertEquals(calls.get(), 5, "Expected task to be resubmitted despite throwing an exception"); }
@Test(groups = "Integration") @Override public void testGetMachineDetails() throws Exception { BasicExecutionManager execManager = new BasicExecutionManager("mycontextid"); BasicExecutionContext execContext = new BasicExecutionContext(execManager); try { MachineDetails details = execContext.submit(new Callable<MachineDetails>() { @Override public MachineDetails call() { return host.getMachineDetails(); }}).get(); LOG.info("machineDetails="+details); assertNotNull(details); } finally { execManager.shutdownNow(); } }
final int SLEEP_TIME = 100; final int EARLY_RETURN_GRACE = 10; BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final List<Long> execTimes = new CopyOnWriteArrayList<Long>();
@Test public void testScheduledTask() throws Exception { int PERIOD = 20; BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final AtomicInteger i = new AtomicInteger(0); ScheduledTask t = new ScheduledTask(MutableMap.of("delay", 2*PERIOD, "period", PERIOD, "maxIterations", 5), new Callable<Task<?>>() { @Override public Task<?> call() throws Exception { return new BasicTask<Integer>(new Callable<Integer>() { @Override public Integer call() { log.debug("task running: "+Tasks.current()+" "+Tasks.current().getStatusDetail(false)); return i.incrementAndGet(); }}); }}); log.info("submitting {} {}", t, t.getStatusDetail(false)); m.submit(t); log.info("submitted {} {}", t, t.getStatusDetail(false)); Integer interimResult = (Integer) t.get(); log.info("done one ({}) {} {}", new Object[] {interimResult, t, t.getStatusDetail(false)}); assertTrue(i.get() > 0, "i="+i); t.blockUntilEnded(); Integer finalResult = (Integer) t.get(); log.info("ended ({}) {} {}", new Object[] {finalResult, t, t.getStatusDetail(false)}); assertEquals(finalResult, (Integer)5); assertEquals(i.get(), 5); }
public void testScheduledTaskSelfEnding() throws Exception { int PERIOD = 20; BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final AtomicInteger i = new AtomicInteger(0); ScheduledTask t = new ScheduledTask(MutableMap.of("delay", 2*PERIOD, "period", PERIOD), new Callable<Task<?>>() {
@Test public void testScheduledTaskCancelEnding() throws Exception { Duration PERIOD = Duration.millis(20); BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final AtomicInteger i = new AtomicInteger(); ScheduledTask t = new ScheduledTask(MutableMap.of("delay", PERIOD.times(2), "period", PERIOD), new Callable<Task<?>>() {
BasicExecutionManager em = new BasicExecutionManager("tests"); BasicExecutionContext ec = new BasicExecutionContext(em); taskQueueingResult.executionContext(ec);
@Test public void testScheduledTaskCancelledIfExceptionThrown() throws Exception { BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final AtomicInteger calls = new AtomicInteger(0); ScheduledTask t = new ScheduledTask(MutableMap.of("period", Duration.ONE_MILLISECOND, "maxIterations", 5), new Callable<Task<?>>() { @Override public Task<?> call() throws Exception { return new BasicTask<>(new Callable<Integer>() { @Override public Integer call() { calls.incrementAndGet(); throw new RuntimeException("boo"); }}); }}); m.submit(t); Runnable callsIsOne = new Runnable() { @Override public void run() { if (calls.get() != 1) { throw new RuntimeException("not yet"); } } }; Asserts.succeedsEventually(callsIsOne); Asserts.succeedsContinually(callsIsOne); }
@Test public void runMultipleBasicTasks() throws Exception { data.put(1, 1); BasicExecutionManager em = new BasicExecutionManager("mycontext"); for (int i = 0; i < 2; i++) { em.submit(MutableMap.of("tag", "A"), new BasicTask<Integer>(newIncrementCallable(1))); em.submit(MutableMap.of("tag", "B"), new BasicTask<Integer>(newIncrementCallable((1)))); } int total = 0; for (Object tag : em.getTaskTags()) { log.debug("tag {}", tag); for (Task<?> task : em.getTasksWithTag(tag)) { log.debug("BasicTask {}, has {}", task, task.get()); total += (Integer)task.get(); } } assertEquals(10, total); //now that all have completed: assertEquals(5, data.get(1)); }
@Test public void testGetMachineDetails() throws Exception { String response = Joiner.on("\n").join( "name:Test OS Y", "version:1.2.3", "architecture:x86_64", "ram:1234", "cpus:3"); RecordingSshTool.setCustomResponse(".*uname.*", new CustomResponse(0, response, "")); BasicExecutionManager execManager = new BasicExecutionManager("mycontextid"); BasicExecutionContext execContext = new BasicExecutionContext(execManager); try { MachineDetails details = execContext.submit(new Callable<MachineDetails>() { @Override public MachineDetails call() { return host.getMachineDetails(); }}).get(); LOG.info("machineDetails="+details); assertNotNull(details); assertEquals(details.getOsDetails().getName(), "Test OS Y", "details="+details); assertEquals(details.getOsDetails().getVersion(), "1.2.3", "details="+details); assertEquals(details.getOsDetails().getArch(), "x86_64", "details="+details); assertEquals(details.getHardwareDetails().getCpuCount(), Integer.valueOf(3), "details="+details); assertEquals(details.getHardwareDetails().getRam(), Integer.valueOf(1234), "details="+details); } finally { execManager.shutdownNow(); } }
RecordingSshTool.setCustomResponse(".*uname.*", new CustomResponse(0, response, "")); BasicExecutionManager execManager = new BasicExecutionManager("mycontextid"); BasicExecutionContext execContext = new BasicExecutionContext(execManager); try {
BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final AtomicInteger i = new AtomicInteger(); ScheduledTask t = new ScheduledTask(MutableMap.of("delay", PERIOD.times(2), "period", PERIOD), new Callable<Task<?>>() {