Search in sources :

Example 21 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project hadoop by apache.

the class TestListStatus method listStatusAclBit.

@Test
public void listStatusAclBit() throws URISyntaxException, IOException {
    // With ACLBIT set to true
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getListFileStatusJSONResponse(true)));
    FileStatus[] ls = null;
    long startTime = Time.monotonicNow();
    ls = getMockAdlFileSystem().listStatus(new Path("/test1/test2"));
    long endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    for (int i = 0; i < ls.length; i++) {
        Assert.assertTrue(ls[i].isDirectory());
        Assert.assertEquals(true, ls[i].getPermission().getAclBit());
    }
    // With ACLBIT set to false
    ls = null;
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getListFileStatusJSONResponse(false)));
    startTime = Time.monotonicNow();
    ls = getMockAdlFileSystem().listStatus(new Path("/test1/test2"));
    endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    for (int i = 0; i < ls.length; i++) {
        Assert.assertTrue(ls[i].isDirectory());
        Assert.assertEquals(false, ls[i].getPermission().getAclBit());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 22 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project hadoop by apache.

the class TestListStatus method listStatusOnFailure.

@Test
public void listStatusOnFailure() throws IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(403).setBody(TestADLResponseData.getErrorIllegalArgumentExceptionJSONResponse()));
    FileStatus[] ls = null;
    long startTime = Time.monotonicNow();
    try {
        ls = getMockAdlFileSystem().listStatus(new Path("/test1/test2"));
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("Invalid"));
    }
    long endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    // to caller. Adding max 10 error responses in the queue to align with SDK.
    for (int i = 0; i < 10; ++i) {
        getMockServer().enqueue(new MockResponse().setResponseCode(500).setBody(TestADLResponseData.getErrorInternalServerExceptionJSONResponse()));
    }
    startTime = Time.monotonicNow();
    try {
        ls = getMockAdlFileSystem().listStatus(new Path("/test1/test2"));
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("Internal Server Error"));
    }
    endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) FileStatus(org.apache.hadoop.fs.FileStatus) IOException(java.io.IOException) Test(org.junit.Test)

Example 23 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project hadoop by apache.

the class TestListStatus method listStatusReturnsAsExpected.

@Test
public void listStatusReturnsAsExpected() throws IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getListFileStatusJSONResponse(10)));
    long startTime = Time.monotonicNow();
    FileStatus[] ls = getMockAdlFileSystem().listStatus(new Path("/test1/test2"));
    long endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    Assert.assertEquals(10, ls.length);
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getListFileStatusJSONResponse(200)));
    startTime = Time.monotonicNow();
    ls = getMockAdlFileSystem().listStatus(new Path("/test1/test2"));
    endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    Assert.assertEquals(200, ls.length);
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getListFileStatusJSONResponse(2048)));
    startTime = Time.monotonicNow();
    ls = getMockAdlFileSystem().listStatus(new Path("/test1/test2"));
    endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    Assert.assertEquals(2048, ls.length);
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 24 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project hadoop by apache.

the class TestACLFeatures method testSetAcl.

@Test(expected = AccessControlException.class)
public void testSetAcl() throws URISyntaxException, IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    List<AclEntry> entries = new ArrayList<AclEntry>();
    AclEntry.Builder aclEntryBuilder = new AclEntry.Builder();
    aclEntryBuilder.setName("hadoop");
    aclEntryBuilder.setType(AclEntryType.USER);
    aclEntryBuilder.setPermission(FsAction.ALL);
    aclEntryBuilder.setScope(AclEntryScope.ACCESS);
    entries.add(aclEntryBuilder.build());
    aclEntryBuilder.setName("hdfs");
    aclEntryBuilder.setType(AclEntryType.GROUP);
    aclEntryBuilder.setPermission(FsAction.READ_WRITE);
    aclEntryBuilder.setScope(AclEntryScope.DEFAULT);
    entries.add(aclEntryBuilder.build());
    getMockAdlFileSystem().setAcl(new Path("/test1/test2"), entries);
    getMockServer().enqueue(new MockResponse().setResponseCode(403).setBody(TestADLResponseData.getAccessControlException()));
    getMockAdlFileSystem().setAcl(new Path("/test1/test2"), entries);
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) ArrayList(java.util.ArrayList) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Test(org.junit.Test)

Example 25 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project hadoop by apache.

the class TestACLFeatures method testSetOwner.

@Test(expected = AccessControlException.class)
public void testSetOwner() throws URISyntaxException, IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().setOwner(new Path("/test1/test2"), "hadoop", "hdfs");
    getMockServer().enqueue(new MockResponse().setResponseCode(403).setBody(TestADLResponseData.getAccessControlException()));
    getMockAdlFileSystem().setOwner(new Path("/test1/test2"), "hadoop", "hdfs");
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) Test(org.junit.Test)

Aggregations

MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)39 Test (org.junit.Test)34 Path (org.apache.hadoop.fs.Path)18 MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)10 FileStatus (org.apache.hadoop.fs.FileStatus)6 AclEntry (org.apache.hadoop.fs.permission.AclEntry)5 RecordedRequest (com.squareup.okhttp.mockwebserver.RecordedRequest)4 AbstractMockServerTest (com.stanfy.enroscar.net.test.AbstractMockServerTest)4 ArrayList (java.util.ArrayList)4 Buffer (okio.Buffer)4 HttpUrl (com.squareup.okhttp.HttpUrl)3 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 Request (com.squareup.okhttp.Request)2 Response (com.squareup.okhttp.Response)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 URI (java.net.URI)2