@Before public void setUp() throws Exception { super.setUp(); // create and put .hiverc sample file to default directory initFile = File.createTempFile("test", "hive"); tmpDir = initFile.getParentFile().getAbsoluteFile() + File.separator + "TestSessionGlobalInitFile"; initFile.delete(); FileUtils.deleteDirectory(new File(tmpDir)); initFile = new File(tmpDir + File.separator + SessionManager.HIVERCFILE); initFile.getParentFile().mkdirs(); initFile.createNewFile(); String[] fileContent = new String[] { "-- global init hive file for test", "set a=1;", "set hiveconf:b=1;", "set hivevar:c=1;", "set d\\", " =1;", "add jar " + initFile.getAbsolutePath() }; FileUtils.writeLines(initFile, Arrays.asList(fileContent)); // set up service and client hiveConf = new HiveConf(); hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION, initFile.getParentFile().getAbsolutePath()); hiveConf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); service = new FakeEmbeddedThriftBinaryCLIService(hiveConf); service.init(new HiveConf()); client = new ThriftCLIServiceClient(service); }
/** * 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); }