Search in sources :

Example 26 with SingularityRequestBuilder

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());
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 27 with SingularityRequestBuilder

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);
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) RequestHistoryHelper(com.hubspot.singularity.data.history.RequestHistoryHelper) HistoryManager(com.hubspot.singularity.data.history.HistoryManager) Test(org.junit.Test)

Example 28 with SingularityRequestBuilder

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());
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 29 with SingularityRequestBuilder

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

Example 30 with SingularityRequestBuilder

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");
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityRequest(com.hubspot.singularity.SingularityRequest) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)52 Test (org.junit.Test)48 SingularityRequest (com.hubspot.singularity.SingularityRequest)37 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)22 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)17 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)12 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)10 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)9 Resources (com.hubspot.mesos.Resources)8 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)7 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)5 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)3 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)3 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)3 SingularityTask (com.hubspot.singularity.SingularityTask)3 ArrayList (java.util.ArrayList)3