Skip to content

Commit

Permalink
Create new session if session is invalid
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <penghuo@gmail.com>
  • Loading branch information
penghuo committed Oct 25, 2023
1 parent a5512f5 commit 0699d58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,9 @@ private DispatchQueryResponse handleNonIndexQuery(DispatchQueryRequest dispatchQ
// get session from request
SessionId sessionId = new SessionId(dispatchQueryRequest.getSessionId());
Optional<Session> createdSession = sessionManager.getSession(sessionId);
if (createdSession.isEmpty()) {
throw new IllegalArgumentException("no session found. " + sessionId);
if (createdSession.isPresent()) {
session = createdSession.get();
}
session = createdSession.get();
}
if (session == null || !session.isReady()) {
// create session if not exist or session dead/fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,24 +460,21 @@ public void recreateSessionIfNotReady() {
}

@Test
public void submitQueryInInvalidSessionThrowException() {
public void submitQueryInInvalidSessionWillCreateNewSession() {
LocalEMRSClient emrsClient = new LocalEMRSClient();
AsyncQueryExecutorService asyncQueryExecutorService =
createAsyncQueryExecutorService(emrsClient);

// enable session
enableSession(true);

// 1. create async query.
SessionId sessionId = SessionId.newSessionId(DATASOURCE);
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
() ->
asyncQueryExecutorService.createAsyncQuery(
new CreateAsyncQueryRequest(
"select 1", DATASOURCE, LangType.SQL, sessionId.getSessionId())));
assertEquals("no session found. " + sessionId, exception.getMessage());
// 1. create async query with invalid sessionId
SessionId invalidSessionId = SessionId.newSessionId(DATASOURCE);
CreateAsyncQueryResponse asyncQuery = asyncQueryExecutorService.createAsyncQuery(
new CreateAsyncQueryRequest(
"select 1", DATASOURCE, LangType.SQL, invalidSessionId.getSessionId()));
assertNotNull(asyncQuery.getSessionId());
assertNotEquals(invalidSessionId.getSessionId(), asyncQuery.getSessionId());
}

private DataSourceServiceImpl createDataSourceService() {
Expand Down

0 comments on commit 0699d58

Please sign in to comment.