Search in sources :

Example 16 with FileStore

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

the class TextAgg method buildResult.

private FileStoreInputStreamFactory buildResult(CommandContext context) throws TeiidProcessingException {
    try {
        // $NON-NLS-1$
        FileStore fs = context.getBufferManager().createFileStore("textagg");
        FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, textLine.getEncoding() == null ? Streamable.ENCODING : textLine.getEncoding());
        Writer w = fisf.getWriter();
        if (textLine.isIncludeHeader()) {
            Object[] header = TextLine.evaluate(textLine.getExpressions(), new TextLine.ValueExtractor<DerivedColumn>() {

                public Object getValue(DerivedColumn t) {
                    if (t.getAlias() == null && t.getExpression() instanceof ElementSymbol) {
                        return ((ElementSymbol) t.getExpression()).getShortName();
                    }
                    return t.getAlias();
                }
            }, textLine);
            writeList(w, header);
        }
        w.flush();
        return fisf;
    } catch (IOException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30420, e);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) TextLine(org.teiid.query.sql.symbol.TextLine) IOException(java.io.IOException) DerivedColumn(org.teiid.query.sql.symbol.DerivedColumn) Writer(java.io.Writer) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 17 with FileStore

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

the class TestBufferFrontedFileStoreCache method createLayeredCache.

private static BufferFrontedFileStoreCache createLayeredCache(int bufferSpace, int objectSize, boolean memStorage, boolean allocate) throws TeiidComponentException {
    BufferFrontedFileStoreCache fsc = new BufferFrontedFileStoreCache();
    // prevent asynch affects
    fsc.cleanerRunning.set(true);
    fsc.setMemoryBufferSpace(bufferSpace);
    fsc.setMaxStorageObjectSize(objectSize);
    fsc.setDirect(false);
    if (memStorage) {
        SplittableStorageManager ssm = new SplittableStorageManager(new MemoryStorageManager());
        ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
        fsc.setStorageManager(ssm);
    } else {
        StorageManager sm = new StorageManager() {

            @Override
            public void initialize() throws TeiidComponentException {
            }

            @Override
            public FileStore createFileStore(String name) {
                return new FileStore() {

                    @Override
                    public void setLength(long length) throws IOException {
                        throw new OutOfDiskException(null);
                    }

                    @Override
                    protected void removeDirect() {
                    }

                    @Override
                    protected int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException {
                        return 0;
                    }

                    @Override
                    public long getLength() {
                        return 0;
                    }
                };
            }

            @Override
            public long getMaxStorageSpace() {
                return -1;
            }
        };
        fsc.setStorageManager(sm);
    }
    fsc.initialize(allocate);
    return fsc;
}
Also used : FileStore(org.teiid.common.buffer.FileStore) StorageManager(org.teiid.common.buffer.StorageManager)

Example 18 with FileStore

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

the class TestBufferManagerImpl method testFileStoreMax.

@Test(expected = IOException.class)
public void testFileStoreMax() throws Exception {
    BufferManagerImpl bufferManager = new BufferManagerImpl();
    bufferManager.setCache(new MemoryStorageManager() {

        @Override
        public long getMaxStorageSpace() {
            return 640;
        }
    });
    bufferManager.setMaxActivePlans(20);
    bufferManager.initialize();
    FileStore fs = bufferManager.createFileStore("x");
    fs.write(new byte[10], 0, 10);
}
Also used : FileStore(org.teiid.common.buffer.FileStore) Test(org.junit.Test)

Example 19 with FileStore

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

the class TestFileStorageManager method testWritingMultipleFiles.

@Test
public void testWritingMultipleFiles() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    // $NON-NLS-1$
    String tsID = "0";
    // Add one batch
    FileStore store = sm.createFileStore(tsID);
    String contentOrig = new String("some file content this will stored in same tmp file with another");
    OutputStream out = store.createOutputStream();
    out.write(contentOrig.getBytes(), 0, contentOrig.getBytes().length);
    out.close();
    out = store.createOutputStream();
    long start = store.getLength();
    byte[] bytesOrig = new byte[2048];
    r.nextBytes(bytesOrig);
    out.write(bytesOrig, 0, 2048);
    byte[] readContent = new byte[2048];
    InputStream in = store.createInputStream(0, contentOrig.getBytes().length);
    int c = in.read(readContent, 0, 3000);
    assertEquals(contentOrig, new String(readContent, 0, c));
    c = in.read(readContent, 0, 3000);
    assertEquals(-1, c);
    in.close();
    in = store.createInputStream(start, 2048);
    c = in.read(readContent, 0, 3000);
    assertTrue(Arrays.equals(bytesOrig, readContent));
    c = in.read(readContent, 0, 3000);
    assertEquals(-1, c);
    in.close();
}
Also used : FileStore(org.teiid.common.buffer.FileStore) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileStoreOutputStream(org.teiid.common.buffer.FileStore.FileStoreOutputStream) Test(org.junit.Test)

Example 20 with FileStore

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

the class TestFileStorageManager method testInitialRead.

@Test
public void testInitialRead() throws Exception {
    FileStorageManager sm = getStorageManager(null, null);
    // $NON-NLS-1$
    String tsID = "0";
    FileStore store = sm.createFileStore(tsID);
    assertEquals(-1, store.read(0, new byte[1], 0, 1));
}
Also used : FileStore(org.teiid.common.buffer.FileStore) Test(org.junit.Test)

Aggregations

FileStore (org.teiid.common.buffer.FileStore)24 Test (org.junit.Test)14 FileStoreInputStreamFactory (org.teiid.common.buffer.FileStoreInputStreamFactory)7 InputStream (java.io.InputStream)5 IOException (java.io.IOException)4 FileStoreOutputStream (org.teiid.common.buffer.FileStore.FileStoreOutputStream)4 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Reader (java.io.Reader)2 Writer (java.io.Writer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FilterReader (java.io.FilterReader)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 OutputStream (java.io.OutputStream)1 SQLException (java.sql.SQLException)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 DataSource (javax.activation.DataSource)1