Search in sources :

Example 1 with JdbcThinPartitionResultDescriptor

use of org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor in project ignite by apache.

the class JdbcThinPartitionAwarenessSelfTest method testPartitionAwarenessLimitedCacheSize.

/**
 * Check that partitionAwarenessSQLCacheSize and partitionAwarenessPartitionDistributionsCacheSize
 * actually limit corresponding caches within partition awareness cache.
 *
 * @throws Exception If failed.
 */
@Test
public void testPartitionAwarenessLimitedCacheSize() throws Exception {
    try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800..10802?partitionAwareness=true" + "&partitionAwarenessSQLCacheSize=1&partitionAwarenessPartitionDistributionsCacheSize=1");
        Statement stmt = conn.createStatement()) {
        final String cacheName1 = UUID.randomUUID().toString().substring(0, 6);
        CacheConfiguration<Object, Object> cache1 = prepareCacheConfig(cacheName1);
        ignite(0).createCache(cache1);
        fillCache(cacheName1);
        final String cacheName2 = UUID.randomUUID().toString().substring(0, 6);
        CacheConfiguration<Object, Object> cache2 = prepareCacheConfig(cacheName2);
        ignite(0).createCache(cache2);
        fillCache(cacheName2);
        stmt.executeQuery("select * from \"" + cacheName1 + "\".Person where _key = 1");
        stmt.executeQuery("select * from \"" + cacheName1 + "\".Person where _key = 1");
        stmt.executeQuery("select * from \"" + cacheName2 + "\".Person where _key = 1");
        stmt.executeQuery("select * from \"" + cacheName2 + "\".Person where _key = 1");
        AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
        GridBoundedLinkedHashMap<Integer, UUID[]> partitionsDistributionCache = GridTestUtils.getFieldValue(affinityCache, "cachePartitionsDistribution");
        GridBoundedLinkedHashMap<QualifiedSQLQuery, JdbcThinPartitionResultDescriptor> sqlCache = GridTestUtils.getFieldValue(affinityCache, "sqlCache");
        assertEquals("Unexpected count of partitions distributions.", 1, partitionsDistributionCache.size());
        assertEquals("Unexpected count of sql queries.", 1, sqlCache.size());
        assertTrue("Unexpected distribution is found.", partitionsDistributionCache.containsKey(GridCacheUtils.cacheId(cacheName2)));
        assertTrue("Unexpected sql query is found.", sqlCache.containsKey(new QualifiedSQLQuery("PUBLIC", "select * from \"" + cacheName2 + "\".Person where _key = 1")));
    }
}
Also used : JdbcThinPartitionResultDescriptor(org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor) AffinityCache(org.apache.ignite.internal.jdbc.thin.AffinityCache) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) QualifiedSQLQuery(org.apache.ignite.internal.jdbc.thin.QualifiedSQLQuery) Test(org.junit.Test)

Example 2 with JdbcThinPartitionResultDescriptor

use of org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor in project ignite by apache.

the class JdbcThinPartitionAwarenessSelfTest method testAffinityCacheStoresSchemaBindedQueries.

/**
 * Check that affinity cache stores sql queries with their schemas.
 *
 * @throws Exception If failed.
 */
@Test
public void testAffinityCacheStoresSchemaBindedQueries() throws Exception {
    final String cacheName = "yacc";
    CacheConfiguration<Object, Object> cache = prepareCacheConfig(cacheName);
    cache.setSqlSchema(cacheName);
    ignite(0).createCache(cache);
    fillCache(cacheName);
    stmt.execute("select * from \"" + cacheName.toUpperCase() + "\".Person where _key = 1");
    conn.setSchema(cacheName.toUpperCase());
    stmt = conn.createStatement();
    stmt.execute("select * from \"" + cacheName.toUpperCase() + "\".Person where _key = 1");
    AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
    GridBoundedLinkedHashMap<QualifiedSQLQuery, JdbcThinPartitionResultDescriptor> sqlCache = GridTestUtils.getFieldValue(affinityCache, "sqlCache");
    Set<String> schemas = sqlCache.keySet().stream().map(QualifiedSQLQuery::schemaName).collect(Collectors.toSet());
    assertTrue("Affinity cache doesn't contain query  sent to 'default' schema.", schemas.contains("default"));
    assertTrue("Affinity cache doesn't contain query  sent to '" + cacheName.toUpperCase() + "' schema.", schemas.contains(cacheName.toUpperCase()));
}
Also used : JdbcThinPartitionResultDescriptor(org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor) AffinityCache(org.apache.ignite.internal.jdbc.thin.AffinityCache) QualifiedSQLQuery(org.apache.ignite.internal.jdbc.thin.QualifiedSQLQuery) Test(org.junit.Test)

Example 3 with JdbcThinPartitionResultDescriptor

use of org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor in project ignite by apache.

the class JdbcThinPartitionAwarenessSelfTest method testAffinityCacheCompactsPartitionDistributions.

/**
 * Check that affinity cache stores compacted version of partitions distributions.
 *
 * @throws Exception If failed.
 */
@Test
public void testAffinityCacheCompactsPartitionDistributions() throws Exception {
    final String cacheName = "yaccc";
    CacheConfiguration<Object, Object> cache = prepareCacheConfig(cacheName);
    ignite(0).createCache(cache);
    fillCache(cacheName);
    stmt.execute("select * from Person where _key = 2");
    stmt.execute("select * from Person where _key = 2");
    stmt.execute("select * from \"" + cacheName + "\".Person where _key = 2");
    stmt.execute("select * from \"" + cacheName + "\".Person where _key = 2");
    AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
    GridBoundedLinkedHashMap<QualifiedSQLQuery, JdbcThinPartitionResultDescriptor> sqlCache = GridTestUtils.getFieldValue(affinityCache, "sqlCache");
    GridBoundedLinkedHashMap<Integer, UUID[]> cachePartitionsDistribution = GridTestUtils.getFieldValue(affinityCache, "cachePartitionsDistribution");
    assertEquals("Sql sub-cache of affinity cache has unexpected number of elements.", 2, sqlCache.size());
    assertEquals("Partitions distribution sub-cache of affinity cache has unexpected number of elements.", 2, cachePartitionsDistribution.size());
    // Main assertion of the test: we are checking that partitions distributions for different caches
    // are equal in therms of (==)
    assertTrue("Partitions distributions are not the same.", cachePartitionsDistribution.get(0) == cachePartitionsDistribution.get(1));
}
Also used : JdbcThinPartitionResultDescriptor(org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor) AffinityCache(org.apache.ignite.internal.jdbc.thin.AffinityCache) QualifiedSQLQuery(org.apache.ignite.internal.jdbc.thin.QualifiedSQLQuery) Test(org.junit.Test)

Aggregations

AffinityCache (org.apache.ignite.internal.jdbc.thin.AffinityCache)3 JdbcThinPartitionResultDescriptor (org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor)3 QualifiedSQLQuery (org.apache.ignite.internal.jdbc.thin.QualifiedSQLQuery)3 Test (org.junit.Test)3 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1