Search in sources :

Example 1 with PlanCache

use of com.hazelcast.sql.impl.plan.cache.PlanCache in project hazelcast by hazelcast.

the class PlanCacheTest method testBasicOperations.

@Test
public void testBasicOperations() {
    PlanCache cache = new PlanCache(10);
    PlanKey key = createKey("sql");
    // Put plan
    SqlPlan plan1 = createPlan(key, PART_MAP_1);
    cache.put(key, plan1);
    assertEquals(1, cache.size());
    assertSame(plan1, cache.get(key));
    // Overwrite plan
    SqlPlan plan2 = createPlan(key, PART_MAP_2);
    cache.put(key, plan2);
    assertEquals(1, cache.size());
    assertSame(plan2, cache.get(key));
    // Invalidate the plan that is no longer cached
    cache.invalidate(plan1);
    assertEquals(1, cache.size());
    assertSame(plan2, cache.get(key));
    // Invalidate cache plan
    cache.invalidate(plan2);
    assertEquals(0, cache.size());
    assertNull(cache.get(key));
    // Clear
    cache.put(key, plan1);
    assertEquals(1, cache.size());
    assertSame(plan1, cache.get(key));
    cache.clear();
    assertEquals(0, cache.size());
    assertNull(cache.get(key));
}
Also used : PlanKey(com.hazelcast.sql.impl.optimizer.PlanKey) SqlPlan(com.hazelcast.sql.impl.optimizer.SqlPlan) PlanCache(com.hazelcast.sql.impl.plan.cache.PlanCache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with PlanCache

use of com.hazelcast.sql.impl.plan.cache.PlanCache in project hazelcast by hazelcast.

the class SqlTestSupport method tearDown.

@After
public void tearDown() {
    // noinspection ConstantConditions
    if (instances() == null) {
        return;
    }
    for (HazelcastInstance instance : instances()) {
        PlanCache planCache = planCache(instance);
        SUPPORT_LOGGER.info("Removing " + planCache.size() + " cached plans in SqlTestSupport.@After");
        planCache.clear();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PlanCache(com.hazelcast.sql.impl.plan.cache.PlanCache) After(org.junit.After)

Example 3 with PlanCache

use of com.hazelcast.sql.impl.plan.cache.PlanCache in project hazelcast by hazelcast.

the class PlanCacheIntegrationTest method testPlanIsCached.

@Test
public void testPlanIsCached() {
    createMapping(mapName, int.class, int.class);
    instance().getMap(mapName).put(1, 1);
    PlanCache planCache = planCache(instance());
    instance().getSql().execute("SELECT * FROM " + mapName);
    assertEquals(1, planCache.size());
    SqlPlan plan1 = planCache.get(planCache.getPlans().keys().nextElement());
    instance().getSql().execute("SELECT * FROM " + mapName);
    assertEquals(1, planCache.size());
    SqlPlan plan2 = planCache.get(planCache.getPlans().keys().nextElement());
    assertSame(plan1, plan2);
}
Also used : SqlPlan(com.hazelcast.sql.impl.optimizer.SqlPlan) PlanCache(com.hazelcast.sql.impl.plan.cache.PlanCache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with PlanCache

use of com.hazelcast.sql.impl.plan.cache.PlanCache in project hazelcast by hazelcast.

the class PlanCacheIntegrationTest method testPlanInvalidatedOnIndexAdd.

@Test
public void testPlanInvalidatedOnIndexAdd() {
    IMap<Integer, Integer> map = instance().getMap(mapName);
    createMapping(mapName, int.class, int.class);
    map.put(1, 1);
    PlanCache planCache = planCache(instance());
    instance().getSql().execute("SELECT * FROM " + mapName + " WHERE this=1");
    assertEquals(1, planCache.size());
    SqlPlan plan1 = planCache.get(planCache.getPlans().keys().nextElement());
    map.addIndex(IndexType.HASH, "this");
    assertTrueEventually(() -> {
        instance().getSql().execute("SELECT * FROM " + mapName + " WHERE this=1");
        assertEquals(1, planCache.size());
        SqlPlan plan2 = planCache.get(planCache.getPlans().keys().nextElement());
        assertNotSame(plan1, plan2);
    });
}
Also used : SqlPlan(com.hazelcast.sql.impl.optimizer.SqlPlan) PlanCache(com.hazelcast.sql.impl.plan.cache.PlanCache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with PlanCache

use of com.hazelcast.sql.impl.plan.cache.PlanCache in project hazelcast by hazelcast.

the class PlanCacheTest method testPlanUsageUpdate.

@Test
public void testPlanUsageUpdate() {
    PlanCache cache = new PlanCache(10);
    PlanKey key = createKey("sql");
    SqlPlan plan = createPlan(key, PART_MAP_1);
    cache.put(key, plan);
    long timestamp1 = plan.getPlanLastUsed();
    assertTrue(timestamp1 > 0);
    advanceTime();
    cache.put(key, plan);
    long timestamp2 = plan.getPlanLastUsed();
    assertTrue(timestamp2 > timestamp1);
    advanceTime();
    cache.get(key);
    long timestamp3 = plan.getPlanLastUsed();
    assertTrue(timestamp3 > timestamp2);
}
Also used : PlanKey(com.hazelcast.sql.impl.optimizer.PlanKey) SqlPlan(com.hazelcast.sql.impl.optimizer.SqlPlan) PlanCache(com.hazelcast.sql.impl.plan.cache.PlanCache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PlanCache (com.hazelcast.sql.impl.plan.cache.PlanCache)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 SqlPlan (com.hazelcast.sql.impl.optimizer.SqlPlan)4 PlanKey (com.hazelcast.sql.impl.optimizer.PlanKey)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 After (org.junit.After)1