You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2015/02/27 22:22:19 UTC
[4/4] incubator-lens git commit: LENS-300: Handles cases when
LensSessionHandle object is null(Jaideep Dhok via prongs) We were getting NPE
when session is gone but the query launched by the session is still getting
submitted
LENS-300: Handles cases when LensSessionHandle object is null(Jaideep Dhok via prongs)
We were getting NPE when session is gone but the query launched by the session is still getting submitted
Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/51486b8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/51486b8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/51486b8e
Branch: refs/heads/master
Commit: 51486b8e357fab15ff7bd9c84c7ffd73fd250ce6
Parents: deb47dc
Author: Jaideep Dhok <jd...@apache.org>
Authored: Sat Feb 28 02:50:23 2015 +0530
Committer: Rajat Khandelwal <pr...@apache.org>
Committed: Sat Feb 28 02:50:23 2015 +0530
----------------------------------------------------------------------
.../org/apache/lens/server/LensService.java | 18 +++++++++--
.../server/session/TestSessionResource.java | 34 ++++++++++++++++++++
2 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/51486b8e/lens-server/src/main/java/org/apache/lens/server/LensService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/LensService.java b/lens-server/src/main/java/org/apache/lens/server/LensService.java
index a8ad087..dd6d41c 100644
--- a/lens-server/src/main/java/org/apache/lens/server/LensService.java
+++ b/lens-server/src/main/java/org/apache/lens/server/LensService.java
@@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.NotAuthorizedException;
+import javax.ws.rs.NotFoundException;
import org.apache.lens.api.LensConf;
import org.apache.lens.api.LensException;
@@ -227,6 +228,10 @@ public abstract class LensService extends CompositeService implements Externaliz
* @return the session
*/
public LensSessionImpl getSession(LensSessionHandle sessionHandle) {
+ if (sessionHandle == null) {
+ throw new ClientErrorException("Session is null " + sessionHandle, 400);
+ }
+
try {
return ((LensSessionImpl) getSessionManager().getSession(getHiveSessionHandle(sessionHandle)));
} catch (HiveSQLException exc) {
@@ -254,7 +259,13 @@ public abstract class LensService extends CompositeService implements Externaliz
* @param sessionHandle public UUID of the session
*/
public void acquire(String sessionHandle) {
- acquire(sessionMap.get(sessionHandle));
+ LensSessionHandle handle = sessionMap.get(sessionHandle);
+
+ if (handle == null) {
+ throw new NotFoundException("Session handle not found " + sessionHandle);
+ }
+
+ acquire(handle);
}
/**
@@ -276,7 +287,10 @@ public abstract class LensService extends CompositeService implements Externaliz
* @throws LensException if session cannot be released
*/
public void release(String sessionHandle) throws LensException {
- getSession(sessionMap.get(sessionHandle)).release();
+ LensSessionHandle handle = sessionMap.get(sessionHandle);
+ if (handle != null) {
+ getSession(handle).release();
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/51486b8e/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 7cff12a..73621a3 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
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.HashMap;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.NotFoundException;
@@ -432,4 +433,37 @@ public class TestSessionResource extends LensJerseyTest {
}
}
+ /**
+ * Test acquire and release behaviour for closed sessions
+ */
+ @Test
+ public void testAcquireReleaseClosedSession() 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.closeSession(sessionHandle);
+ final String sessionIdentifier = sessionHandle.getPublicId().toString();
+
+ try {
+ sessionService.acquire(sessionIdentifier);
+ // Above statement should throw notfound exception
+ Assert.fail("Should not reach here since above statement should have thrown NotFoundException");
+ } catch (NotFoundException nfe) {
+ // Pass
+ } finally {
+ // Should not do anything
+ sessionService.release(sessionIdentifier);
+ }
+
+ // Get session for null handle should throw bad request
+ try {
+ sessionService.getSession(sessionHandle);
+ Assert.fail("Above statement should have thrown erorr");
+ } catch (ClientErrorException cee) {
+ // PASS
+ }
+ }
+
}