Search in sources :

Example 51 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project SSM by Intel-bigdata.

the class TestAlluxioActions method testLoadAction.

@Test
public void testLoadAction() throws Exception {
    // write a file but not loaded in cache
    fs.createDirectory(new AlluxioURI("/dir1"));
    CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.THROUGH);
    FileOutStream fos = fs.createFile(new AlluxioURI("/dir1/file1"), options);
    fos.write(new byte[] { 1 });
    fos.close();
    // check file is not cached
    URIStatus status1 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(0, status1.getInMemoryPercentage());
    // run load action
    LoadAction loadAction = new LoadAction();
    Map<String, String> args = new HashMap<>();
    args.put("-path", "/dir1/file1");
    loadAction.init(args);
    loadAction.execute();
    // check file cached status
    URIStatus status2 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(100, status2.getInMemoryPercentage());
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) HashMap(java.util.HashMap) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 52 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project SSM by Intel-bigdata.

the class TestAlluxioActions method testPersistAction.

@Test
public void testPersistAction() throws Exception {
    // write a file and not persisted
    fs.createDirectory(new AlluxioURI("/dir1"));
    CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE);
    FileOutStream fos = fs.createFile(new AlluxioURI("/dir1/file1"), options);
    fos.write(new byte[] { 1 });
    fos.close();
    // check status not persisted
    URIStatus status1 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(status1.getPersistenceState(), "NOT_PERSISTED");
    // run persist action
    PersistAction persistAction = new PersistAction();
    Map<String, String> args = new HashMap<>();
    args.put("-path", "/dir1/file1");
    persistAction.init(args);
    persistAction.execute();
    // check status persisted
    URIStatus status2 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(status2.getPersistenceState(), "PERSISTED");
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) HashMap(java.util.HashMap) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 53 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project SSM by Intel-bigdata.

the class TestAlluxioActions method testFreeAction.

@Test
public void testFreeAction() throws Exception {
    // write a file and loaded in cache
    fs.createDirectory(new AlluxioURI("/dir1"));
    CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
    FileOutStream fos = fs.createFile(new AlluxioURI("/dir1/file1"), options);
    fos.write(new byte[] { 1 });
    fos.close();
    // check file is cached
    URIStatus status1 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(100, status1.getInMemoryPercentage());
    // run load action
    FreeAction freeAction = new FreeAction();
    Map<String, String> args = new HashMap<>();
    args.put("-path", "/dir1/file1");
    freeAction.init(args);
    freeAction.execute();
    // sleep to wait cache freed
    Thread.sleep(2000);
    // check file cached status
    URIStatus status2 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(0, status2.getInMemoryPercentage());
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) HashMap(java.util.HashMap) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 54 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project SSM by Intel-bigdata.

the class TestAlluxioActions method testSetTTLAction.

@Test
public void testSetTTLAction() throws Exception {
    // write a file and loaded in cache
    fs.createDirectory(new AlluxioURI("/dir1"));
    CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
    FileOutStream fos = fs.createFile(new AlluxioURI("/dir1/file1"), options);
    fos.write(new byte[] { 1 });
    fos.close();
    // check file is cached
    URIStatus status1 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(-1, status1.getTtl());
    // run ttl action
    SetTTLAction setTTLAction = new SetTTLAction();
    Map<String, String> args = new HashMap<>();
    args.put("-path", "/dir1/file1");
    args.put("TTL", "10000");
    setTTLAction.init(args);
    setTTLAction.execute();
    // check file cached status
    URIStatus status2 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    assertEquals(10000, status2.getTtl());
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) HashMap(java.util.HashMap) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 55 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions in project SSM by Intel-bigdata.

the class TestAlluxioActions method testPinUnpinAction.

@Test
public void testPinUnpinAction() throws Exception {
    // write a file and loaded in cache
    fs.createDirectory(new AlluxioURI("/dir1"));
    CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
    FileOutStream fos = fs.createFile(new AlluxioURI("/dir1/file1"), options);
    fos.write(new byte[] { 1 });
    fos.close();
    // check file not pinned
    URIStatus status1 = fs.getStatus(new AlluxioURI("/dir1/file1"));
    Set<Long> pinSet1 = mLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class).getPinIdList();
    assertFalse(pinSet1.contains(status1.getFileId()));
    // run pin action
    PinAction pinAction = new PinAction();
    Map<String, String> args = new HashMap<>();
    args.put("-path", "/dir1/file1");
    pinAction.init(args);
    pinAction.execute();
    // check file pinned
    Set<Long> pinSet2 = mLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class).getPinIdList();
    assertTrue(pinSet2.contains(status1.getFileId()));
    // run unpin action
    UnpinAction unpinAction = new UnpinAction();
    Map<String, String> args1 = new HashMap<>();
    args1.put("-path", "/dir1/file1");
    unpinAction.init(args1);
    unpinAction.execute();
    // check file unpinned
    Set<Long> pinSet3 = mLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class).getPinIdList();
    assertFalse(pinSet3.contains(status1.getFileId()));
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) HashMap(java.util.HashMap) FileOutStream(alluxio.client.file.FileOutStream) FileSystemMaster(alluxio.master.file.FileSystemMaster) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

CreateFileOptions (alluxio.client.file.options.CreateFileOptions)57 AlluxioURI (alluxio.AlluxioURI)51 Test (org.junit.Test)45 FileInStream (alluxio.client.file.FileInStream)21 FileOutStream (alluxio.client.file.FileOutStream)16 URIStatus (alluxio.client.file.URIStatus)11 HashMap (java.util.HashMap)5 CreateDirectoryOptions (alluxio.client.file.options.CreateDirectoryOptions)4 BeforeClass (org.junit.BeforeClass)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AlluxioException (alluxio.exception.AlluxioException)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DeleteOptions (alluxio.client.file.options.DeleteOptions)1 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)1 SetAttributeOptions (alluxio.client.file.options.SetAttributeOptions)1 LineageFileSystem (alluxio.client.lineage.LineageFileSystem)1 LineageMasterClient (alluxio.client.lineage.LineageMasterClient)1