use of com.aliyun.oss.model.DeleteObjectsRequest in project aliyun-oss-java-sdk by aliyun.
the class DeleteObjectsTest method testDeleleNonexistentObjects.
@Test
public void testDeleleNonexistentObjects() {
List<String> nonexistentKeys = new ArrayList<String>();
final int keyCount = 100;
final String keyPrefix = "delete-nonexistent-objects";
for (int i = 0; i < keyCount; i++) {
nonexistentKeys.add(keyPrefix + i);
}
DeleteObjectsRequest request = new DeleteObjectsRequest(bucketName);
request.setKeys(nonexistentKeys);
try {
DeleteObjectsResult result = ossClient.deleteObjects(request);
List<String> deletedObjects = result.getDeletedObjects();
Assert.assertEquals(keyCount, deletedObjects.size());
Assert.assertEquals(result.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.DeleteObjectsRequest in project aliyun-oss-java-sdk by aliyun.
the class DeleteObjectsTest method testDeleleExistingObjects.
@Test
public void testDeleleExistingObjects() {
List<String> existingKeys = new ArrayList<String>();
final int keyCount = 100;
final String keyPrefix = "delete-existing-objects";
for (int i = 0; i < keyCount; i++) {
existingKeys.add(keyPrefix + i);
}
if (!batchPutObject(ossClient, bucketName, existingKeys)) {
Assert.fail("batch put object failed");
}
DeleteObjectsRequest request = new DeleteObjectsRequest(bucketName);
request.setKeys(existingKeys);
try {
DeleteObjectsResult result = ossClient.deleteObjects(request);
List<String> deletedObjects = result.getDeletedObjects();
Assert.assertEquals(keyCount, deletedObjects.size());
Assert.assertEquals(result.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.DeleteObjectsRequest in project aliyun-oss-java-sdk by aliyun.
the class DeleteObjectsSample method main.
public static void main(String[] args) throws IOException {
/*
* Constructs a client instance with your account for accessing OSS
*/
OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
/*
* Batch put objects into the bucket
*/
final String content = "Thank you for using Aliyun Object Storage Service";
final String keyPrefix = "MyObjectKey";
List<String> keys = new ArrayList<String>();
for (int i = 0; i < 100; i++) {
String key = keyPrefix + i;
InputStream instream = new ByteArrayInputStream(content.getBytes());
client.putObject(bucketName, key, instream);
System.out.println("Succeed to put object " + key);
keys.add(key);
}
System.out.println();
/*
* Delete all objects uploaded recently under the bucket
*/
System.out.println("\nDeleting all objects:");
DeleteObjectsResult deleteObjectsResult = client.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(keys));
List<String> deletedObjects = deleteObjectsResult.getDeletedObjects();
for (String object : deletedObjects) {
System.out.println("\t" + object);
}
System.out.println();
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, " + "but was rejected with an error response for some reason.");
System.out.println("Error Message: " + oe.getErrorCode());
System.out.println("Error Code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered " + "a serious internal problem while trying to communicate with OSS, " + "such as not being able to access the network.");
System.out.println("Error Message: " + ce.getMessage());
} finally {
/*
* Do not forget to shut down the client finally to release all allocated resources.
*/
client.shutdown();
}
}
use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.
the class OssDataSegmentKillerTest method test_killAll_noException_deletesAllSegments.
@Test
public void test_killAll_noException_deletesAllSegments() throws IOException {
OSSObjectSummary objectSummary1 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_1, TIME_0);
OSSObjectSummary objectSummary2 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_2, TIME_1);
OssTestUtils.expectListObjects(client, PREFIX_URI, ImmutableList.of(objectSummary1, objectSummary2));
DeleteObjectsRequest deleteRequest1 = new DeleteObjectsRequest(TEST_BUCKET);
deleteRequest1.setKeys(Collections.singletonList(KEY_1));
DeleteObjectsRequest deleteRequest2 = new DeleteObjectsRequest(TEST_BUCKET);
deleteRequest2.setKeys(Collections.singletonList(KEY_2));
OssTestUtils.mockClientDeleteObjects(client, ImmutableList.of(deleteRequest1, deleteRequest2), ImmutableMap.of());
EasyMock.expect(segmentPusherConfig.getBucket()).andReturn(TEST_BUCKET);
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(segmentPusherConfig.getPrefix()).andReturn(TEST_PREFIX);
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(client, segmentPusherConfig, inputDataConfig);
segmentKiller = new OssDataSegmentKiller(Suppliers.ofInstance(client), segmentPusherConfig, inputDataConfig);
segmentKiller.killAll();
EasyMock.verify(client, segmentPusherConfig, inputDataConfig);
}
use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.
the class OssDataSegmentKillerTest method test_killAll_nonrecoverableExceptionWhenListingObjects_deletesAllSegments.
@Test
public void test_killAll_nonrecoverableExceptionWhenListingObjects_deletesAllSegments() {
boolean ioExceptionThrown = false;
try {
OSSObjectSummary objectSummary1 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_1, TIME_0);
OssTestUtils.expectListObjects(client, PREFIX_URI, ImmutableList.of(objectSummary1));
DeleteObjectsRequest deleteRequest1 = new DeleteObjectsRequest(TEST_BUCKET);
deleteRequest1.withKeys(ImmutableList.of(KEY_1));
OssTestUtils.mockClientDeleteObjects(client, ImmutableList.of(), ImmutableMap.of(deleteRequest1, NON_RECOVERABLE_EXCEPTION));
EasyMock.expect(segmentPusherConfig.getBucket()).andReturn(TEST_BUCKET);
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(segmentPusherConfig.getPrefix()).andReturn(TEST_PREFIX);
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(client, segmentPusherConfig, inputDataConfig);
segmentKiller = new OssDataSegmentKiller(Suppliers.ofInstance(client), segmentPusherConfig, inputDataConfig);
segmentKiller.killAll();
} catch (IOException e) {
ioExceptionThrown = true;
}
Assert.assertTrue(ioExceptionThrown);
EasyMock.verify(client, segmentPusherConfig, inputDataConfig);
}
Aggregations