Package fm.last.citrine.model

Examples of fm.last.citrine.model.Task


   * @throws InterruptedException
   */
  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  public void testRunNow_ChildDiamond_StopOnError_2And3Fail() throws InterruptedException {
    String group = "diamondTest";
    Task task1 = new Task("task1", group, BEAN_WAIT_JOB, true, true, "3000", "");
    taskManager.save(task1);
    // set tasks 2 and 3 to fail
    Task task2 = new Task("task2", group, "failJob", true, true, "true", "");
    taskManager.save(task2);
    Task task3 = new Task("task3", group, "failJob", true, true, "true", "");
    taskManager.save(task3);
    Task task4 = new Task("task4", group, BEAN_WAIT_JOB, true, true, "1000", "");
    taskManager.save(task4);

    // now create our task "diamond"
    task1.addChildTask(task2);
    task1.addChildTask(task3);
View Full Code Here


    assertEquals(0, taskRunManager.findByTaskId(100).size());
  }

  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  public void testStopTaskRun() throws InterruptedException {
    Task task = new Task("name", "groupName", "sysExecJob", false, true, "sleep 15", defaultTimerSchedule);
    taskManager.save(task);
    schedulerManager.runTaskNow(task);
    Thread.sleep(1000); // give job time to get started
    long taskRunId = taskRunManager.getMostRecent(task.getId()).getId();
    assertTrue(taskRunManager.isRunning(task.getId()));

    taskRunManager.stop(taskRunId);
    Thread.sleep(1000); // give job time to die
    assertFalse(taskRunManager.isRunning(task.getId()));
    List<TaskRun> taskRuns = taskRunManager.findByTaskId(task.getId());
    assertEquals(1, taskRuns.size());
    TaskRun taskRun = taskRuns.get(0);
    assertEquals(Status.CANCELLED, taskRun.getStatus());

    assertNotNull(taskRun.getStackTrace());
View Full Code Here

  /**
   * Test that scheduling a task to run using a cron trigger works.
   */
  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  public void testTimedScheduledRun() throws InterruptedException {
    Task task = new Task("testTimerScheduledRun", "groupName", "sysExecJob");
    task.setErrorIfRunning(true);
    task.setCommand("sleep 1");
    task.setTimerSchedule("*/10 * * * * ?");
    taskManager.save(task);
    waitForTask(task);

    List<TaskRun> taskRuns = taskRunManager.findByTaskId(task.getId());
    assertEquals(1, taskRuns.size());
    TaskRun taskRun = taskRuns.get(0);
    assertEquals(Status.SUCCESS, taskRun.getStatus());
  }
View Full Code Here

   * set to error if running, so the other runs should show up as aborted.
   */
  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  @DirtiesContext
  public void testTaskConflict_ErrorIfRunningTrue() throws InterruptedException {
    Task task = new Task("errorIfRunningTask", "groupName", "sysExecJob");
    task.setErrorIfRunning(true);
    task.setCommand("sleep 10");
    task.setTimerSchedule("*/3 * * * * ?");
    taskManager.save(task);
    waitForTask(task);

    List<TaskRun> taskRuns = taskRunManager.findByTaskId(task.getId());
    assertTrue(taskRuns.size() >= 3); // should be at least 1 success run and two aborted
    int successCount = 0;
    int abortCount = 0;
    for (TaskRun taskRun : taskRuns) {
      // there might be more than 1 successful run depending on timing above, all others should be aborted
View Full Code Here

   * set NOT to error if running, so the other runs should not show up in task runs table at all.
   */
  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  @DirtiesContext
  public void testTaskConflict_ErrorIfRunningFalse() throws InterruptedException {
    Task task = new Task("noErrorIfRunningTask", "groupName", "sysExecJob");
    task.setErrorIfRunning(false);
    task.setCommand("sleep 10");
    task.setTimerSchedule("*/3 * * * * ?");
    taskManager.save(task);
    waitForTask(task);

    List<TaskRun> taskRuns = taskRunManager.findByTaskId(task.getId());
    assertTrue(taskRuns.size() >= 1); // should be at least 1 run, maybe more depending on timing
    for (TaskRun taskRun : taskRuns) { // all runs should be marked as success (all aborts ignored)
      assertEquals(Status.SUCCESS, taskRun.getStatus());
    }
  }
View Full Code Here

    }
  }

  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  public void testGetCurrentlyRunningTaskIds() throws InterruptedException, SchedulerException {
    Task task = new Task("name", "groupName", "sysExecJob", false, true, "sleep 5", defaultTimerSchedule);
    taskManager.save(task);
    assertEquals(0, schedulerManager.getCurrentlyRunningTaskIds().size());
    schedulerManager.runTaskNow(task);
    Thread.sleep(1000); // give task time to get started
    assertTrue(taskRunManager.isRunning(task.getId()));
    List<Long> taskIds = schedulerManager.getCurrentlyRunningTaskIds();
    assertEquals(1, taskIds.size());
    assertEquals(task.getId(), (long) taskIds.get(0));
    waitForTask(task);
    assertEquals(0, schedulerManager.getCurrentlyRunningTaskIds().size());
  }
View Full Code Here

  }

  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  @DirtiesContext
  public void testReset() throws InterruptedException {
    Task task = new Task("testReset", "groupName", "sysExecJob");
    task.setErrorIfRunning(true);
    task.setCommand("sleep 1");
    task.setTimerSchedule("*/10 * * * * ?");
    taskManager.save(task); // save triggers schedule
    waitForTask(task);

    List<TaskRun> taskRuns = taskRunManager.findByTaskId(task.getId());
    int runCount = taskRuns.size();
    assertTrue(runCount >= 1); // in most cases will be 1, but might get triggered again before we get here
    TaskRun taskRun = taskRuns.get(0);
    assertEquals(Status.SUCCESS, taskRun.getStatus());

    schedulerManager.resetTask(task); // this will delete the job and reschedule it
    Thread.sleep(5000); // wait for job to run at least one more time to check reschedule worked
    waitForTask(task);

    taskRuns = taskRunManager.findByTaskId(task.getId());
    assertTrue(taskRuns.size() > runCount); // should have run at least one more time
  }
View Full Code Here

  @Test(timeout = DEFAULT_TEST_TIMEOUT)
  @DirtiesContext
  public void testPrepareForShutdown() throws InterruptedException {
    assertEquals(SchedulerStatus.STARTED, schedulerManager.getStatus());
    Task task = new Task("name", "groupName", "sysExecJob", false, true, "sleep 5", defaultTimerSchedule);
    taskManager.save(task);
    schedulerManager.runTaskNow(task);
    Thread.sleep(1000); // give task time to get started
    assertTrue(taskRunManager.isRunning(task.getId()));
    schedulerManager.prepareForShutdown();
    // task is still running, so should still be in "preparing for shutdown" mode
    assertEquals(SchedulerStatus.PREPARING_FOR_SHUTDOWN, schedulerManager.getStatus());
    waitForTask(task);
    // task no longer running, ready
    assertEquals(SchedulerStatus.READY_FOR_SHUTDOWN, schedulerManager.getStatus());
    schedulerManager.runTaskNow(task);
    Thread.sleep(1000); // give task time to get started
    assertFalse(taskRunManager.isRunning(task.getId())); // scheduler should not run anything anymore
    assertEquals(SchedulerStatus.READY_FOR_SHUTDOWN, schedulerManager.getStatus());
    schedulerManager.shutdown();
    assertEquals(SchedulerStatus.SHUTDOWN, schedulerManager.getStatus());
  }
View Full Code Here

TOP

Related Classes of fm.last.citrine.model.Task

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.