@Test
  public void testExternalAbort() throws Exception {
    printTitle("testExternalAbort");
    String source = "src/test/resources/cosim/externalAbort.cml";

    ConsoleWatcher watch =
        new ConsoleWatcher("coordinator", "A aborted with error:999 execution error");

    final ProcessInfo coordinator = setUpCoordinator(source, "P", "A", watch);

    setUpExternalClient(SubSystem.class, "A", new String[] {port.toString()});

    watch.setMatchHandler(
        new IMatchHandler() {

          @Override
          public void matched(IConsoleWatcher watch) {
            System.out.println("Match handler killing");
            killAllProcesses();
            self.interrupt();
          }
        });

    waitForCompletion(coordinator.process, DEFAULT_TIMEOUT);

    Assert.assertTrue("Simulators did not abort successfully", watch.isMatched());
  }
  public ProcessInfo setUpCoordinator(
      String file,
      String mainProcess,
      String delegatedProcesses,
      ConsoleWatcher... additionalWatches)
      throws Exception {
    Process process =
        startSecondJVM(
            CMLJ.class,
            new String[] {
              "-process",
              mainProcess,
              "-delegatedprocessed",
              delegatedProcesses,
              "-mode",
              "server",
              "-cosimport",
              port.toString(),
              "-simulate",
              file.replace('/', File.separatorChar)
            });
    ConsoleWatcher watch = new ConsoleWatcher("coordinator", ConsoleWatcher.FINISHED_MATCH_TEXT);
    ConsoleWatcher listningWatch = new ConsoleWatcher("coordinator", "Waiting for clients...");
    this.watched.add(watch);

    ConsoleWatcher[] watches = new ConsoleWatcher[2 + additionalWatches.length];
    watches[0] = watch;
    watches[1] = listningWatch;
    if (additionalWatches.length > 0) {
      int i = 2;
      for (int j = 0; j < additionalWatches.length; j++, i++) {
        watches[i] = additionalWatches[j];
      }
    }
    startAutoRead(process, "server", quiet, watches);

    int time = 0;
    final int RETRY_WAIT = 200;
    while (!listningWatch.isMatched()) {
      int exit = 0;
      try {
        try {
          // the build server is slow
          Thread.sleep(500);
        } catch (InterruptedException e) {

        }
        process.exitValue();
        exit = -1;
      } catch (IllegalThreadStateException e) {

      }
      if (time * 1000 >= DEFAULT_TIMEOUT || exit == -1) {
        throw new TimeoutException("Server never started to listen for clients");
      }
      Utils.milliPause(RETRY_WAIT);
      time += RETRY_WAIT;
    }
    return new ProcessInfo(process, watch);
  }
  @Test
  public void testMainDeadlocked() throws Exception {
    printTitle("testMainDeadlocked");
    String source = "src/test/resources/cosim/main-deadlocked.cml";
    final ConsoleWatcher deadlockedWatch =
        new ConsoleWatcher("Main", SIMULATOR_STATUS_EVENT_DEADLOCKED);
    ProcessInfo coordinator = setUpCoordinator(source, "P", "B", deadlockedWatch);
    setUpClient(source, "B");

    waitForCompletion(coordinator.process, DEFAULT_TIMEOUT);

    Assert.assertTrue("Simulators did not finish successfully", deadlockedWatch.isMatched());
  }