Example #1
0
  // THIS ADDS A PART TO THE LANE AND UPDATES AGENT INFO
  @Override
  public void msgDoAddPart(GUIPart guipart) {
    state = State.LANE_MOVING;
    parts.add(guipart);
    if (parts.size() >= almostFull && toldAgentItsFull == false) {
      myAgent.msgGuiLaneAlmostFull();
      toldAgentItsFull = true;
    }
    if (parts.size() < almostFull && toldAgentItsFull == true) {
      myAgent.msgGuiLaneNoLongerFull();
      toldAgentItsFull = false;
    }

    MyPart partAdd = new MyPart(guipart);
    partsLane.add(partAdd);
  }
Example #2
0
  public void testLaneFull() {
    // WIP

    int scheduleCounter = 0;
    System.out.println("------------------------------\n" + "testLaneFull():");

    Lane lane = new LaneAgent("Lane1");
    GUILane guiLane = new GUILane(1, 2, 3, new GUINest(1, 2, 3));

    MockFeeder feeder = new MockFeeder("Feeder1");
    MockDiverter diverter = new MockDiverter("Diverter1");
    MockNest nest = new MockNest("Nest1");

    lane.setFeederAgent(feeder);
    lane.setDiverterAgent(diverter);
    lane.setNestAgent(nest);
    lane.setGuiLane(guiLane);
    guiLane.setLaneAgent(lane);

    assertEquals(
        "Mock Feeder should have an empty event log before the Lane's scheduler is called. Instead, the Mock Feeder's event log reads: "
            + feeder.log.toString(),
        0,
        feeder.log.size());
    assertEquals(
        "Mock Diverter should have an empty event log before the Lane's scheduler is called. Instead, the Mock Diverter's event log reads: "
            + diverter.log.toString(),
        0,
        diverter.log.size());
    assertEquals(
        "Mock Nest should have an empty event log before the Lane's scheduler is called. Instead, the Mock Nest's event log reads: "
            + nest.log.toString(),
        0,
        nest.log.size());

    for (int pn = 0; pn < 7; pn++) {
      // create a part used for testing
      Part part1 = new Part(PartType.A);

      lane.msgPartReady(part1);
      System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
      lane.pickAndExecuteAnAction();
      assertTrue(
          "Mock diverter should have received msgReadyToReceive. Event log: "
              + diverter.log.toString(),
          diverter
              .log
              .getLastLoggedEvent()
              .getMessage()
              .contains("msgReadyToReceive from lane for " + part1.type));

      lane.msgHereIsPart(part1);
      System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
      lane.pickAndExecuteAnAction();
    }

    lane.msgGuiLaneAlmostFull();
    System.out.println("SCHEDULER CALLED **");
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock feeder should have received msgHoldOn. Event log: " + feeder.log.toString(),
        feeder.log.getLastLoggedEvent().getMessage().contains("msgHoldOn"));

    // create a part used for testing
    Part part2 = new Part(PartType.B);

    lane.msgPartReady(part2);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    // gui lane should move all its parts

    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    // gui lane should move all its parts

    lane.msgGuiLaneNoLongerFull();
    System.out.println("SCHEDULER CALLED ***");
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock diverter should have received msgReadyToReceive. Event log: "
            + diverter.log.toString(),
        diverter
            .log
            .getLastLoggedEvent()
            .getMessage()
            .contains("msgReadyToReceive from lane for " + part2.type));

    lane.msgHereIsPart(part2);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();

    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    // GUI Lane should move the parts on the lane here

    System.out.println("END OF TEST");
  }