Search in sources :

Example 1 with FileOutStream

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();
}
Also used : FileInStream(alluxio.client.file.FileInStream) FileOutStream(alluxio.client.file.FileOutStream) Test(org.junit.Test)

Example 2 with FileOutStream

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());
}
Also used : FileInStream(alluxio.client.file.FileInStream) FileOutStream(alluxio.client.file.FileOutStream) Test(org.junit.Test)

Example 3 with FileOutStream

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);
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileOutStream(alluxio.client.file.FileOutStream) AlluxioURI(alluxio.AlluxioURI)

Example 4 with FileOutStream

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());
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) LocalFirstPolicy(alluxio.client.file.policy.LocalFirstPolicy) AlluxioURI(alluxio.AlluxioURI)

Example 5 with FileOutStream

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();
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

FileOutStream (alluxio.client.file.FileOutStream)39 AlluxioURI (alluxio.AlluxioURI)28 Test (org.junit.Test)25 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)11 FileInStream (alluxio.client.file.FileInStream)9 URIStatus (alluxio.client.file.URIStatus)9 AlluxioException (alluxio.exception.AlluxioException)5 IOException (java.io.IOException)5 FileSystem (alluxio.client.file.FileSystem)4 ByteBuffer (java.nio.ByteBuffer)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 LocalFirstPolicy (alluxio.client.file.policy.LocalFirstPolicy)2 LineageFileSystem (alluxio.client.lineage.LineageFileSystem)2 LineageMasterClient (alluxio.client.lineage.LineageMasterClient)2 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 Closer (com.google.common.io.Closer)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ExpectedException (org.junit.rules.ExpectedException)2 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)1