Exemplo n.º 1
0
  /**
   * Test : verify the PreconditionException is thrown when actionCheckDelay > 0
   *
   * @throws Exception
   */
  public void testActionCheckPreCondition1() throws Exception {
    Instrumentation inst = Services.get().get(InstrumentationService.class).get();

    WorkflowJobBean job =
        this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action =
        this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP);

    ActionCheckXCommand checkCmd = new ActionCheckXCommand(action.getId(), 10);

    long counterVal;

    try {
      counterVal =
          inst.getCounters()
              .get(XCommand.INSTRUMENTATION_GROUP)
              .get(checkCmd.getName() + ".preconditionfailed")
              .getValue();
    } catch (NullPointerException e) {
      // counter might be null
      counterVal = 0L;
    }

    assertEquals(0L, counterVal);

    checkCmd.call();

    // precondition failed because of actionCheckDelay > 0
    counterVal =
        inst.getCounters()
            .get(XCommand.INSTRUMENTATION_GROUP)
            .get(checkCmd.getName() + ".preconditionfailed")
            .getValue();
    assertEquals(1L, counterVal);
  }
 /**
  * Instruments the configuration service.
  *
  * <p>It sets instrumentation variables indicating the config dir and config file used.
  *
  * @param instr instrumentation to use.
  */
 public void instrument(Instrumentation instr) {
   instr.addVariable(
       INSTRUMENTATION_GROUP,
       "config.dir",
       new Instrumentation.Variable<String>() {
         public String getValue() {
           return configDir;
         }
       });
   instr.addVariable(
       INSTRUMENTATION_GROUP,
       "config.file",
       new Instrumentation.Variable<String>() {
         public String getValue() {
           return configFile;
         }
       });
 }
Exemplo n.º 3
0
  /**
   * Test : verify the PreconditionException is thrown when job != RUNNING && job != SUSPENDED
   *
   * @throws Exception
   */
  public void testActionCheckPreCondition4() throws Exception {
    Instrumentation inst = Services.get().get(InstrumentationService.class).get();

    WorkflowJobBean job =
        this.addRecordToWfJobTable(WorkflowJob.Status.FAILED, WorkflowInstance.Status.FAILED);
    WorkflowActionBean action =
        this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING);

    ActionCheckXCommand checkCmd = new ActionCheckXCommand(action.getId());

    long counterVal;

    try {
      counterVal =
          inst.getCounters()
              .get(XCommand.INSTRUMENTATION_GROUP)
              .get(checkCmd.getName() + ".preconditionfailed")
              .getValue();
    } catch (NullPointerException e) {
      // counter might be null
      counterVal = 0L;
    }

    assertEquals(0L, counterVal);

    checkCmd.call();

    // precondition failed because of job != RUNNING && job != SUSPENDED
    counterVal =
        inst.getCounters()
            .get(XCommand.INSTRUMENTATION_GROUP)
            .get(checkCmd.getName() + ".preconditionfailed")
            .getValue();
    assertEquals(1L, counterVal);

    job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING);

    checkCmd = new ActionCheckXCommand(action.getId());

    checkCmd.call();

    // precondition passed because job == RUNNING so counter shouldn't have incremented
    counterVal =
        inst.getCounters()
            .get(XCommand.INSTRUMENTATION_GROUP)
            .get(checkCmd.getName() + ".preconditionfailed")
            .getValue();
    assertEquals(1L, counterVal);

    job =
        this.addRecordToWfJobTable(WorkflowJob.Status.SUSPENDED, WorkflowInstance.Status.SUSPENDED);
    action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING);

    checkCmd = new ActionCheckXCommand(action.getId());

    checkCmd.call();

    // precondition passed because job == SUSPENDED so counter shouldn't have incremented
    counterVal =
        inst.getCounters()
            .get(XCommand.INSTRUMENTATION_GROUP)
            .get(checkCmd.getName() + ".preconditionfailed")
            .getValue();
    assertEquals(1L, counterVal);

    job =
        this.addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING);

    checkCmd = new ActionCheckXCommand(action.getId());

    checkCmd.call();

    // precondition failed because of job != RUNNING && job != SUSPENDED
    counterVal =
        inst.getCounters()
            .get(XCommand.INSTRUMENTATION_GROUP)
            .get(checkCmd.getName() + ".preconditionfailed")
            .getValue();
    assertEquals(2L, counterVal);

    job = this.addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED);
    action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING);

    checkCmd = new ActionCheckXCommand(action.getId());

    checkCmd.call();

    // precondition failed because of job != RUNNING && job != SUSPENDED
    counterVal =
        inst.getCounters()
            .get(XCommand.INSTRUMENTATION_GROUP)
            .get(checkCmd.getName() + ".preconditionfailed")
            .getValue();
    assertEquals(3L, counterVal);
  }
Exemplo n.º 4
0
 /**
  * Convenience method for instrumentation counters.
  *
  * @param name counter name.
  * @param count count to increment the counter.
  */
 private void incrCounter(String name, int count) {
   if (instrumentation != null) {
     instrumentation.incr(INSTRUMENTATION_GROUP, name, count);
   }
 }