Exemple #1
0
  protected List<PingData> read(InputStream in) {
    List<PingData> retval = null;
    try {
      while (true) {
        try {
          String name_str = Util.readToken(in);
          String uuid_str = Util.readToken(in);
          String addr_str = Util.readToken(in);
          String coord_str = Util.readToken(in);
          if (name_str == null || uuid_str == null || addr_str == null || coord_str == null) break;

          UUID uuid = null;
          try {
            long tmp = Long.valueOf(uuid_str);
            uuid = new UUID(0, tmp);
          } catch (Throwable t) {
            uuid = UUID.fromString(uuid_str);
          }

          PhysicalAddress phys_addr = new IpAddress(addr_str);
          boolean is_coordinator = coord_str.trim().equals("T") || coord_str.trim().equals("t");

          if (retval == null) retval = new ArrayList<>();
          retval.add(new PingData(uuid, true, name_str, phys_addr).coord(is_coordinator));
        } catch (Throwable t) {
          log.error(Util.getMessage("FailedReadingLineOfInputStream"), t);
        }
      }
      return retval;
    } finally {
      Util.close(in);
    }
  }
  protected void setupStreams(ITestResult result, boolean printMethodName) {
    String test_name = result.getTestClass().getName();
    File dir = new File(output_dir + File.separator + test_name);
    if (!dir.exists()) dir.mkdirs();
    File _tests = new File(dir, TESTS),
        _stdout = new File(dir, STDOUT),
        _stderr = new File(dir, STDERR);
    try {
      Class<?> clazz = result.getTestClass().getRealClass();
      if (!tests.containsKey(clazz)) {
        DataOutputStream output = new DataOutputStream(new FileOutputStream(_tests, true));
        DataOutputStream tmp = tests.putIfAbsent(clazz, output);
        if (tmp != null) {
          Util.close(output);
          output = tmp;
        }
      }

      if (stdout.get() == null) stdout.set(new PrintStream(new FileOutputStream(_stdout, true)));
      if (stderr.get() == null) stderr.set(new PrintStream(new FileOutputStream(_stderr, true)));
      if (printMethodName)
        stdout.get().println("\n\n------------- " + getMethodName(result) + " -----------");
    } catch (IOException e) {
      error(e.toString());
    }
  }
 /** Invoked after all test classes in this test have been run */
 public void onFinish(ITestContext context) {
   try {
     for (DataOutputStream out : tests.values()) Util.close(out);
     tests.clear();
     generateReports();
   } catch (IOException e) {
     error(e.toString());
   } finally {
     System.setOut(old_stdout);
     System.setErr(old_stderr);
   }
 }
  protected static void process(File dir) throws IOException {
    File file = new File(dir, TESTS);
    if (!file.exists()) throw new IOException(file + " not found");
    List<TestCase> test_cases = new ArrayList<>();
    DataInputStream input = new DataInputStream(new FileInputStream(file));
    try {
      for (; ; ) {
        TestCase test_case = new TestCase();
        try {
          test_case.readFrom(input);
          test_cases.add(test_case);
        } catch (Exception e) {
          break;
        }
      }
    } finally {
      Util.close(input);
    }

    if (test_cases.isEmpty()) return;

    Reader stdout_reader = null, stderr_reader = null;
    File tmp = new File(dir, STDOUT);
    if (tmp.exists() && tmp.length() > 0) stdout_reader = new FileReader(tmp);

    tmp = new File(dir, STDERR);
    if (tmp.exists() && tmp.length() > 0) stderr_reader = new FileReader(tmp);
    File parent = dir.getParentFile();
    File xml_file = new File(parent, "TESTS-" + dir.getName() + "-" + parent.getName() + ".xml");
    Writer out = new FileWriter(xml_file);
    String classname = dir.getName();
    String suffix = parent.getName();
    if (suffix != null && !suffix.isEmpty()) classname = classname + "-" + suffix;
    try {
      generateReport(out, classname, test_cases, stdout_reader, stderr_reader);
    } finally {
      out.close();
      if (stdout_reader != null) stdout_reader.close();
      if (stderr_reader != null) stderr_reader.close();
    }
  }
Exemple #5
0
  protected void write(List<PingData> list, OutputStream out) throws Exception {
    try {
      for (PingData data : list) {
        String logical_name = data.getLogicalName();
        Address addr = data.getAddress();
        PhysicalAddress phys_addr = data.getPhysicalAddr();
        if (logical_name == null || addr == null || phys_addr == null) continue;
        out.write(logical_name.getBytes());
        out.write(WHITESPACE);

        out.write(addressAsString(addr).getBytes());
        out.write(WHITESPACE);

        out.write(phys_addr.toString().getBytes());
        out.write(WHITESPACE);

        out.write(
            data.isCoord() ? String.format("T%n").getBytes() : String.format("F%n").getBytes());
      }
    } finally {
      Util.close(out);
    }
  }
 protected static void closeStreams() {
   Util.close(stdout.get());
   stdout.set(null);
   Util.close(stderr.get());
   stderr.set(null);
 }