Search in sources :

Example 1 with ApiTaskManager

use of org.opengrok.web.api.ApiTaskManager in project OpenGrok by OpenGrok.

the class StatusControllerTest method testGet.

@Test
void testGet() throws InterruptedException {
    int sleepTime = 3000;
    ApiTask apiTask = new ApiTask("foo", () -> {
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    }, Response.Status.CREATED);
    String uuidString = apiTask.getUuid().toString();
    ApiTaskManager apiTaskManager = ApiTaskManager.getInstance();
    String poolName = "foo";
    apiTaskManager.addPool(poolName, 1);
    apiTaskManager.submitApiTask(poolName, apiTask);
    Response response = target(StatusController.PATH).path(uuidString).request().get();
    assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
    Thread.sleep(sleepTime);
    response = target(StatusController.PATH).path(uuidString).request().get();
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) ApiTaskManager(org.opengrok.web.api.ApiTaskManager) ApiTask(org.opengrok.web.api.ApiTask) Test(org.junit.jupiter.api.Test)

Example 2 with ApiTaskManager

use of org.opengrok.web.api.ApiTaskManager in project OpenGrok by OpenGrok.

the class StatusControllerTest method testDelete.

@Test
void testDelete() throws InterruptedException {
    ApiTask apiTask = new ApiTask("foo", this::doNothing);
    String uuidString = apiTask.getUuid().toString();
    ApiTaskManager apiTaskManager = ApiTaskManager.getInstance();
    String poolName = "deleteCompleted";
    apiTaskManager.addPool(poolName, 1);
    apiTaskManager.submitApiTask(poolName, apiTask);
    Thread.sleep(1000);
    Response response = target(StatusController.PATH).path(uuidString).request().delete();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) ApiTaskManager(org.opengrok.web.api.ApiTaskManager) ApiTask(org.opengrok.web.api.ApiTask) Test(org.junit.jupiter.api.Test)

Example 3 with ApiTaskManager

use of org.opengrok.web.api.ApiTaskManager in project OpenGrok by OpenGrok.

the class StatusControllerTest method testDeleteNotCompleted.

@Test
void testDeleteNotCompleted() {
    int sleepTime = 3000;
    ApiTask apiTask = new ApiTask("foo", () -> {
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    });
    String uuidString = apiTask.getUuid().toString();
    ApiTaskManager apiTaskManager = ApiTaskManager.getInstance();
    String poolName = "deleteNotCompleted";
    apiTaskManager.addPool(poolName, 1);
    apiTaskManager.submitApiTask(poolName, apiTask);
    Response response = target(StatusController.PATH).path(uuidString).request().delete();
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) ApiTaskManager(org.opengrok.web.api.ApiTaskManager) ApiTask(org.opengrok.web.api.ApiTask) Test(org.junit.jupiter.api.Test)

Aggregations

Response (jakarta.ws.rs.core.Response)3 Test (org.junit.jupiter.api.Test)3 ApiTask (org.opengrok.web.api.ApiTask)3 ApiTaskManager (org.opengrok.web.api.ApiTaskManager)3