private void RunTest(File logFile, String hiveLog4jProperty, String hiveExecLog4jProperty) throws Exception { // clean test space cleanLog(logFile); assertFalse(logFile + " should not exist", logFile.exists()); // config log4j with customized files // check whether HiveConf initialize log4j correctly configLog(hiveLog4jProperty, hiveExecLog4jProperty); // check whether log file is created on test running assertTrue(logFile + " should exist", logFile.exists()); }
public void testHiveLogging() throws Exception { // customized log4j config log file to be: /${test.tmp.dir}/TestHiveLogging/hiveLog4jTest.log File customLogPath = new File(new File(System.getProperty("test.tmp.dir")), System.getProperty("user.name") + "-TestHiveLogging/"); String customLogName = "hiveLog4j2Test.log"; File customLogFile = new File(customLogPath, customLogName); RunTest(customLogFile, "hive-log4j2-test.properties", "hive-exec-log4j2-test.properties"); } }
private void configLog(String hiveLog4jTest, String hiveExecLog4jTest) throws Exception { String expectedLog4jTestPath = HiveTestUtils.getFileFromClasspath(hiveLog4jTest); String expectedLog4jExecPath = HiveTestUtils.getFileFromClasspath(hiveExecLog4jTest); System.setProperty(ConfVars.HIVE_LOG4J_FILE.varname, expectedLog4jTestPath); System.setProperty(ConfVars.HIVE_EXEC_LOG4J_FILE.varname, expectedLog4jExecPath); LogUtils.initHiveLog4j(); HiveConf conf = new HiveConf(); assertEquals(expectedLog4jTestPath, conf.getVar(ConfVars.HIVE_LOG4J_FILE)); assertEquals(expectedLog4jExecPath, conf.getVar(ConfVars.HIVE_EXEC_LOG4J_FILE)); }