@Test public void testParseException() { MessageParser<JSONObject> parser = new TestMessageParser() { @Override public List<JSONObject> parse(byte[] rawMessage) { throw new RuntimeException("parse exception"); } }; Optional<MessageParserResult<JSONObject>> ret = parser.parseOptionalResult("message".getBytes()); Assert.assertTrue(ret.isPresent()); Assert.assertTrue(ret.get().getMasterThrowable().isPresent()); Assert.assertEquals("parse exception", ret.get().getMasterThrowable().get().getMessage()); }
@Test public void testParseOptionalException() { MessageParser<JSONObject> parser = new TestMessageParser() { @Override public Optional<List<JSONObject>> parseOptional(byte[] rawMessage) { throw new RuntimeException("parse exception"); } }; Optional<MessageParserResult<JSONObject>> ret = parser.parseOptionalResult("message".getBytes()); Assert.assertTrue(ret.isPresent()); Assert.assertTrue(ret.get().getMasterThrowable().isPresent()); Assert.assertEquals("parse exception", ret.get().getMasterThrowable().get().getMessage()); }
if (result.get().getMasterThrowable().isPresent()) { throw new RestException("Error parsing sample data",result.get().getMasterThrowable().get());
messageParserResult.getMasterThrowable().ifPresent(throwable -> parserRunnerResults.addError(new MetronError() .withErrorType(Constants.ErrorType.PARSER_ERROR) .withThrowable(throwable)
Optional<MessageParserResult<JSONObject>> resultOptional = grokParser.parseOptionalResult(rawMessage); Assert.assertTrue(resultOptional.isPresent()); Optional<Throwable> throwableOptional = resultOptional.get().getMasterThrowable(); List<JSONObject> resultList = resultOptional.get().getMessages(); Map<Object,Throwable> errorMap = resultOptional.get().getMessageThrowables();
Optional<MessageParserResult<JSONObject>> resultOptional = grokParser.parseOptionalResult(rawMessage); Assert.assertTrue(resultOptional.isPresent()); Optional<Throwable> throwableOptional = resultOptional.get().getMasterThrowable(); List<JSONObject> resultList = resultOptional.get().getMessages(); Map<Object,Throwable> errorMap = resultOptional.get().getMessageThrowables();