/** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { // Find a free port port = MetaStoreTestUtils.findFreePort(); hiveServer2 = new HiveServer2(); hiveConf = new HiveConf(); }
} catch (Exception t) { HiveConf.setIntVar(hiveConf, HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, MetaStoreTestUtils.findFreePort()); HiveConf.setIntVar(hiveConf, HiveConf.ConfVars.HIVE_SERVER2_THRIFT_HTTP_PORT, MetaStoreTestUtils.findFreePort()); HiveConf.setIntVar(hiveConf, HiveConf.ConfVars.HIVE_SERVER2_WEBUI_PORT, MetaStoreTestUtils.findFreePort()); webUIPort = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_PORT);
protected static void startHiveServer2WithConf(HiveConf hiveConf) throws Exception { Exception HS2Exception = null; boolean HS2Started = false; for (int tryCount = 0; tryCount < MetaStoreTestUtils.RETRY_COUNT; tryCount++) { try { hiveServer2.init(hiveConf); hiveServer2.start(); HS2Started = true; break; } catch (Exception t) { HS2Exception = t; port = MetaStoreTestUtils.findFreePort(); hiveConf.setIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_PORT, port); hiveServer2 = new HiveServer2(); } } if (!HS2Started) { HS2Exception.printStackTrace(); fail(); } // Wait for startup to complete Thread.sleep(2000); System.out.println("HiveServer2 started on port " + port); }
@Test public void testEventListenerException() throws Throwable { System.setProperty("hive.metastore.init.hooks", ""); System.setProperty("hive.metastore.event.listeners", ErrorEventListener.class.getName()); Configuration conf = MetastoreConf.newMetastoreConf(); MetaStoreTestUtils.setConfForStandloneMode(conf); int port = MetaStoreTestUtils.findFreePort(); try { HiveMetaStore.startMetaStore(port, HadoopThriftAuthBridge.getBridge(), conf); Assert.fail(); } catch (Throwable throwable) { Assert.assertEquals(MetaException.class, throwable.getClass()); Assert.assertEquals( "Failed to instantiate listener named: " + "org.apache.hadoop.hive.metastore.TestMetaStoreListenersError$ErrorEventListener, " + "reason: java.lang.IllegalArgumentException: exception on constructor", throwable.getMessage()); } }
@Test public void testInitListenerException() throws Throwable { System.setProperty("hive.metastore.init.hooks", ErrorInitListener.class.getName()); Configuration conf = MetastoreConf.newMetastoreConf(); MetaStoreTestUtils.setConfForStandloneMode(conf); int port = MetaStoreTestUtils.findFreePort(); try { HiveMetaStore.startMetaStore(port, HadoopThriftAuthBridge.getBridge(), conf); Assert.fail(); } catch (Throwable throwable) { Assert.assertEquals(MetaException.class, throwable.getClass()); Assert.assertEquals( "Failed to instantiate listener named: " + "org.apache.hadoop.hive.metastore.TestMetaStoreListenersError$ErrorInitListener, " + "reason: java.lang.IllegalArgumentException: exception on constructor", throwable.getMessage()); } }
int metaStorePort = findFreePort();
/** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { // Find a free port port = MetaStoreTestUtils.findFreePort(); hiveServer2 = new HiveServer2(); hiveConf = new HiveConf(); hiveConf.setBoolVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_COOKIE_AUTH_ENABLED, true); // Set the cookie max age to a very low value so that // the server sends 401 very frequently hiveConf.setTimeVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_COOKIE_MAX_AGE, 1, TimeUnit.SECONDS); hiveConf.setVar(ConfVars.HIVE_SERVER2_TRANSPORT_MODE, "http"); hiveConf.setVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_PATH, "cliservice"); assertNotNull(port); assertNotNull(hiveServer2); assertNotNull(hiveConf); hiveConf.setBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS, false); hiveConf.setVar(ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST, host); hiveConf.setIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_PORT, port); hiveConf.setVar(ConfVars.HIVE_SERVER2_AUTHENTICATION, HiveAuthConstants.AuthTypes.NOSASL.toString()); startHiveServer2WithConf(hiveConf); client = getServiceClientInternal(); }