Repository: lens Updated Branches: refs/heads/master 1924bbb01 -> 0debd08ca
LENS-1199: NPE while closing session Project: http://git-wip-us.apache.org/repos/asf/lens/repo Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/0debd08c Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/0debd08c Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/0debd08c Branch: refs/heads/master Commit: 0debd08ca27e993990e55ce04fda795a487604bf Parents: 1924bbb Author: Raju Bairishetti <r...@apache.org> Authored: Tue Jul 26 17:09:39 2016 +0530 Committer: Rajat Khandelwal <rajatgupt...@gmail.com> Committed: Tue Jul 26 17:09:39 2016 +0530 ---------------------------------------------------------------------- .../org/apache/lens/server/BaseLensService.java | 7 +++++-- .../lens/server/session/TestSessionResource.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lens/blob/0debd08c/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java ---------------------------------------------------------------------- diff --git a/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java b/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java index d706306..19a86c6 100644 --- a/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java +++ b/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java @@ -306,13 +306,17 @@ public abstract class BaseLensService extends CompositeService implements Extern public void closeSession(LensSessionHandle sessionHandle) throws LensException { try { LensSessionImpl session = getSession(sessionHandle); + boolean shouldDecrementOpenedSessionCount = !session.getLensSessionPersistInfo().isMarkedForClose(); if (session.activeOperationsPresent()) { session.markForClose(); } else { cliService.closeSession(getHiveSessionHandle(sessionHandle)); SESSION_MAP.remove(sessionHandle.getPublicId().toString()); + log.info("Closed session {} for {} user", sessionHandle, session.getLoggedInUser()); + } + if (shouldDecrementOpenedSessionCount) { + decrementSessionCountForUser(sessionHandle, session.getLoggedInUser()); } - decrementSessionCountForUser(sessionHandle, session.getLoggedInUser()); if (!SESSION_MAP.containsKey(sessionHandle.getPublicId().toString())) { // Inform query service BaseLensService svc = LensServices.get().getService(QueryExecutionService.NAME); @@ -333,7 +337,6 @@ public abstract class BaseLensService extends CompositeService implements Extern } synchronized (sessionUser) { Integer sessionCount = SESSIONS_PER_USER.get(userName); - log.info("Closed session {} for {} user", sessionHandle, userName); if (sessionCount == 1) { SESSIONS_PER_USER.remove(userName); } else { http://git-wip-us.apache.org/repos/asf/lens/blob/0debd08c/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java ---------------------------------------------------------------------- diff --git a/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java b/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java index ed463a9..33791ea 100644 --- a/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java +++ b/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; +import java.util.UUID; import javax.ws.rs.ClientErrorException; import javax.ws.rs.NotFoundException; @@ -41,6 +42,7 @@ import org.apache.lens.api.LensConf; import org.apache.lens.api.LensSessionHandle; import org.apache.lens.api.StringList; import org.apache.lens.api.jaxb.LensJAXBContextResolver; +import org.apache.lens.api.query.*; import org.apache.lens.server.LensJerseyTest; import org.apache.lens.server.LensServerConf; import org.apache.lens.server.LensServices; @@ -484,6 +486,21 @@ public class TestSessionResource extends LensJerseyTest { } /** + * Test multiple closeSession invocations for a session + */ + @Test(dataProvider = "mediaTypeData") + public void testCloseSessionMultipleTimes(MediaType mt) throws Exception { + HiveSessionService sessionService = LensServices.get().getService(SessionService.NAME); + + LensSessionHandle sessionHandle = sessionService.openSession("foo@localhost", "bar", new HashMap<String, String>()); + Assert.assertNotNull(sessionHandle, "Expected session to be opened"); + sessionService.getSession(sessionHandle).addToActiveQueries(QueryHandle.fromString(UUID.randomUUID().toString())); + // Closing multiple times should not cause any issues + sessionService.closeSession(sessionHandle); + sessionService.closeSession(sessionHandle); + } + + /** * Test acquire and release behaviour for closed sessions */ @Test(dataProvider = "mediaTypeData")