use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testTaskBounce.
@Test
public void testTaskBounce() {
initRequest();
initFirstDeploy();
SingularityTask firstTask = startTask(firstDeploy);
taskResource.killTask(firstTask.getTaskId().getId(), Optional.of(new SingularityKillTaskRequest(Optional.absent(), Optional.of("msg"), Optional.absent(), Optional.of(true), Optional.absent())), singularityUser);
cleaner.drainCleanupQueue();
killKilledTasks();
Assert.assertEquals(1, taskManager.getNumCleanupTasks());
Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
resourceOffers();
runLaunchedTasks();
Assert.assertEquals(1, taskManager.getNumCleanupTasks());
Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
Assert.assertEquals(2, taskManager.getNumActiveTasks());
cleaner.drainCleanupQueue();
killKilledTasks();
Assert.assertEquals(0, taskManager.getNumCleanupTasks());
Assert.assertEquals(1, taskManager.getNumActiveTasks());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCooldownOnlyWhenTasksRapidlyFail.
@Test
public void testCooldownOnlyWhenTasksRapidlyFail() {
initRequest();
initFirstDeploy();
configuration.setCooldownAfterFailures(1);
SingularityTask firstTask = startTask(firstDeploy);
statusUpdate(firstTask, TaskState.TASK_FAILED, Optional.of(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(5)));
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.ACTIVE);
SingularityTask secondTask = startTask(firstDeploy);
statusUpdate(secondTask, TaskState.TASK_FAILED);
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.SYSTEM_COOLDOWN);
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testLBCleanup.
@Test
public void testLBCleanup() {
initLoadBalancedRequest();
initFirstDeploy();
configuration.setLoadBalancerRemovalGracePeriodMillis(10000);
SingularityTask task = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
saveLoadBalancerState(BaragonRequestState.SUCCESS, task.getTaskId(), LoadBalancerRequestType.ADD);
statusUpdate(task, TaskState.TASK_FAILED);
Assert.assertTrue(!taskManager.getLBCleanupTasks().isEmpty());
testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING);
cleaner.drainCleanupQueue();
Assert.assertTrue(!taskManager.getLBCleanupTasks().isEmpty());
Optional<SingularityLoadBalancerUpdate> lbUpdate = taskManager.getLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.REMOVE);
Assert.assertTrue(lbUpdate.isPresent());
Assert.assertTrue(lbUpdate.get().getLoadBalancerState() == BaragonRequestState.WAITING);
testingLbClient.setNextBaragonRequestState(BaragonRequestState.FAILED);
cleaner.drainCleanupQueue();
Assert.assertTrue(!taskManager.getLBCleanupTasks().isEmpty());
lbUpdate = taskManager.getLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.REMOVE);
Assert.assertTrue(lbUpdate.isPresent());
Assert.assertTrue(lbUpdate.get().getLoadBalancerState() == BaragonRequestState.FAILED);
testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS);
cleaner.drainCleanupQueue();
Assert.assertTrue(!taskManager.getLBCleanupTasks().isEmpty());
configuration.setLoadBalancerRemovalGracePeriodMillis(0);
cleaner.drainCleanupQueue();
Assert.assertTrue(taskManager.getLBCleanupTasks().isEmpty());
lbUpdate = taskManager.getLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.REMOVE);
Assert.assertTrue(lbUpdate.isPresent());
Assert.assertTrue(lbUpdate.get().getLoadBalancerState() == BaragonRequestState.SUCCESS);
Assert.assertTrue(lbUpdate.get().getLoadBalancerRequestId().getAttemptNumber() == 2);
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testIncrementalBounceShutsDownOldTasksPerNewHealthyTask.
@Test
public void testIncrementalBounceShutsDownOldTasksPerNewHealthyTask() {
initRequest();
requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
initFirstDeploy();
startTask(firstDeploy, 1);
startTask(firstDeploy, 2);
startTask(firstDeploy, 3);
requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.of(true), Optional.absent(), Optional.of(1L), Optional.absent(), Optional.of("msg"), Optional.absent())), singularityUser);
Assert.assertTrue(requestManager.cleanupRequestExists(requestId));
cleaner.drainCleanupQueue();
Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
Assert.assertEquals(3, taskManager.getCleanupTaskIds().size());
SingularityTask newTask = launchTask(request, firstDeploy, 5, TaskState.TASK_STARTING);
cleaner.drainCleanupQueue();
Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
statusUpdate(newTask, TaskState.TASK_RUNNING);
cleaner.drainCleanupQueue();
Assert.assertEquals(1, taskManager.getKilledTaskIdRecords().size());
Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testReconciliation.
@Test
public void testReconciliation() {
Assert.assertTrue(!taskReconciliation.isReconciliationRunning());
configuration.setCheckReconcileWhenRunningEveryMillis(1);
initRequest();
initFirstDeploy();
Assert.assertTrue(taskReconciliation.startReconciliation() == ReconciliationState.STARTED);
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !taskReconciliation.isReconciliationRunning());
SingularityTask taskOne = launchTask(request, firstDeploy, 1, TaskState.TASK_STARTING);
SingularityTask taskTwo = launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
saveLastActiveTaskStatus(taskOne, Optional.absent(), -1000);
Assert.assertTrue(taskReconciliation.startReconciliation() == ReconciliationState.STARTED);
Assert.assertTrue(taskReconciliation.startReconciliation() == ReconciliationState.ALREADY_RUNNING);
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> taskReconciliation.isReconciliationRunning());
saveLastActiveTaskStatus(taskOne, Optional.of(buildTaskStatus(taskOne)), +1000);
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> taskReconciliation.isReconciliationRunning());
saveLastActiveTaskStatus(taskTwo, Optional.of(buildTaskStatus(taskTwo)), +1000);
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !taskReconciliation.isReconciliationRunning());
}
Aggregations