Search in sources :

Example 1 with SuiteRunnerMap

use of org.testng.internal.SuiteRunnerMap in project druid by druid-io.

the class TestNG method createSuiteRunners.

/**
   * Creates the {@code SuiteRunner}s and populates the suite runner map with
   * this information
   *
   * @param suiteRunnerMap Map with XMLSuite as key and it's respective
   *                       SuiteRunner as value. This is updated as part of this method call
   * @param xmlSuite       Xml Suite (and its children) for which {@code SuiteRunner}s are created
   */
private void createSuiteRunners(SuiteRunnerMap suiteRunnerMap, /* OUT */
XmlSuite xmlSuite) {
    if (null != m_isJUnit && !m_isJUnit.equals(XmlSuite.DEFAULT_JUNIT)) {
        xmlSuite.setJUnit(m_isJUnit);
    }
    // takes precedence
    if (null != m_skipFailedInvocationCounts) {
        xmlSuite.setSkipFailedInvocationCounts(m_skipFailedInvocationCounts);
    }
    // Override the XmlSuite verbose value with the one from TestNG
    if (m_verbose != null) {
        xmlSuite.setVerbose(m_verbose);
    }
    if (null != m_configFailurePolicy) {
        xmlSuite.setConfigFailurePolicy(m_configFailurePolicy);
    }
    for (XmlTest t : xmlSuite.getTests()) {
        for (Map.Entry<String, Integer> ms : m_methodDescriptors.entrySet()) {
            XmlMethodSelector xms = new XmlMethodSelector();
            xms.setName(ms.getKey());
            xms.setPriority(ms.getValue());
            t.getMethodSelectors().add(xms);
        }
    }
    suiteRunnerMap.put(xmlSuite, createSuiteRunner(xmlSuite));
    for (XmlSuite childSuite : xmlSuite.getChildSuites()) {
        createSuiteRunners(suiteRunnerMap, childSuite);
    }
}
Also used : XmlSuite(org.testng.xml.XmlSuite) XmlMethodSelector(org.testng.xml.XmlMethodSelector) XmlTest(org.testng.xml.XmlTest) Map(java.util.Map) SuiteRunnerMap(org.testng.internal.SuiteRunnerMap)

Example 2 with SuiteRunnerMap

use of org.testng.internal.SuiteRunnerMap 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

SuiteRunnerMap (org.testng.internal.SuiteRunnerMap)2 XmlSuite (org.testng.xml.XmlSuite)2 Map (java.util.Map)1 DynamicGraph (org.testng.internal.DynamicGraph)1 GraphThreadPoolExecutor (org.testng.internal.thread.graph.GraphThreadPoolExecutor)1 SuiteWorkerFactory (org.testng.internal.thread.graph.SuiteWorkerFactory)1 XmlMethodSelector (org.testng.xml.XmlMethodSelector)1 XmlTest (org.testng.xml.XmlTest)1