Search in sources :

Example 16 with TestCase

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

the class FileSystemMasterClientRestApiTest method rename.

@Test
public void rename() throws Exception {
    AlluxioURI uri1 = new AlluxioURI("/file1");
    AlluxioURI uri2 = new AlluxioURI("/file2");
    mFileSystemMaster.createFile(uri1, CreateFileOptions.defaults());
    mFileSystemMaster.completeFile(uri1, CompleteFileOptions.defaults());
    Map<String, String> params = new HashMap<>();
    params.put("srcPath", uri1.toString());
    params.put("dstPath", uri2.toString());
    new TestCase(mHostname, mPort, getEndpoint(FileSystemMasterClientRestServiceHandler.RENAME), params, HttpMethod.POST, null).run();
    try {
        mFileSystemMaster.getFileInfo(uri1);
        Assert.fail("file should have been removed");
    } catch (FileDoesNotExistException e) {
    // Expected
    }
    mFileSystemMaster.getFileInfo(uri2);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 17 with TestCase

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

the class BlockWorkerClientRestApiTest method readBlock.

@Test
public void readBlock() throws Exception {
    // Write a block and acquire a lock for it.
    mBlockWorker.createBlock(SESSION_ID, BLOCK_ID, TIER_ALIAS, INITIAL_BYTES);
    BlockWriter writer = mBlockWorker.getTempBlockWriterRemote(SESSION_ID, BLOCK_ID);
    writer.append(BYTE_BUFFER);
    writer.close();
    mBlockWorker.commitBlock(SESSION_ID, BLOCK_ID);
    long lockId = mBlockWorker.lockBlock(SESSION_ID, BLOCK_ID);
    Map<String, String> params = new HashMap<>();
    params.put("blockId", Long.toString(BLOCK_ID));
    params.put("sessionId", Long.toString(SESSION_ID));
    params.put("lockId", Long.toString(lockId));
    params.put("offset", "0");
    params.put("length", Long.toString(INITIAL_BYTES));
    TestCase testCase = new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.READ_BLOCK), params, HttpMethod.GET, BYTE_BUFFER);
    HttpURLConnection connection = (HttpURLConnection) testCase.createURL().openConnection();
    connection.setRequestMethod(testCase.getMethod());
    connection.connect();
    Assert.assertEquals(testCase.getEndpoint(), Response.Status.OK.getStatusCode(), connection.getResponseCode());
    Assert.assertEquals(new String(BYTE_BUFFER.array()), testCase.getResponse(connection));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) BlockWriter(alluxio.worker.block.io.BlockWriter) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 18 with TestCase

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

the class BlockWorkerClientRestApiTest method cacheBlock.

@Test
public void cacheBlock() 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));
    new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.CACHE_BLOCK), params, HttpMethod.POST, null).run();
}
Also used : HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 19 with TestCase

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

the class BlockWorkerClientRestApiTest method unlockBlock.

@Test
public void unlockBlock() throws Exception {
    // Write a block and acquire a lock for it.
    mBlockWorker.createBlock(SESSION_ID, BLOCK_ID, TIER_ALIAS, INITIAL_BYTES);
    BlockWriter writer = mBlockWorker.getTempBlockWriterRemote(SESSION_ID, BLOCK_ID);
    writer.append(BYTE_BUFFER);
    writer.close();
    mBlockWorker.commitBlock(SESSION_ID, BLOCK_ID);
    mBlockWorker.lockBlock(SESSION_ID, BLOCK_ID);
    Map<String, String> params = new HashMap<>();
    params.put("blockId", Long.toString(BLOCK_ID));
    params.put("sessionId", Long.toString(SESSION_ID));
    new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.UNLOCK_BLOCK), params, HttpMethod.POST, null).run();
}
Also used : HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) BlockWriter(alluxio.worker.block.io.BlockWriter) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 20 with TestCase

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

the class BlockWorkerClientRestApiTest method accessBlock.

@Test
public void accessBlock() 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));
    new TestCase(mHostname, mPort, getEndpoint(BlockWorkerClientRestServiceHandler.ACCESS_BLOCK), params, HttpMethod.POST, null).run();
}
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