⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commonapitest.java

📁 pastry的java实现的2.0b版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//    if (PROTOCOL.equalsIgnoreCase(PROTOCOL_DIRECT)) {//      while (simulator.simulate()) {}//    } else {//      pause(500);//    }  }  /**   * Method which creates a single node, given it's node number   *   * @param num The number of creation order   * @return The created node   */  protected Node createNode(int num) {    PastryNode ret;    if (num == 0) {      ret = factory.newNode((rice.pastry.NodeHandle) null);    } else {      ret = factory.newNode(getBootstrap());    }    synchronized (ret) {      while (!ret.isReady()) {        try {          ret.wait(1000);        } catch (InterruptedException ie) {          ie.printStackTrace();          return null;        }        if (!ret.isReady()) {          if (logger.level <= Logger.INFO) {            logger.log("Node " + ret + " is not yet ready.");          }        }      }    }    return ret;  }  /**   * Method which pauses for the provided number of milliseconds   *   * @param ms The number of milliseconds to pause   */  protected synchronized void pause(int ms) {    if (!PROTOCOL.equalsIgnoreCase(PROTOCOL_DIRECT)) {      try {        wait(ms);      } catch (InterruptedException e) {      }    }  }  /**   * Method which kills the specified node   *   * @param n The node to kill   */  protected void kill(int n) {    //if (PROTOCOL.equalsIgnoreCase(PROTOCOL_DIRECT))    ((PastryNode) nodes[n]).destroy();    if (!PROTOCOL.equalsIgnoreCase(PROTOCOL_DIRECT)) {      // give node time to show up dead      pause(60000);    }//      simulator.setAlive((rice.pastry.NodeId) nodes[n].getId(), false);  }  // ----- METHODS TO BE PROVIDED BY IMPLEMENTATIONS -----  /**   * Method which should process the given newly-created node   *   * @param num The number o the node   * @param node The newly created node   */  protected abstract void processNode(int num, Node node);  /**   * Method which should run the test - this is called once all of the nodes   * have been created and are ready.   */  protected abstract void runTest();  // ----- TESTING UTILITY METHODS -----  /**   * Method which prints the beginning of a test section.   *   * @param name The name of section   */  protected final void sectionStart(String name) {    System.out.println(name);  }  /**   * Method which prints the end of a test section.   */  protected final void sectionDone() {    System.out.println();  }  /**   * Method which prints the beginning of a test section step.   *   * @param name The name of step   */  protected final void stepStart(String name) {    System.out.print(pad("  " + name));  }  /**   * Method which prints the end of a test section step, with an assumed   * success.   */  protected final void stepDone() {    stepDone(SUCCESS);  }  /**   * Method which prints the end of a test section step.   *   * @param status The status of step   */  protected final void stepDone(String status) {    stepDone(status, "");  }  /**   * Method which prints the end of a test section step, as well as a message.   *   * @param status The status of section   * @param message The message   */  protected final void stepDone(String status, String message) {    System.out.println("[" + status + "]");    if ((message != null) && (!message.equals(""))) {      System.out.println("     " + message);    }    if (status.equals(FAILURE)) {      System.exit(0);    }  }  /**   * Method which prints an exception which occured during testing.   *   * @param e The exception which was thrown   */  protected final void stepException(Exception e) {    System.out.println("\nException " + e + " occurred during testing.");    e.printStackTrace();    System.exit(0);  }  /**   * Method which pads a given string with "." characters.   *   * @param start The string   * @return The result.   */  private final String pad(String start) {    if (start.length() >= PAD_SIZE) {      return start.substring(0, PAD_SIZE);    } else {      int spaceLength = PAD_SIZE - start.length();      char[] spaces = new char[spaceLength];      Arrays.fill(spaces, '.');      return start.concat(new String(spaces));    }  }  /**   * Throws an exception if the test condition is not met.   *   * @param intention DESCRIBE THE PARAMETER   * @param test DESCRIBE THE PARAMETER   */  protected final void assertTrue(String intention, boolean test) {    if (!test) {      stepDone(FAILURE, "Assertion '" + intention + "' failed.");    }  }  /**   * Thows an exception if expected is not equal to actual.   *   * @param description DESCRIBE THE PARAMETER   * @param expected DESCRIBE THE PARAMETER   * @param actual DESCRIBE THE PARAMETER   */  protected final void assertEquals(String description,                                    Object expected,                                    Object actual) {    if (!expected.equals(actual)) {      stepDone(FAILURE, "Assertion '" + description +        "' failed, expected: '" + expected +        "' got: " + actual + "'");    }  }  // ----- COMMAND LINE PARSING METHODS -----  /**   * process command line args   *   * @param args DESCRIBE THE PARAMETER   * @return DESCRIBE THE RETURN VALUE   * @exception IOException DESCRIBE THE EXCEPTION   */  protected static Environment parseArgs(String args[]) throws IOException {    // process command line arguments    for (int i = 0; i < args.length; i++) {      if (args[i].equals("-help")) {        System.out.println("Usage: DistCommonAPITest [-params paramsfile] [-port p] [-protocol (direct|socket)] [-bootstrap host[:port]] [-help]");        System.exit(1);      }    }    Parameters params = null;    for (int i = 0; i < args.length; i++) {      if (args[i].equals("-params") && i + 1 < args.length) {        params = new SimpleParameters(Environment.defaultParamFileArray, args[i + 1]);        break;      }    }    if (params == null) {      params = new SimpleParameters(Environment.defaultParamFileArray, null);    }    for (int i = 0; i < args.length; i++) {      if (args[i].equals("-protocol") && i + 1 < args.length) {        params.setString("commonapi_testing_protocol", args[i + 1]);        break;      }    }    for (int i = 0; i < args.length; i++) {      if (args[i].equals("-simulator") && i + 1 < args.length) {        params.setString("direct_simulator_topology", args[i + 1]);        break;      }    }    for (int i = 0; i < args.length; i++) {      if (args[i].equals("-nodes") && i + 1 < args.length) {        int p = Integer.parseInt(args[i + 1]);        if (p > 0) {          params.setInt("commonapi_testing_num_nodes", p);        }        break;      }    }    for (int i = 0; i < args.length; i++) {      if (args[i].equals("-port") && i + 1 < args.length) {        int p = Integer.parseInt(args[i + 1]);        if (p > 0) {          params.setInt("commonapi_testing_startPort", p);        }        break;      }    }    for (int i = 0; i < args.length; i++) {      if (args[i].equals("-bootstrap") && i + 1 < args.length) {        String str = args[i + 1];        int index = str.indexOf(':');        if (index == -1) {          // no port specified          params.setInetSocketAddress("commonapi_testing_bootstrap",            new InetSocketAddress(InetAddress.getByName(str),            params.getInt("commonapi_testing_startPort")));        } else {          params.setString("commonapi_testing_bootstrap", str);        }        break;      }    }    // ----- ATTEMPT TO LOAD LOCAL HOSTNAME -----    if (!params.contains("commonapi_testing_bootstrap")) {      try {        InetAddress localHost = InetAddress.getLocalHost();        params.setInetSocketAddress("commonapi_testing_bootstrap",          new InetSocketAddress(localHost,          params.getInt("commonapi_testing_startPort")));      } catch (UnknownHostException e) {        System.err.println("Error determining local host: " + e);      }    }    TimeSource timeSource;    SelectorManager selector = null;    Processor proc = null;    LogManager logManager = null;    if (params.getString("commonapi_testing_protocol").equals("direct")) {      timeSource = new DirectTimeSource(params);      logManager = Environment.generateDefaultLogManager(timeSource, params);      ((DirectTimeSource) timeSource).setLogManager(logManager);      selector = Environment.generateDefaultSelectorManager(timeSource, logManager);      proc = new SimProcessor(selector);    } else {      timeSource = new SimpleTimeSource();    }    return new Environment(selector, proc, null, timeSource, logManager, params);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -