feat(batch): add update and delete job queue endpoints with corresponding service logic (#2807)

This commit is contained in:
Matheus André authored and GitHub committed 2026-08-30 23:35:09 -04:00
1 parent 66d910c613
commit 6f123e83b8
5 files changed
+211

No files matched your search

@@ -447,6 +447,57 @@ class BatchIntegrationTest {
.body("__type", equalTo("ClientException"));
}
@Test
void updateAndDeleteJobQueueSupportsTeardownFlow() {
String suffix = uniqueSuffix();
String queueName = "teardown-queue-" + suffix;
String queueArn = createQueue(queueName, createComputeEnvironment("teardown-ce-" + suffix));
givenJson("{\"jobQueue\":\"%s\"}".formatted(queueName))
.when()
.post("/v1/deletejobqueue")
.then()
.statusCode(400)
.body("__type", equalTo("ClientException"));
givenJson("{\"jobQueue\":\"%s\",\"state\":\"DISABLED\",\"priority\":9}".formatted(queueName))
.when()
.post("/v1/updatejobqueue")
.then()
.statusCode(200)
.body("jobQueueName", equalTo(queueName))
.body("jobQueueArn", equalTo(queueArn));
givenJson("{\"jobQueues\":[\"%s\"]}".formatted(queueArn))
.when()
.post("/v1/describejobqueues")
.then()
.statusCode(200)
.body("jobQueues", hasSize(1))
.body("jobQueues[0].state", equalTo("DISABLED"))
.body("jobQueues[0].priority", equalTo(9));
givenJson("{\"jobQueue\":\"%s\"}".formatted(queueName))
.when()
.post("/v1/deletejobqueue")
.then()
.statusCode(200)
.body("isEmpty()", equalTo(true));
givenJson("{\"jobQueues\":[\"%s\"]}".formatted(queueArn))
.when()
.post("/v1/describejobqueues")
.then()
.statusCode(200)
.body("jobQueues", hasSize(0));
givenJson("{\"jobQueue\":\"%s\"}".formatted(queueName))
.when()
.post("/v1/deletejobqueue")
.then()
.statusCode(200);
}
@Test
void describeUnknownJobsReturnsEmptyList() {
givenJson("{\"jobs\":[\"does-not-exist\"]}")
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
@@ -24,6 +25,7 @@ import java.util.function.Predicate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
@@ -207,6 +209,108 @@ class BatchServiceTest {
assertEquals("b-job", secondPage.path("jobSummaryList").get(0).path("jobId").asText());
}
@Test
void updateJobQueueChangesPriorityStateAndComputeEnvironmentOrder() throws Exception {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
String firstComputeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"update-ce-1","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
String secondComputeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"update-ce-2","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
String queueArn = service.createJobQueue(json("""
{
"jobQueueName":"update-queue",
"priority":1,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(firstComputeArn)), REGION).path("jobQueueArn").asText();
JsonNode updated = service.updateJobQueue(json("""
{
"jobQueue":"update-queue",
"state":"DISABLED",
"priority":5,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(secondComputeArn)));
assertEquals("update-queue", updated.path("jobQueueName").asText());
assertEquals(queueArn, updated.path("jobQueueArn").asText());
JsonNode detail = service.describeJobQueues(json("""
{"jobQueues":["%s"]}
""".formatted(queueArn))).path("jobQueues").get(0);
assertEquals("DISABLED", detail.path("state").asText());
assertEquals(5, detail.path("priority").asInt());
assertEquals(secondComputeArn,
detail.path("computeEnvironmentOrder").get(0).path("computeEnvironment").asText());
}
@Test
void updateJobQueueRejectsUnknownQueue() {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
AwsException e = assertThrows(AwsException.class, () -> service.updateJobQueue(json("""
{"jobQueue":"missing-queue","priority":2}
""")));
assertEquals("ClientException", e.getErrorCode());
}
@Test
void deleteJobQueueRejectsEnabledQueue() throws Exception {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
String computeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"delete-enabled-ce","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
service.createJobQueue(json("""
{
"jobQueueName":"delete-enabled-queue",
"priority":1,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(computeArn)), REGION);
AwsException e = assertThrows(AwsException.class, () -> service.deleteJobQueue(json("""
{"jobQueue":"delete-enabled-queue"}
""")));
assertEquals("ClientException", e.getErrorCode());
}
@Test
void deleteJobQueueRemovesDisabledQueueAndToleratesRepeatDeletes() throws Exception {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
String computeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"delete-ce","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
String queueArn = service.createJobQueue(json("""
{
"jobQueueName":"delete-queue",
"priority":1,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(computeArn)), REGION).path("jobQueueArn").asText();
service.updateJobQueue(json("""
{"jobQueue":"delete-queue","state":"DISABLED"}
"""));
JsonNode deleted = service.deleteJobQueue(json("""
{"jobQueue":"delete-queue"}
"""));
assertEquals(0, deleted.size());
JsonNode queues = service.describeJobQueues(json("""
{"jobQueues":["%s"]}
""".formatted(queueArn))).path("jobQueues");
assertEquals(0, queues.size());
JsonNode repeated = service.deleteJobQueue(json("""
{"jobQueue":"delete-queue"}
"""));
assertEquals(0, repeated.size());
}
private BatchService dockerService(BatchDockerRunner runner) {
EmulatorConfig config = mock(EmulatorConfig.class);
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);