Search in sources :

Example 1 with MockResponse

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

the class TestCustomTokenProvider method testCustomTokenManagement.

@Test
public void testCustomTokenManagement() throws IOException, URISyntaxException {
    int accessTokenCallbackDuringExec = 0;
    init();
    for (TestableAdlFileSystem tfs : fileSystems) {
        for (int i = 0; i < backendCallCount; ++i) {
            getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getGetFileStatusJSONResponse()));
            FileStatus fileStatus = tfs.getFileStatus(new Path("/test1/test2"));
            Assert.assertTrue(fileStatus.isFile());
            Assert.assertEquals("adl://" + getMockServer().getHostName() + ":" + getMockServer().getPort() + "/test1/test2", fileStatus.getPath().toString());
            Assert.assertEquals(4194304, fileStatus.getLen());
            Assert.assertEquals(ADL_BLOCK_SIZE, fileStatus.getBlockSize());
            Assert.assertEquals(1, fileStatus.getReplication());
            Assert.assertEquals(new FsPermission("777"), fileStatus.getPermission());
            Assert.assertEquals("NotSupportYet", fileStatus.getOwner());
            Assert.assertEquals("NotSupportYet", fileStatus.getGroup());
        }
        accessTokenCallbackDuringExec += ((CustomMockTokenProvider) tfs.getAzureTokenProvider()).getAccessTokenRequestCount();
    }
    Assert.assertEquals(expectedCallbackToAccessToken, accessTokenCallbackDuringExec);
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) FileStatus(org.apache.hadoop.fs.FileStatus) FsPermission(org.apache.hadoop.fs.permission.FsPermission) Test(org.junit.Test)

Example 2 with MockResponse

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

the class TestACLFeatures method getAclStatusAsExpected.

@Test
public void getAclStatusAsExpected() throws URISyntaxException, IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getGetAclStatusJSONResponse()));
    AclStatus aclStatus = getMockAdlFileSystem().getAclStatus(new Path("/test1/test2"));
    Assert.assertEquals(aclStatus.getGroup(), "supergroup");
    Assert.assertEquals(aclStatus.getOwner(), "hadoop");
    Assert.assertEquals((Short) aclStatus.getPermission().toShort(), Short.valueOf("775", 8));
    for (AclEntry entry : aclStatus.getEntries()) {
        if (!(entry.toString().equalsIgnoreCase("user:carla:rw-") || entry.toString().equalsIgnoreCase("group::r-x"))) {
            Assert.fail("Unexpected entry : " + entry.toString());
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Test(org.junit.Test)

Example 3 with MockResponse

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

the class TestACLFeatures method getAclStatusNotExists.

@Test(expected = FileNotFoundException.class)
public void getAclStatusNotExists() throws URISyntaxException, IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(404).setBody(TestADLResponseData.getFileNotFoundException()));
    getMockAdlFileSystem().getAclStatus(new Path("/test1/test2"));
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) Test(org.junit.Test)

Example 4 with MockResponse

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

the class TestACLFeatures method testModifyAclEntries.

@Test(expected = AccessControlException.class)
public void testModifyAclEntries() 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().modifyAclEntries(new Path("/test1/test2"), entries);
    getMockServer().enqueue(new MockResponse().setResponseCode(403).setBody(TestADLResponseData.getAccessControlException()));
    getMockAdlFileSystem().modifyAclEntries(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 5 with MockResponse

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

the class TestACLFeatures method testRemoveAclEntries.

@Test(expected = AccessControlException.class)
public void testRemoveAclEntries() 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().removeAclEntries(new Path("/test1/test2"), entries);
    getMockServer().enqueue(new MockResponse().setResponseCode(403).setBody(TestADLResponseData.getAccessControlException()));
    getMockAdlFileSystem().removeAclEntries(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)

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