@Ignore("[CALCITE-687] Make RemoteDriverTest.testStatementLifecycle thread-safe") @Test public void testConnectionIsolation() throws Exception { final String sql = "select * from (values (1, 'a'))"; Connection conn1 = ljs(); Connection conn2 = ljs(); Cache<String, Connection> connectionMap = QuasiRemoteJdbcServiceFactory.getRemoteConnectionMap((AvaticaConnection) conn1); assertEquals("connection cache should start empty", 0, connectionMap.size()); PreparedStatement conn1stmt1 = conn1.prepareStatement(sql); assertEquals( "statement creation implicitly creates a connection server-side", 1, connectionMap.size()); PreparedStatement conn2stmt1 = conn2.prepareStatement(sql); assertEquals( "statement creation implicitly creates a connection server-side", 2, connectionMap.size()); AvaticaPreparedStatement s1 = (AvaticaPreparedStatement) conn1stmt1; AvaticaPreparedStatement s2 = (AvaticaPreparedStatement) conn2stmt1; assertFalse( "connection id's should be unique", s1.handle.connectionId.equalsIgnoreCase(s2.handle.connectionId)); conn2.close(); assertEquals("closing a connection closes the server-side connection", 1, connectionMap.size()); conn1.close(); assertEquals("closing a connection closes the server-side connection", 0, connectionMap.size()); }
@Ignore("[CALCITE-687] Make RemoteDriverTest.testStatementLifecycle thread-safe") @Test public void testStatementLifecycle() throws Exception { try (AvaticaConnection connection = (AvaticaConnection) ljs()) { Map<Integer, AvaticaStatement> clientMap = connection.statementMap; Cache<Integer, Object> serverMap = QuasiRemoteJdbcServiceFactory.getRemoteStatementMap(connection); assertEquals(0, clientMap.size()); assertEquals(0, serverMap.size()); Statement stmt = connection.createStatement(); assertEquals(1, clientMap.size()); assertEquals(1, serverMap.size()); stmt.close(); assertEquals(0, clientMap.size()); assertEquals(0, serverMap.size()); } }
public static synchronized Session getSession(String host, int port) throws UnknownHostException { Session session = hostConnectionMap.getIfPresent(host); if (session == null || session.isClosed()) { Cluster.Builder builder = Cluster.builder().addContactPoint(host).withPort(port); Cluster cluster = builder.build(); session = cluster.connect(); hostConnectionMap.put(host, session); logger.debug("Created connection to {}.", host); logger.debug("Number of sessions opened are {}.", hostConnectionMap.size()); } return session; }
/* * (non-Javadoc) * * @see org.apache.bookkeeper.mledger.ManagedLedger#close() */ @Override public synchronized void close() throws InterruptedException, ManagedLedgerException { checkFenced(); for (LedgerHandle ledger : ledgerCache.asMap().values()) { log.debug("Closing ledger: {}", ledger.getId()); try { ledger.close(); } catch (BKException e) { throw new ManagedLedgerException(e); } } ledgerCache.invalidateAll(); log.info("Invalidated {} ledgers in cache", ledgerCache.size()); factory.close(this); }
private void printMemoryCaches( Map<String, H2CacheImpl<?, ?>> disks, Map<String, Cache<?, ?>> caches) { for (Map.Entry<String, Cache<?, ?>> entry : caches.entrySet()) { Cache<?, ?> cache = entry.getValue(); if (cache instanceof H2CacheImpl) { disks.put(entry.getKey(), (H2CacheImpl<?, ?>) cache); continue; } CacheStats stat = cache.stats(); stdout.print( String.format( " %-" + nw + "s|%6s %6s %7s| %7s |%4s %4s|\n", entry.getKey(), count(cache.size()), "", "", duration(stat.averageLoadPenalty()), percent(stat.hitCount(), stat.requestCount()), "")); } }
public static final long getCacheSize() { if (singleCache != null) { return singleCache.size(); } return 0; }