use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method open.
@Test
public void open() throws Exception {
// mocks set-up
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
FileInfo fi = new FileInfo();
fi.setFolder(false);
URIStatus status = new URIStatus(fi);
when(mFileSystem.exists(expectedPath)).thenReturn(true);
when(mFileSystem.getStatus(expectedPath)).thenReturn(status);
mFileInfo.flags.set(O_RDONLY.intValue());
// actual test
mFuseFs.open("/foo/bar", mFileInfo);
verify(mFileSystem).exists(expectedPath);
verify(mFileSystem).openFile(expectedPath);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method read.
@Test
public void read() throws Exception {
// mocks set-up
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
FileInfo fi = new FileInfo();
fi.setFolder(false);
URIStatus status = new URIStatus(fi);
when(mFileSystem.exists(expectedPath)).thenReturn(true);
when(mFileSystem.getStatus(expectedPath)).thenReturn(status);
FileInStream fakeInStream = mock(FileInStream.class);
when(fakeInStream.read(any(byte[].class), anyInt(), anyInt())).then(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
byte[] myDest = (byte[]) invocationOnMock.getArguments()[0];
for (byte i = 0; i < 4; i++) {
myDest[i] = i;
}
return 4;
}
});
when(mFileSystem.openFile(expectedPath)).thenReturn(fakeInStream);
mFileInfo.flags.set(O_RDONLY.intValue());
// prepare something to read to it
Runtime r = Runtime.getSystemRuntime();
Pointer ptr = r.getMemoryManager().allocateTemporary(4, true);
// actual test
mFuseFs.open("/foo/bar", mFileInfo);
mFuseFs.read("/foo/bar", ptr, 4, 0, mFileInfo);
final byte[] dst = new byte[4];
ptr.get(0, dst, 0, 4);
final byte[] expected = new byte[] { 0, 1, 2, 3 };
assertArrayEquals("Source and dst data should be equal", expected, dst);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterClientRestApiTest method getStatus.
@Test
public void getStatus() throws Exception {
AlluxioURI uri = new AlluxioURI("/file");
mFileSystemMaster.createFile(uri, CreateFileOptions.defaults());
mFileSystemMaster.completeFile(uri, CompleteFileOptions.defaults());
Map<String, String> params = new HashMap<>();
params.put("path", uri.toString());
String result = new TestCase(mHostname, mPort, getEndpoint(FileSystemMasterClientRestServiceHandler.GET_STATUS), params, HttpMethod.GET, null).call();
FileInfo fileInfo = new ObjectMapper().readValue(result, FileInfo.class);
Assert.assertEquals(uri.getPath(), fileInfo.getPath());
Assert.assertEquals(0, fileInfo.getLength());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterClientRestApiTest method setAttribute.
@Test
public void setAttribute() throws Exception {
AlluxioURI uri = new AlluxioURI("/file");
mFileSystemMaster.createFile(uri, CreateFileOptions.defaults());
mFileSystemMaster.completeFile(uri, CompleteFileOptions.defaults());
Map<String, String> params = new HashMap<>();
params.put("path", uri.toString());
params.put("pinned", "true");
params.put("ttl", "100000");
params.put("ttlAction", TtlAction.DELETE.toString());
params.put("persisted", "true");
params.put("recursive", "false");
new TestCase(mHostname, mPort, getEndpoint(FileSystemMasterClientRestServiceHandler.SET_ATTRIBUTE), params, HttpMethod.POST, null).run();
FileInfo fileInfo = mFileSystemMaster.getFileInfo(uri);
Assert.assertEquals(uri.toString(), fileInfo.getPath());
Assert.assertTrue(fileInfo.isPinned());
Assert.assertEquals(100000, fileInfo.getTtl());
Assert.assertEquals(TtlAction.DELETE, fileInfo.getTtlAction());
Assert.assertTrue(fileInfo.isPersisted());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterClientRestApiTest method listStatus.
@Test
public void listStatus() throws Exception {
AlluxioURI uri = new AlluxioURI("/file");
mFileSystemMaster.createFile(uri, CreateFileOptions.defaults());
mFileSystemMaster.completeFile(uri, CompleteFileOptions.defaults());
Map<String, String> params = new HashMap<>();
params.put("path", uri.toString());
params.put("loadDirectChildren", "false");
params.put("loadMetadataType", "Always");
String result = new TestCase(mHostname, mPort, getEndpoint(FileSystemMasterClientRestServiceHandler.LIST_STATUS), params, HttpMethod.GET, null).call();
List<FileInfo> fileInfos = new ObjectMapper().readValue(result, new TypeReference<List<FileInfo>>() {
});
FileInfo fileInfo = Iterables.getOnlyElement(fileInfos);
Assert.assertEquals(uri.getPath(), fileInfo.getPath());
Assert.assertEquals(0, fileInfo.getLength());
}
Aggregations