use of alluxio.rest.TestCase in project alluxio by Alluxio.
the class BlockMasterClientRestApiTest method getBlockInfo.
@Test
public void getBlockInfo() throws Exception {
long sessionId = 1;
long blockId = 2;
String tierAlias = "MEM";
long initialBytes = 3;
BlockWorker blockWorker = mResource.get().getWorker().getBlockWorker();
String file = blockWorker.createBlock(sessionId, blockId, tierAlias, initialBytes);
FileOutputStream outStream = new FileOutputStream(file);
outStream.write("abc".getBytes());
outStream.close();
blockWorker.commitBlock(sessionId, blockId);
Map<String, String> params = new HashMap<>();
params.put("blockId", Long.toString(blockId));
String response = new TestCase(mHostname, mPort, getEndpoint(BlockMasterClientRestServiceHandler.GET_BLOCK_INFO), params, HttpMethod.GET, null).call();
BlockInfo blockInfo = new ObjectMapper().readValue(response, BlockInfo.class);
Assert.assertEquals(blockId, blockInfo.getBlockId());
Assert.assertEquals(initialBytes, blockInfo.getLength());
Assert.assertEquals("MEM", Iterables.getOnlyElement(blockInfo.getLocations()).getTierAlias());
}
use of alluxio.rest.TestCase in project alluxio by Alluxio.
the class AlluxioMasterRestApiTest method getInfo.
private AlluxioMasterInfo getInfo(Map<String, String> params) throws Exception {
String result = new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_INFO), params, HttpMethod.GET, null).call();
AlluxioMasterInfo info = new ObjectMapper().readValue(result, AlluxioMasterInfo.class);
return info;
}
use of alluxio.rest.TestCase in project alluxio by Alluxio.
the class FileSystemClientRestApiTest method delete.
@Test
public void delete() throws Exception {
AlluxioURI uri = new AlluxioURI("/file");
writeFile(uri, null);
new TestCase(mHostname, mPort, PATHS_PREFIX + uri.toString() + "/" + PathsRestServiceHandler.DELETE, NO_PARAMS, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(DeleteOptions.defaults())).run();
try {
mFileSystemMaster.getFileInfo(uri);
Assert.fail("file should have been removed");
} catch (FileDoesNotExistException e) {
// Expected
}
}
use of alluxio.rest.TestCase in project alluxio by Alluxio.
the class FileSystemClientRestApiTest method writeFile.
private void writeFile(AlluxioURI path, byte[] input) throws Exception {
String result = new TestCase(mHostname, mPort, PATHS_PREFIX + path.toString() + "/" + PathsRestServiceHandler.CREATE_FILE, NO_PARAMS, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(CreateFileOptions.defaults())).call();
Integer id = new ObjectMapper().readValue(result, Integer.TYPE);
TestCaseOptions options = TestCaseOptions.defaults();
long expected = 0;
if (input != null) {
options.setInputStream(new ByteArrayInputStream(input));
expected = input.length;
}
new TestCase(mHostname, mPort, STREAMS_PREFIX + id.toString() + "/" + StreamsRestServiceHandler.WRITE, NO_PARAMS, HttpMethod.POST, expected, options).run();
new TestCase(mHostname, mPort, STREAMS_PREFIX + id.toString() + "/" + StreamsRestServiceHandler.CLOSE, NO_PARAMS, HttpMethod.POST, null).run();
}
use of alluxio.rest.TestCase in project alluxio by Alluxio.
the class FileSystemClientRestApiTest method listStatus.
@Test
public void listStatus() throws Exception {
AlluxioURI uri = new AlluxioURI("/file");
writeFile(uri, null);
String result = new TestCase(mHostname, mPort, PATHS_PREFIX + uri.toString() + "/" + PathsRestServiceHandler.LIST_STATUS, NO_PARAMS, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(ListStatusOptions.defaults())).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