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())));
}
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)));
}
Aggregations