Search in sources :

Example 1 with RetryPolicyFactory

use of io.druid.indexing.common.RetryPolicyFactory in project druid by druid-io.

the class RemoteTaskActionClientTest method testSubmitSimple.

@Test
public void testSubmitSimple() throws JsonProcessingException {
    // return status code 200 and a list with size equals 1
    Map<String, Object> responseBody = new HashMap<String, Object>();
    responseBody.put("result", result);
    String strResult = objectMapper.writeValueAsString(responseBody);
    StatusResponseHolder responseHolder = new StatusResponseHolder(HttpResponseStatus.OK, new StringBuilder().append(strResult));
    // set up mocks
    expect(selector.pick()).andReturn(server);
    replay(selector);
    expect(httpClient.go(anyObject(Request.class), anyObject(StatusResponseHandler.class))).andReturn(Futures.immediateFuture(responseHolder));
    replay(httpClient);
    Task task = new NoopTask("id", 0, 0, null, null, null);
    RemoteTaskActionClient client = new RemoteTaskActionClient(task, httpClient, selector, new RetryPolicyFactory(new RetryPolicyConfig()), objectMapper);
    try {
        result = client.submit(new LockListAction());
    } catch (IOException e) {
        Assert.fail("unexpected IOException");
    }
    Assert.assertEquals(1, result.size());
    EasyMock.verify(selector, httpClient);
}
Also used : Task(io.druid.indexing.common.task.Task) NoopTask(io.druid.indexing.common.task.NoopTask) RetryPolicyConfig(io.druid.indexing.common.RetryPolicyConfig) HashMap(java.util.HashMap) Request(com.metamx.http.client.Request) IOException(java.io.IOException) NoopTask(io.druid.indexing.common.task.NoopTask) RetryPolicyFactory(io.druid.indexing.common.RetryPolicyFactory) StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) EasyMock.anyObject(org.easymock.EasyMock.anyObject) StatusResponseHandler(com.metamx.http.client.response.StatusResponseHandler) Test(org.junit.Test)

Example 2 with RetryPolicyFactory

use of io.druid.indexing.common.RetryPolicyFactory in project druid by druid-io.

the class RemoteTaskActionClientTest method testSubmitWithIllegalStatusCode.

@Test(expected = IOException.class)
public void testSubmitWithIllegalStatusCode() throws IOException {
    // return status code 400 and a list with size equals 1
    Map<String, Object> responseBody = new HashMap<String, Object>();
    responseBody.put("result", result);
    String strResult = objectMapper.writeValueAsString(responseBody);
    StatusResponseHolder responseHolder = new StatusResponseHolder(HttpResponseStatus.BAD_REQUEST, new StringBuilder().append(strResult));
    // set up mocks
    expect(selector.pick()).andReturn(server);
    replay(selector);
    expect(httpClient.go(anyObject(Request.class), anyObject(StatusResponseHandler.class))).andReturn(Futures.immediateFuture(responseHolder));
    replay(httpClient);
    Task task = new NoopTask("id", 0, 0, null, null, null);
    RemoteTaskActionClient client = new RemoteTaskActionClient(task, httpClient, selector, new RetryPolicyFactory(objectMapper.readValue("{\"maxRetryCount\":0}", RetryPolicyConfig.class)), objectMapper);
    result = client.submit(new LockListAction());
}
Also used : Task(io.druid.indexing.common.task.Task) NoopTask(io.druid.indexing.common.task.NoopTask) HashMap(java.util.HashMap) Request(com.metamx.http.client.Request) NoopTask(io.druid.indexing.common.task.NoopTask) RetryPolicyFactory(io.druid.indexing.common.RetryPolicyFactory) StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) EasyMock.anyObject(org.easymock.EasyMock.anyObject) StatusResponseHandler(com.metamx.http.client.response.StatusResponseHandler) Test(org.junit.Test)

Aggregations

Request (com.metamx.http.client.Request)2 StatusResponseHandler (com.metamx.http.client.response.StatusResponseHandler)2 StatusResponseHolder (com.metamx.http.client.response.StatusResponseHolder)2 RetryPolicyFactory (io.druid.indexing.common.RetryPolicyFactory)2 NoopTask (io.druid.indexing.common.task.NoopTask)2 Task (io.druid.indexing.common.task.Task)2 HashMap (java.util.HashMap)2 EasyMock.anyObject (org.easymock.EasyMock.anyObject)2 Test (org.junit.Test)2 RetryPolicyConfig (io.druid.indexing.common.RetryPolicyConfig)1 IOException (java.io.IOException)1