use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.
the class EligibleForTerminationPredicateTest method shouldReturnTrueWhenInstanceIsStoppedLongerThanTheTimeConfiguredInPluginSettings.
@ParameterizedTest
@EnumSource(Platform.class)
void shouldReturnTrueWhenInstanceIsStoppedLongerThanTheTimeConfiguredInPluginSettings(Platform platform) {
final Clock.TestClock testClock = new Clock.TestClock();
final Instance instance = instance("i-abcd123", STOPPED, platform.name()).withTags(new Tag(STOPPED_AT, String.valueOf(testClock.now().getMillis())));
when(pluginSettings.terminateStoppedLinuxInstanceAfter()).thenReturn(Period.seconds(20));
when(pluginSettings.terminateStoppedWindowsInstanceAfter()).thenReturn(Period.seconds(20));
testClock.forward(Period.seconds(21));
final boolean testResult = new EligibleForTerminationPredicate(pluginSettings, testClock).test(instance);
assertThat(testResult).isTrue();
}
use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.
the class SpotInstanceEligibleForTerminationPredicateTest method shouldReturnFalseIfInstanceDoesNotHaveLastSeenIdleLabel.
@Test
void shouldReturnFalseIfInstanceDoesNotHaveLastSeenIdleLabel() {
final Instance instance = linuxInstanceWithTag("i-abcd123", STOPPED, new Tag("Foo", "Bar"));
final boolean testResult = new SpotInstanceEligibleForTerminationPredicate(null).test(instance);
assertThat(testResult).isFalse();
}
use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.
the class SpotInstanceEligibleForTerminationPredicateTest method shouldReturnFalseWhenTerminationTimeIsNotReached.
@ParameterizedTest
@EnumSource(Platform.class)
void shouldReturnFalseWhenTerminationTimeIsNotReached(Platform platform) {
final Clock.TestClock testClock = new Clock.TestClock();
final Instance instance = spotInstance("i-abcd123", RUNNING, platform.name()).withTags(new Tag(LAST_SEEN_IDLE, String.valueOf(testClock.now().getMillis())));
when(pluginSettings.terminateIdleLinuxSpotInstanceAfter()).thenReturn(Period.seconds(20));
when(pluginSettings.terminateIdleWindowsSpotInstanceAfter()).thenReturn(Period.seconds(20));
testClock.forward(Period.seconds(19));
final boolean testResult = new SpotInstanceEligibleForTerminationPredicate(pluginSettings, testClock).test(instance);
assertThat(testResult).isFalse();
}
use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.
the class ServerPingRequestExecutorTest method shouldTerminateStoppedIdleInstance.
@ParameterizedTest
@EnumSource(Platform.class)
void shouldTerminateStoppedIdleInstance(Platform platform) throws Exception {
final List<Instance> allInstances = Arrays.asList(instance("i-abcdxyz", RUNNING, platform.name()), instance("i-abcd123", STOPPED, platform.name()));
final ContainerInstance stoppedContainerInstance = containerInstance("i-abcd123");
final List<ContainerInstance> containerInstances = Arrays.asList(containerInstance("i-abcdxyz"), stoppedContainerInstance);
when(containerInstanceHelper.getAllOnDemandInstances(clusterProfileProperties)).thenReturn(allInstances);
when(containerInstanceHelper.onDemandContainerInstances(clusterProfileProperties)).thenReturn(containerInstances);
when(pluginRequest.listAgents()).thenReturn(new Agents(new ArrayList<>()));
executor.execute();
verify(terminationOperation).execute(clusterProfileProperties, singletonList(stoppedContainerInstance));
}
use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.
the class ClusterStatusReportExecutorTest method shouldGenerateHealthView.
@Test
void shouldGenerateHealthView() throws Exception {
final List<ContainerInstance> containerInstances = Collections.emptyList();
final List<Instance> ec2Instances = Collections.emptyList();
final List<ECSContainer> ecsContainers = Collections.emptyList();
final Cluster cluster = mock(Cluster.class);
when(request.clusterProfileProperties()).thenReturn(clusterProfileProperties);
when(containerInstanceHelper.getCluster(clusterProfileProperties)).thenReturn(cluster);
when(containerInstanceHelper.getContainerInstances(clusterProfileProperties)).thenReturn(containerInstances);
when(containerInstanceHelper.ec2InstancesFromContainerInstances(clusterProfileProperties, containerInstances)).thenReturn(ec2Instances);
when(taskHelper.allRunningContainers(clusterProfileProperties)).thenReturn(ecsContainers);
when(pluginStatusReportViewBuilder.build(any(), anyMap())).thenReturn("plugin_health_html");
final GoPluginApiResponse response = clusterStatusReportExecutor.execute();
final String expectedJSON = "{\n" + "\"view\" : \"plugin_health_html\"\n" + "}";
assertThat(response.responseCode()).isEqualTo(200);
JSONAssert.assertEquals(expectedJSON, response.responseBody(), true);
}
Aggregations