Skip to content

Commit af10ead

Browse files
author
Burak Serdar
committed
Fix #781: Do not get results if there is an error
1 parent bb38898 commit af10ead

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

crud/src/main/java/com/redhat/lightblue/mediator/Mediator.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -499,25 +499,25 @@ public Response find(FindRequest req) {
499499
CRUDFindResponse result = finder.find(ctx, req.getCRUDFindRequest());
500500
ctx.measure.end("finder.find");
501501

502-
ctx.measure.begin("postProcessFound");
503-
DocumentStream<DocCtx> docStream=ctx.getDocumentStream();
504-
List<ResultMetadata> rmd=new ArrayList<>();
505-
response.setEntityData(factory.getNodeFactory().arrayNode());
506-
for(;docStream.hasNext();) {
507-
DocCtx doc=docStream.next();
508-
if(!doc.hasErrors()) {
509-
response.addEntityData(doc.getOutputDocument().getRoot());
510-
rmd.add(doc.getResultMetadata());
502+
if(!ctx.hasErrors()) {
503+
ctx.measure.begin("postProcessFound");
504+
DocumentStream<DocCtx> docStream=ctx.getDocumentStream();
505+
List<ResultMetadata> rmd=new ArrayList<>();
506+
response.setEntityData(factory.getNodeFactory().arrayNode());
507+
for(;docStream.hasNext();) {
508+
DocCtx doc=docStream.next();
509+
if(!doc.hasErrors()) {
510+
response.addEntityData(doc.getOutputDocument().getRoot());
511+
rmd.add(doc.getResultMetadata());
511512
} else {
512-
DataError error=doc.getDataError();
513-
if(error!=null)
514-
response.getDataErrors().add(error);
513+
DataError error=doc.getDataError();
514+
if(error!=null)
515+
response.getDataErrors().add(error);
516+
}
515517
}
516-
}
517-
docStream.close();
518-
response.setResultMetadata(rmd);
519-
ctx.measure.end("postProcessFound");
520-
if (!ctx.hasErrors()) {
518+
docStream.close();
519+
response.setResultMetadata(rmd);
520+
ctx.measure.end("postProcessFound");
521521
ctx.setStatus(OperationStatus.COMPLETE);
522522
} else {
523523
ctx.setStatus(OperationStatus.ERROR);

crud/src/test/java/com/redhat/lightblue/mediator/MediatorTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.redhat.lightblue.query.ValueComparisonExpression;
5454
import com.redhat.lightblue.util.JsonDoc;
5555
import com.redhat.lightblue.util.Path;
56+
import com.redhat.lightblue.util.Error;
5657

5758
public class MediatorTest extends AbstractMediatorTest {
5859

@@ -383,6 +384,22 @@ public void findResultMdTest() throws Exception {
383384
}
384385
}
385386

387+
@Test
388+
public void queryTimeoutTest() throws Exception {
389+
FindRequest req = new FindRequest();
390+
req.setEntityVersion(new EntityVersion("test", "1.0"));
391+
392+
mdManager.md.getAccess().getFind().setRoles("anyone");
393+
mockCrudController.findResponse = new CRUDFindResponse();
394+
mockCrudController.findCb=ctx->{
395+
ctx.addError(Error.get(CrudConstants.ERR_DATASOURCE_TIMEOUT,"timeout"));
396+
};
397+
Response response = mediator.find(req);
398+
Assert.assertEquals(OperationStatus.ERROR, response.getStatus());
399+
Assert.assertEquals(1,response.getErrors().size());
400+
Assert.assertEquals(CrudConstants.ERR_DATASOURCE_TIMEOUT,response.getErrors().get(0).getErrorCode());
401+
}
402+
386403
@Test
387404
public void findQueryFieldRoleTest() throws Exception {
388405
FindRequest req = new FindRequest();

0 commit comments

Comments
 (0)