use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class StreamCacheTest method operations.
@Test
public void operations() throws Exception {
StreamCache streamCache = new StreamCache(Constants.HOUR_MS);
FileInStream is = Mockito.mock(FileInStream.class);
FileOutStream os = Mockito.mock(FileOutStream.class);
Integer isId = streamCache.put(is);
Integer osId = streamCache.put(os);
Assert.assertSame(is, streamCache.getInStream(isId));
Assert.assertNull(streamCache.getInStream(osId));
Assert.assertNull(streamCache.getOutStream(isId));
Assert.assertSame(os, streamCache.getOutStream(osId));
Assert.assertSame(is, streamCache.invalidate(isId));
Assert.assertSame(os, streamCache.invalidate(osId));
Assert.assertNull(streamCache.invalidate(isId));
Assert.assertNull(streamCache.invalidate(osId));
Assert.assertNull(streamCache.getInStream(isId));
Assert.assertNull(streamCache.getOutStream(osId));
Mockito.verify(is).close();
Mockito.verify(os).close();
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class StreamCacheTest method size.
@Test
public void size() throws Exception {
StreamCache streamCache = new StreamCache(Constants.HOUR_MS);
FileInStream is = Mockito.mock(FileInStream.class);
FileOutStream os = Mockito.mock(FileOutStream.class);
Assert.assertEquals(0, streamCache.size());
int isId = streamCache.put(is);
Assert.assertEquals(1, streamCache.size());
int osId = streamCache.put(os);
Assert.assertEquals(2, streamCache.size());
streamCache.invalidate(isId);
Assert.assertEquals(1, streamCache.size());
streamCache.invalidate(osId);
Assert.assertEquals(0, streamCache.size());
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class MiniBenchmark method writeFile.
/**
* Writes a file.
*
* @param fileSize the file size
* @param iterations number of iterations
* @throws Exception it if fails to write
*/
private static void writeFile(long fileSize, int iterations) throws Exception {
FileSystem fileSystem = FileSystem.Factory.get();
byte[] buffer = new byte[(int) Math.min(fileSize, 4 * Constants.MB)];
Arrays.fill(buffer, (byte) 'a');
AlluxioURI path = new AlluxioURI(TEST_PATH);
long runTime = 0;
for (int i = 0; i < iterations; i++) {
if (fileSystem.exists(path)) {
fileSystem.delete(path);
}
long bytesWritten = 0;
long start = System.nanoTime();
try (FileOutStream outStream = fileSystem.createFile(new AlluxioURI(TEST_PATH))) {
while (bytesWritten < fileSize) {
outStream.write(buffer, 0, (int) Math.min(buffer.length, fileSize - bytesWritten));
bytesWritten += buffer.length;
}
}
runTime += System.nanoTime() - start;
}
System.out.printf("Runtime: %f seconds.%n", runTime * 1.0 / Constants.SECOND_NANO);
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class SpecificTierWriteIntegrationTest method writeFileAndCheckUsage.
/**
* Writes a file into a specified tier, and then verifies the expected bytes on each tier.
*
* @param writeTier the specific tier to write the file to
* @param memBytes the expected number of bytes used in the MEM tier
* @param ssdBytes the expected number of bytes used in the SSD tier
* @param hddBytes the expected number of bytes used in the HDD tier
* @throws Exception when an error occurs
*/
private void writeFileAndCheckUsage(int writeTier, long memBytes, long ssdBytes, long hddBytes) throws Exception {
FileOutStream os = mFileSystem.createFile(new AlluxioURI("/tier-" + writeTier + "_" + CommonUtils.randomAlphaNumString(5)), CreateFileOptions.defaults().setWriteTier(writeTier).setWriteType(WriteType.MUST_CACHE).setLocationPolicy(new LocalFirstPolicy()));
os.write(BufferUtils.getIncreasingByteArray(FILE_SIZE));
os.close();
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
long totalBytes = memBytes + ssdBytes + hddBytes;
Assert.assertEquals("Total bytes used", totalBytes, mLocalAlluxioClusterResource.get().getMaster().getInternalMaster().getBlockMaster().getUsedBytes());
Map<String, Long> bytesOnTiers = mLocalAlluxioClusterResource.get().getMaster().getInternalMaster().getBlockMaster().getUsedBytesOnTiers();
Assert.assertEquals("MEM tier usage", memBytes, bytesOnTiers.get("MEM").longValue());
Assert.assertEquals("SSD tier usage", ssdBytes, bytesOnTiers.get("SSD").longValue());
Assert.assertEquals("HDD tier usage", hddBytes, bytesOnTiers.get("HDD").longValue());
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method flush.
@Test
public void flush() throws Exception {
FileOutStream fos = mock(FileOutStream.class);
AlluxioURI anyURI = any();
when(mFileSystem.createFile(anyURI)).thenReturn(fos);
// open a file
mFileInfo.flags.set(O_WRONLY.intValue());
mFuseFs.create("/foo/bar", 0, mFileInfo);
//then call flush into it
mFuseFs.flush("/foo/bar", mFileInfo);
verify(fos).flush();
}
Aggregations