Пример #1
0
  public void run(CommandExecutor executor) {

    TestCase[] testcases = {
      new TestCase(1, "testcaseMethod1"),
      new TestCase(2, "testcaseMethod2"),
      new TestCase(3, "testcaseMethod3"),
      new TestCase(4, "testcaseMethod4"),
    };

    // Lock compilation makes all compiles stay in queue or compile thread before completion
    WB.lockCompilation();

    // Enqueue one test method for each available level
    int[] complevels = CompilerUtils.getAvailableCompilationLevels();
    for (int level : complevels) {
      TestCase testcase = testcases[level - 1];

      boolean added = WB.enqueueMethodForCompilation(testcase.method, testcase.level);
      // Set results to false for those methods we must to find
      // We will also assert if we find any test method we don't expect
      Assert.assertEquals(added, WB.isMethodQueuedForCompilation(testcase.method));
      testcase.check = false;
    }

    // Get output from dcmd (diagnostic command)
    OutputAnalyzer output = executor.execute("Compiler.queue");
    Iterator<String> lines = output.asLines().iterator();

    // Loop over output set result for all found methods
    while (lines.hasNext()) {
      String str = lines.next();
      // Fast check for common part of method name
      if (str.contains("testcaseMethod")) {
        for (TestCase testcase : testcases) {
          if (str.contains(testcase.methodName)) {
            Assert.assertFalse(testcase.check, "Must not be found or already found.");
            testcase.check = true;
          }
        }
      }
    }

    for (TestCase testcase : testcases) {
      if (!testcase.check) {
        // If this method wasn't found it must have been removed by policy,
        // verify that it is now removed from the queue
        Assert.assertFalse(
            WB.isMethodQueuedForCompilation(testcase.method), "Must be found or not in queue");
      }
      // Otherwise all good.
    }

    // Enable compilations again
    WB.unlockCompilation();
  }