Search in sources :

Example 86 with TimeProvider

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());
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluginDescriptor(com.thoughtworks.go.plugin.api.info.PluginDescriptor) TimeProvider(com.thoughtworks.go.util.TimeProvider) ArrayList(java.util.ArrayList) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Before(org.junit.Before)

Example 87 with TimeProvider

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]."));
    }
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 88 with TimeProvider

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()));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 89 with TimeProvider

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 90 with TimeProvider

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)177 Test (org.junit.Test)122 Date (java.util.Date)29 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)28 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)25 DateTime (org.joda.time.DateTime)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 Username (com.thoughtworks.go.server.domain.Username)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 Before (org.junit.Before)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)11 Materials (com.thoughtworks.go.config.materials.Materials)10 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 Material (com.thoughtworks.go.domain.materials.Material)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6