Search in sources :

Example 16 with MetronError

use of org.apache.metron.common.error.MetronError 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);
}
Also used : JSONObject(org.json.simple.JSONObject) MetronError(org.apache.metron.common.error.MetronError) ExpectedException(org.junit.rules.ExpectedException) BulkWriterResponse(org.apache.metron.common.writer.BulkWriterResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with MetronError

use of org.apache.metron.common.error.MetronError in project metron by apache.

the class ParserBolt method handleError.

protected void handleError(byte[] originalMessage, Tuple tuple, Throwable ex, OutputCollector collector) {
    MetronError error = new MetronError().withErrorType(Constants.ErrorType.PARSER_ERROR).withThrowable(ex).withSensorType(getSensorType()).addRawMessage(originalMessage);
    ErrorUtils.handleError(collector, error);
    collector.ack(tuple);
}
Also used : MetronError(org.apache.metron.common.error.MetronError)

Aggregations

MetronError (org.apache.metron.common.error.MetronError)17 JSONObject (org.json.simple.JSONObject)11 Test (org.junit.Test)9 MetronErrorJSONMatcher (org.apache.metron.test.error.MetronErrorJSONMatcher)6 HashMap (java.util.HashMap)5 Values (org.apache.storm.tuple.Values)4 ExpectedException (org.junit.rules.ExpectedException)4 IOException (java.io.IOException)3 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)3 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)3 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)3 Tuple (org.apache.storm.tuple.Tuple)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 BulkWriterResponse (org.apache.metron.common.writer.BulkWriterResponse)2 BaseEnrichmentBoltTest (org.apache.metron.test.bolt.BaseEnrichmentBoltTest)2 OutputCollector (org.apache.storm.task.OutputCollector)2 ParseException (org.json.simple.parser.ParseException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1