Search in sources :

Example 21 with TestCase

use of alluxio.rest.TestCase in project alluxio by Alluxio.

the class BlockWorkerClientRestApiTest method writeBlock.

@Test
public void writeBlock() throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("blockId", Long.toString(BLOCK_ID));
    params.put("sessionId", Long.toString(SESSION_ID));
    params.put("offset", "0");
    params.put("length", Long.toString(INITIAL_BYTES));
    TestCase testCase = new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.WRITE_BLOCK), params, HttpMethod.POST, null);
    HttpURLConnection connection = (HttpURLConnection) testCase.createURL().openConnection();
    connection.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
    connection.setRequestMethod(testCase.getMethod());
    connection.setDoOutput(true);
    connection.connect();
    connection.getOutputStream().write(BYTE_BUFFER.array());
    Assert.assertEquals(testCase.getEndpoint(), Response.Status.OK.getStatusCode(), connection.getResponseCode());
    Assert.assertEquals("", testCase.getResponse(connection));
    // Verify that the right data was written.
    mBlockWorker.commitBlock(SESSION_ID, BLOCK_ID);
    long lockId = mBlockWorker.lockBlock(SESSION_ID, BLOCK_ID);
    String file = mBlockWorker.readBlock(SESSION_ID, BLOCK_ID, lockId);
    byte[] result = new byte[INITIAL_BYTES];
    IOUtils.readFully(new FileInputStream(file), result);
    Assert.assertArrayEquals(BYTE_BUFFER.array(), result);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 22 with TestCase

use of alluxio.rest.TestCase in project alluxio by Alluxio.

the class AlluxioWorkerRestApiTest method getInfo.

private AlluxioWorkerInfo getInfo() throws Exception {
    String result = new TestCase(mHostname, mPort, getEndpoint(AlluxioWorkerRestServiceHandler.GET_INFO), NO_PARAMS, HttpMethod.GET, null).call();
    AlluxioWorkerInfo info = new ObjectMapper().readValue(result, AlluxioWorkerInfo.class);
    return info;
}
Also used : TestCase(alluxio.rest.TestCase) AlluxioWorkerInfo(alluxio.wire.AlluxioWorkerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with TestCase

use of alluxio.rest.TestCase in project alluxio by Alluxio.

the class BlockWorkerClientRestApiTest method lockBlock.

@Test
public void lockBlock() throws Exception {
    mBlockWorker.createBlock(SESSION_ID, BLOCK_ID, TIER_ALIAS, INITIAL_BYTES);
    mBlockWorker.commitBlock(SESSION_ID, BLOCK_ID);
    Map<String, String> params = new HashMap<>();
    params.put("blockId", Long.toString(BLOCK_ID));
    params.put("sessionId", Long.toString(SESSION_ID));
    String result = new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.LOCK_BLOCK), params, HttpMethod.POST, null).call();
    LockBlockResult lockBlockResult = new ObjectMapper().readValue(result, LockBlockResult.class);
    Assert.assertTrue(lockBlockResult.getBlockPath().contains(Configuration.get(PropertyKey.WORKER_DATA_FOLDER)));
}
Also used : HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) LockBlockResult(alluxio.wire.LockBlockResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 24 with TestCase

use of alluxio.rest.TestCase in project alluxio by Alluxio.

the class BlockWorkerClientRestApiTest method requestSpace.

@Test
public void requestSpace() throws Exception {
    mBlockWorker.createBlock(SESSION_ID, BLOCK_ID, TIER_ALIAS, INITIAL_BYTES);
    Map<String, String> params = new HashMap<>();
    params.put("blockId", Long.toString(BLOCK_ID));
    params.put("sessionId", Long.toString(SESSION_ID));
    params.put("requestBytes", "10");
    new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.REQUEST_SPACE), params, HttpMethod.POST, null).run();
}
Also used : HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 25 with TestCase

use of alluxio.rest.TestCase in project alluxio by Alluxio.

the class BlockWorkerClientRestApiTest method requestBlockLocation.

@Test
public void requestBlockLocation() throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("blockId", "1");
    params.put("sessionId", "1");
    params.put("initialBytes", "1");
    String location = new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.REQUEST_BLOCK_LOCATION), params, HttpMethod.POST, null).call();
    Assert.assertTrue(location.contains(Configuration.get(PropertyKey.WORKER_DATA_FOLDER)));
}
Also used : HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) 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