Search in sources :

Example 1 with BufferServiceImpl

use of org.teiid.services.BufferServiceImpl in project teiid by teiid.

the class TestLocalBufferService method testCheckMemPropertyGotSet.

@Test
public void testCheckMemPropertyGotSet() throws Exception {
    BufferServiceImpl svc = new BufferServiceImpl();
    svc.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/1");
    svc.setUseDisk(true);
    svc.setInlineLobs(false);
    svc.start();
    // all the properties are set
    // $NON-NLS-1$
    assertTrue("Not Directory", svc.getBufferDirectory().isDirectory());
    // $NON-NLS-1$
    assertTrue("does not exist", svc.getBufferDirectory().exists());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue("does not end with one", svc.getBufferDirectory().getParent().endsWith("1"));
    assertTrue(svc.isUseDisk());
    assertFalse(svc.isInlineLobs());
    BufferManagerImpl mgr = svc.getBufferManager();
    SplittableStorageManager ssm = (SplittableStorageManager) ((BufferFrontedFileStoreCache) mgr.getCache()).getStorageManager();
    assertTrue(((FileStorageManager) ssm.getStorageManager()).getDirectory().endsWith(svc.getBufferDirectory().getName()));
}
Also used : SplittableStorageManager(org.teiid.common.buffer.impl.SplittableStorageManager) BufferServiceImpl(org.teiid.services.BufferServiceImpl) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) FileStorageManager(org.teiid.common.buffer.impl.FileStorageManager) Test(org.junit.Test)

Example 2 with BufferServiceImpl

use of org.teiid.services.BufferServiceImpl in project teiid by teiid.

the class TestLocalBufferService method testUseDiskFalse.

@Test
public void testUseDiskFalse() throws Exception {
    BufferServiceImpl svc = new BufferServiceImpl();
    svc.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/1");
    svc.setUseDisk(false);
    svc.start();
    // all the properties are set
    BufferManagerImpl mgr = svc.getBufferManager();
    FileStore f = mgr.getCache().createFileStore("x");
    f.write(new byte[1234], 0, 1234);
}
Also used : FileStore(org.teiid.common.buffer.FileStore) BufferServiceImpl(org.teiid.services.BufferServiceImpl) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) Test(org.junit.Test)

Example 3 with BufferServiceImpl

use of org.teiid.services.BufferServiceImpl in project teiid by teiid.

the class TestLocalBufferService method testSchemaSize.

@Test
public void testSchemaSize() throws Exception {
    // 82 strings of Total Length 2515 charcacters
    // 11 Dates
    // 1 Long
    // 1 short
    // 20 bigdecimal with 671 total integers in them.
    List<Expression> schema = new ArrayList<Expression>();
    for (int i = 0; i < 82; i++) {
        schema.add(new Constant(null, DataTypeManager.DefaultDataClasses.STRING));
    }
    for (int i = 0; i < 11; i++) {
        schema.add(new Constant(null, DataTypeManager.DefaultDataClasses.DATE));
    }
    schema.add(new Constant(null, DataTypeManager.DefaultDataClasses.LONG));
    schema.add(new Constant(null, DataTypeManager.DefaultDataClasses.SHORT));
    for (int i = 0; i < 20; i++) {
        schema.add(new Constant(null, DataTypeManager.DefaultDataClasses.BIG_DECIMAL));
    }
    BufferServiceImpl svc = new BufferServiceImpl();
    svc.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/1");
    svc.setUseDisk(false);
    svc.start();
    BufferManager mgr = svc.getBufferManager();
    assertEquals(3364096, mgr.getSchemaSize(schema));
    assertEquals(128, mgr.getProcessorBatchSize(schema));
}
Also used : BufferServiceImpl(org.teiid.services.BufferServiceImpl) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 4 with BufferServiceImpl

use of org.teiid.services.BufferServiceImpl 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)

Example 5 with BufferServiceImpl

use of org.teiid.services.BufferServiceImpl in project teiid by teiid.

the class TestLocalBufferService method testCheckMemPropertyGotSet2.

@Test
public void testCheckMemPropertyGotSet2() throws Exception {
    BufferServiceImpl svc = new BufferServiceImpl();
    svc.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/1");
    svc.setUseDisk(false);
    svc.start();
    // all the properties are set
    assertFalse(svc.isUseDisk());
}
Also used : BufferServiceImpl(org.teiid.services.BufferServiceImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 BufferServiceImpl (org.teiid.services.BufferServiceImpl)5 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)3 ArrayList (java.util.ArrayList)2 BufferManager (org.teiid.common.buffer.BufferManager)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 List (java.util.List)1 FileStore (org.teiid.common.buffer.FileStore)1 TupleBatch (org.teiid.common.buffer.TupleBatch)1 TupleBuffer (org.teiid.common.buffer.TupleBuffer)1 FileStorageManager (org.teiid.common.buffer.impl.FileStorageManager)1 SplittableStorageManager (org.teiid.common.buffer.impl.SplittableStorageManager)1 Constant (org.teiid.query.sql.symbol.Constant)1 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)1 Expression (org.teiid.query.sql.symbol.Expression)1