Search in sources :

Example 6 with BulkDocumentWriterResults

use of org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults in project metron by apache.

the class ElasticsearchWriterTest method shouldHandleWriteFailure.

@Test
public void shouldHandleWriteFailure() {
    // create a message id and a message associated with that id
    List<BulkMessage<JSONObject>> messages = createMessages(3);
    Exception cause = new Exception();
    // create a document writer which will fail all writes
    BulkDocumentWriterResults<MessageIdBasedDocument> results = new BulkDocumentWriterResults<>();
    results.addFailure(createDocument(messages.get(0)), cause, "error");
    BulkDocumentWriter<MessageIdBasedDocument> docWriter = mock(BulkDocumentWriter.class);
    when(docWriter.write()).thenReturn(results);
    // attempt to write
    ElasticsearchWriter esWriter = new ElasticsearchWriter();
    esWriter.setDocumentWriter(docWriter);
    esWriter.init(stormConf, writerConfiguration);
    BulkWriterResponse response = esWriter.write("bro", writerConfiguration, messages);
    // the writer response should only contain failures
    assertEquals(0, response.getSuccesses().size());
    assertEquals(1, response.getErrors().size());
    Collection<MessageId> errors = response.getErrors().get(cause);
    assertTrue(errors.contains(new MessageId("message1")));
}
Also used : BulkMessage(org.apache.metron.common.writer.BulkMessage) BulkDocumentWriterResults(org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults) BulkWriterResponse(org.apache.metron.common.writer.BulkWriterResponse) MessageId(org.apache.metron.common.writer.MessageId) Test(org.junit.jupiter.api.Test)

Example 7 with BulkDocumentWriterResults

use of org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults in project metron by apache.

the class ElasticsearchWriterTest method shouldWriteSuccessfullyWhenMissingGUID.

@Test
public void shouldWriteSuccessfullyWhenMissingGUID() {
    // create a message id and a message associated with that tuple
    List<BulkMessage<JSONObject>> messages = createMessages(1);
    // remove the GUID from the message
    assertNotNull(messages.get(0).getMessage().remove(Constants.GUID));
    // create a document writer which will successfully write all
    BulkDocumentWriterResults<MessageIdBasedDocument> results = new BulkDocumentWriterResults<>();
    results.addSuccess(createDocument(messages.get(0)));
    BulkDocumentWriter<MessageIdBasedDocument> docWriter = mock(BulkDocumentWriter.class);
    when(docWriter.write()).thenReturn(results);
    // attempt to write
    ElasticsearchWriter esWriter = new ElasticsearchWriter();
    esWriter.setDocumentWriter(docWriter);
    esWriter.init(stormConf, writerConfiguration);
    BulkWriterResponse response = esWriter.write("bro", writerConfiguration, messages);
    // response should only contain successes
    assertFalse(response.hasErrors());
    assertTrue(response.getSuccesses().contains(new MessageId("message1")));
}
Also used : BulkMessage(org.apache.metron.common.writer.BulkMessage) BulkDocumentWriterResults(org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults) BulkWriterResponse(org.apache.metron.common.writer.BulkWriterResponse) MessageId(org.apache.metron.common.writer.MessageId) Test(org.junit.jupiter.api.Test)

Example 8 with BulkDocumentWriterResults

use of org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults in project metron by apache.

the class ElasticsearchWriterTest method shouldWriteSuccessfully.

@Test
public void shouldWriteSuccessfully() {
    // create a message id and a message associated with that id
    List<BulkMessage<JSONObject>> messages = createMessages(1);
    // create a document writer which will successfully write all
    BulkDocumentWriterResults<MessageIdBasedDocument> results = new BulkDocumentWriterResults<>();
    results.addSuccess(createDocument(messages.get(0)));
    BulkDocumentWriter<MessageIdBasedDocument> docWriter = mock(BulkDocumentWriter.class);
    when(docWriter.write()).thenReturn(results);
    // attempt to write
    ElasticsearchWriter esWriter = new ElasticsearchWriter();
    esWriter.setDocumentWriter(docWriter);
    esWriter.init(stormConf, writerConfiguration);
    BulkWriterResponse response = esWriter.write("bro", writerConfiguration, messages);
    // response should only contain successes
    assertFalse(response.hasErrors());
    assertTrue(response.getSuccesses().contains(new MessageId("message1")));
}
Also used : BulkMessage(org.apache.metron.common.writer.BulkMessage) BulkDocumentWriterResults(org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults) BulkWriterResponse(org.apache.metron.common.writer.BulkWriterResponse) MessageId(org.apache.metron.common.writer.MessageId) Test(org.junit.jupiter.api.Test)

Aggregations

BulkMessage (org.apache.metron.common.writer.BulkMessage)8 BulkWriterResponse (org.apache.metron.common.writer.BulkWriterResponse)8 MessageId (org.apache.metron.common.writer.MessageId)8 BulkDocumentWriterResults (org.apache.metron.elasticsearch.bulk.BulkDocumentWriterResults)8 Test (org.junit.jupiter.api.Test)8 SimpleDateFormat (java.text.SimpleDateFormat)1 JSONObject (org.json.simple.JSONObject)1