use of org.teiid.dqp.internal.process.SessionAwareCache.CacheID in project teiid by teiid.
the class TestSessionAwareCache method testSessionSpecfic.
@Test
public void testSessionSpecfic() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
cache.put(id, Determinism.SESSION_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
Mockito.verify(result, times(0)).prepare((BufferManager) anyObject());
Object c = cache.get(id);
Mockito.verify(result, times(0)).restore((BufferManager) anyObject());
assertTrue(result == c);
}
use of org.teiid.dqp.internal.process.SessionAwareCache.CacheID in project teiid by teiid.
the class TestSessionAwareCache method testTtl.
@Test
public void testTtl() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
// make sure defaults are returned
assertNull(cache.computeTtl(id, result, null));
assertEquals(Long.valueOf(1), cache.computeTtl(id, result, 1l));
AccessInfo ai = new AccessInfo();
Mockito.stub(result.getAccessInfo()).toReturn(ai);
Table t = new Table();
t.setProperty(DataModifiable.DATA_TTL, "2");
ai.addAccessedObject(t);
assertEquals(Long.valueOf(2), cache.computeTtl(id, result, null));
Table t1 = new Table();
Schema s = new Schema();
t1.setParent(s);
s.setProperty(DataModifiable.DATA_TTL, "0");
ai.addAccessedObject(t1);
// ensure that the min and the parent are used
assertEquals(Long.valueOf(0), cache.computeTtl(id, result, null));
}
use of org.teiid.dqp.internal.process.SessionAwareCache.CacheID in project teiid by teiid.
the class TestSessionAwareCache method testNoScope.
@Test
public void testNoScope() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
Mockito.stub(result.prepare((BufferManager) anyObject())).toReturn(true);
Mockito.stub(result.restore((BufferManager) anyObject())).toReturn(true);
cache.put(id, Determinism.VDB_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
Mockito.verify(result, times(1)).prepare((BufferManager) anyObject());
id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Object c = cache.get(id);
Mockito.verify(result, times(1)).restore((BufferManager) anyObject());
assertTrue(result == c);
}
use of org.teiid.dqp.internal.process.SessionAwareCache.CacheID in project teiid by teiid.
the class TestSessionAwareCache method testUserSpecfic.
@Test
public void testUserSpecfic() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
Mockito.stub(result.prepare((BufferManager) anyObject())).toReturn(true);
Mockito.stub(result.restore((BufferManager) anyObject())).toReturn(true);
cache.put(id, Determinism.USER_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
Mockito.verify(result, times(1)).prepare((BufferManager) anyObject());
id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Object c = cache.get(id);
Mockito.verify(result, times(1)).restore((BufferManager) anyObject());
assertTrue(result == c);
}
use of org.teiid.dqp.internal.process.SessionAwareCache.CacheID in project teiid by teiid.
the class TestPreparedPlanCache method testGet.
@Test
public void testGet() {
SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
helpPutPreparedPlans(cache, token, 0, 10);
helpPutPreparedPlans(cache, token2, 0, 15);
// read an entry for session2 (token2)
PreparedPlan pPlan = cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 12));
// $NON-NLS-1$
assertNotNull("Unable to get prepared plan from cache", pPlan);
// $NON-NLS-1$
assertEquals("Error getting plan from cache", new RelationalPlan(new ProjectNode(12)).toString(), pPlan.getPlan().toString());
// $NON-NLS-1$
assertEquals("Error getting command from cache", EXAMPLE_QUERY + 12, pPlan.getCommand().toString());
// $NON-NLS-1$
assertNotNull("Error getting plan description from cache", pPlan.getAnalysisRecord());
// $NON-NLS-1$
assertEquals("Error gettting reference from cache", new Reference(1), pPlan.getReferences().get(0));
}
Aggregations