Search in sources :

Example 6 with MetronErrorJSONMatcher

use of org.apache.metron.test.error.MetronErrorJSONMatcher in project metron by apache.

the class JoinBoltTest method testExecuteShouldReportError.

@SuppressWarnings("unchecked")
@Test
public void testExecuteShouldReportError() throws ExecutionException {
    joinBolt.withMaxCacheSize(100);
    joinBolt.withMaxTimeRetain(10000);
    joinBolt.prepare(new HashMap(), topologyContext, outputCollector);
    when(tuple.getValueByField("key")).thenReturn(key);
    when(tuple.getValueByField("message")).thenReturn(new JSONObject());
    joinBolt.cache = mock(LoadingCache.class);
    when(joinBolt.cache.get(any())).thenThrow(new RuntimeException(new Exception("join exception")));
    joinBolt.execute(tuple);
    RuntimeException expectedExecutionException = new RuntimeException(new Exception("join exception"));
    MetronError error = new MetronError().withErrorType(Constants.ErrorType.ENRICHMENT_ERROR).withMessage("Joining problem: {}").withThrowable(expectedExecutionException).addRawMessage(new JSONObject());
    verify(outputCollector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject())));
    verify(outputCollector, times(1)).reportError(any(ExecutionException.class));
    verify(outputCollector, times(1)).ack(eq(tuple));
    verifyNoMoreInteractions(outputCollector);
}
Also used : MetronErrorJSONMatcher(org.apache.metron.test.error.MetronErrorJSONMatcher) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) MetronError(org.apache.metron.common.error.MetronError) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) ExecutionException(java.util.concurrent.ExecutionException) ParseException(org.json.simple.parser.ParseException) ExecutionException(java.util.concurrent.ExecutionException) BaseEnrichmentBoltTest(org.apache.metron.test.bolt.BaseEnrichmentBoltTest) Test(org.junit.Test)

Aggregations

MetronError (org.apache.metron.common.error.MetronError)6 MetronErrorJSONMatcher (org.apache.metron.test.error.MetronErrorJSONMatcher)6 Test (org.junit.Test)6 JSONObject (org.json.simple.JSONObject)4 HashMap (java.util.HashMap)3 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)3 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)3 IOException (java.io.IOException)2 BaseEnrichmentBoltTest (org.apache.metron.test.bolt.BaseEnrichmentBoltTest)2 ParseException (org.json.simple.parser.ParseException)2 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)1 ParserWriterConfiguration (org.apache.metron.common.configuration.writer.ParserWriterConfiguration)1 Enrichment (org.apache.metron.enrichment.configuration.Enrichment)1 EnrichmentAdapter (org.apache.metron.enrichment.interfaces.EnrichmentAdapter)1 OutputCollector (org.apache.storm.task.OutputCollector)1