Example #1
0
  public void startServer() throws Exception {
    String[] vmArgs =
        new String[] {
          "-Dorg.hornetq.logger-delegate-factory-class-name=org.hornetq.jms.SysoutLoggerDelegateFactory"
        };
    serverProcess = SpawnedVMSupport.spawnVM(SpawnedJMSServer.class.getName(), vmArgs, false);
    InputStreamReader isr = new InputStreamReader(serverProcess.getInputStream());

    final BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ((line = br.readLine()) != null) {
      System.out.println("SERVER: " + line);
      line.replace('|', '\n');
      if ("OK".equals(line.trim())) {
        new Thread() {
          @Override
          public void run() {
            try {
              String line = null;
              while ((line = br.readLine()) != null) {
                System.out.println("SERVER: " + line);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }.start();
        return;
      } else if ("KO".equals(line.trim())) {
        // something went wrong with the server, destroy it:
        serverProcess.destroy();
        throw new IllegalStateException("Unable to start the spawned server :" + line);
      }
    }
  }
Example #2
0
  /**
   * @throws Exception
   * @throws InterruptedException
   */
  private void runExternalProcess(final int start, final int end)
      throws Exception, InterruptedException {
    System.err.println("running external process...");
    Process process =
        SpawnedVMSupport.spawnVM(
            this.getClass().getCanonicalName(),
            "-Xms128m -Xmx128m ",
            new String[] {},
            true,
            true,
            Integer.toString(start),
            Integer.toString(end));

    Assert.assertEquals(100, process.waitFor());
  }