// Tests that files are evicted when there is not enough space in the worker. @Test public void evictionTest() throws Exception { final int blockSize = (int) WORKER_CAPACITY_BYTES / 2; AlluxioURI file1 = new AlluxioURI("/file1"); FileSystemTestUtils.createByteFile(mFileSystem, file1, WriteType.MUST_CACHE, blockSize); // File should be in memory after it is written with MUST_CACHE URIStatus fileInfo1 = mFileSystem.getStatus(file1); Assert.assertEquals(100, fileInfo1.getInMemoryPercentage()); AlluxioURI file2 = new AlluxioURI("/file2"); FileSystemTestUtils.createByteFile(mFileSystem, file2, WriteType.MUST_CACHE, blockSize); // Both file 1 and 2 should be in memory since the combined size is not larger than worker space fileInfo1 = mFileSystem.getStatus(file1); URIStatus fileInfo2 = mFileSystem.getStatus(file2); Assert.assertEquals(100, fileInfo1.getInMemoryPercentage()); Assert.assertEquals(100, fileInfo2.getInMemoryPercentage()); AlluxioURI file3 = new AlluxioURI("/file3"); FileSystemTestUtils.createByteFile(mFileSystem, file3, WriteType.MUST_CACHE, blockSize); waitForHeartbeat(); fileInfo1 = mFileSystem.getStatus(file1); fileInfo2 = mFileSystem.getStatus(file2); URIStatus fileInfo3 = mFileSystem.getStatus(file3); // File 3 should be in memory and one of file 1 or 2 should be in memory Assert.assertEquals(100, fileInfo3.getInMemoryPercentage()); Assert.assertTrue( "Exactly one of file1 and file2 should be 100% in memory", fileInfo1.getInMemoryPercentage() == 100 ^ fileInfo2.getInMemoryPercentage() == 100); }
@Test public void catTest() throws IOException { FileSystemTestUtils.createByteFile(mFileSystem, "/testFile", WriteType.MUST_CACHE, 10); mFsShell.run("cat", "/testFile"); byte[] expect = BufferUtils.getIncreasingByteArray(10); Assert.assertArrayEquals(expect, mOutput.toByteArray()); }
@BeforeClass public static void beforeClass() throws Exception { Configuration conf = new Configuration(); conf.set("fs.alluxio.impl", FileSystem.class.getName()); alluxio.client.file.FileSystem alluxioFS = sLocalAlluxioClusterResource.get().getClient(); FileSystemTestUtils.createByteFile(alluxioFS, "/testFile1", WriteType.CACHE_THROUGH, FILE_LEN); URI uri = URI.create(sLocalAlluxioClusterResource.get().getMasterURI()); sTFS = org.apache.hadoop.fs.FileSystem.get(uri, conf); }