/** {@inheritDoc} */
  @Override
  public void tearDown() {
    if (appender != null) {
      Logger.getRootLogger().removeAppender(GridLog4jRollingFileAppender.class.getSimpleName());

      GridLog4jLogger.removeAppender(appender);
    }
  }
  /** {@inheritDoc} */
  @Override
  protected void setUp() throws Exception {
    Logger root = Logger.getRootLogger();

    for (Enumeration appenders = root.getAllAppenders(); appenders.hasMoreElements(); ) {
      if (appenders.nextElement() instanceof GridLog4jRollingFileAppender) return;
    }

    appender = createAppender();

    root.addAppender(appender);
  }
Ejemplo n.º 3
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);
  }