Search in sources :

Example 1 with Task

use of com.scythe.instrumenter.analysis.task.Task in project kanonizo by kanonizo.

the class AbstractSearchAlgorithm method start.

@Override
public void start() {
    startTime = System.currentTimeMillis();
    Task timerTask = new AbstractTask() {

        @Override
        public String asString() {
            return "Running " + getClass().getSimpleName();
        }
    };
    if (InstrumentationProperties.LOG) {
        TaskTimer.taskStart(timerTask);
    }
    fw.getDisplay().notifyTaskStart("Running Test Prioritisation", false);
    generateSolution();
    TaskTimer.taskEnd(timerTask);
    BufferedOutputStream stream = null;
    try {
        File file = new File(InstrumentationProperties.LOG_DIR + "/algorithm_time.dat");
        File logdir = new File(InstrumentationProperties.LOG_DIR);
        if (!logdir.exists()) {
            logdir.mkdirs();
        }
        if (!file.exists()) {
            file.createNewFile();
        }
        stream = new BufferedOutputStream(new FileOutputStream(file));
        stream.write(String.valueOf(System.currentTimeMillis() - startTime).getBytes());
    } catch (final IOException e) {
        e.printStackTrace();
    } finally {
        totalTime = System.currentTimeMillis() - startTime;
        if (stream != null) {
            try {
                stream.close();
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Task(com.scythe.instrumenter.analysis.task.Task) AbstractTask(com.scythe.instrumenter.analysis.task.AbstractTask) AbstractTask(com.scythe.instrumenter.analysis.task.AbstractTask) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 2 with Task

use of com.scythe.instrumenter.analysis.task.Task in project kanonizo by kanonizo.

the class TestCase method run.

/**
 * Executes a single test method on the JUnitCore class, using default
 * Runners and configuration. This method must reload the class from the
 * class loader as it will have been instrumented since it is first created.
 * If the instrumented version is not loaded, code coverage goes a little
 * bit funky.
 *
 * @throws ClassNotFoundException if the ClassLoader can't find the {@link #testClass} by name
 */
public void run() {
    long startTime = System.currentTimeMillis();
    // reload testclass from memory class loader to get the instrumented
    // version
    Task timerTask = new TestCaseExecutionTimer(testClass.getName(), testMethod.getName());
    if (InstrumentationProperties.LOG) {
        TaskTimer.taskStart(timerTask);
    }
    File rootFolder;
    if (EXECUTE_IN_ROOT_FOLDER && (rootFolder = Framework.getInstance().getRootFolder()) != null) {
        System.setProperty("user.dir", rootFolder.getAbsolutePath());
    }
    KanonizoTestRunner testCaseRunner = TestingUtils.isJUnit4Class(testClass) ? new JUnit4TestRunner() : new JUnit3TestRunner();
    KanonizoTestResult result = null;
    if (USE_TIMEOUT) {
        ExecutorService service = Executors.newSingleThreadExecutor();
        Future<KanonizoTestResult> res = service.submit(() -> testCaseRunner.runTest(this));
        try {
            result = res.get(TIMEOUT, UNIT);
        } catch (TimeoutException e) {
            logger.debug("Test " + testMethod.getName() + " timed out.");
            return;
        } catch (InterruptedException e) {
            logger.error(e);
        } catch (ExecutionException e) {
            logger.error(e);
        }
    } else {
        result = testCaseRunner.runTest(this);
    }
    setResult(result);
    if (InstrumentationProperties.LOG) {
        TaskTimer.taskEnd(timerTask);
    }
}
Also used : Task(com.scythe.instrumenter.analysis.task.Task) AbstractTask(com.scythe.instrumenter.analysis.task.AbstractTask) KanonizoTestRunner(org.kanonizo.junit.runners.KanonizoTestRunner) JUnit3TestRunner(org.kanonizo.junit.runners.JUnit3TestRunner) JUnit4TestRunner(org.kanonizo.junit.runners.JUnit4TestRunner) ExecutorService(java.util.concurrent.ExecutorService) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

AbstractTask (com.scythe.instrumenter.analysis.task.AbstractTask)2 Task (com.scythe.instrumenter.analysis.task.Task)2 File (java.io.File)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 KanonizoTestResult (org.kanonizo.junit.KanonizoTestResult)1 JUnit3TestRunner (org.kanonizo.junit.runners.JUnit3TestRunner)1 JUnit4TestRunner (org.kanonizo.junit.runners.JUnit4TestRunner)1 KanonizoTestRunner (org.kanonizo.junit.runners.KanonizoTestRunner)1