public static FileStorageManager getStorageManager(Integer openFiles, String dir) throws TeiidComponentException { FileStorageManager sm = new FileStorageManager(); sm.setStorageDirectory(UnitTestUtil.getTestScratchPath() + (dir != null ? File.separator + dir : "")); //$NON-NLS-1$ if (openFiles != null) { sm.setMaxOpenFiles(openFiles); } sm.initialize(); return sm; }
public long getUsedDiskBufferSpaceMb() { if (fsm != null) { return fsm.getUsedBufferSpace()/MB; } return 0; }
/** * Initialize */ public void initialize() throws TeiidComponentException { if(this.directory == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30040, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30040)); } dirFile = new File(this.directory); makeDir(dirFile); for (int i = 0; i < subDirectories.length; i++) { subDirectories[i] = new File(this.directory, "b" +i); //$NON-NLS-1$ makeDir(subDirectories[i]); } }
fsm = new FileStorageManager(); fsm.setStorageDirectory(bufferDir.getCanonicalPath()); fsm.setMaxOpenFiles(maxOpenFiles); fsm.setMaxBufferSpace(maxDiskBufferSpace*MB); SplittableStorageManager ssm = new SplittableStorageManager(fsm); ssm.setMaxFileSize(maxFileSize);
@Test public void testSetLength() throws Exception { FileStorageManager sm = getStorageManager(null, null); String tsID = "0"; //$NON-NLS-1$ FileStore store = sm.createFileStore(tsID); store.setLength(1000); assertEquals(1000, sm.getUsedBufferSpace()); store.setLength(200); assertEquals(200, sm.getUsedBufferSpace()); store.setLength(1000); assertEquals(1000, sm.getUsedBufferSpace()); }
@Override public synchronized void setLength(long length) throws IOException { if (fileInfo == null) { fileInfo = new FileInfo(createFile(name)); } try { setLength(fileInfo.open(), length, true); } finally { fileInfo.close(); } }
@Test(expected=IOException.class) public void testMaxSpaceSplit() throws Exception { FileStorageManager sm = getStorageManager(null, null); sm.setMaxBufferSpace(1); String tsID = "0"; //$NON-NLS-1$ SplittableStorageManager ssm = new SplittableStorageManager(sm); FileStore store = ssm.createFileStore(tsID); try { writeBytes(store); } finally { assertEquals(0, sm.getUsedBufferSpace()); } }
@Test(expected=IOException.class) public void testMaxSpace() throws Exception { FileStorageManager sm = getStorageManager(null, null); sm.setMaxBufferSpace(1); String tsID = "0"; //$NON-NLS-1$ // Add one batch FileStore store = sm.createFileStore(tsID); writeBytes(store); }
String tsID = "0"; //$NON-NLS-1$ 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();
@Test public void testWrite() throws Exception { FileStorageManager sm = getStorageManager(null, null); String tsID = "0"; //$NON-NLS-1$ FileStore store = sm.createFileStore(tsID); writeBytes(store); assertEquals(2048, sm.getUsedBufferSpace()); store.remove(); assertEquals(0, sm.getUsedBufferSpace()); }
@Override public synchronized void setLength(long length) throws IOException { if (fileInfo == null) { fileInfo = new FileInfo(createFile(name)); } try { setLength(fileInfo.open(), length, true); } finally { fileInfo.close(); } }
@Test public void testInitialRead() throws Exception { FileStorageManager sm = getStorageManager(null, null); String tsID = "0"; //$NON-NLS-1$ FileStore store = sm.createFileStore(tsID); assertEquals(-1, store.read(0, new byte[1], 0, 1)); }
@Test public void testPositionalWrite() throws Exception { FileStorageManager sm = getStorageManager(null, null); String tsID = "0"; //$NON-NLS-1$ FileStore store = sm.createFileStore(tsID); byte[] expectedBytes = writeBytes(store, 2048); assertEquals(4096, sm.getUsedBufferSpace()); writeBytes(store, 4096); assertEquals(6144, sm.getUsedBufferSpace()); byte[] bytesRead = new byte[2048]; store.readFully(2048, bytesRead, 0, bytesRead.length); assertArrayEquals(expectedBytes, bytesRead); store.remove(); assertEquals(0, sm.getUsedBufferSpace()); }
@Override public synchronized void setLength(long length) throws IOException { if (fileInfo == null) { fileInfo = new FileInfo(createFile(name)); } try { setLength(fileInfo.open(), length, true); } finally { fileInfo.close(); } }
/** * Initialize */ public void initialize() throws TeiidComponentException { if(this.directory == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30040, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30040)); } dirFile = new File(this.directory); makeDir(dirFile); for (int i = 0; i < subDirectories.length; i++) { subDirectories[i] = new File(this.directory, "b" +i); //$NON-NLS-1$ makeDir(subDirectories[i]); } }
@Test public void testClose() throws Exception { FileStorageManager sm = getStorageManager(null, null); FileStore store = sm.createFileStore("0"); FileStoreOutputStream fsos = store.createOutputStream(2); fsos.write(new byte[100000]); fsos.close(); fsos.close(); }
@Override protected synchronized int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException { if (!write) { if (fileInfo == null) { return -1; } try { RandomAccessFile fileAccess = fileInfo.open(); fileAccess.seek(fileOffset); return fileAccess.read(b, offSet, length); } finally { fileInfo.close(); } } if (fileInfo == null) { fileInfo = new FileInfo(createFile(name)); } try { RandomAccessFile fileAccess = fileInfo.open(); long newLength = fileOffset + length; setLength(fileAccess, newLength, false); fileAccess.seek(fileOffset); fileAccess.write(b, offSet, length); } finally { fileInfo.close(); } return length; }
/** * Initialize */ public void initialize() throws TeiidComponentException { if(this.directory == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30040, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30040)); } dirFile = new File(this.directory); makeDir(dirFile); for (int i = 0; i < subDirectories.length; i++) { subDirectories[i] = new File(this.directory, "b" +i); //$NON-NLS-1$ makeDir(subDirectories[i]); } }
@Test public void testFlush() throws Exception { FileStorageManager sm = getStorageManager(null, null); FileStore store = sm.createFileStore("0"); FileStoreOutputStream fsos = store.createOutputStream(2); fsos.write(new byte[3]); fsos.write(1); fsos.flush(); assertEquals(0, fsos.getCount()); }
@Override protected synchronized int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException { if (!write) { if (fileInfo == null) { return -1; } try { RandomAccessFile fileAccess = fileInfo.open(); fileAccess.seek(fileOffset); return fileAccess.read(b, offSet, length); } finally { fileInfo.close(); } } if (fileInfo == null) { fileInfo = new FileInfo(createFile(name)); } try { RandomAccessFile fileAccess = fileInfo.open(); long newLength = fileOffset + length; setLength(fileAccess, newLength, false); fileAccess.seek(fileOffset); fileAccess.write(b, offSet, length); } finally { fileInfo.close(); } return length; }