Search in sources :

Example 1 with GraphThreadPoolExecutor

use of org.testng.internal.thread.graph.GraphThreadPoolExecutor in project druid by druid-io.

the class TestNG method runSuitesLocally.

/**
   * This needs to be public for maven2, for now..At least
   * until an alternative mechanism is found.
   */
public List<ISuite> runSuitesLocally() {
    SuiteRunnerMap suiteRunnerMap = new SuiteRunnerMap();
    if (m_suites.size() > 0) {
        if (m_suites.get(0).getVerbose() >= 2) {
            Version.displayBanner();
        }
        // Create a map with XmlSuite as key and corresponding SuiteRunner as value
        for (XmlSuite xmlSuite : m_suites) {
            createSuiteRunners(suiteRunnerMap, xmlSuite);
        }
        //
        if (m_suiteThreadPoolSize == 1 && !m_randomizeSuites) {
            // Single threaded and not randomized: run the suites in order
            for (XmlSuite xmlSuite : m_suites) {
                runSuitesSequentially(xmlSuite, suiteRunnerMap, getVerbose(xmlSuite), getDefaultSuiteName());
            }
        } else {
            // Multithreaded: generate a dynamic graph that stores the suite hierarchy. This is then
            // used to run related suites in specific order. Parent suites are run only
            // once all the child suites have completed execution
            DynamicGraph<ISuite> suiteGraph = new DynamicGraph<ISuite>();
            for (XmlSuite xmlSuite : m_suites) {
                populateSuiteGraph(suiteGraph, suiteRunnerMap, xmlSuite);
            }
            IThreadWorkerFactory<ISuite> factory = new SuiteWorkerFactory(suiteRunnerMap, 0, /* verbose hasn't been set yet */
            getDefaultSuiteName());
            GraphThreadPoolExecutor<ISuite> pooledExecutor = new GraphThreadPoolExecutor<ISuite>(suiteGraph, factory, m_suiteThreadPoolSize, m_suiteThreadPoolSize, Integer.MAX_VALUE, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
            Utils.log("TestNG", 2, "Starting executor for all suites");
            // Run all suites in parallel
            pooledExecutor.run();
            try {
                pooledExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
                pooledExecutor.shutdownNow();
            } catch (InterruptedException handled) {
                Thread.currentThread().interrupt();
                error("Error waiting for concurrent executors to finish " + handled.getMessage());
            }
        }
    } else {
        setStatus(HAS_NO_TEST);
        error("No test suite found. Nothing to run");
        usage();
    }
    //
    return Lists.newArrayList(suiteRunnerMap.values());
}
Also used : XmlSuite(org.testng.xml.XmlSuite) SuiteWorkerFactory(org.testng.internal.thread.graph.SuiteWorkerFactory) SuiteRunnerMap(org.testng.internal.SuiteRunnerMap) GraphThreadPoolExecutor(org.testng.internal.thread.graph.GraphThreadPoolExecutor) DynamicGraph(org.testng.internal.DynamicGraph)

Aggregations

DynamicGraph (org.testng.internal.DynamicGraph)1 SuiteRunnerMap (org.testng.internal.SuiteRunnerMap)1 GraphThreadPoolExecutor (org.testng.internal.thread.graph.GraphThreadPoolExecutor)1 SuiteWorkerFactory (org.testng.internal.thread.graph.SuiteWorkerFactory)1 XmlSuite (org.testng.xml.XmlSuite)1