use of org.apache.metron.common.writer.BulkWriterResponse in project metron by apache.
the class WriterBoltTest method testBatchErrorPath.
@Test
public void testBatchErrorPath() throws Exception {
ParserConfigurations configurations = getConfigurations(5);
String sensorType = "test";
List<Tuple> tuples = new ArrayList<>();
for (int i = 0; i < 4; ++i) {
Tuple t = mock(Tuple.class);
when(t.getValueByField(eq("message"))).thenReturn(new JSONObject());
tuples.add(t);
}
Tuple errorTuple = mock(Tuple.class);
Tuple goodTuple = mock(Tuple.class);
when(goodTuple.getValueByField(eq("message"))).thenReturn(new JSONObject());
when(errorTuple.getValueByField(eq("message"))).thenThrow(new IllegalStateException());
WriterBolt bolt = new WriterBolt(new WriterHandler(batchWriter), configurations, sensorType);
bolt.prepare(new HashMap(), topologyContext, outputCollector);
verify(batchWriter, times(1)).init(any(), any(), any());
for (int i = 0; i < 4; ++i) {
Tuple t = tuples.get(i);
bolt.execute(t);
verify(outputCollector, times(0)).ack(t);
verify(batchWriter, times(0)).write(eq(sensorType), any(), any(), any());
}
// Add the good tuples. Do not add the error tuple, because this is testing an exception on access, not a failure on write.
BulkWriterResponse writerResponse = new BulkWriterResponse();
writerResponse.addAllSuccesses(tuples);
writerResponse.addSuccess(goodTuple);
when(batchWriter.write(any(), any(), any(), any())).thenReturn(writerResponse);
bolt.execute(errorTuple);
for (Tuple t : tuples) {
verify(outputCollector, times(0)).ack(t);
}
bolt.execute(goodTuple);
for (Tuple t : tuples) {
verify(outputCollector, times(1)).ack(t);
}
verify(outputCollector, times(1)).ack(goodTuple);
verify(batchWriter, times(1)).write(eq(sensorType), any(), any(), any());
verify(outputCollector, times(1)).reportError(any());
verify(outputCollector, times(0)).fail(any());
}
use of org.apache.metron.common.writer.BulkWriterResponse in project metron by apache.
the class BulkWriterComponentTest method writeShouldProperlyHandleWriterErrors.
@Test
public void writeShouldProperlyHandleWriterErrors() throws Exception {
Throwable e = new Exception("test exception");
MetronError error = new MetronError().withSensorType(sensorType).withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e).withRawMessages(Arrays.asList(message1, message2));
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);
bulkWriterComponent.write(sensorType, tuple1, message1, bulkMessageWriter, configurations, messageGetStrategy);
bulkWriterComponent.write(sensorType, tuple2, message2, bulkMessageWriter, configurations, messageGetStrategy);
verifyStatic(times(1));
ErrorUtils.handleError(collector, error);
}
Aggregations