Search in sources :

Example 11 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testDeleteWithHeaders.

@Test
public void testDeleteWithHeaders() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
    String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    //now, verify GET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
    GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
    //now, perform DELETE
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.DELETE);
    DeleteResponse deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DeleteResponse.class);
    assertNotNull("response should not be null", deleteResponse);
    //now, verify GET fails to find the indexed value
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
    response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNull("response source should be null", response.getSource());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) HashMap(java.util.HashMap) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 12 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testDelete.

@Test
public void testDelete() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    sendBody("direct:index", map);
    String indexId = template.requestBody("direct:index", map, String.class);
    assertNotNull("indexId should be set", indexId);
    //now, verify GET succeeded
    GetResponse response = template.requestBody("direct:get", indexId, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
    //now, perform DELETE
    DeleteResponse deleteResponse = template.requestBody("direct:delete", indexId, DeleteResponse.class);
    assertNotNull("response should not be null", deleteResponse);
    //now, verify GET fails to find the indexed value
    response = template.requestBody("direct:get", indexId, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNull("response source should be null", response.getSource());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 13 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testDeleteWithHeaders.

@Test
public void testDeleteWithHeaders() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
    String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    //now, verify GET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
    GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
    //now, perform DELETE
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_DELETE);
    DeleteResponse deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DeleteResponse.class);
    assertNotNull("response should not be null", deleteResponse);
    //now, verify GET fails to find the indexed value
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
    response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNull("response source should be null", response.getSource());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) HashMap(java.util.HashMap) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 14 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method deleteRequestBody.

@Test
public void deleteRequestBody() throws Exception {
    String prefix = createPrefix();
    // given
    DeleteRequest request = new DeleteRequest(prefix + "foo").type(prefix + "bar");
    // when
    String documentId = template.requestBody("direct:index", new IndexRequest("" + prefix + "foo", "" + prefix + "bar", "" + prefix + "testId").source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
    DeleteResponse response = template.requestBody("direct:delete", request.id(documentId), DeleteResponse.class);
    // then
    assertThat(response, notNullValue());
    assertThat(documentId, equalTo(response.getId()));
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) Test(org.junit.Test)

Example 15 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project nifi by apache.

the class TestDeleteElasticsearch5 method testDeleteRetryableException.

@Test
public void testDeleteRetryableException() throws IOException {
    mockDeleteProcessor = new DeleteElasticsearch5() {

        @Override
        protected DeleteRequestBuilder prepareDeleteRequest(String index, String docId, String docType) {
            return null;
        }

        @Override
        protected DeleteResponse doDelete(DeleteRequestBuilder requestBuilder) throws InterruptedException, ExecutionException {
            throw new ElasticsearchTimeoutException("timeout");
        }

        @Override
        public void setup(ProcessContext context) {
        }
    };
    runner = TestRunners.newTestRunner(mockDeleteProcessor);
    runner.setValidateExpressionUsage(true);
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.CLUSTER_NAME, "elasticsearch");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.PING_TIMEOUT, "5s");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.SAMPLER_INTERVAL, "5s");
    runner.setProperty(DeleteElasticsearch5.INDEX, INDEX1);
    runner.setProperty(DeleteElasticsearch5.TYPE, TYPE1);
    runner.setProperty(DeleteElasticsearch5.DOCUMENT_ID, "${documentId}");
    runner.assertValid();
    runner.enqueue(new byte[] {}, new HashMap<String, String>() {

        {
            put("documentId", documentId);
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(DeleteElasticsearch5.REL_RETRY, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(DeleteElasticsearch5.REL_RETRY).get(0);
    assertNotNull(out);
    assertEquals("timeout", out.getAttribute(DeleteElasticsearch5.ES_ERROR_MESSAGE));
    out.assertAttributeEquals(DeleteElasticsearch5.ES_REST_STATUS, null);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_FILENAME, documentId);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_INDEX, INDEX1);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_TYPE, TYPE1);
}
Also used : DeleteRequestBuilder(org.elasticsearch.action.delete.DeleteRequestBuilder) MockFlowFile(org.apache.nifi.util.MockFlowFile) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Aggregations

DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)42 Test (org.junit.Test)14 IndexResponse (org.elasticsearch.action.index.IndexResponse)13 GetResponse (org.elasticsearch.action.get.GetResponse)11 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)8 HashMap (java.util.HashMap)7 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)7 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 IndexRequest (org.elasticsearch.action.index.IndexRequest)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)3 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)3 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2