Search in sources :

Example 6 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class AgentTest method agentsWithDifferentAttributesDoNotShareSameHashCode.

@Test
void agentsWithDifferentAttributesDoNotShareSameHashCode() throws Exception {
    Agent agent1 = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    Agent agent2 = new Agent();
    assertThat(agent1.hashCode()).isNotEqualTo(agent2.hashCode());
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) Test(org.junit.jupiter.api.Test)

Example 7 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class JobCompletionRequestExecutorTest method shouldTerminateElasticAgentOnJobCompletion.

@Test
public void shouldTerminateElasticAgentOnJobCompletion() throws Exception {
    JobIdentifier jobIdentifier = new JobIdentifier("test", 1L, "test", "test_stage", "1", "test_job", 100L);
    String elasticAgentId = "agent-1";
    ClusterProfileProperties clusterProfileProperties = new ClusterProfileProperties();
    JobCompletionRequest request = new JobCompletionRequest(elasticAgentId, jobIdentifier, new ElasticAgentProfileProperties(), clusterProfileProperties);
    JobCompletionRequestExecutor executor = new JobCompletionRequestExecutor(request, mockAgentInstances, mockPluginRequest);
    Agents agents = new Agents();
    agents.add(new Agent(elasticAgentId));
    when(mockPluginRequest.listAgents()).thenReturn(agents);
    GoPluginApiResponse response = executor.execute();
    InOrder inOrder = inOrder(mockPluginRequest, mockAgentInstances);
    inOrder.verify(mockPluginRequest).disableAgents(agentsArgumentCaptor.capture());
    inOrder.verify(mockAgentInstances).terminate(elasticAgentId, clusterProfileProperties);
    inOrder.verify(mockPluginRequest).deleteAgents(agentsArgumentCaptor.capture());
    List<Agent> agentsToDisabled = agentsArgumentCaptor.getValue();
    assertThat(1).isEqualTo(agentsToDisabled.size());
    assertThat(elasticAgentId).isEqualTo(agentsToDisabled.get(0).elasticAgentId());
    List<Agent> agentsToDelete = agentsArgumentCaptor.getValue();
    assertThat(agentsToDisabled).isEqualTo(agentsToDelete);
    assertThat(200).isEqualTo(response.responseCode());
    assertThat(response.responseBody().isEmpty()).isTrue();
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) InOrder(org.mockito.InOrder) Agents(com.thoughtworks.gocd.elasticagent.ecs.Agents) JobCompletionRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) ElasticAgentProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties) Test(org.junit.jupiter.api.Test)

Example 8 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class ShouldAssignWorkRequestExecutorTest method shouldAssignWorkToContainerWithMatchingJobIdentifier.

@Test
void shouldAssignWorkToContainerWithMatchingJobIdentifier() {
    ShouldAssignWorkRequest request = new ShouldAssignWorkRequest(new Agent(task.name(), null, null, null), environment, elasticAgentProfileProperties, getJobIdentifierWithId(1), clusterProfileProperties);
    GoPluginApiResponse response = new ShouldAssignWorkRequestExecutor(request, agentInstances).execute();
    assertThat(response.responseCode()).isEqualTo(200);
    assertThat(response.responseBody()).isEqualTo("true");
}
Also used : ShouldAssignWorkRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.ShouldAssignWorkRequest) Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Example 9 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class AgentTest method agentShouldNotEqualAnotherAgentWithDifferentAttributes.

@Test
void agentShouldNotEqualAnotherAgentWithDifferentAttributes() throws Exception {
    Agent agent = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    assertThat(agent).isNotEqualTo(new Agent());
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) Test(org.junit.jupiter.api.Test)

Example 10 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class AgentTest method agentShouldEqualItself.

@Test
void agentShouldEqualItself() throws Exception {
    Agent agent = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    assertThat(agent).isEqualTo(agent);
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) Test(org.junit.jupiter.api.Test)

Aggregations

Agent (com.thoughtworks.gocd.elasticagent.ecs.domain.Agent)12 Test (org.junit.jupiter.api.Test)11 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)3 Agents (com.thoughtworks.gocd.elasticagent.ecs.Agents)2 ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)2 ShouldAssignWorkRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.ShouldAssignWorkRequest)2 ElasticAgentProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)1 JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)1 PluginSettings (com.thoughtworks.gocd.elasticagent.ecs.domain.PluginSettings)1 JobCompletionRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest)1 HashMap (java.util.HashMap)1 InOrder (org.mockito.InOrder)1