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