Search in sources :

Example 1 with OzoneClientStub

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);
}
Also used : Response(javax.ws.rs.core.Response) HttpHeaders(javax.ws.rs.core.HttpHeaders) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneClientStub(org.apache.hadoop.ozone.client.OzoneClientStub) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Test(org.junit.Test)

Example 2 with OzoneClientStub

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());
}
Also used : OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneClientStub(org.apache.hadoop.ozone.client.OzoneClientStub) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Before(org.junit.Before)

Example 3 with OzoneClientStub

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());
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneClientStub(org.apache.hadoop.ozone.client.OzoneClientStub) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Test(org.junit.Test)

Example 4 with OzoneClientStub

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"));
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) Response(javax.ws.rs.core.Response) HttpHeaders(javax.ws.rs.core.HttpHeaders) OzoneInputStream(org.apache.hadoop.ozone.client.io.OzoneInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneClientStub(org.apache.hadoop.ozone.client.OzoneClientStub) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Test(org.junit.Test)

Example 5 with OzoneClientStub

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());
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) DeleteObject(org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject) OzoneClientStub(org.apache.hadoop.ozone.client.OzoneClientStub) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Test(org.junit.Test)

Aggregations

OzoneClientStub (org.apache.hadoop.ozone.client.OzoneClientStub)16 OzoneClient (org.apache.hadoop.ozone.client.OzoneClient)10 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)8 Before (org.junit.Before)7 HttpHeaders (javax.ws.rs.core.HttpHeaders)6 Test (org.junit.Test)6 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)5 Response (javax.ws.rs.core.Response)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DeleteObject (org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject)2 BeforeClass (org.junit.BeforeClass)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 OzoneInputStream (org.apache.hadoop.ozone.client.io.OzoneInputStream)1 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)1 OS3Exception (org.apache.hadoop.ozone.s3.exception.OS3Exception)1