use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class ValidatorTest method whenRunNowIfNoRunIdSetItWillGenerateAnId.
@Test
public void whenRunNowIfNoRunIdSetItWillGenerateAnId() {
String deployID = "deploy";
Optional<String> userEmail = Optional.absent();
SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.ON_DEMAND).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.of(runNowRequest());
List<SingularityTaskId> activeTasks = Collections.emptyList();
List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
SingularityPendingRequest pendingRequest = validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
Assert.assertTrue(pendingRequest.getRunId().isPresent());
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class BlendedHistoryTest method testBlendedRequestHistory.
// DESCENDING
@Test
public void testBlendedRequestHistory() {
HistoryManager hm = mock(HistoryManager.class);
String rid = "rid";
request = new SingularityRequestBuilder(rid, RequestType.WORKER).build();
RequestHistoryHelper rhh = new RequestHistoryHelper(requestManager, hm);
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
Assert.assertTrue(rhh.getBlendedHistory(rid, 0, 100).isEmpty());
Assert.assertTrue(!rhh.getFirstHistory(rid).isPresent());
Assert.assertTrue(!rhh.getLastHistory(rid).isPresent());
mockRequestHistory(hm, Arrays.asList(makeHistory(52, RequestHistoryType.EXITED_COOLDOWN), makeHistory(51, RequestHistoryType.ENTERED_COOLDOWN), makeHistory(50, RequestHistoryType.CREATED)));
List<SingularityRequestHistory> history = rhh.getBlendedHistory(rid, 0, 5);
Assert.assertTrue(history.size() == 3);
saveHistory(100, RequestHistoryType.DELETED);
saveHistory(120, RequestHistoryType.CREATED);
history = rhh.getBlendedHistory(rid, 0, 5);
Assert.assertTrue(history.size() == 5);
Assert.assertTrue(history.get(0).getCreatedAt() == 120);
Assert.assertTrue(history.get(4).getCreatedAt() == 50);
history = rhh.getBlendedHistory(rid, 1, 5);
Assert.assertTrue(history.size() == 4);
Assert.assertTrue(history.get(0).getCreatedAt() == 100);
Assert.assertTrue(history.get(3).getCreatedAt() == 50);
history = rhh.getBlendedHistory(rid, 2, 5);
Assert.assertTrue(history.size() == 3);
Assert.assertTrue(history.get(0).getCreatedAt() == 52);
Assert.assertTrue(history.get(2).getCreatedAt() == 50);
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
history = rhh.getBlendedHistory(rid, 3, 5);
Assert.assertTrue(history.isEmpty());
history = rhh.getBlendedHistory(rid, 1, 5);
Assert.assertTrue(history.size() == 1);
Assert.assertTrue(history.get(0).getCreatedAt() == 100);
Assert.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 100);
Assert.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
mockRequestHistory(hm, Arrays.asList(makeHistory(1, RequestHistoryType.EXITED_COOLDOWN)));
Assert.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 1);
Assert.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class ValidatorTest method whenDeployHasRunNowSetItValidatesThatItIsLessThanACertaionLength.
@Test(expected = WebApplicationException.class)
public void whenDeployHasRunNowSetItValidatesThatItIsLessThanACertaionLength() {
String requestId = "request";
String deployID = "deploy";
SingularityRequest request = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.of(runNowRequest(tooLongId()));
SingularityDeploy deploy = SingularityDeploy.newBuilder(requestId, deployID).setCommand(Optional.of("printenv")).setRunImmediately(runNowRequest).build();
validator.checkDeploy(request, deploy, Collections.emptyList(), Collections.emptyList());
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class ValidatorTest method itDoesNotAllowOtherRequestTypesToChange.
@Test(expected = WebApplicationException.class)
public void itDoesNotAllowOtherRequestTypesToChange() {
SingularityRequest request = new SingularityRequestBuilder("test", RequestType.ON_DEMAND).build();
SingularityRequest newRequest = new SingularityRequestBuilder("test", RequestType.SCHEDULED).build();
validator.checkSingularityRequest(newRequest, Optional.of(request), Optional.absent(), Optional.absent());
}
use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.
the class ValidatorTest method itForbidsHealthCheckStartupDelaysLongerThanKillWait.
@Test
public void itForbidsHealthCheckStartupDelaysLongerThanKillWait() {
// Default kill wait time is 10 minutes (600 seconds)
HealthcheckOptions healthCheck = new HealthcheckOptionsBuilder("/").setPortNumber(Optional.of(8080L)).setStartupDelaySeconds(Optional.of(10000)).build();
SingularityDeploy deploy = SingularityDeploy.newBuilder("1234567", "1234567").setHealthcheck(Optional.of(healthCheck)).build();
SingularityRequest request = new SingularityRequestBuilder("1234567", RequestType.SERVICE).build();
WebApplicationException exn = (WebApplicationException) catchThrowable(() -> validator.checkDeploy(request, deploy, Collections.emptyList(), Collections.emptyList()));
assertThat((String) exn.getResponse().getEntity()).contains("Health check startup delay");
}
Aggregations