Search in sources :

Example 1 with TestCase

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());
}
Also used : HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) BlockInfo(alluxio.wire.BlockInfo) FileOutputStream(java.io.FileOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BlockWorker(alluxio.worker.block.BlockWorker) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 2 with TestCase

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;
}
Also used : TestCase(alluxio.rest.TestCase) AlluxioMasterInfo(alluxio.wire.AlluxioMasterInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with TestCase

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
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) TestCase(alluxio.rest.TestCase) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 4 with TestCase

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();
}
Also used : TestCaseOptions(alluxio.rest.TestCaseOptions) TestCase(alluxio.rest.TestCase) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with TestCase

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());
}
Also used : FileInfo(alluxio.wire.FileInfo) TestCase(alluxio.rest.TestCase) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Aggregations

TestCase (alluxio.rest.TestCase)44 RestApiTest (alluxio.rest.RestApiTest)40 Test (org.junit.Test)40 HashMap (java.util.HashMap)30 AlluxioURI (alluxio.AlluxioURI)29 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 FileInfo (alluxio.wire.FileInfo)7 Config (alluxio.LocalAlluxioClusterResource.Config)5 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)4 List (java.util.List)3 CommandLineJob (alluxio.job.CommandLineJob)2 JobConf (alluxio.job.JobConf)2 BlockWriter (alluxio.worker.block.io.BlockWriter)2 HttpURLConnection (java.net.HttpURLConnection)2 TestCaseOptions (alluxio.rest.TestCaseOptions)1 AlluxioMasterInfo (alluxio.wire.AlluxioMasterInfo)1 AlluxioWorkerInfo (alluxio.wire.AlluxioWorkerInfo)1 BlockInfo (alluxio.wire.BlockInfo)1 LineageInfo (alluxio.wire.LineageInfo)1 LockBlockResult (alluxio.wire.LockBlockResult)1