Search in sources :

Example 21 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.

the class OssDataSegmentKillerTest method test_killAll_recoverableExceptionWhenListingObjects_deletesAllSegments.

@Test
public void test_killAll_recoverableExceptionWhenListingObjects_deletesAllSegments() throws IOException {
    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.setKeys(Collections.singletonList(KEY_1));
    OssTestUtils.mockClientDeleteObjects(client, ImmutableList.of(deleteRequest1), ImmutableMap.of(deleteRequest1, 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();
    EasyMock.verify(client, segmentPusherConfig, inputDataConfig);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest) Test(org.junit.Test)

Example 22 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.

the class OssTaskLogsTest method test_killAll_noException_deletesAllTaskLogs.

@Test
public void test_killAll_noException_deletesAllTaskLogs() throws IOException {
    OSSObjectSummary objectSummary1 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_1, TIME_0);
    OSSObjectSummary objectSummary2 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_2, TIME_1);
    EasyMock.expect(timeSupplier.getAsLong()).andReturn(TIME_NOW);
    OssTestUtils.expectListObjects(ossClient, 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(ossClient, ImmutableList.of(deleteRequest1, deleteRequest2), ImmutableMap.of());
    EasyMock.replay(ossClient, timeSupplier);
    OssTaskLogsConfig config = new OssTaskLogsConfig();
    config.setBucket(TEST_BUCKET);
    config.setPrefix(TEST_PREFIX);
    OssInputDataConfig inputDataConfig = new OssInputDataConfig();
    inputDataConfig.setMaxListingLength(MAX_KEYS);
    OssTaskLogs taskLogs = new OssTaskLogs(ossClient, config, inputDataConfig, timeSupplier);
    taskLogs.killAll();
    EasyMock.verify(ossClient, timeSupplier);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest) Test(org.junit.Test)

Example 23 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.

the class OssTaskLogsTest method test_killOlderThan_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs.

@Test
public void test_killOlderThan_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs() {
    boolean ioExceptionThrown = false;
    try {
        OSSObjectSummary objectSummary1 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_1, TIME_0);
        OssTestUtils.expectListObjects(ossClient, PREFIX_URI, ImmutableList.of(objectSummary1));
        DeleteObjectsRequest deleteRequest1 = new DeleteObjectsRequest(TEST_BUCKET);
        deleteRequest1.setKeys(Collections.singletonList(KEY_1));
        OssTestUtils.mockClientDeleteObjects(ossClient, ImmutableList.of(), ImmutableMap.of(deleteRequest1, NON_RECOVERABLE_EXCEPTION));
        EasyMock.replay(ossClient, timeSupplier);
        OssTaskLogsConfig config = new OssTaskLogsConfig();
        config.setBucket(TEST_BUCKET);
        config.setPrefix(TEST_PREFIX);
        OssInputDataConfig inputDataConfig = new OssInputDataConfig();
        inputDataConfig.setMaxListingLength(MAX_KEYS);
        OssTaskLogs taskLogs = new OssTaskLogs(ossClient, config, inputDataConfig, timeSupplier);
        taskLogs.killOlderThan(TIME_NOW);
    } catch (IOException e) {
        ioExceptionThrown = true;
    }
    Assert.assertTrue(ioExceptionThrown);
    EasyMock.verify(ossClient, timeSupplier);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) IOException(java.io.IOException) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest) Test(org.junit.Test)

Aggregations

DeleteObjectsRequest (com.aliyun.oss.model.DeleteObjectsRequest)23 Test (org.junit.Test)15 OSSObjectSummary (com.aliyun.oss.model.OSSObjectSummary)12 ArrayList (java.util.ArrayList)10 DeleteObjectsResult (com.aliyun.oss.model.DeleteObjectsResult)9 IOException (java.io.IOException)4 ListObjectsRequest (com.aliyun.oss.model.ListObjectsRequest)3 ObjectListing (com.aliyun.oss.model.ObjectListing)3 ClientException (com.aliyun.oss.ClientException)2 OSS (com.aliyun.oss.OSS)2 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)2 OSSException (com.aliyun.oss.OSSException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 AbortMultipartUploadRequest (com.aliyun.oss.model.AbortMultipartUploadRequest)1 AppendObjectRequest (com.aliyun.oss.model.AppendObjectRequest)1 AppendObjectResult (com.aliyun.oss.model.AppendObjectResult)1 CompleteMultipartUploadRequest (com.aliyun.oss.model.CompleteMultipartUploadRequest)1 CompleteMultipartUploadResult (com.aliyun.oss.model.CompleteMultipartUploadResult)1 CopyObjectResult (com.aliyun.oss.model.CopyObjectResult)1