Search in sources :

Example 1 with CacheID

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);
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 2 with CacheID

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));
}
Also used : Table(org.teiid.metadata.Table) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) Schema(org.teiid.metadata.Schema) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 3 with CacheID

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);
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 4 with CacheID

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);
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 5 with CacheID

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));
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) Reference(org.teiid.query.sql.symbol.Reference) ProjectNode(org.teiid.query.processor.relational.ProjectNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Aggregations

CacheID (org.teiid.dqp.internal.process.SessionAwareCache.CacheID)16 ParseInfo (org.teiid.query.parser.ParseInfo)11 Test (org.junit.Test)8 Cachable (org.teiid.cache.Cachable)6 Reference (org.teiid.query.sql.symbol.Reference)4 TupleBuffer (org.teiid.common.buffer.TupleBuffer)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 Determinism (org.teiid.metadata.FunctionMethod.Determinism)2 BatchCollector (org.teiid.query.processor.BatchCollector)2 ProjectNode (org.teiid.query.processor.relational.ProjectNode)2 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)2 Command (org.teiid.query.sql.lang.Command)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 QueryParserException (org.teiid.api.exception.query.QueryParserException)1 BlockedException (org.teiid.common.buffer.BlockedException)1 TupleBatch (org.teiid.common.buffer.TupleBatch)1 TupleSource (org.teiid.common.buffer.TupleSource)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)1