Search in sources :

Example 36 with Cache

use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project calcite-avatica by apache.

the class ConnectionPropertiesTest method getConnection.

private static Connection getConnection(JdbcMeta m, String id) throws Exception {
    Field f = JdbcMeta.class.getDeclaredField("connectionCache");
    f.setAccessible(true);
    // noinspection unchecked
    Cache<String, Connection> connectionCache = (Cache<String, Connection>) f.get(m);
    return connectionCache.getIfPresent(id);
}
Also used : Field(java.lang.reflect.Field) Connection(java.sql.Connection) AvaticaConnection(org.apache.calcite.avatica.AvaticaConnection) Cache(com.google.common.cache.Cache)

Example 37 with Cache

use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project calcite-avatica by apache.

the class RemoteMetaTest method getConnection.

private static Connection getConnection(JdbcMeta m, String id) throws Exception {
    Field f = JdbcMeta.class.getDeclaredField("connectionCache");
    f.setAccessible(true);
    // noinspection unchecked
    Cache<String, Connection> connectionCache = (Cache<String, Connection>) f.get(m);
    return connectionCache.getIfPresent(id);
}
Also used : Field(java.lang.reflect.Field) HttpURLConnection(java.net.HttpURLConnection) Connection(java.sql.Connection) AvaticaConnection(org.apache.calcite.avatica.AvaticaConnection) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Cache(com.google.common.cache.Cache)

Example 38 with Cache

use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project calcite-avatica by apache.

the class JdbcMetaTest method testPrepareAndExecuteSetsMaxRows.

@Test
public void testPrepareAndExecuteSetsMaxRows() throws Exception {
    final String id = UUID.randomUUID().toString();
    final int statementId = 12345;
    final String sql = "SELECT * FROM FOO";
    final int maxRows = 500;
    JdbcMeta meta = Mockito.mock(JdbcMeta.class);
    PreparedStatement statement = Mockito.mock(PreparedStatement.class);
    @SuppressWarnings("unchecked") Cache<Integer, StatementInfo> statementCache = (Cache<Integer, StatementInfo>) Mockito.mock(Cache.class);
    Signature signature = Mockito.mock(Signature.class);
    final StatementInfo statementInfo = new StatementInfo(statement);
    final StatementHandle statementHandle = new StatementHandle(id, statementId, signature);
    Mockito.when(meta.getStatementCache()).thenReturn(statementCache);
    Mockito.when(statementCache.getIfPresent(statementId)).thenReturn(statementInfo);
    Mockito.when(statement.getResultSet()).thenReturn(null);
    // The real methods
    Mockito.when(meta.prepareAndExecute(statementHandle, sql, maxRows, 50, null)).thenCallRealMethod();
    Mockito.doCallRealMethod().when(meta).setMaxRows(statement, maxRows);
    // Call our method
    meta.prepareAndExecute(statementHandle, sql, maxRows, 50, null);
    // Verify we called setMaxRows with the right value
    Mockito.verify(statement).setMaxRows(maxRows);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatementHandle(org.apache.calcite.avatica.Meta.StatementHandle) Signature(org.apache.calcite.avatica.Meta.Signature) PreparedStatement(java.sql.PreparedStatement) AvaticaPreparedStatement(org.apache.calcite.avatica.AvaticaPreparedStatement) Cache(com.google.common.cache.Cache) Test(org.junit.Test)

Aggregations

Cache (com.google.common.cache.Cache)38 List (java.util.List)18 CacheBuilder (com.google.common.cache.CacheBuilder)17 Optional (java.util.Optional)10 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)10 Module (com.google.inject.Module)9 TimeUnit (java.util.concurrent.TimeUnit)9 Collectors (java.util.stream.Collectors)9 CachingOrcFileTailSource (com.facebook.presto.orc.cache.CachingOrcFileTailSource)8 OrcFileTailSource (com.facebook.presto.orc.cache.OrcFileTailSource)8 StorageOrcFileTailSource (com.facebook.presto.orc.cache.StorageOrcFileTailSource)8 OrcFileTail (com.facebook.presto.orc.metadata.OrcFileTail)8 RowGroupIndex (com.facebook.presto.orc.metadata.RowGroupIndex)8 ArrayList (java.util.ArrayList)8 ExecutorService (java.util.concurrent.ExecutorService)8 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)7 CachingStripeMetadataSource (com.facebook.presto.orc.CachingStripeMetadataSource)7 DwrfAwareStripeMetadataSourceFactory (com.facebook.presto.orc.DwrfAwareStripeMetadataSourceFactory)7 OrcDataSourceId (com.facebook.presto.orc.OrcDataSourceId)7 StorageStripeMetadataSource (com.facebook.presto.orc.StorageStripeMetadataSource)7