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);
}
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;
}
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)));
}
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();
}
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)));
}
Aggregations