Search in sources :

Example 46 with BufferManager

use of org.teiid.common.buffer.BufferManager in project teiid by teiid.

the class TestLocalBufferService method testStateTransfer.

@Test
public void testStateTransfer() throws Exception {
    BufferServiceImpl svc = new BufferServiceImpl();
    svc.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/1");
    svc.setUseDisk(true);
    svc.start();
    BufferManager mgr = svc.getBufferManager();
    List<ElementSymbol> schema = new ArrayList<ElementSymbol>(2);
    // $NON-NLS-1$
    ElementSymbol es = new ElementSymbol("x");
    es.setType(DataTypeManager.getDataTypeClass(DefaultDataTypes.STRING));
    schema.add(es);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("y");
    es2.setType(DataTypeManager.getDataTypeClass(DefaultDataTypes.INTEGER));
    schema.add(es2);
    // $NON-NLS-1$
    TupleBuffer buffer = mgr.createTupleBuffer(schema, "cached", TupleSourceType.FINAL);
    buffer.setBatchSize(50);
    buffer.setId("state_id");
    for (int batch = 0; batch < 3; batch++) {
        for (int row = 0; row < 50; row++) {
            int val = (batch * 50) + row;
            buffer.addTuple(Arrays.asList(new Object[] { "String" + val, new Integer(val) }));
        }
    }
    buffer.close();
    mgr.distributeTupleBuffer(buffer.getId(), buffer);
    FileOutputStream fo = new FileOutputStream(UnitTestUtil.getTestScratchPath() + "/teiid/statetest");
    ((BufferManagerImpl) mgr).getState(buffer.getId(), fo);
    fo.close();
    svc.stop();
    // now read back
    BufferServiceImpl svc2 = new BufferServiceImpl();
    svc2.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/2");
    svc2.setUseDisk(true);
    svc2.start();
    BufferManagerImpl mgr2 = svc2.getBufferManager();
    FileInputStream fis = new FileInputStream(UnitTestUtil.getTestScratchPath() + "/teiid/statetest");
    mgr2.setState(buffer.getId(), fis);
    fis.close();
    String id = "state_id";
    buffer = mgr2.getTupleBuffer(id);
    for (int batch = 0; batch < 3; batch++) {
        TupleBatch tb = buffer.getBatch((batch * 50) + 1);
        List[] rows = tb.getAllTuples();
        for (int row = 0; row < 50; row++) {
            int val = (batch * 50) + row;
            assertEquals("String" + val, rows[row].get(0));
            assertEquals(val, rows[row].get(1));
        }
    }
    svc2.stop();
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) ArrayList(java.util.ArrayList) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) FileInputStream(java.io.FileInputStream) BufferServiceImpl(org.teiid.services.BufferServiceImpl) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Aggregations

BufferManager (org.teiid.common.buffer.BufferManager)46 Test (org.junit.Test)32 List (java.util.List)23 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)22 CommandContext (org.teiid.query.util.CommandContext)18 ArrayList (java.util.ArrayList)17 TupleBuffer (org.teiid.common.buffer.TupleBuffer)16 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)8 BlockedException (org.teiid.common.buffer.BlockedException)6 BigDecimal (java.math.BigDecimal)5 TupleSource (org.teiid.common.buffer.TupleSource)5 CachedResults (org.teiid.dqp.internal.process.CachedResults)5 SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)5 FakeTupleSource (org.teiid.query.processor.FakeTupleSource)5 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)5 TupleBatch (org.teiid.common.buffer.TupleBatch)4 TempTableDataManager (org.teiid.query.tempdata.TempTableDataManager)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ClobImpl (org.teiid.core.types.ClobImpl)2 ClobType (org.teiid.core.types.ClobType)2