@Test public void findAndStream_ErrorHandling() throws Exception { mdManager.md = null; FindRequest req = new FindRequest(); req.setEntityVersion(new EntityVersion("foo", "0.0.1")); mockCrudController.findCb=ctx->ctx.setDocumentStream(new ListDocumentStream<DocCtx>(new ArrayList<DocCtx>())); mockCrudController.findResponse = new CRUDFindResponse(); StreamingResponse response = mediator.findAndStream(req); Assert.assertEquals(OperationStatus.ERROR, response.getStatus()); Assert.assertEquals(0, response.getModifiedCount()); Assert.assertEquals(0, response.getMatchCount()); Assert.assertEquals(0, response.getDataErrors().size()); Assert.assertEquals(1, response.getErrors().size()); Assert.assertEquals(CrudConstants.ERR_UNKNOWN_ENTITY, response.getErrors().get(0).getErrorCode()); }
public StreamingResponse findAndStream(FindRequest req) { LOGGER.debug("findAndStream {}", req.getEntityVersion()); Error.push("findAndStream(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.FIND); ctx.setComputeCounts(false); ctx.measure.begin("find"); return _findAndStream(req,ctx); } catch (Error e) { LOGGER.debug("Error during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } }
Mediator { public StreamingResponse findAndStream(FindRequest req) { LOGGER.debug("findAndStream {}", req.getEntityVersion()); Error.push("findAndStream(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.FIND); ctx.setComputeCounts(false); ctx.measure.begin("find"); return _findAndStream(req,ctx); } catch (Error e) { LOGGER.debug("Error during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } } }
Mediator { public StreamingResponse findAndStream(FindRequest req) { LOGGER.debug("findAndStream {}", req.getEntityVersion()); Error.push("findAndStream(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.FIND); ctx.setComputeCounts(false); ctx.measure.begin("find"); return _findAndStream(req,ctx); } catch (Error e) { LOGGER.debug("Error during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } } Mediator(Metadata md,
                    Factory factory); }
Mediator { public StreamingResponse findAndStream(FindRequest req) { LOGGER.debug("findAndStream {}", req.getEntityVersion()); Error.push("findAndStream(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.FIND); ctx.setComputeCounts(false); ctx.measure.begin("find"); return _findAndStream(req,ctx); } catch (Error e) { LOGGER.debug("Error during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } } Mediator(Metadata md,
                    Factory factory); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response insert(InsertionRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response save(SaveRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response update(UpdateRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response delete(DeleteRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response find(FindRequest req); StreamingResponse findAndStream(FindRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator") Response explain(FindRequest req); BulkResponse bulkRequest(BulkRequest requests, RequestMetrics metrics); }
Mediator { public StreamingResponse findAndStream(FindRequest req) { LOGGER.debug("findAndStream {}", req.getEntityVersion()); Error.push("findAndStream(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.FIND); ctx.setComputeCounts(false); ctx.measure.begin("find"); return _findAndStream(req,ctx); } catch (Error e) { LOGGER.debug("Error during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); return StreamingResponse.withError(factory.getNodeFactory(), Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } } Mediator(Metadata md,
                    Factory factory); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response insert(InsertionRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response save(SaveRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response update(UpdateRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response delete(DeleteRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response find(FindRequest req); StreamingResponse findAndStream(FindRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator") Response explain(FindRequest req); BulkResponse bulkRequest(BulkRequest requests, RequestMetrics metrics); static final String CTX_QPLAN; static final String CRUD_MSG_PREFIX; final Metadata metadata; final Factory factory; }