Exemplo n.º 1
0
  /** The plan body. */
  public void body() {
    TestReport tr = new TestReport("#1", "Test normal timed wait.");
    long start = getTime();
    long test = 200;
    waitFor(test);
    long dur = getTime() - start;
    double diff = ((double) Math.abs(dur - test)) / ((double) test) * 100;
    if (diff < 5) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Difference greater than 5 percent: " + diff);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#2", "Testing timeout with catch.");
    try {
      //			waitFor(IFilter.NEVER, 200);
      waitForWaitAbstraction(createWaitAbstraction(), 200);
      tr.setReason("No timeout exception occurred.");
    } catch (TimeoutException e) {
      tr.setSucceeded(true);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    this.tr = new TestReport("#3", "Testing timeout without catch.");
    //		waitFor(IFilter.NEVER, 200);
    waitForWaitAbstraction(createWaitAbstraction(), 200);
    this.tr.setReason("No timeout exception occurred.");
  }
Exemplo n.º 2
0
 /** Test if a short waitFor(...) succeeds. */
 protected void testWait(long wait, TestReport tr) {
   getLogger().info("Now waiting for " + wait + " ms");
   waitFor(wait);
   getLogger().info("Finished waiting");
   if (tr != null) {
     tr.setSucceeded(true);
     getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);
   }
 }
Exemplo n.º 3
0
  /**
   * Test initiating a contract net interaction with given settings.
   *
   * @param executeall True, if all acceptable proposals should be executed.
   * @param cfp_info Use given cfp info (e.g. for default plans)
   */
  protected void performTest(String name, String description, boolean executeall, Object cfp_info) {
    // Create 3 participants with different offers.
    Map[] args = new Map[] {new HashMap(), new HashMap(), new HashMap()};

    args[0].put("offer", new Integer(5));
    args[0].put("execute", Boolean.TRUE);

    args[1].put("offer", new Integer(1));
    args[1].put("execute", Boolean.TRUE);

    args[2].put("offer", new Integer(7));
    args[2].put(
        "execute",
        new Boolean(
            executeall)); // Fails when only one is needed, to check if proposal 5 gets executed.

    List agents = createAgents("/jadex/bdi/testcases/planlib/ICNPReceiver.agent.xml", args);

    TestReport tr = new TestReport(name, description);
    if (assureTest(tr)) {
      try {
        IGoal cnpini = createGoal("cnpcap.icnp_initiate");
        cnpini
            .getParameterSet("receivers")
            .addValues(agents.toArray(new IComponentIdentifier[agents.size()]));
        cnpini.getParameter("cfp").setValue("CFP for a task.");
        cnpini.getParameter("cfp_info").setValue(cfp_info);
        cnpini.getParameter("executeall").setValue(new Boolean(executeall));
        dispatchSubgoalAndWait(cnpini);
        getLogger()
            .info(
                "CNP result:" + SUtil.arrayToString(cnpini.getParameterSet("result").getValues()));

        // Check for correct number of negotiation rounds.
        NegotiationRecord[] history =
            (NegotiationRecord[]) cnpini.getParameterSet("history").getValues();
        if (history.length == 4) // 3 rounds + execution.
        {
          // Check final proposals executed in last round.
          ParticipantProposal[] finalproposals = history[history.length - 1].getProposals();

          if (executeall) {
            // Check number of proposals.
            if (finalproposals.length == 2) {
              // Check values of proposals.
              if (((Number) finalproposals[0].getProposal()).intValue() == 7
                  && ((Number) finalproposals[1].getProposal()).intValue() == 5) {
                // For executeall, both evaluation values should be success.
                if ("success".equals(finalproposals[0].getEvaluation())
                    && "success".equals(finalproposals[1].getEvaluation())) {
                  tr.setSucceeded(true);
                } else {
                  tr.setFailed(
                      "Wrong evaluations for accepted proposals: "
                          + SUtil.arrayToString(finalproposals));
                }
              } else {
                tr.setFailed(
                    "Wrong values for accepted proposals: " + SUtil.arrayToString(finalproposals));
              }
            } else {
              tr.setFailed(
                  "Wrong number of accepted proposals: " + SUtil.arrayToString(finalproposals));
            }
          } else {
            // Check number of proposals.
            if (finalproposals.length == 1) {
              // Check values of proposals.
              if (((Number) finalproposals[0].getProposal()).intValue() == 5) {
                // For not executeall, evaluation value should be success.
                if ("success".equals(finalproposals[0].getEvaluation())) {
                  tr.setSucceeded(true);
                } else {
                  tr.setFailed(
                      "Wrong evaluations for accepted proposals: "
                          + SUtil.arrayToString(finalproposals));
                }
              } else {
                tr.setFailed(
                    "Wrong values for accepted proposals: " + SUtil.arrayToString(finalproposals));
              }
            } else {
              tr.setFailed(
                  "Wrong number of accepted proposals: " + SUtil.arrayToString(finalproposals));
            }
          }
        } else {
          tr.setFailed("Wrong number of negotiation rounds: " + history.length);
        }
      } catch (GoalFailureException e) {
        tr.setFailed("Exception occurred: " + e);
      }
    }

    // Destroy agents first, as setting report might abort plan unexpectedly.
    destroyAgents();

    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);
  }
Exemplo n.º 4
0
  /** The plan body. */
  public void body() {
    IComponentManagementService cms =
        (IComponentManagementService)
            SServiceProvider.getService(
                    getScope().getServiceProvider(), IComponentManagementService.class)
                .get(this);

    TestReport tr = new TestReport("#1", "Start agent as suspended.");
    CreationInfo ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setSuspend(Boolean.TRUE);
    IComponentIdentifier cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    IComponentDescription desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (IComponentDescription.STATE_SUSPENDED.equals(desc.getState())) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not suspended: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#2", "Start agent as master.");
    ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setMaster(Boolean.TRUE);
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getMaster() != null && desc.getMaster().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not master: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#3", "Start agent as daemon.");
    ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setDaemon(Boolean.TRUE);
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getDaemon() != null && desc.getDaemon().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not daemon: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#4", "Start agent as autoshutdown.");
    ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setAutoshutdown(Boolean.TRUE);
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getAutoShutdown() != null && desc.getAutoShutdown().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not autoshutdown: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#5", "Start agent as suspended.");
    ci = new CreationInfo("suspend", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (IComponentDescription.STATE_SUSPENDED.equals(desc.getState())) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not suspended: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#6", "Start agent as master.");
    ci = new CreationInfo("master", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getMaster() != null && desc.getMaster().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not master: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#7", "Start agent as daemon.");
    ci = new CreationInfo("daemon", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getDaemon() != null && desc.getDaemon().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not daemon: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#8", "Start agent as autoshutdown.");
    ci = new CreationInfo("autoshutdown", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getAutoShutdown() != null && desc.getAutoShutdown().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not autoshutdown: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);
  }
Exemplo n.º 5
0
 /** Called when plan failed. */
 public void failed() {
   tr.setSucceeded(true);
   getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);
 }