@Test public void testSessionHook () throws Exception { // create session, test if the hook got fired by checking the expected property SessionHandle sessionHandle = client.openSession(sessionUserName, "foobar", Collections.<String, String>emptyMap()); Assert.assertEquals(1, SessionHookTest.runCount.get()); client.closeSession(sessionHandle); }
/*** * Create session with proxy user property. Verify the effective session user * @throws Exception */ @Test public void testProxyUser() throws Exception { String connectingUser = "user1"; String proxyUser = System.getProperty("user.name"); Map<String, String>sessConf = new HashMap<String,String>(); sessConf.put(HiveAuthConstants.HS2_PROXY_USER, proxyUser); sessionUserName = proxyUser; SessionHandle sessionHandle = client.openSession(connectingUser, "foobar", sessConf); Assert.assertEquals(1, SessionHookTest.runCount.get()); client.closeSession(sessionHandle); } }
@Test public void testOpenSession() throws Exception { // Open a new client session SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>()); // Session handle should not be null assertNotNull("Session handle should not be null", sessHandle); // Close client session client.closeSession(sessHandle); }
@Test public void testOpenSession() throws Exception { // Open a new client session SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>()); // Session handle should not be null assertNotNull("Session handle should not be null", sessHandle); // Close client session client.closeSession(sessHandle); }
@Test public void testSessionGlobalInitFileAndConfOverlay() throws Exception { // Test if the user session specific conf overlaying global init conf. Map<String, String> confOverlay = new HashMap<String, String>(); confOverlay.put("a", "2"); confOverlay.put("set:hiveconf:b", "2"); confOverlay.put("set:hivevar:c", "2"); SessionHandle sessionHandle = client.openSession(null, null, confOverlay); verifyInitProperty("a", "2", sessionHandle); verifyInitProperty("b", "2", sessionHandle); verifyInitProperty("c", "2", sessionHandle); client.closeSession(sessionHandle); sessionHandle = client.openSession("hive", "password", confOverlay); verifyInitProperty("a", "2", sessionHandle); client.closeSession(sessionHandle); }
@Test public void testSessionGlobalInitFileWithUser() throws Exception { //Test when the session is opened by a user. (HiveSessionImplwithUGI) SessionHandle sessionHandle = client.openSession("hive", "password", null); verifyInitProperty("a", "1", sessionHandle); client.closeSession(sessionHandle); }
@Test public void testGetFunctions() throws Exception { SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>()); assertNotNull("Session handle should not be null", sessHandle); String catalogName = null; String schemaName = null; String functionName = "*"; OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName); assertNotNull("Operation handle should not be null", opHandle); client.closeSession(sessHandle); }
@Test public void testGetFunctions() throws Exception { SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>()); assertNotNull("Session handle should not be null", sessHandle); String catalogName = null; String schemaName = null; String functionName = "*"; OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName); assertNotNull("Operation handle should not be null", opHandle); client.closeSession(sessHandle); }
@Test // This is to test session temporary files are cleaned up after HIVE-11768 public void testTempSessionFileCleanup() throws Exception { EmbeddedThriftBinaryCLIService service = new EmbeddedThriftBinaryCLIService(); HiveConf hiveConf = new HiveConf(); hiveConf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); service.init(hiveConf); ThriftCLIServiceClient client = new ThriftCLIServiceClient(service); Set<String> existingPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); SessionHandle sessionHandle = client.openSession("user1", "foobar", Collections.<String, String>emptyMap()); client.executeStatement(sessionHandle, "set a=b", null); File operationLogRootDir = new File( new HiveConf().getVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION)); Assert.assertNotEquals(operationLogRootDir.list().length, 0); client.closeSession(sessionHandle); // Check if session files are removed Assert.assertEquals(operationLogRootDir.list().length, 0); // Check if the pipeout files are removed Set<String> finalPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); finalPipeoutFiles.removeAll(existingPipeoutFiles); Assert.assertTrue(finalPipeoutFiles.isEmpty()); }
Map<String, String> opConf = new HashMap<String, String>(); SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
/** * create session, and fetch the property set in global init file. Test if * the global init file .hiverc is loaded correctly by checking the expected * setting property. */ private void doTestSessionGlobalInitFile() throws Exception { OperationManager operationManager = service.getService().getSessionManager() .getOperationManager(); SessionHandle sessionHandle = client.openSession(null, null, null); // ensure there is no operation related object leak Assert.assertEquals("Verifying all operations used for init file are closed", 0, operationManager.getOperations().size()); verifyInitProperty("a", "1", sessionHandle); verifyInitProperty("b", "1", sessionHandle); verifyInitProperty("c", "1", sessionHandle); verifyInitProperty("hivevar:c", "1", sessionHandle); verifyInitProperty("d", "1", sessionHandle); /** * TODO: client.executeStatement do not support listing resources command * (beeline> list jar) */ // Assert.assertEquals("expected uri", api.getAddedResource("jar")); Assert.assertEquals("Verifying all operations used for checks are closed", 0, operationManager.getOperations().size()); client.closeSession(sessionHandle); }
@Test public void testSessionImplWithUGI() throws Exception { HiveConf hiveConf = new HiveConf(); hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER.getDefaultValue()); hiveConf.setVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_WITH_UGI_CLASSNAME, SampleHiveSessionImplWithUGI.class.getName()); hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, true); CLIService cliService = new CLIService(null, true); cliService.init(hiveConf); ThriftBinaryCLIService service = new ThriftBinaryCLIService(cliService, null); service.init(hiveConf); ThriftCLIServiceClient client = new ThriftCLIServiceClient(service); SessionHandle sessionHandle = null; sessionHandle = client.openSession("tom", "password"); assertEquals(SampleHiveSessionImplWithUGI.class.getName(), service.getHiveConf().getVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_WITH_UGI_CLASSNAME)); HiveSession session = cliService.getSessionManager().getSession(sessionHandle); assertEquals(SampleHiveSessionImplWithUGI.MAGIC_RETURN_VALUE, session.getNoOperationTime()); client.closeSession(sessionHandle); }
@Test public void testSessionImpl() throws Exception { HiveConf hiveConf = new HiveConf(); hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER.getDefaultValue()); hiveConf.setVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME, SampleHiveSessionImpl.class.getName()); hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, false); CLIService cliService = new CLIService(null, true); cliService.init(hiveConf); ThriftBinaryCLIService service = new ThriftBinaryCLIService(cliService, null); service.init(hiveConf); ThriftCLIServiceClient client = new ThriftCLIServiceClient(service); SessionHandle sessionHandle = null; sessionHandle = client.openSession("tom", "password"); assertEquals(SampleHiveSessionImpl.class.getName(), service.getHiveConf().getVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME)); HiveSession session = cliService.getSessionManager().getSession(sessionHandle); assertEquals(SampleHiveSessionImpl.MAGIC_RETURN_VALUE, session.getNoOperationTime()); client.closeSession(sessionHandle); }
Map<String, String> opConf = new HashMap<String, String>(); SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
Map<String, String> opConf = new HashMap<String, String>(); SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
@Override public SessionHandle openSession(String username, String password) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { return super.openSession(username, password); } } }
public SessionHandle openSession(String username, String password, Map<String, String> configuration) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { return super.openSession(username, password, configuration); } }
public SessionHandle openSession(String username, String password, Map<String, String> configuration) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { return super.openSession(username, password, configuration); } }
@Override public SessionHandle openSession(String username, String password) throws HiveSQLException { try (SessionStateContext ignored = new SessionStateContext()) { return super.openSession(username, password); } } }