Пример #1
0
  /**
   * Starts Grid instance. Note that if grid is already started, then it will be looked up and
   * returned from this method.
   *
   * @return Started grid.
   */
  private Grid startGrid() {
    Properties props = System.getProperties();

    gridName = props.getProperty(GRIDGAIN_NAME.name());

    if (!props.containsKey(GRIDGAIN_NAME.name()) || G.state(gridName) != GridFactoryState.STARTED) {
      selfStarted = true;

      // Set class loader for the spring.
      ClassLoader curCl = Thread.currentThread().getContextClassLoader();

      // Add no-op logger to remove no-appender warning.
      Appender app = new NullAppender();

      Logger.getRootLogger().addAppender(app);

      try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        Grid grid = G.start(cfgPath);

        gridName = grid.name();

        System.setProperty(GRIDGAIN_NAME.name(), grid.name());

        return grid;
      } catch (GridException e) {
        throw new GridRuntimeException("Failed to start grid: " + cfgPath, e);
      } finally {
        Logger.getRootLogger().removeAppender(app);

        Thread.currentThread().setContextClassLoader(curCl);
      }
    }

    return G.grid(gridName);
  }
  /**
   * Starts the local node and checks for presence of log file. Also checks that this is really a
   * log of a started node.
   *
   * @param id Test-local node ID.
   * @throws Exception If error occurred.
   */
  private void checkOneNode(int id) throws Exception {
    try (Grid grid = G.start(getConfiguration("grid" + id))) {
      String id8 = U.id8(grid.localNode().id());
      String logPath = "work/log/gridgain-" + id8 + ".log";
      File logFile = U.resolveGridGainPath(logPath);

      assertNotNull("Failed to resolve path: " + logPath, logFile);
      assertTrue("Log file does not exist: " + logFile, logFile.exists());

      String logContent = U.readFileToString(logFile.getAbsolutePath(), "UTF-8");

      assertTrue(
          "Log file does not contain it's node ID: " + logFile,
          logContent.contains(">>> Local node [ID=" + id8.toUpperCase()));
    }
  }
Пример #3
0
 /** Stops grid only if it was started by this test suite. */
 private void stopGrid() {
   // Only stop grid if it was started here.
   if (selfStarted) {
     G.stop(gridName, true);
   }
 }