use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class ElasticAgentPluginServiceTest method setUp.
@Before
public void setUp() throws Exception {
initMocks(this);
ArrayList<PluginDescriptor> plugins = new ArrayList<>();
plugins.add(new GoPluginDescriptor("p1", null, null, null, null, true));
plugins.add(new GoPluginDescriptor("p2", null, null, null, null, true));
plugins.add(new GoPluginDescriptor("docker", null, null, null, null, true));
when(registry.getPlugins()).thenReturn(plugins);
when(registry.has("docker")).thenReturn(true);
when(registry.has("p1")).thenReturn(true);
when(registry.has("p2")).thenReturn(true);
when(registry.has("missing")).thenReturn(false);
when(agentService.allElasticAgents()).thenReturn(new LinkedMultiValueMap<>());
elasticAgentMetadataStore = ElasticAgentMetadataStore.instance();
timeProvider = new TimeProvider();
service = new ElasticAgentPluginService(pluginManager, registry, agentService, environmentConfigService, createAgentQueue, serverPingQueue, goConfigService, timeProvider, serverHealthService, elasticAgentMetadataStore);
when(goConfigService.serverConfig()).thenReturn(GoConfigMother.configWithAutoRegisterKey(autoRegisterKey).server());
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldFailWhenNoAgentsmatchAJob.
@Test
public void shouldFailWhenNoAgentsmatchAJob() throws Exception {
DefaultSchedulingContext context = new DefaultSchedulingContext("raghu/vinay", new Agents());
JobConfig fooJob = new JobConfig(new CaseInsensitiveString("foo"), new ResourceConfigs(), new ArtifactConfigs());
fooJob.setRunOnAllAgents(true);
StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("blah-stage"), new JobConfigs(fooJob, new JobConfig(new CaseInsensitiveString("bar"), new ResourceConfigs(), new ArtifactConfigs())));
try {
instanceFactory.createStageInstance(stageConfig, context, "md5", new TimeProvider());
fail("expected exception but not thrown");
} catch (Exception e) {
assertThat(e.getMessage(), is("Could not find matching agents to run job [foo] of stage [blah-stage]."));
}
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldReturnBuildInstance.
@Test
public void shouldReturnBuildInstance() {
ArtifactConfigs artifactConfigs = new ArtifactConfigs();
JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test"), null, artifactConfigs);
RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(jobConfig.name()));
JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("stage_foo"), jobConfig, new DefaultSchedulingContext(), new TimeProvider(), jobNameGenerator);
JobInstance jobInstance = jobs.first();
assertThat(jobConfig.name(), is(new CaseInsensitiveString(jobInstance.getName())));
assertThat(jobInstance.getState(), is(JobState.Scheduled));
assertThat(jobInstance.getScheduledDate(), is(notNullValue()));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldCreateASingleJobIfRunOnAllAgentsIsFalse.
/*
SingleJobInstance
*/
@Test
public void shouldCreateASingleJobIfRunOnAllAgentsIsFalse() throws Exception {
JobConfig jobConfig = new JobConfig("foo");
SchedulingContext context = mock(SchedulingContext.class);
when(context.getEnvironmentVariablesConfig()).thenReturn(new EnvironmentVariablesConfig());
when(context.overrideEnvironmentVariables(any(EnvironmentVariablesConfig.class))).thenReturn(context);
RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(jobConfig.name()));
JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("someStage"), jobConfig, new DefaultSchedulingContext(), new TimeProvider(), jobNameGenerator);
assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo"))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", IsNull.nullValue())));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(false))));
assertThat(jobs.size(), is(1));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldSetAutoApprovalOnStageInstance.
@Test
public void shouldSetAutoApprovalOnStageInstance() {
StageConfig stageConfig = StageConfigMother.custom("test", Approval.automaticApproval());
Stage instance = instanceFactory.createStageInstance(stageConfig, new DefaultSchedulingContext("anyone"), "md5", new TimeProvider());
assertThat(instance.getApprovalType(), is(GoConstants.APPROVAL_SUCCESS));
}
Aggregations