Search in sources :

Example 1 with ScriptCoverageStatistics

use of com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics in project saga by timurstrekalov.

the class DefaultCoverageGenerator method runTests.

private void runTests(final List<URI> tests, final int actualThreadCount, final OutputStrategy outputStrategy, final TestRunCoverageStatistics totalStats) throws IOException {
    final ExecutorService executorService = Executors.newFixedThreadPool(actualThreadCount);
    final CompletionService<TestRunCoverageStatistics> completionService = new ExecutorCompletionService<TestRunCoverageStatistics>(executorService);
    for (final URI test : tests) {
        completionService.submit(new TestRunCoverageStatisticsCallable(config, test, outputStrategy));
    }
    final List<TestRunCoverageStatistics> allRunStats = Lists.newLinkedList();
    final int submittedTasks = tests.size();
    try {
        for (int i = 0; i < submittedTasks; i++) {
            try {
                final Future<TestRunCoverageStatistics> future = completionService.take();
                final TestRunCoverageStatistics runStats = future.get();
                allRunStats.add(runStats);
            } catch (final Exception e) {
                logger.debug(e.getMessage(), e);
            }
        }
    } finally {
        executorService.shutdown();
    }
    logger.info("Test run finished");
    if (outputStrategy.contains(OutputStrategy.TOTAL)) {
        for (final TestRunCoverageStatistics runStats : allRunStats) {
            if (runStats != TestRunCoverageStatistics.EMPTY) {
                for (final ScriptCoverageStatistics scriptCoverageStatistics : runStats) {
                    totalStats.add(scriptCoverageStatistics);
                }
            }
        }
        new WritesStatistics().write(config, totalStats);
    }
}
Also used : TestRunCoverageStatistics(com.github.timurstrekalov.saga.core.model.TestRunCoverageStatistics) ExecutorService(java.util.concurrent.ExecutorService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) URI(java.net.URI) IOException(java.io.IOException) ScriptCoverageStatistics(com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics)

Example 2 with ScriptCoverageStatistics

use of com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics in project saga by timurstrekalov.

the class TestRunCoverageStatisticsCallable method collectAndWriteRunStats.

private TestRunCoverageStatistics collectAndWriteRunStats(final URI test, final Map<String, Map<String, Long>> coverageDataForAllScripts) throws IOException {
    final TestRunCoverageStatistics runStats = new TestRunCoverageStatistics(test);
    runStats.setSortBy(config.getSortBy());
    runStats.setOrder(config.getOrder());
    final URI baseUri = config.getBaseUri();
    for (final ScriptData data : getLocalBrowser().getScriptDataList()) {
        final String sourceUri = data.getSourceUriAsString();
        @SuppressWarnings("unchecked") final Map<String, Long> coverageDataForScript = coverageDataForAllScripts.get(sourceUri);
        final ScriptCoverageStatistics scriptCoverageStatistics = data.generateScriptCoverageStatistics(baseUri, coverageDataForScript);
        runStats.add(scriptCoverageStatistics);
    }
    return runStats;
}
Also used : TestRunCoverageStatistics(com.github.timurstrekalov.saga.core.model.TestRunCoverageStatistics) ScriptData(com.github.timurstrekalov.saga.core.model.ScriptData) URI(java.net.URI) ScriptCoverageStatistics(com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics)

Example 3 with ScriptCoverageStatistics

use of com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics in project saga by timurstrekalov.

the class PdfReporter method addFileStatsRows.

private void addFileStatsRows(final TestRunCoverageStatistics runStats, final PdfPTable table) {
    final List<ScriptCoverageStatistics> allFileStats = runStats.getFileStats();
    for (int i = 0; i < allFileStats.size(); i++) {
        final ScriptCoverageStatistics scriptCoverageStatistics = allFileStats.get(i);
        final boolean hasStatements = scriptCoverageStatistics.getHasStatements();
        final Phrase fileName = new Phrase();
        if (scriptCoverageStatistics.getParentName() != null) {
            fileName.add(new Chunk(scriptCoverageStatistics.getParentName() + "/", hasStatements ? FONT_TD : FONT_TD_EMPTY_FILE));
            fileName.add(new Chunk(scriptCoverageStatistics.getFileName(), hasStatements ? FONT_TD_BOLD : FONT_TD_BOLD_EMPTY_FILE));
        } else {
            fileName.add(new Chunk(scriptCoverageStatistics.getFileName(), hasStatements ? FONT_TD : FONT_TD_EMPTY_FILE));
        }
        final BaseColor bgColor = (i % 2 == 1) ? COLOR_ROW_ODD : COLOR_ROW_EVEN;
        final Font font = FONT_TD;
        table.addCell(createCell(fileName, 0, bgColor));
        table.addCell(createCell(String.valueOf(scriptCoverageStatistics.getStatements()), font, 1, bgColor));
        table.addCell(createCell(String.valueOf(scriptCoverageStatistics.getExecuted()), font, 2, bgColor));
        table.addCell(createCell(scriptCoverageStatistics.getCoverage() + "%", FONT_TD, 3, bgColor));
    }
}
Also used : BaseColor(com.itextpdf.text.BaseColor) Phrase(com.itextpdf.text.Phrase) Chunk(com.itextpdf.text.Chunk) Font(com.itextpdf.text.Font) ScriptCoverageStatistics(com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics)

Aggregations

ScriptCoverageStatistics (com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics)3 TestRunCoverageStatistics (com.github.timurstrekalov.saga.core.model.TestRunCoverageStatistics)2 URI (java.net.URI)2 ScriptData (com.github.timurstrekalov.saga.core.model.ScriptData)1 BaseColor (com.itextpdf.text.BaseColor)1 Chunk (com.itextpdf.text.Chunk)1 Font (com.itextpdf.text.Font)1 Phrase (com.itextpdf.text.Phrase)1 IOException (java.io.IOException)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1