@Override public boolean isClosed() { return this.conn.isClosed(); }
@Override public void close() throws IOException { if (this.connection != null && !this.connection.isClosed()) { this.connection.close(); } }
@Override public void close() throws IOException { if (this.connection != null && !this.connection.isClosed()) { this.connection.close(); } }
private boolean isValid(Connection conn) { return conn != null && !conn.isAborted() && !conn.isClosed(); }
/** * Callers should call close on the returned {@link Table} instance. * @param connection connection we're using to access Meta * @return An {@link Table} for <code>hbase:meta</code> */ public static Table getMetaHTable(final Connection connection) throws IOException { // We used to pass whole CatalogTracker in here, now we just pass in Connection if (connection == null) { throw new NullPointerException("No connection"); } else if (connection.isClosed()) { throw new IOException("connection is closed"); } return connection.getTable(TableName.META_TABLE_NAME); }
public Connection getConnection() { if (conn == null || conn.isAborted() || conn.isClosed()) { initConn(); } return conn; }
synchronized boolean updateAccessTime() { if (closed) { return false; } if (connection.isAborted() || connection.isClosed()) { LOG.info("Unexpected: cached Connection is aborted/closed, removed from cache"); connections.remove(userName); return false; } lastAccessTime = EnvironmentEdgeManager.currentTime(); return true; }
@SuppressWarnings("resource") public static Connection get(StorageURL url) { // find configuration Configuration conf = configCache.get(url); if (conf == null) { conf = newHBaseConfiguration(url); configCache.put(url, conf); } Connection connection = connPool.get(url); try { while (true) { // I don't use DCL since recreate a connection is not a big issue. if (connection == null || connection.isClosed()) { logger.info("connection is null or closed, creating a new one"); connection = ConnectionFactory.createConnection(conf); connPool.put(url, connection); } if (connection == null || connection.isClosed()) { Thread.sleep(10000);// wait a while and retry } else { break; } } } catch (Throwable t) { logger.error("Error when open connection " + url, t); throw new RuntimeException("Error when open connection " + url, t); } return connection; }
@Override public synchronized void close() { if (this.hbaseTable != null) { try { this.hbaseTable.close(); this.hbaseTable = null; } catch (IOException e) { logger.warn("Caught exception while closing HBase table.", e); } } if (this.connection != null && !this.connection.isClosed()) { try { this.connection.close(); } catch (IOException e) { logger.warn("Caught exception while closing HBase connection.", e); } this.connection = null; } }
@Override public void close() throws IOException { if (this.admin != null) { admin.close(); } if (this.connection != null && !this.connection.isClosed()) { this.connection.close(); } }
@Before public void setUp() throws IOException { ReplicationSource source = mock(ReplicationSource.class); when(source.getPeerId()).thenReturn(PEER_ID); when(source.getQueueStorage()).thenReturn(QUEUE_STORAGE); conn = mock(Connection.class); when(conn.isClosed()).thenReturn(false); doAnswer(new Answer<Table>() { @Override public Table answer(InvocationOnMock invocation) throws Throwable { return UTIL.getConnection().getTable((TableName) invocation.getArgument(0)); } }).when(conn).getTable(any(TableName.class)); Server server = mock(Server.class); when(server.getConnection()).thenReturn(conn); when(source.getServer()).thenReturn(server); checker = new SerialReplicationChecker(UTIL.getConfiguration(), source); tableName = TableName.valueOf(name.getMethodName()); }
@Test public void testClosing() throws Exception { Configuration configuration = new Configuration(TEST_UTIL.getConfiguration()); configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(ThreadLocalRandom.current().nextInt())); // as connection caching is going away, now we're just testing // that closed connection does actually get closed. Connection c1 = ConnectionFactory.createConnection(configuration); Connection c2 = ConnectionFactory.createConnection(configuration); // no caching, different connections assertTrue(c1 != c2); // closing independently c1.close(); assertTrue(c1.isClosed()); assertFalse(c2.isClosed()); c2.close(); assertTrue(c2.isClosed()); }
@AfterClass public static void tearDownAfterClass() throws Exception { if (ADMIN != null) ADMIN.close(); if (CONNECTION != null && !CONNECTION.isClosed()) CONNECTION.close(); TEST_UTIL.shutdownMiniCluster(); }
/** * test for ConnectionCache cleaning expired Connection */ @Test public void testConnectionChore() throws Exception { UTIL.startMiniCluster(); //1s for clean interval & 5s for maxIdleTime ConnectionCache cache = new ConnectionCache(UTIL.getConfiguration(), UserProvider.instantiate(UTIL.getConfiguration()), 1000, 5000); ConnectionCache.ConnectionInfo info = cache.getCurrentConnection(); assertEquals(false, info.connection.isClosed()); Thread.sleep(7000); assertEquals(true, info.connection.isClosed()); UTIL.shutdownMiniCluster(); }
if(admin != null) { admin.close(); if (admin.getConnection().isClosed()) { rpcClient = (RandomTimeoutRpcClient) RpcClientFactory .createClient(TEST_UTIL.getConfiguration(), TEST_UTIL.getClusterKey());
/** * Test that Connection or Pool are not closed when managed externally * @throws Exception */ @Test public void testConnectionManagement() throws Exception{ Table table0 = TEST_UTIL.createTable(TABLE_NAME1, FAM_NAM); Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()); Table table = conn.getTable(TABLE_NAME1); table.close(); assertFalse(conn.isClosed()); if(table instanceof HTable) { assertFalse(((HTable) table).getPool().isShutdown()); } table = conn.getTable(TABLE_NAME1); table.close(); if(table instanceof HTable) { assertFalse(((HTable) table).getPool().isShutdown()); } conn.close(); if(table instanceof HTable) { assertTrue(((HTable) table).getPool().isShutdown()); } table0.close(); }
@Override protected void doClose() { if (this.hbase == null || this.hbase.isClosed()) { return; } try { this.hbase.close(); } catch (IOException e) { throw new BackendException("Failed to close HBase connection", e); } }
@SuppressWarnings("unchecked") @Test public void testCheckRegionServerStoppingOnException() throws Exception { StatisticsScannerCallable realCallable = mockScanner.new StatisticsScannerCallable(); doThrow(new IOException()).when(statsWriter).deleteStatsForRegion(any(Region.class), any(StatisticsCollector.class), any(ImmutableBytesPtr.class), any(List.class)); when(conn.isClosed()).thenReturn(true); when(conn.isAborted()).thenReturn(false); // Should not throw an exception realCallable.call(); verify(conn).isClosed(); }
@Test public void testCheckRegionServerStoppedOnClose() throws Exception { when(conn.isClosed()).thenReturn(false); when(conn.isAborted()).thenReturn(true); mockScanner.close(); verify(conn).isClosed(); verify(conn).isAborted(); verify(callable, never()).call(); verify(runTracker, never()).runTask(callable); }