コード例 #1
0
  /**
   * 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()));
    }
  }
コード例 #2
0
  /**
   * Runs all tests belonging to this test suite on the grid.
   *
   * @param result Test result collector.
   */
  @Override
  public void run(TestResult result) {
    if (isDisabled) {
      copy.run(result);
    } else {
      GridTestRouter router = createRouter();

      Grid grid = startGrid();

      try {
        List<GridTaskFuture<?>> futs = new ArrayList<GridTaskFuture<?>>(testCount());

        List<GridJunit3SerializableTest> tests =
            new ArrayList<GridJunit3SerializableTest>(testCount());

        for (int i = 0; i < testCount(); i++) {
          Test junit = testAt(i);

          GridJunit3SerializableTest test;

          if (junit instanceof TestSuite) {
            test = new GridJunit3SerializableTestSuite((TestSuite) junit);
          } else {
            assert junit instanceof TestCase
                : "Test must be either TestSuite or TestCase: " + junit;

            test = new GridJunit3SerializableTestCase((TestCase) junit);
          }

          tests.add(test);

          if (clsLdr == null) {
            clsLdr = U.detectClassLoader(junit.getClass());
          }

          futs.add(
              grid.execute(
                  new GridJunit3Task(junit.getClass(), clsLdr),
                  new GridJunit3Argument(router, test, locTests.contains(test.getName())),
                  timeout));
        }

        for (int i = 0; i < testCount(); i++) {
          GridTaskFuture<?> fut = futs.get(i);

          GridJunit3SerializableTest origTest = tests.get(i);

          try {
            GridJunit3SerializableTest resTest = (GridJunit3SerializableTest) fut.get();

            origTest.setResult(resTest);

            origTest.getTest().run(result);
          } catch (GridException e) {
            handleFail(result, origTest, e);
          }
        }
      } finally {
        stopGrid();
      }
    }
  }