Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <penghuo@gmail.com>
  • Loading branch information
penghuo committed Nov 12, 2022
1 parent 75c2194 commit faff812
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public class QueryService {
*/
public void execute(UnresolvedPlan plan,
ResponseListener<ExecutionEngine.QueryResponse> listener) {
executePlan(analyze(plan), PlanContext.emptyPlanContext(), listener);
try {
executePlan(analyze(plan), PlanContext.emptyPlanContext(), listener);
} catch (Exception e) {
listener.onFailure(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.sql.executor;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -64,7 +65,7 @@ class QueryServiceTest {
@BeforeEach
public void setUp() {
lenient().when(analyzer.analyze(any(), any())).thenReturn(logicalPlan);
when(planner.plan(any())).thenReturn(plan);
lenient().when(planner.plan(any())).thenReturn(plan);

queryService = new QueryService(analyzer, executionEngine, planner);
}
Expand All @@ -86,7 +87,7 @@ public void testExecuteShouldPass() {
new ResponseListener<>() {
@Override
public void onResponse(ExecutionEngine.QueryResponse pplQueryResponse) {

assertNotNull(pplQueryResponse);
}

@Override
Expand Down Expand Up @@ -115,7 +116,7 @@ public void testExplainShouldPass() {
new ResponseListener<>() {
@Override
public void onResponse(ExecutionEngine.ExplainResponse pplQueryResponse) {

assertNotNull(pplQueryResponse);
}

@Override
Expand Down Expand Up @@ -185,7 +186,7 @@ public void testExecutePlanShouldPass() {
new ResponseListener<>() {
@Override
public void onResponse(ExecutionEngine.QueryResponse pplQueryResponse) {

assertNotNull(pplQueryResponse);
}

@Override
Expand All @@ -194,4 +195,23 @@ public void onFailure(Exception e) {
}
});
}

@Test
public void analyzeExceptionShouldBeCached() {
when(analyzer.analyze(any(), any())).thenThrow(IllegalStateException.class);

queryService.execute(
ast,
new ResponseListener<>() {
@Override
public void onResponse(ExecutionEngine.QueryResponse pplQueryResponse) {
fail();
}

@Override
public void onFailure(Exception e) {
assertTrue(e instanceof IllegalStateException);
}
});
}
}

0 comments on commit faff812

Please sign in to comment.