Search in sources :

Example 1 with FakeBufferService

use of org.teiid.dqp.service.FakeBufferService in project teiid by teiid.

the class TestDataTierManager method helpSetupDataTierManager.

private void helpSetupDataTierManager() {
    FakeBufferService bs = new FakeBufferService();
    rm = new DQPCore();
    rm.setTransactionService(new FakeTransactionService());
    rm.setBufferManager(bs.getBufferManager());
    CacheConfiguration config = new CacheConfiguration();
    config.setMaxAgeInSeconds(-1);
    rm.setResultsetCache(new SessionAwareCache<CachedResults>("resultset", new DefaultCacheFactory(config), SessionAwareCache.Type.RESULTSET, 0));
    rm.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>("preparedplan", new DefaultCacheFactory(config), SessionAwareCache.Type.PREPAREDPLAN, 0));
    rm.start(new DQPConfiguration());
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(connectorManager);
    vdb.addAttchment(ConnectorManagerRepository.class, repo);
    dtm = new DataTierManagerImpl(rm, bs.getBufferManager(), true);
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) DefaultCacheFactory(org.teiid.cache.DefaultCacheFactory) FakeBufferService(org.teiid.dqp.service.FakeBufferService) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) CacheConfiguration(org.teiid.cache.CacheConfiguration)

Example 2 with FakeBufferService

use of org.teiid.dqp.service.FakeBufferService in project teiid by teiid.

the class TestDQPCore method setUp.

@Before
public void setUp() throws Exception {
    agds = new AutoGenDataService();
    DQPWorkContext context = RealMetadataFactory.buildWorkContext(RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.exampleBQTCached().getMetadataStore(), "bqt"));
    // $NON-NLS-1$
    context.getVDB().getModel("BQT3").setVisible(false);
    // $NON-NLS-1$
    context.getVDB().getModel("VQT").setVisible(false);
    HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
    policies.put("foo", new DataPolicyMetadata());
    context.setPolicies(policies);
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    context.getVDB().addAttchment(ConnectorManagerRepository.class, repo);
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(agds);
    BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
    bm.setInlineLobs(false);
    FakeBufferService bs = new FakeBufferService(bm, bm);
    core = new DQPCore();
    core.setBufferManager(bs.getBufferManager());
    core.setResultsetCache(new SessionAwareCache<CachedResults>("resultset", new DefaultCacheFactory(new CacheConfiguration()), SessionAwareCache.Type.RESULTSET, 0));
    core.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>("preparedplan", new DefaultCacheFactory(new CacheConfiguration()), SessionAwareCache.Type.PREPAREDPLAN, 0));
    core.setTransactionService(new FakeTransactionService());
    config = new DQPConfiguration();
    config.setMaxActivePlans(1);
    config.setUserRequestSourceConcurrency(2);
    DefaultAuthorizationValidator daa = new DefaultAuthorizationValidator();
    daa.setPolicyDecider(new DataRolePolicyDecider());
    config.setAuthorizationValidator(daa);
    core.start(config);
    core.getPrepPlanCache().setModTime(1);
    core.getRsCache().setTupleBufferCache(bs.getBufferManager());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) HashMap(java.util.HashMap) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) DefaultCacheFactory(org.teiid.cache.DefaultCacheFactory) FakeBufferService(org.teiid.dqp.service.FakeBufferService) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPolicy(org.teiid.adminapi.DataPolicy) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService) CacheConfiguration(org.teiid.cache.CacheConfiguration) Before(org.junit.Before)

Example 3 with FakeBufferService

use of org.teiid.dqp.service.FakeBufferService in project teiid by teiid.

the class TestCachedResults method testCaching.

@Test
public void testCaching() throws Exception {
    FakeBufferService fbs = new FakeBufferService(true);
    // $NON-NLS-1$
    ElementSymbol x = new ElementSymbol("x");
    x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List<ElementSymbol> schema = Arrays.asList(x);
    // $NON-NLS-1$
    TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR);
    tb.setForwardOnly(false);
    tb.addTuple(Arrays.asList(1));
    tb.addTuple(Arrays.asList(2));
    tb.addTuple(Arrays.asList(3));
    tb.addTuple(Arrays.asList(4));
    tb.addTuple(Arrays.asList(5));
    tb.addTuple(Arrays.asList(6));
    tb.addTuple(Arrays.asList(7));
    tb.addTuple(Arrays.asList(8));
    tb.addTuple(Arrays.asList(9));
    tb.addTuple(Arrays.asList(10));
    tb.close();
    BufferManager bm = fbs.getBufferManager();
    CachedResults results = new CachedResults();
    ProcessorPlan plan = new FakeProcessorPlan(0);
    CommandContext cc = new CommandContext();
    Table t = RealMetadataFactory.exampleBQT().getGroupID("bqt1.smalla");
    cc.accessedDataObject(t);
    plan.setContext(cc);
    results.setResults(tb, plan);
    results.setCommand(new Query());
    // Cache cache = new DefaultCache("dummy"); //$NON-NLS-1$
    long ts = results.getAccessInfo().getCreationTime();
    // in cache
    for (int row = 1; row <= tb.getRowCount(); row += 4) {
    // cache.put(results.getId()+","+row, tb.getBatch(row), null); //$NON-NLS-1$
    }
    results.prepare(bm);
    // simulate distribute
    TupleBuffer distributedTb = bm.getTupleBuffer(results.getId());
    CachedResults cachedResults = UnitTestUtil.helpSerialize(results);
    RealMetadataFactory.buildWorkContext(RealMetadataFactory.exampleBQT());
    BufferManager bm2 = fbs.getBufferManager();
    bm2.distributeTupleBuffer(results.getId(), distributedTb);
    assertTrue(cachedResults.restore(bm2));
    // since restored, simulate a async cache flush
    // cache.clear();
    TupleBuffer cachedTb = cachedResults.getResults();
    assertTrue(cachedTb.isFinal());
    assertEquals(tb.getRowCount(), cachedTb.getRowCount());
    assertEquals(tb.getBatchSize(), cachedTb.getBatchSize());
    assertArrayEquals(tb.getBatch(1).getAllTuples(), cachedTb.getBatch(1).getAllTuples());
    assertArrayEquals(tb.getBatch(9).getAllTuples(), cachedTb.getBatch(9).getAllTuples());
    assertTrue(ts - cachedResults.getAccessInfo().getCreationTime() <= 5000);
// ensure that an incomplete load fails ( is this still valid use case?)
// bm2.getTupleBuffer(results.getId()).remove();
// cachedResults = UnitTestUtil.helpSerialize(results);
// assertFalse(cachedResults.restore(cache, bm2));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) Query(org.teiid.query.sql.lang.Query) TupleBuffer(org.teiid.common.buffer.TupleBuffer) FakeBufferService(org.teiid.dqp.service.FakeBufferService) BufferManager(org.teiid.common.buffer.BufferManager) FakeProcessorPlan(org.teiid.query.processor.FakeProcessorPlan) FakeProcessorPlan(org.teiid.query.processor.FakeProcessorPlan) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

FakeBufferService (org.teiid.dqp.service.FakeBufferService)3 CacheConfiguration (org.teiid.cache.CacheConfiguration)2 DefaultCacheFactory (org.teiid.cache.DefaultCacheFactory)2 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)2 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1 DataPolicy (org.teiid.adminapi.DataPolicy)1 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)1 BufferManager (org.teiid.common.buffer.BufferManager)1 TupleBuffer (org.teiid.common.buffer.TupleBuffer)1 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)1 AutoGenDataService (org.teiid.dqp.service.AutoGenDataService)1 Table (org.teiid.metadata.Table)1 FakeProcessorPlan (org.teiid.query.processor.FakeProcessorPlan)1 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)1 Query (org.teiid.query.sql.lang.Query)1 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)1 CommandContext (org.teiid.query.util.CommandContext)1