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()));
}
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);
}
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);
}
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));
}
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);
}
}
Aggregations