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