Search in sources :

Example 1 with TestClassProcessor

use of org.gradle.api.internal.tasks.testing.TestClassProcessor in project gradle by gradle.

the class DefaultTestExecuter method execute.

@Override
public void execute(final Test testTask, TestResultProcessor testResultProcessor) {
    final TestFramework testFramework = testTask.getTestFramework();
    final WorkerTestClassProcessorFactory testInstanceFactory = testFramework.getProcessorFactory();
    final BuildOperationWorkerRegistry.Operation currentOperation = buildOperationWorkerRegistry.getCurrent();
    final Set<File> classpath = ImmutableSet.copyOf(testTask.getClasspath());
    final Factory<TestClassProcessor> forkingProcessorFactory = new Factory<TestClassProcessor>() {

        public TestClassProcessor create() {
            return new ForkingTestClassProcessor(workerFactory, testInstanceFactory, testTask, classpath, testFramework.getWorkerConfigurationAction(), moduleRegistry, currentOperation);
        }
    };
    Factory<TestClassProcessor> reforkingProcessorFactory = new Factory<TestClassProcessor>() {

        public TestClassProcessor create() {
            return new RestartEveryNTestClassProcessor(forkingProcessorFactory, testTask.getForkEvery());
        }
    };
    TestClassProcessor processor = new MaxNParallelTestClassProcessor(getMaxParallelForks(testTask), reforkingProcessorFactory, actorFactory);
    final FileTree testClassFiles = testTask.getCandidateClassFiles();
    Runnable detector;
    if (testTask.isScanForTestClasses()) {
        TestFrameworkDetector testFrameworkDetector = testTask.getTestFramework().getDetector();
        testFrameworkDetector.setTestClassesDirectory(testTask.getTestClassesDir());
        testFrameworkDetector.setTestClasspath(classpath);
        detector = new DefaultTestClassScanner(testClassFiles, testFrameworkDetector, processor);
    } else {
        detector = new DefaultTestClassScanner(testClassFiles, null, processor);
    }
    final Object testTaskOperationId = buildOperationExecutor.getCurrentOperation().getParentId();
    new TestMainAction(detector, processor, testResultProcessor, new TrueTimeProvider(), testTaskOperationId, testTask.getPath(), "Gradle Test Run " + testTask.getIdentityPath()).run();
}
Also used : WorkerTestClassProcessorFactory(org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory) BuildOperationWorkerRegistry(org.gradle.internal.operations.BuildOperationWorkerRegistry) WorkerProcessFactory(org.gradle.process.internal.worker.WorkerProcessFactory) Factory(org.gradle.internal.Factory) WorkerTestClassProcessorFactory(org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory) ActorFactory(org.gradle.internal.actor.ActorFactory) TestMainAction(org.gradle.api.internal.tasks.testing.processors.TestMainAction) TestClassProcessor(org.gradle.api.internal.tasks.testing.TestClassProcessor) RestartEveryNTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor) ForkingTestClassProcessor(org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor) MaxNParallelTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor) RestartEveryNTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor) TestFramework(org.gradle.api.internal.tasks.testing.TestFramework) MaxNParallelTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor) TrueTimeProvider(org.gradle.internal.time.TrueTimeProvider) ForkingTestClassProcessor(org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor) FileTree(org.gradle.api.file.FileTree) File(java.io.File)

Example 2 with TestClassProcessor

use of org.gradle.api.internal.tasks.testing.TestClassProcessor in project gradle by gradle.

the class TestWorker method startReceivingTests.

private void startReceivingTests(WorkerProcessContext workerProcessContext, ServiceRegistry testServices) {
    TestClassProcessor targetProcessor = factory.create(testServices);
    IdGenerator<Object> idGenerator = testServices.get(IdGenerator.class);
    targetProcessor = new WorkerTestClassProcessor(targetProcessor, idGenerator.generateId(), workerProcessContext.getDisplayName(), testServices.get(TimeProvider.class));
    ContextClassLoaderProxy<TestClassProcessor> proxy = new ContextClassLoaderProxy<TestClassProcessor>(TestClassProcessor.class, targetProcessor, workerProcessContext.getApplicationClassLoader());
    processor = proxy.getSource();
    ObjectConnection serverConnection = workerProcessContext.getServerConnection();
    serverConnection.useParameterSerializers(TestEventSerializer.create());
    this.resultProcessor = serverConnection.addOutgoing(TestResultProcessor.class);
    serverConnection.addIncoming(RemoteTestClassProcessor.class, this);
    serverConnection.connect();
}
Also used : TestResultProcessor(org.gradle.api.internal.tasks.testing.TestResultProcessor) ContextClassLoaderProxy(org.gradle.internal.dispatch.ContextClassLoaderProxy) ObjectConnection(org.gradle.internal.remote.ObjectConnection) TestClassProcessor(org.gradle.api.internal.tasks.testing.TestClassProcessor)

Example 3 with TestClassProcessor

use of org.gradle.api.internal.tasks.testing.TestClassProcessor in project gradle by gradle.

the class MaxNParallelTestClassProcessor method processTestClass.

@Override
public void processTestClass(TestClassRunInfo testClass) {
    TestClassProcessor processor;
    if (processors.size() < maxProcessors) {
        processor = factory.create();
        Actor actor = actorFactory.createActor(processor);
        processor = actor.getProxy(TestClassProcessor.class);
        actors.add(actor);
        processors.add(processor);
        processor.startProcessing(resultProcessor);
    } else {
        processor = processors.get(pos);
        pos = (pos + 1) % processors.size();
    }
    processor.processTestClass(testClass);
}
Also used : Actor(org.gradle.internal.actor.Actor) TestClassProcessor(org.gradle.api.internal.tasks.testing.TestClassProcessor)

Aggregations

TestClassProcessor (org.gradle.api.internal.tasks.testing.TestClassProcessor)3 File (java.io.File)1 FileTree (org.gradle.api.file.FileTree)1 TestFramework (org.gradle.api.internal.tasks.testing.TestFramework)1 TestResultProcessor (org.gradle.api.internal.tasks.testing.TestResultProcessor)1 WorkerTestClassProcessorFactory (org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory)1 MaxNParallelTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor)1 RestartEveryNTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor)1 TestMainAction (org.gradle.api.internal.tasks.testing.processors.TestMainAction)1 ForkingTestClassProcessor (org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor)1 Factory (org.gradle.internal.Factory)1 Actor (org.gradle.internal.actor.Actor)1 ActorFactory (org.gradle.internal.actor.ActorFactory)1 ContextClassLoaderProxy (org.gradle.internal.dispatch.ContextClassLoaderProxy)1 BuildOperationWorkerRegistry (org.gradle.internal.operations.BuildOperationWorkerRegistry)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 TrueTimeProvider (org.gradle.internal.time.TrueTimeProvider)1 WorkerProcessFactory (org.gradle.process.internal.worker.WorkerProcessFactory)1