use of org.apache.metron.common.writer.BulkWriterResponse in project metron by apache.
the class BulkWriterComponentTest method writeShouldThrowExceptionWhenHandleErrorIsFalse.
@Test
public void writeShouldThrowExceptionWhenHandleErrorIsFalse() throws Exception {
exception.expect(IllegalStateException.class);
Throwable e = new Exception("test exception");
BulkWriterResponse response = new BulkWriterResponse();
response.addAllErrors(e, tupleList);
when(bulkMessageWriter.write(sensorType, configurations, Arrays.asList(tuple1, tuple2), Arrays.asList(message1, message2))).thenReturn(response);
BulkWriterComponent<JSONObject> bulkWriterComponent = new BulkWriterComponent<>(collector, true, false);
bulkWriterComponent.write(sensorType, tuple1, message1, bulkMessageWriter, configurations, messageGetStrategy);
bulkWriterComponent.write(sensorType, tuple2, message2, bulkMessageWriter, configurations, messageGetStrategy);
}
use of org.apache.metron.common.writer.BulkWriterResponse in project metron by apache.
the class ElasticsearchWriter method buildWriteReponse.
protected BulkWriterResponse buildWriteReponse(Iterable<Tuple> tuples, BulkResponse bulkResponse) throws Exception {
// Elasticsearch responses are in the same order as the request, giving us an implicit mapping with Tuples
BulkWriterResponse writerResponse = new BulkWriterResponse();
if (bulkResponse.hasFailures()) {
Iterator<BulkItemResponse> respIter = bulkResponse.iterator();
Iterator<Tuple> tupleIter = tuples.iterator();
while (respIter.hasNext() && tupleIter.hasNext()) {
BulkItemResponse item = respIter.next();
Tuple tuple = tupleIter.next();
if (item.isFailed()) {
writerResponse.addError(item.getFailure().getCause(), tuple);
} else {
writerResponse.addSuccess(tuple);
}
// Should never happen, so fail the entire batch if it does.
if (respIter.hasNext() != tupleIter.hasNext()) {
throw new Exception(bulkResponse.buildFailureMessage());
}
}
} else {
writerResponse.addAllSuccesses(tuples);
}
return writerResponse;
}
use of org.apache.metron.common.writer.BulkWriterResponse in project metron by apache.
the class ElasticsearchWriterTest method testSuccessAndFailure.
@Test
public void testSuccessAndFailure() throws Exception {
Tuple tuple1 = mock(Tuple.class);
Tuple tuple2 = mock(Tuple.class);
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(true);
Exception e = new IllegalStateException("Cause");
BulkItemResponse itemResponse = buildBulkItemFailure(e);
BulkItemResponse itemResponse2 = mock(BulkItemResponse.class);
when(itemResponse2.isFailed()).thenReturn(false);
when(response.iterator()).thenReturn(ImmutableList.of(itemResponse, itemResponse2).iterator());
BulkWriterResponse expected = new BulkWriterResponse();
expected.addError(e, tuple1);
expected.addSuccess(tuple2);
ElasticsearchWriter esWriter = new ElasticsearchWriter();
BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);
assertEquals("Response should have one error and one success", expected, actual);
}
use of org.apache.metron.common.writer.BulkWriterResponse in project metron by apache.
the class ElasticsearchWriterTest method testSingleSuccesses.
@Test
public void testSingleSuccesses() throws Exception {
Tuple tuple1 = mock(Tuple.class);
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(false);
BulkWriterResponse expected = new BulkWriterResponse();
expected.addSuccess(tuple1);
ElasticsearchWriter esWriter = new ElasticsearchWriter();
BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1), response);
assertEquals("Response should have no errors and single success", expected, actual);
}
use of org.apache.metron.common.writer.BulkWriterResponse in project metron by apache.
the class ElasticsearchWriterTest method testMultipleSuccesses.
@Test
public void testMultipleSuccesses() throws Exception {
Tuple tuple1 = mock(Tuple.class);
Tuple tuple2 = mock(Tuple.class);
BulkResponse response = mock(BulkResponse.class);
when(response.hasFailures()).thenReturn(false);
BulkWriterResponse expected = new BulkWriterResponse();
expected.addSuccess(tuple1);
expected.addSuccess(tuple2);
ElasticsearchWriter esWriter = new ElasticsearchWriter();
BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);
assertEquals("Response should have no errors and two successes", expected, actual);
}
Aggregations