Search in sources :

Example 6 with DefaultGoPublisher

use of com.thoughtworks.go.work.DefaultGoPublisher in project gocd by gocd.

the class PluggableTaskBuilderTest method shouldBuildExecutorConfigPlusExecutionContextAndInvokeTheTaskExecutorWithIt.

@Test
public void shouldBuildExecutorConfigPlusExecutionContextAndInvokeTheTaskExecutorWithIt() throws Exception {
    Task task = mock(Task.class);
    TaskConfig defaultTaskConfig = mock(TaskConfig.class);
    when(task.config()).thenReturn(defaultTaskConfig);
    final TaskConfig executorTaskConfig = mock(TaskConfig.class);
    final TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class);
    PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {

        @Override
        protected TaskConfig buildTaskConfig(TaskConfig config) {
            return executorTaskConfig;
        }

        @Override
        protected TaskExecutionContext buildTaskContext(BuildLogElement buildLogElement, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext) {
            return taskExecutionContext;
        }
    };
    TaskExecutor taskExecutor = mock(TaskExecutor.class);
    when(taskExecutor.execute(executorTaskConfig, taskExecutionContext)).thenReturn(new ExecutionResult());
    when(task.executor()).thenReturn(taskExecutor);
    taskBuilder.executeTask(task, null, null, null);
    verify(task).config();
    verify(task).executor();
    verify(taskExecutor).execute(executorTaskConfig, taskExecutionContext);
    assertThat(ReflectionUtil.getStaticField(JobConsoleLogger.class, "context"), is(not(nullValue())));
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) BuildLogElement(com.thoughtworks.go.domain.BuildLogElement) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) ExecutionResult(com.thoughtworks.go.plugin.api.response.execution.ExecutionResult) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 7 with DefaultGoPublisher

use of com.thoughtworks.go.work.DefaultGoPublisher in project gocd by gocd.

the class KillAllChildProcessTaskBuilderTest method shouldKillAllChildProcessOnbuild.

//11 minutes
@Test(timeout = 11 * 60 * 1000)
public void shouldKillAllChildProcessOnbuild() throws Exception {
    ProcessWrapper processWrapper = CommandLine.createCommandLine("sleep").withArg(String.valueOf(10 * 60)).execute(ProcessOutputStreamConsumer.inMemoryConsumer(), new EnvironmentVariableContext(), //60 mins
    null);
    assertThat(processWrapper.isRunning(), is(true));
    BuildLogElement log = mock(BuildLogElement.class);
    DefaultGoPublisher publisher = mock(DefaultGoPublisher.class);
    EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    long before = getSystemTime();
    Builder builder = new KillAllChildProcessTaskBuilder().createBuilder(builderFactory, new KillAllChildProcessTask(), null, null);
    builder.build(log, publisher, environmentVariableContext, null);
    assertThat(processWrapper.waitForExit(), is(greaterThan(0)));
    //min = 10; sec = 60*min; mills = 1000*sec; micro = 1000*mills; nano = 1000*micro;
    assertThat(getSystemTime() - before, is(lessThan(10 * 60 * 1000 * 1000 * 1000L)));
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper) BuildLogElement(com.thoughtworks.go.domain.BuildLogElement) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) Builder(com.thoughtworks.go.domain.builder.Builder) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) KillAllChildProcessTask(com.thoughtworks.go.domain.KillAllChildProcessTask) Test(org.junit.Test)

Aggregations

DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)7 Test (org.junit.Test)5 BuildLogElement (com.thoughtworks.go.domain.BuildLogElement)4 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)4 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)3 ExecutionResult (com.thoughtworks.go.plugin.api.response.execution.ExecutionResult)3 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)2 ActionWithReturn (com.thoughtworks.go.plugin.infra.ActionWithReturn)2 CruiseControlException (com.thoughtworks.go.util.command.CruiseControlException)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ArtifactPlan (com.thoughtworks.go.config.ArtifactPlan)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 KillAllChildProcessTask (com.thoughtworks.go.domain.KillAllChildProcessTask)1 Builder (com.thoughtworks.go.domain.builder.Builder)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 BuildRepositoryRemoteStub (com.thoughtworks.go.remote.work.BuildRepositoryRemoteStub)1 GoArtifactsManipulatorStub (com.thoughtworks.go.remote.work.GoArtifactsManipulatorStub)1 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)1 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)1