HDDS-743. S3 multi delete request should return XML header in quiet mode. Contributed by Elek Marton.

This commit is contained in:
Bharat Viswanadham 2018-10-29 12:59:41 -07:00
parent a58048e8d5
commit 3655e573e2
2 changed files with 48 additions and 22 deletions

View File

@ -223,7 +223,7 @@ public Response delete(@PathParam("bucket") String bucketName)
*/
@POST
@Produces(MediaType.APPLICATION_XML)
public Response multiDelete(@PathParam("bucket") String bucketName,
public MultiDeleteResponse multiDelete(@PathParam("bucket") String bucketName,
@QueryParam("delete") String delete,
MultiDeleteRequest request) throws OS3Exception, IOException {
OzoneBucket bucket = getBucket(bucketName);
@ -251,11 +251,6 @@ public Response multiDelete(@PathParam("bucket") String bucketName,
}
}
}
ResponseBuilder response = Response.ok();
if (!request.isQuiet() || result.getErrors().size() > 0) {
response = response.entity(result);
}
return response.build();
return result;
}
}

View File

@ -46,16 +46,7 @@ public class TestObjectMultiDelete {
public void delete() throws IOException, OS3Exception, JAXBException {
//GIVEN
OzoneClient client = new OzoneClientStub();
client.getObjectStore().createS3Bucket("bilbo", "b1");
String volumeName = client.getObjectStore().getOzoneVolumeName("b1");
OzoneBucket bucket =
client.getObjectStore().getVolume(volumeName).getBucket("b1");
bucket.createKey("key1", 0).close();
bucket.createKey("key2", 0).close();
bucket.createKey("key3", 0).close();
OzoneBucket bucket = initTestData(client);
BucketEndpoint rest = new BucketEndpoint();
rest.setClient(client);
@ -66,11 +57,9 @@ public void delete() throws IOException, OS3Exception, JAXBException {
mdr.getObjects().add(new DeleteObject("key4"));
//WHEN
Response response = rest.multiDelete("b1", "", mdr);
MultiDeleteResponse response = rest.multiDelete("b1", "", mdr);
//THEN
MultiDeleteResponse mdresponse = (MultiDeleteResponse) response.getEntity();
Set<String> keysAtTheEnd = Sets.newHashSet(bucket.listKeys("")).stream()
.map(OzoneKey::getName)
.collect(Collectors.toSet());
@ -80,7 +69,49 @@ public void delete() throws IOException, OS3Exception, JAXBException {
//THEN
Assert.assertEquals(expectedResult, keysAtTheEnd);
Assert.assertEquals(3, mdresponse.getDeletedObjects().size());
Assert.assertEquals(0, mdresponse.getErrors().size());
Assert.assertEquals(3, response.getDeletedObjects().size());
Assert.assertEquals(0, response.getErrors().size());
}
@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(0, response.getDeletedObjects().size());
Assert.assertEquals(0, response.getErrors().size());
}
private OzoneBucket initTestData(OzoneClient client) throws IOException {
client.getObjectStore().createS3Bucket("bilbo", "b1");
String volumeName = client.getObjectStore().getOzoneVolumeName("b1");
OzoneBucket bucket =
client.getObjectStore().getVolume(volumeName).getBucket("b1");
bucket.createKey("key1", 0).close();
bucket.createKey("key2", 0).close();
bucket.createKey("key3", 0).close();
return bucket;
}
}