public static HiveConf getHiveConf(Configuration conf) throws IOException { HiveConf hiveConf = new HiveConf(conf, HCatUtil.class); // copy the hive conf into the job conf and restore it // in the backend context if (conf.get(HCatConstants.HCAT_KEY_HIVE_CONF) == null) { conf.set(HCatConstants.HCAT_KEY_HIVE_CONF, HCatUtil.serialize(hiveConf.getAllProperties())); } else { // Copy configuration properties into the hive conf Properties properties = (Properties) HCatUtil.deserialize(conf.get(HCatConstants.HCAT_KEY_HIVE_CONF)); for (Map.Entry<Object, Object> prop : properties.entrySet()) { if (prop.getValue() instanceof String) { hiveConf.set((String) prop.getKey(), (String) prop.getValue()); } else if (prop.getValue() instanceof Integer) { hiveConf.setInt((String) prop.getKey(), (Integer) prop.getValue()); } else if (prop.getValue() instanceof Boolean) { hiveConf.setBoolean((String) prop.getKey(), (Boolean) prop.getValue()); } else if (prop.getValue() instanceof Long) { hiveConf.setLong((String) prop.getKey(), (Long) prop.getValue()); } else if (prop.getValue() instanceof Float) { hiveConf.setFloat((String) prop.getKey(), (Float) prop.getValue()); } } } if (conf.get(HCatConstants.HCAT_KEY_TOKEN_SIGNATURE) != null) { hiveConf.set( "hive.metastore.token.signature", conf.get(HCatConstants.HCAT_KEY_TOKEN_SIGNATURE)); } return hiveConf; }
@BeforeClass public static void setUpOneTime() throws Exception { fs = new LocalFileSystem(); fs.initialize(fs.getWorkingDirectory().toUri(), new Configuration()); HiveConf hiveConf = new HiveConf(); hiveConf.setInt(HCatConstants.HCAT_HIVE_CLIENT_EXPIRY_TIME, 0); // Hack to initialize cache with 0 expiry time causing it to return a new hive client every time // Otherwise the cache doesn't play well with the second test method with the client gets // closed() in the // tearDown() of the previous test HCatUtil.getHiveMetastoreClient(hiveConf); MapCreate.writeCount = 0; MapRead.readCount = 0; }
public void testSessionExpiryInterval() throws Exception { HiveConf conf = LensServerConf.createHiveConf(); conf.setVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME, LensSessionImpl.class.getName()); conf.setLong(LensConfConstants.SESSION_TIMEOUT_SECONDS, 1L); conf.setInt(LensConfConstants.SESSION_EXPIRY_SERVICE_INTERVAL_IN_SECS, 1); CLIService cliService = new CLIService(); cliService.init(conf); HiveSessionService lensService = new HiveSessionService(cliService); lensService.init(conf); lensService.start(); MetricsService metricSvc = LensServices.get().getService(MetricsService.NAME); try { LensSessionHandle sessionHandle = lensService.openSession("foo", "bar", new HashMap<String, String>()); LensSessionImpl session = lensService.getSession(sessionHandle); assertTrue(session.isActive()); session.setLastAccessTime( session.getLastAccessTime() - 2000 * conf.getLong( LensConfConstants.SESSION_TIMEOUT_SECONDS, LensConfConstants.SESSION_TIMEOUT_SECONDS_DEFAULT)); assertFalse(session.isActive()); log.info( "Keeping a sleep of 3 seconds to make sure SessionExpiryService is running and gets enough time to" + "close inactive sessions"); Thread.sleep(3000); assertTrue(metricSvc.getTotalExpiredSessions() >= 1); assertTrue(metricSvc.getTotalClosedSessions() >= 1); try { lensService.getSession(sessionHandle); // should throw exception since session should be expired by now fail("Expected get session to fail for session " + sessionHandle.getPublicId()); } catch (Exception e) { // pass } } finally { lensService.stop(); } }