Search in sources :

Example 21 with SingularityTask

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());
}
Also used : SingularityKillTaskRequest(com.hubspot.singularity.api.SingularityKillTaskRequest) SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Example 22 with SingularityTask

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);
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Example 23 with SingularityTask

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);
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Example 24 with SingularityTask

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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) Test(org.junit.Test)

Example 25 with SingularityTask

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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Aggregations

SingularityTask (com.hubspot.singularity.SingularityTask)94 Test (org.junit.Test)66 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)33 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 SingularityRequest (com.hubspot.singularity.SingularityRequest)15 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)12 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)11 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)9 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)9 Resources (com.hubspot.mesos.Resources)7 ArrayList (java.util.ArrayList)7 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)6 List (java.util.List)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)5 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)5 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)4 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)4 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)3