use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testMaxOnDemandTasks.
@Test
public void testMaxOnDemandTasks() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
bldr.setInstances(Optional.of(1));
requestResource.postRequest(bldr.build(), singularityUser);
deploy("on_demand_deploy");
deployChecker.checkDeploys();
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>absent(), PendingType.ONEOFF, Optional.<List<String>>absent(), Optional.<String>absent(), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent()));
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>absent(), PendingType.ONEOFF, Optional.<List<String>>absent(), Optional.<String>absent(), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent()));
scheduler.drainPendingQueue();
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRetries.
@Test
public void testRetries() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
request = bldr.setNumRetriesOnFailure(Optional.of(2)).build();
saveRequest(request);
deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
scheduler.drainPendingQueue();
deployChecker.checkDeploys();
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testInvalidQuartzTimeZoneErrors.
@Test(expected = WebApplicationException.class)
public void testInvalidQuartzTimeZoneErrors() {
SingularityRequest req = new SingularityRequestBuilder(requestId, RequestType.SCHEDULED).setQuartzSchedule(Optional.of("*/1 * * * * ? 2020")).setScheduleType(Optional.of(ScheduleType.QUARTZ)).setScheduleTimeZone(Optional.of("invalid_timezone")).build();
requestResource.postRequest(req, singularityUser);
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testOneOffsDontRunByThemselves.
@Test
public void testOneOffsDontRunByThemselves() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
requestResource.postRequest(bldr.build(), singularityUser);
Assert.assertTrue(requestManager.getPendingRequests().isEmpty());
deploy("d2");
Assert.assertTrue(requestManager.getPendingRequests().isEmpty());
deployChecker.checkDeploys();
Assert.assertTrue(requestManager.getPendingRequests().isEmpty());
requestResource.scheduleImmediately(singularityUser, requestId);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_FINISHED);
resourceOffers();
Assert.assertEquals(0, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, taskManager.getPendingTaskIds().size());
requestResource.scheduleImmediately(singularityUser, requestId);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertEquals(0, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, taskManager.getPendingTaskIds().size());
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCronScheduleChanges.
@Test
public void testCronScheduleChanges() throws Exception {
final String requestId = "test-change-cron";
final String oldSchedule = "*/5 * * * *";
final String oldScheduleQuartz = "0 */5 * * * ?";
final String newSchedule = "*/30 * * * *";
final String newScheduleQuartz = "0 */30 * * * ?";
SingularityRequest request = new SingularityRequestBuilder(requestId, RequestType.SCHEDULED).setSchedule(Optional.of(oldSchedule)).build();
request = validator.checkSingularityRequest(request, Optional.<SingularityRequest>absent(), Optional.<SingularityDeploy>absent(), Optional.<SingularityDeploy>absent());
saveRequest(request);
Assert.assertEquals(oldScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
initAndFinishDeploy(request, "1");
scheduler.drainPendingQueue();
final SingularityRequest newRequest = request.toBuilder().setSchedule(Optional.of(newSchedule)).setQuartzSchedule(Optional.<String>absent()).build();
final SingularityDeploy newDeploy = new SingularityDeployBuilder(request.getId(), "2").setCommand(Optional.of("sleep 100")).build();
deployResource.deploy(new SingularityDeployRequest(newDeploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
Assert.assertEquals(newScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
}
Aggregations