@Test public void testNoLimit() throws HiveSQLException { conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testInvalidUserIpaddress() throws HiveSQLException { conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, " ", "bar", null, null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testInvalidUserName() throws HiveSQLException { conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, null, "bar", "127.0.0.1", null); sessionHandles.add(session); } for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testInvalidIpaddress() throws HiveSQLException { conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", null, null); sessionHandles.add(session); } for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testRestore() throws HiveSQLException { SessionHandle session = service.openSession("foo", "bar", null); service.stop(); service = getService(); try { service.getSessionManager().getSession(session); Assert.fail("session already exists before restore"); } catch (HiveSQLException e) { Assert.assertTrue(e.getMessage().contains("Invalid SessionHandle")); } service.createSessionWithSessionHandle(session, "foo", "bar", null); Assert.assertNotNull(service.getSessionManager().getSession(session)); service.stop(); }
@Test public void testIncrementAndDecrementConnectionsUser() throws HiveSQLException { conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { // open 5 connections for (int i = 0; i < limit / 2; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } // close them all for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } sessionHandles.clear(); // open till limit but not exceed for (int i = 0; i < limit; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "ff", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testConnectionForwardedIpAddresses() throws HiveSQLException { thrown.expect(HiveSQLException.class); thrown.expectMessage("Connection limit per ipaddress reached (ipaddress: 194.167.0.3 limit: 10)"); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 10); CLIService service = getService(conf); SessionManager.setForwardedAddresses(Lists.newArrayList("194.167.0.3", "194.167.0.2", "194.167.0.1")); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "194.167.0.1", null); sessionHandles.add(session); } } finally { SessionManager.setForwardedAddresses(Collections.emptyList()); for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testConnectionLimitPerUserIpAddress() throws HiveSQLException { thrown.expect(HiveSQLException.class); thrown.expectMessage("Connection limit per user:ipaddress reached (user:ipaddress: foo:127.0.0.1 limit: 10)"); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 10); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testConnectionLimitPerUser() throws HiveSQLException { thrown.expect(HiveSQLException.class); thrown.expectMessage("Connection limit per user reached (user: foo limit: 10)"); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testConnectionMultipleLimitsUserAndIP() throws HiveSQLException { thrown.expect(HiveSQLException.class); thrown.expectMessage("Connection limit per user reached (user: foo limit: 5)"); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 5); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testConnectionLimitPerIpAddress() throws HiveSQLException { thrown.expect(HiveSQLException.class); thrown.expectMessage("Connection limit per ipaddress reached (ipaddress: 127.0.0.1 limit: 10)"); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 10); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 0); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testConnectionMultipleLimitsUserIPAndUser() throws HiveSQLException { thrown.expect(HiveSQLException.class); thrown.expectMessage("Connection limit per user:ipaddress reached (user:ipaddress: foo:127.0.0.1 limit: 10)"); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 15); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 10); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Test public void testConnectionMultipleLimitsIPAndUserIP() throws HiveSQLException { thrown.expect(HiveSQLException.class); thrown.expectMessage("Connection limit per ipaddress reached (ipaddress: 127.0.0.1 limit: 5)"); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER, 0); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_IPADDRESS, 5); conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_LIMIT_CONNECTIONS_PER_USER_IPADDRESS, 10); CLIService service = getService(conf); List<SessionHandle> sessionHandles = new ArrayList<>(); try { for (int i = 0; i < limit + 1; i++) { SessionHandle session = service.openSession(CLIService.SERVER_VERSION, "foo", "bar", "127.0.0.1", null); sessionHandles.add(session); } } finally { for (SessionHandle sessionHandle : sessionHandles) { service.closeSession(sessionHandle); } service.stop(); } }
@Override protected void shutDown() throws Exception { LOG.info("Stopping {}...", BaseHiveExploreService.class.getSimpleName()); // By this time we should not get anymore new requests, since HTTP service has already been stopped. // Close all handles if (!activeHandleCache.asMap().isEmpty()) { LOG.info("Timing out active handles..."); } activeHandleCache.invalidateAll(); // Make sure the cache entries get expired. runCacheCleanup(); // Wait for all cleanup jobs to complete scheduledExecutorService.awaitTermination(10, TimeUnit.SECONDS); scheduledExecutorService.shutdown(); metastoreClientsExecutorService.shutdownNow(); // Go through all non-cleanup'ed clients and call close() upon them for (IMetaStoreClient client : metastoreClientReferences.values()) { closeMetastoreClient(client); } cliService.stop(); }
@Override protected void shutDown() throws Exception { LOG.info("Stopping {}...", BaseHiveExploreService.class.getSimpleName()); // By this time we should not get anymore new requests, since HTTP service has already been stopped. // Close all handles if (!activeHandleCache.asMap().isEmpty()) { LOG.info("Timing out active handles..."); } activeHandleCache.invalidateAll(); // Make sure the cache entries get expired. runCacheCleanup(); // Wait for all cleanup jobs to complete scheduledExecutorService.awaitTermination(10, TimeUnit.SECONDS); scheduledExecutorService.shutdown(); metastoreClientsExecutorService.shutdownNow(); // Go through all non-cleanup'ed clients and call close() upon them for (IMetaStoreClient client : metastoreClientReferences.values()) { closeMetastoreClient(client); } cliService.stop(); }