public void stop() {
   // 1. Stop handling disconnects. Blocks until the handler has finished.
   // 2. Stop the connection. This means that the thread receiving from the connection will receive
   // a null and finish up.
   // 3. Stop receiving incoming messages. Blocks until the receive thread has finished. This will
   // notify the stdin and receive queues to signal end of input.
   // 4. Stop the receive queue, to unblock any threads blocked in receive().
   // 5. Stop handling stdin. Blocks until the handler has finished. Discards any queued input.
   CompositeStoppable.stoppable(disconnectQueue, connection, executor, receiveQueue, stdinQueue)
       .stop();
 }
Beispiel #2
0
 @Override
 public void close() {
   if (singleUseSession) {
     // This song and dance is to let CompositeStoppable deal with making sure everything
     // is closed when something errors while stopping
     CompositeStoppable.stoppable(
             new Stoppable() {
               @Override
               public void stop() {
                 BuildScopeServices.super.close();
               }
             },
             sessionServices)
         .stop();
   } else {
     super.close();
   }
 }
 public DefaultLoggingManager stop() {
   try {
     CompositeStoppable.stoppable(
             loggingSystem, javaUtilLoggingSystem, stdOutLoggingSystem, stdErrLoggingSystem)
         .stop();
     for (StandardOutputListener stdoutListener : stdoutListeners) {
       loggingOutput.removeStandardOutputListener(stdoutListener);
     }
     for (StandardOutputListener stderrListener : stderrListeners) {
       loggingOutput.removeStandardErrorListener(stderrListener);
     }
     for (OutputEventListener listener : outputEventListeners) {
       loggingOutput.removeOutputEventListener(listener);
     }
   } finally {
     started = false;
   }
   return this;
 }
  @Override
  public void wait(
      FileSystemSubset taskFileSystemInputs,
      final BuildCancellationToken cancellationToken,
      Runnable notifier) {
    if (cancellationToken.isCancellationRequested()) {
      return;
    }

    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
    final StoppableExecutor executorService = executorFactory.create("continuous build - wait");

    final Lock lock = new ReentrantLock();
    final Condition condition = lock.newCondition();
    final AtomicLong lastChangeAt = new AtomicLong(0);

    Runnable cancellationHandler =
        new Runnable() {
          @Override
          public void run() {
            signal(lock, condition);
          }
        };

    FileWatcher watcher =
        fileWatcherFactory.watch(
            taskFileSystemInputs,
            new Action<Throwable>() {
              @Override
              public void execute(Throwable throwable) {
                error.set(throwable);
                signal(lock, condition);
              }
            },
            new FileWatcherListener() {
              @Override
              public void onChange(final FileWatcher watcher, FileWatcherEvent event) {
                if (!(event.getType() == FileWatcherEvent.Type.MODIFY
                    && event.getFile().isDirectory())) {
                  signal(
                      lock,
                      condition,
                      new Runnable() {
                        @Override
                        public void run() {
                          lastChangeAt.set(System.currentTimeMillis());
                        }
                      });
                }
              }
            });

    try {
      cancellationToken.addCallback(cancellationHandler);
      notifier.run();
      lock.lock();
      try {
        long lastChangeAtValue = lastChangeAt.get();
        while (!cancellationToken.isCancellationRequested()
            && error.get() == null
            && (lastChangeAtValue == 0
                || System.currentTimeMillis() - lastChangeAtValue < quietPeriodMillis)) {
          condition.await(quietPeriodMillis, TimeUnit.MILLISECONDS);
          lastChangeAtValue = lastChangeAt.get();
        }
      } finally {
        lock.unlock();
      }
      Throwable throwable = error.get();
      if (throwable != null) {
        throw throwable;
      }
    } catch (Throwable e) {
      throw UncheckedException.throwAsUncheckedException(e);
    } finally {
      cancellationToken.removeCallback(cancellationHandler);
      CompositeStoppable.stoppable(watcher, executorService).stop();
    }
  }
Beispiel #5
0
  @TaskAction
  public void executeTests() {
    LogLevel currentLevel = getCurrentLogLevel();
    TestLogging levelLogging = testLogging.get(currentLevel);
    TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
    TestEventLogger eventLogger =
        new TestEventLogger(textOutputFactory, currentLevel, levelLogging, exceptionFormatter);
    addTestListener(eventLogger);
    addTestOutputListener(eventLogger);
    if (!getFilter().getIncludePatterns().isEmpty()) {
      addTestListener(
          new NoMatchingTestsReporter(
              "No tests found for given includes: " + getFilter().getIncludePatterns()));
    }

    File binaryResultsDir = getBinResultsDir();
    getProject().delete(binaryResultsDir);
    getProject().mkdir(binaryResultsDir);

    Map<String, TestClassResult> results = new HashMap<String, TestClassResult>();
    TestOutputStore testOutputStore = new TestOutputStore(binaryResultsDir);

    TestOutputStore.Writer outputWriter = testOutputStore.writer();
    TestReportDataCollector testReportDataCollector =
        new TestReportDataCollector(results, outputWriter);

    addTestListener(testReportDataCollector);
    addTestOutputListener(testReportDataCollector);

    TestCountLogger testCountLogger = new TestCountLogger(progressLoggerFactory);
    addTestListener(testCountLogger);

    TestResultProcessor resultProcessor =
        new TestListenerAdapter(
            getTestListenerBroadcaster().getSource(), testOutputListenerBroadcaster.getSource());

    try {
      testExecuter.execute(this, resultProcessor);
    } finally {
      testListenerBroadcaster.removeAll();
      testOutputListenerBroadcaster.removeAll();
      outputWriter.close();
    }

    new TestResultSerializer(binaryResultsDir).write(results.values());

    TestResultsProvider testResultsProvider =
        new InMemoryTestResultsProvider(results.values(), testOutputStore.reader());

    try {
      JUnitXmlReport junitXml = reports.getJunitXml();
      if (junitXml.isEnabled()) {
        TestOutputAssociation outputAssociation =
            junitXml.isOutputPerTestCase()
                ? TestOutputAssociation.WITH_TESTCASE
                : TestOutputAssociation.WITH_SUITE;
        Binary2JUnitXmlReportGenerator binary2JUnitXmlReportGenerator =
            new Binary2JUnitXmlReportGenerator(
                junitXml.getDestination(), testResultsProvider, outputAssociation);
        binary2JUnitXmlReportGenerator.generate();
      }

      DirectoryReport html = reports.getHtml();
      if (!html.isEnabled()) {
        getLogger().info("Test report disabled, omitting generation of the HTML test report.");
      } else {
        testReporter.generateReport(testResultsProvider, html.getDestination());
      }
    } finally {
      CompositeStoppable.stoppable(testResultsProvider).stop();
    }

    testFramework = null;

    if (testCountLogger.hadFailures()) {
      handleTestFailures();
    }
  }