use of org.apache.hadoop.ozone.client.OzoneClientStub in project ozone by apache.
the class TestInitiateMultipartUpload method testInitiateMultipartUpload.
@Test
public void testInitiateMultipartUpload() throws Exception {
String bucket = OzoneConsts.S3_BUCKET;
String key = OzoneConsts.KEY;
OzoneClient client = new OzoneClientStub();
client.getObjectStore().createS3Bucket(bucket);
HttpHeaders headers = Mockito.mock(HttpHeaders.class);
when(headers.getHeaderString(STORAGE_CLASS_HEADER)).thenReturn("STANDARD");
ObjectEndpoint rest = new ObjectEndpoint();
rest.setHeaders(headers);
rest.setClient(client);
rest.setOzoneConfiguration(new OzoneConfiguration());
Response response = rest.initializeMultipartUpload(bucket, key);
assertEquals(200, response.getStatus());
MultipartUploadInitiateResponse multipartUploadInitiateResponse = (MultipartUploadInitiateResponse) response.getEntity();
assertNotNull(multipartUploadInitiateResponse.getUploadID());
String uploadID = multipartUploadInitiateResponse.getUploadID();
// Calling again should return different uploadID.
response = rest.initializeMultipartUpload(bucket, key);
assertEquals(200, response.getStatus());
multipartUploadInitiateResponse = (MultipartUploadInitiateResponse) response.getEntity();
assertNotNull(multipartUploadInitiateResponse.getUploadID());
assertNotEquals(multipartUploadInitiateResponse.getUploadID(), uploadID);
}
use of org.apache.hadoop.ozone.client.OzoneClientStub in project ozone by apache.
the class TestObjectHead method setup.
@Before
public void setup() throws IOException {
// Create client stub and object store stub.
OzoneClient clientStub = new OzoneClientStub();
// Create volume and bucket
clientStub.getObjectStore().createS3Bucket(bucketName);
bucket = clientStub.getObjectStore().getS3Bucket(bucketName);
// Create HeadBucket and setClient to OzoneClientStub
keyEndpoint = new ObjectEndpoint();
keyEndpoint.setClient(clientStub);
keyEndpoint.setOzoneConfiguration(new OzoneConfiguration());
}
use of org.apache.hadoop.ozone.client.OzoneClientStub in project ozone by apache.
the class TestObjectDelete method delete.
@Test
public void delete() throws IOException, OS3Exception {
// GIVEN
OzoneClient client = new OzoneClientStub();
client.getObjectStore().createS3Bucket("b1");
OzoneBucket bucket = client.getObjectStore().getS3Bucket("b1");
bucket.createKey("key1", 0).close();
ObjectEndpoint rest = new ObjectEndpoint();
rest.setClient(client);
rest.setOzoneConfiguration(new OzoneConfiguration());
// WHEN
rest.delete("b1", "key1", null);
// THEN
Assert.assertFalse("Bucket Should not contain any key after delete", bucket.listKeys("").hasNext());
}
use of org.apache.hadoop.ozone.client.OzoneClientStub in project ozone by apache.
the class TestObjectGet method get.
@Test
public void get() throws IOException, OS3Exception {
// GIVEN
OzoneClient client = new OzoneClientStub();
client.getObjectStore().createS3Bucket("b1");
OzoneBucket bucket = client.getObjectStore().getS3Bucket("b1");
OzoneOutputStream keyStream = bucket.createKey("key1", CONTENT.getBytes(UTF_8).length);
keyStream.write(CONTENT.getBytes(UTF_8));
keyStream.close();
ObjectEndpoint rest = new ObjectEndpoint();
rest.setClient(client);
rest.setOzoneConfiguration(new OzoneConfiguration());
HttpHeaders headers = Mockito.mock(HttpHeaders.class);
rest.setHeaders(headers);
ByteArrayInputStream body = new ByteArrayInputStream(CONTENT.getBytes(UTF_8));
// WHEN
Response response = rest.get("b1", "key1", null, 0, null, body);
// THEN
OzoneInputStream ozoneInputStream = client.getObjectStore().getS3Bucket("b1").readKey("key1");
String keyContent = IOUtils.toString(ozoneInputStream, UTF_8);
Assert.assertEquals(CONTENT, keyContent);
Assert.assertEquals("" + keyContent.length(), response.getHeaderString("Content-Length"));
DateTimeFormatter.RFC_1123_DATE_TIME.parse(response.getHeaderString("Last-Modified"));
}
use of org.apache.hadoop.ozone.client.OzoneClientStub in project ozone by apache.
the class TestObjectMultiDelete method deleteQuiet.
@Test
public void deleteQuiet() throws IOException, OS3Exception, JAXBException {
// GIVEN
OzoneClient client = new OzoneClientStub();
OzoneBucket bucket = initTestData(client);
BucketEndpoint rest = new BucketEndpoint();
rest.setClient(client);
MultiDeleteRequest mdr = new MultiDeleteRequest();
mdr.setQuiet(true);
mdr.getObjects().add(new DeleteObject("key1"));
mdr.getObjects().add(new DeleteObject("key2"));
mdr.getObjects().add(new DeleteObject("key4"));
// WHEN
MultiDeleteResponse response = rest.multiDelete("b1", "", mdr);
// THEN
Set<String> keysAtTheEnd = Sets.newHashSet(bucket.listKeys("")).stream().map(OzoneKey::getName).collect(Collectors.toSet());
// THEN
Assert.assertEquals(singleton("key3"), keysAtTheEnd);
Assert.assertEquals(0, response.getDeletedObjects().size());
Assert.assertEquals(0, response.getErrors().size());
}
Aggregations