Search in sources :

Example 6 with Response

use of javax.ws.rs.core.Response in project druid by druid-io.

the class SupervisorResourceTest method testReset.

@Test
public void testReset() throws Exception {
    Capture<String> id1 = Capture.newInstance();
    Capture<String> id2 = Capture.newInstance();
    EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)).times(2);
    EasyMock.expect(supervisorManager.resetSupervisor(EasyMock.capture(id1), EasyMock.anyObject(DataSourceMetadata.class))).andReturn(true);
    EasyMock.expect(supervisorManager.resetSupervisor(EasyMock.capture(id2), EasyMock.anyObject(DataSourceMetadata.class))).andReturn(false);
    replayAll();
    Response response = supervisorResource.reset("my-id");
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("id", "my-id"), response.getEntity());
    response = supervisorResource.reset("my-id-2");
    Assert.assertEquals(404, response.getStatus());
    Assert.assertEquals("my-id", id1.getValue());
    Assert.assertEquals("my-id-2", id2.getValue());
    verifyAll();
    resetAll();
    EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.<SupervisorManager>absent());
    replayAll();
    response = supervisorResource.shutdown("my-id");
    Assert.assertEquals(503, response.getStatus());
    verifyAll();
}
Also used : Response(javax.ws.rs.core.Response) DataSourceMetadata(io.druid.indexing.overlord.DataSourceMetadata) Test(org.junit.Test)

Example 7 with Response

use of javax.ws.rs.core.Response in project druid by druid-io.

the class SupervisorResourceTest method testSpecPost.

@Test
public void testSpecPost() throws Exception {
    SupervisorSpec spec = new TestSupervisorSpec("my-id", null);
    EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager));
    EasyMock.expect(supervisorManager.createOrUpdateAndStartSupervisor(spec)).andReturn(true);
    replayAll();
    Response response = supervisorResource.specPost(spec);
    verifyAll();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("id", "my-id"), response.getEntity());
    resetAll();
    EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.<SupervisorManager>absent());
    replayAll();
    response = supervisorResource.specPost(spec);
    verifyAll();
    Assert.assertEquals(503, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 8 with Response

use of javax.ws.rs.core.Response in project druid by druid-io.

the class OverlordResourceTest method testSecuredTaskPost.

@Test
public void testSecuredTaskPost() {
    EasyMock.replay(taskRunner, taskMaster, tsqa, req);
    Task task = NoopTask.create();
    Response response = overlordResource.taskPost(task, req);
    Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Task(io.druid.indexing.common.task.Task) AbstractTask(io.druid.indexing.common.task.AbstractTask) NoopTask(io.druid.indexing.common.task.NoopTask) Test(org.junit.Test)

Example 9 with Response

use of javax.ws.rs.core.Response in project druid by druid-io.

the class OverlordTest method testOverlordRun.

@Test(timeout = 2000L)
public void testOverlordRun() throws Exception {
    // basic task master lifecycle test
    taskMaster.start();
    announcementLatch.await();
    while (!taskMaster.isLeading()) {
        // I believe the control will never reach here and thread will never sleep but just to be on safe side
        Thread.sleep(10);
    }
    Assert.assertEquals(taskMaster.getLeader(), druidNode.getHostAndPort());
    // Test Overlord resource stuff
    overlordResource = new OverlordResource(taskMaster, new TaskStorageQueryAdapter(taskStorage), null, null, null, new AuthConfig());
    Response response = overlordResource.getLeader();
    Assert.assertEquals(druidNode.getHostAndPort(), response.getEntity());
    final String taskId_0 = "0";
    NoopTask task_0 = new NoopTask(taskId_0, 0, 0, null, null, null);
    response = overlordResource.taskPost(task_0, req);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("task", taskId_0), response.getEntity());
    // Duplicate task - should fail
    response = overlordResource.taskPost(task_0, req);
    Assert.assertEquals(400, response.getStatus());
    // Task payload for task_0 should be present in taskStorage
    response = overlordResource.getTaskPayload(taskId_0);
    Assert.assertEquals(task_0, ((Map) response.getEntity()).get("payload"));
    // Task not present in taskStorage - should fail
    response = overlordResource.getTaskPayload("whatever");
    Assert.assertEquals(404, response.getStatus());
    // Task status of the submitted task should be running
    response = overlordResource.getTaskStatus(taskId_0);
    Assert.assertEquals(taskId_0, ((Map) response.getEntity()).get("task"));
    Assert.assertEquals(TaskStatus.running(taskId_0).getStatusCode(), ((TaskStatus) ((Map) response.getEntity()).get("status")).getStatusCode());
    // Simulate completion of task_0
    taskCompletionCountDownLatches[Integer.parseInt(taskId_0)].countDown();
    // Wait for taskQueue to handle success status of task_0
    waitForTaskStatus(taskId_0, TaskStatus.Status.SUCCESS);
    // Manually insert task in taskStorage
    // Verifies sync from storage
    final String taskId_1 = "1";
    NoopTask task_1 = new NoopTask(taskId_1, 0, 0, null, null, null);
    taskStorage.insert(task_1, TaskStatus.running(taskId_1));
    // Wait for task runner to run task_1
    runTaskCountDownLatches[Integer.parseInt(taskId_1)].await();
    response = overlordResource.getRunningTasks(req);
    // 1 task that was manually inserted should be in running state
    Assert.assertEquals(1, (((List) response.getEntity()).size()));
    final OverlordResource.TaskResponseObject taskResponseObject = ((List<OverlordResource.TaskResponseObject>) response.getEntity()).get(0);
    Assert.assertEquals(taskId_1, taskResponseObject.toJson().get("id"));
    Assert.assertEquals(TASK_LOCATION, taskResponseObject.toJson().get("location"));
    // Simulate completion of task_1
    taskCompletionCountDownLatches[Integer.parseInt(taskId_1)].countDown();
    // Wait for taskQueue to handle success status of task_1
    waitForTaskStatus(taskId_1, TaskStatus.Status.SUCCESS);
    // should return number of tasks which are not in running state
    response = overlordResource.getCompleteTasks(req);
    Assert.assertEquals(2, (((List) response.getEntity()).size()));
    taskMaster.stop();
    Assert.assertFalse(taskMaster.isLeading());
    EasyMock.verify(taskLockbox, taskActionClientFactory);
}
Also used : Response(javax.ws.rs.core.Response) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AuthConfig(io.druid.server.security.AuthConfig) NoopTask(io.druid.indexing.common.task.NoopTask) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TaskStorageQueryAdapter(io.druid.indexing.overlord.TaskStorageQueryAdapter) Test(org.junit.Test)

Example 10 with Response

use of javax.ws.rs.core.Response in project druid by druid-io.

the class WorkerResourceTest method testDoDisable.

@Test
public void testDoDisable() throws Exception {
    Worker theWorker = jsonMapper.readValue(cf.getData().forPath(announcementsPath), Worker.class);
    Assert.assertEquals("v1", theWorker.getVersion());
    Response res = workerResource.doDisable();
    Assert.assertEquals(Response.Status.OK.getStatusCode(), res.getStatus());
    theWorker = jsonMapper.readValue(cf.getData().forPath(announcementsPath), Worker.class);
    Assert.assertTrue(theWorker.getVersion().isEmpty());
}
Also used : Response(javax.ws.rs.core.Response) Worker(io.druid.indexing.worker.Worker) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)10205 Test (org.junit.Test)5764 Test (org.testng.annotations.Test)1113 JerseyTest (org.glassfish.jersey.test.JerseyTest)870 Test (org.junit.jupiter.api.Test)701 WebTarget (javax.ws.rs.client.WebTarget)668 Builder (javax.ws.rs.client.Invocation.Builder)638 WebClient (org.apache.cxf.jaxrs.client.WebClient)620 DBUnitTest (org.orcid.test.DBUnitTest)611 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)577 Parameters (org.testng.annotations.Parameters)537 URI (java.net.URI)515 HashMap (java.util.HashMap)508 Path (javax.ws.rs.Path)506 List (java.util.List)465 ArrayList (java.util.ArrayList)419 Produces (javax.ws.rs.Produces)396 IOException (java.io.IOException)393 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)354 GET (javax.ws.rs.GET)348