Package org.teiid.dqp.internal.process.SessionAwareCache

Examples of org.teiid.dqp.internal.process.SessionAwareCache.CacheID


  @Test
  public void testSessionSpecfic() {
   
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>();
   
    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((Cache)anyObject(), (BufferManager)anyObject());
View Full Code Here


  @Test
  public void testUserSpecfic() {
   
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>();
   
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
   
    Cachable result = Mockito.mock(Cachable.class);
    Mockito.stub(result.prepare((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);
    Mockito.stub(result.restore((Cache)anyObject(), (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((Cache)anyObject(), (BufferManager)anyObject());
   
    id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
   
    Object c = cache.get(id);
   
    Mockito.verify(result, times(1)).restore((Cache)anyObject(), (BufferManager)anyObject());   
   
View Full Code Here

  @Test
  public void testNoScope() {
   
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>();
   
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
   
    Cachable result = Mockito.mock(Cachable.class);
    Mockito.stub(result.prepare((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);
    Mockito.stub(result.restore((Cache)anyObject(), (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((Cache)anyObject(), (BufferManager)anyObject());
   
    id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
   
    Object c = cache.get(id);
   
    Mockito.verify(result, times(1)).restore((Cache)anyObject(), (BufferManager)anyObject());   
   
View Full Code Here

  @Test
  public void testVDBRemoval() {
   
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>();
   
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
   
    Cachable result = Mockito.mock(Cachable.class);
    Mockito.stub(result.prepare((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);
    Mockito.stub(result.restore((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);   
   
    id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    cache.put(id, Determinism.VDB_DETERMINISTIC, result, null);
   
    Object c = cache.get(id);
   
    assertTrue(result==c);
View Full Code Here

   
    //====Tests====//
    @Test public void testPutPreparedPlan(){
      SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>();
     
      CacheID id = new CacheID(token, pi, EXAMPLE_QUERY + 1);
     
      //No PreparedPlan at the begining
      assertNull(cache.get(id));
      //create one
      cache.put(id, Determinism.SESSION_DETERMINISTIC, new PreparedPlan(), null);
View Full Code Here

      SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>();
      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));
      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)); //$NON-NLS-1$
View Full Code Here

     
      //create one for each session token
      helpPutPreparedPlans(cache, token, 1, 1);
      helpPutPreparedPlans(cache, token2, 1, 1);
      //should have one
      assertNotNull("Unable to get prepared plan from cache for token", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
      cache.clearAll();
      //should not exist for token
      assertNull("Failed remove from cache", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
      //should not exist for token2
      assertNull("Unable to get prepared plan from cache for token2", cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
    }
View Full Code Here

   
    @Test public void testMaxSize(){
        SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>(100);
        helpPutPreparedPlans(cache, token, 0, 101);
        //the first one should be gone because the max size is 100
        assertNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 0)));
       
        assertNotNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 12)));
        helpPutPreparedPlans(cache, token, 102, 50);
        //"sql12" should still be there based on lru  policy
        assertNotNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 12)));
       
        helpPutPreparedPlans(cache, token2, 0, 121);
        helpPutPreparedPlans(cache, token, 0, 50);
        assertTrue(cache.getTotalCacheEntries() <= 100);
    }
View Full Code Here

        SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>(0);
        assertEquals(0, cache.getSpaceAllowed());
       
        // Add 1 plan and verify it is not in the cache
        helpPutPreparedPlans(cache, token, 0, 1);
        assertNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 0)));
        assertEquals(0, cache.getTotalCacheEntries());
       
        // Add another plan and verify it is not in the cache
        helpPutPreparedPlans(cache, token, 1, 1);
        assertNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1)));
        assertEquals(0, cache.getTotalCacheEntries());       
    }
View Full Code Here

      try {
        dummy = QueryParser.getQueryParser().parseCommand(EXAMPLE_QUERY + (start + i));
      } catch (QueryParserException e) {
        throw new RuntimeException(e);
      }
        CacheID id = new CacheID(session, pi, dummy.toString());

        PreparedPlan pPlan = new PreparedPlan();
        cache.put(id, Determinism.SESSION_DETERMINISTIC, pPlan, null);
        pPlan.setCommand(dummy);
        pPlan.setPlan(new RelationalPlan(new ProjectNode(i)), new CommandContext());
View Full Code Here

TOP

Related Classes of org.teiid.dqp.internal.process.SessionAwareCache.CacheID

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.