MetronError error = new MetronError() .withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withMessage("Joining problem: " + message) .withThrowable(e) .addRawMessage(message);
@Test public void handleErrorShouldEmitAndReportError() throws Exception { Throwable e = new Exception("error"); MetronError error = new MetronError().withMessage("error message").withThrowable(e); OutputCollector collector = mock(OutputCollector.class); ErrorUtils.handleError(collector, error); verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject()))); verify(collector, times(1)).reportError(any()); } }
@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); } }
MetronError metronError = new MetronError() .withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withMessage("Unable to find SensorEnrichmentConfig for sourceType: " + sourceType) .addRawMessage(rawMessage); ErrorUtils.handleError(collector, metronError);
MetronError error = new MetronError() .withErrorType(strategy.getErrorType()) .withMessage(t.getValue().getMessage()) .withThrowable(t.getValue()) .addRawMessage(t.getKey()); MetronError error = new MetronError() .withErrorType(strategy.getErrorType()) .withMessage(e.getMessage()) .withThrowable(e) .addRawMessage(message);
@Test public void getJSONObjectShouldReturnBasicInformation() { MetronError error = new MetronError() .withMessage("test message") .withErrorType(Constants.ErrorType.PARSER_ERROR) .withSensorType(Collections.singleton("sensorType")); JSONObject errorJSON = error.getJSONObject(); assertEquals("test message", errorJSON.get(Constants.ErrorFields.MESSAGE.getName())); assertEquals(Constants.ErrorType.PARSER_ERROR.getType(), errorJSON.get(Constants.ErrorFields.ERROR_TYPE.getName())); assertEquals("error", errorJSON.get(Constants.SENSOR_TYPE)); assertEquals("sensorType", errorJSON.get(Constants.ErrorFields.FAILED_SENSOR_TYPE.getName())); String hostName = null; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { // unable to get the hostname on this machine, don't test it } if (!StringUtils.isEmpty(hostName)) { assertTrue(((String) errorJSON.get(Constants.ErrorFields.HOSTNAME.getName())).length() > 0); assertEquals(hostName, (String) errorJSON.get(Constants.ErrorFields.HOSTNAME.getName())); } assertTrue(((long) errorJSON.get(Constants.ErrorFields.TIMESTAMP.getName())) > 0); }
JSONObject processedMessage = new JSONObject(); processedMessage.put("field", "processedMessage1"); MetronError processedError = new MetronError().withMessage("processedError"); ProcessResult processedMessageResult = mock(ProcessResult.class); ProcessResult processedErrorResult = mock(ProcessResult.class);