private Meta getErrorMeta(Exception e) { return Meta.of(BulletError.makeError(e.getMessage(), TRY_AGAIN_LATER)); }
/** * Write this error as a JSON Bullet error response in the {@link Meta} of a {@link Clip}. * * @return A String JSON version of this error. */ public String asJSONClip() { return Clip.of(Meta.of(this)).asJSON(); } }
/** * Write this error as a JSON Bullet error response in the {@link Meta} of a {@link Clip}. * * @return A String JSON version of this error. */ public String asJSONClip() { return Clip.of(Meta.of(this)).asJSON(); } }
private void emitErrorsAsResult(String id, Metadata metadata, List<BulletError> errors) { updateCount(improperQueriesCount, 1L); emitResult(id, withSignal(metadata, Metadata.Signal.FAIL), Clip.of(Meta.of(errors))); }
private void emitErrorsAsResult(String id, Metadata metadata, List<BulletError> errors) { updateCount(improperQueriesCount, 1L); emitResult(id, withSignal(metadata, Metadata.Signal.FAIL), Clip.of(Meta.of(errors))); }
@Test public void testErrorInQueryWithoutMetadata() { Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{\"aggregation\": {\"type\": \"garbage\"}}"); bolt.execute(query); Assert.assertEquals(collector.getEmittedCount(), 1); BulletError expectedError = Aggregation.TYPE_NOT_SUPPORTED_ERROR; Meta expectedMetadata = Meta.of(expectedError); List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), FAILED).getValues(); List<Object> actual = collector.getNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1).get(); Assert.assertTrue(isSameResult(actual, expected)); Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1); Assert.assertEquals(collector.getEmittedCount(), 1); }
@Test public void testUnknownAggregation() { // Lowercase "top" is not valid and will not be parsed since there is no enum for it // In this case aggregation type should be set to null and an error should be emitted Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{\"aggregation\": {\"type\": \"garbage\"}}", EMPTY); bolt.execute(query); Assert.assertEquals(collector.getEmittedCount(), 1); BulletError expectedError = Aggregation.TYPE_NOT_SUPPORTED_ERROR; Meta expectedMetadata = Meta.of(expectedError); List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), FAILED).getValues(); List<Object> actual = collector.getNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1).get(); Assert.assertTrue(isSameResult(actual, expected)); }
@Test public void testErrorEmittedProperly() { Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "garbage", EMPTY); bolt.execute(query); Assert.assertEquals(collector.getEmittedCount(), 1); String error = ParsingError.GENERIC_JSON_ERROR + ":\ngarbage\n" + "IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"; BulletError expectedError = ParsingError.makeError(error, ParsingError.GENERIC_JSON_RESOLUTION); Meta expectedMetadata = Meta.of(expectedError); List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), FAILED).getValues(); List<Object> actual = collector.getNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1).get(); Assert.assertTrue(isSameResult(actual, expected)); }
@Test public void testUnhandledExceptionErrorEmitted() { // An empty query should throw an null-pointer exception which should be caught in JoinBolt // and an error should be emitted Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "", EMPTY); bolt.execute(query); sendRawRecordTuplesTo(bolt, "42"); Assert.assertEquals(collector.getEmittedCount(), 1); String error = ParsingError.GENERIC_JSON_ERROR + ":\n\nNullPointerException: "; BulletError expectedError = ParsingError.makeError(error, ParsingError.GENERIC_JSON_RESOLUTION); Meta expectedMetadata = Meta.of(expectedError); List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), FAILED).getValues(); List<Object> actual = collector.getNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1).get(); Assert.assertTrue(isSameResult(actual, expected)); }