Search in sources :

Example 6 with AffinityCache

use of org.apache.ignite.internal.jdbc.thin.AffinityCache 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 7 with AffinityCache

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

the class JdbcThinPartitionAwarenessSelfTest method testChangeTopologyDetectionWithinQueryExecutionResponse.

/**
 * Check that affinity cache is invalidated in case of changing topology,
 * detected during query response retrieval.
 *
 * @throws Exception If failed.
 */
@Test
public void testChangeTopologyDetectionWithinQueryExecutionResponse() throws Exception {
    final String sqlQry = "select * from Person where _key = 1";
    stmt.executeQuery(sqlQry);
    stmt.executeQuery(sqlQry);
    AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
    startGrid(4);
    stmt.executeQuery("select * from Person where _key = 2");
    AffinityCache recreatedAffinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
    assertTrue(recreatedAffinityCache.version().compareTo(affinityCache.version()) > 0);
}
Also used : AffinityCache(org.apache.ignite.internal.jdbc.thin.AffinityCache) Test(org.junit.Test)

Example 8 with AffinityCache

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

the class JdbcThinPartitionAwarenessSelfTest method testChangeTopologyDetectionWithinPartitionAwarenessUnrelatedQuery.

/**
 * Check that affinity cache is invalidated in case of changing topology,
 * detected during affinity-awareness-unrelated-query response retrieval.
 *
 * @throws Exception If failed.
 */
@Test
public void testChangeTopologyDetectionWithinPartitionAwarenessUnrelatedQuery() throws Exception {
    final String sqlQry = "select * from Person where _key = 1";
    ResultSet rs = stmt.executeQuery(sqlQry);
    AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
    startGrid(5);
    rs.getMetaData();
    AffinityCache recreatedAffinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
    assertTrue(recreatedAffinityCache.version().compareTo(affinityCache.version()) > 0);
}
Also used : AffinityCache(org.apache.ignite.internal.jdbc.thin.AffinityCache) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 9 with AffinityCache

use of org.apache.ignite.internal.jdbc.thin.AffinityCache 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)

Example 10 with AffinityCache

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

the class JdbcThinPartitionAwarenessSelfTest method testPartitionAwarenessIsSkippedIfItIsSwitchedOff.

/**
 * Check that client side partition awareness optimizations are skipped if partitionAwareness is switched off.
 *
 * @throws Exception If failed.
 */
@Test
public void testPartitionAwarenessIsSkippedIfItIsSwitchedOff() throws Exception {
    try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800..10802?partitionAwareness=false");
        Statement stmt = conn.createStatement()) {
        final String cacheName = "yac";
        CacheConfiguration<Object, Object> cache = prepareCacheConfig(cacheName);
        ignite(0).createCache(cache);
        stmt.executeQuery("select * from \"" + cacheName + "\".Person where _key = 1");
        AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache");
        assertNull("Affinity cache is not null.", affinityCache);
    }
}
Also used : AffinityCache(org.apache.ignite.internal.jdbc.thin.AffinityCache) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Aggregations

AffinityCache (org.apache.ignite.internal.jdbc.thin.AffinityCache)10 Test (org.junit.Test)9 QualifiedSQLQuery (org.apache.ignite.internal.jdbc.thin.QualifiedSQLQuery)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 Statement (java.sql.Statement)4 JdbcThinPartitionResultDescriptor (org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor)3 ResultSet (java.sql.ResultSet)2 UUID (java.util.UUID)1 LogRecord (java.util.logging.LogRecord)1 JdbcThinConnection (org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)1 PartitionResult (org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult)1 PartitionSingleNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionSingleNode)1