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")));
}
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")));
}
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")));
}
Aggregations