Search in sources :

Example 1 with GetBucketReplicationProgressRequest

use of com.aliyun.oss.model.GetBucketReplicationProgressRequest in project aliyun-oss-java-sdk by aliyun.

the class BucketReplicationTest method testUnormalGetBucketReplicationProgressInvalidParam.

@Test
public void testUnormalGetBucketReplicationProgressInvalidParam() throws ParseException {
    final String bucketName = "test-unormal-bucket-replication-progress";
    final String ruleId = "bucket-replication-rule-id";
    try {
        ossClient.createBucket(bucketName);
        AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
        request.setTargetBucketName(targetBucketName);
        request.setTargetBucketLocation(targetBucketLoc);
        request.setReplicationRuleID(ruleId);
        ossClient.addBucketReplication(request);
        try {
            ossClient.getBucketReplicationProgress(new GetBucketReplicationProgressRequest(bucketName));
            Assert.fail("Get bucket replication should not be successful.");
        } catch (NullPointerException e) {
        }
        ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, ruleId));
    } catch (OSSException e) {
        Assert.fail(e.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : AddBucketReplicationRequest(com.aliyun.oss.model.AddBucketReplicationRequest) OSSException(com.aliyun.oss.OSSException) GetBucketReplicationProgressRequest(com.aliyun.oss.model.GetBucketReplicationProgressRequest) DeleteBucketReplicationRequest(com.aliyun.oss.model.DeleteBucketReplicationRequest) Test(org.junit.Test)

Example 2 with GetBucketReplicationProgressRequest

use of com.aliyun.oss.model.GetBucketReplicationProgressRequest in project aliyun-oss-java-sdk by aliyun.

the class BucketReplicationTest method testNormalGetBucketReplicationProgressWithDisableHistory.

@Test
public void testNormalGetBucketReplicationProgressWithDisableHistory() throws ParseException {
    final String bucketName = "test-bucket-replication-progress-disable-history";
    final String repRuleID = "test-replication-ruleid";
    try {
        ossClient.createBucket(bucketName);
        AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
        request.setReplicationRuleID(repRuleID);
        request.setTargetBucketName(targetBucketName);
        request.setTargetBucketLocation(targetBucketLoc);
        request.setEnableHistoricalObjectReplication(false);
        ossClient.addBucketReplication(request);
        List<ReplicationRule> rules = ossClient.getBucketReplication(bucketName);
        Assert.assertEquals(rules.size(), 1);
        ReplicationRule r0 = rules.get(0);
        Assert.assertEquals(r0.getReplicationRuleID(), repRuleID);
        Assert.assertEquals(r0.getTargetBucketName(), targetBucketName);
        Assert.assertEquals(r0.getTargetBucketLocation(), targetBucketLoc);
        Assert.assertEquals(r0.isEnableHistoricalObjectReplication(), false);
        Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Starting);
        BucketReplicationProgress process = ossClient.getBucketReplicationProgress(new GetBucketReplicationProgressRequest(bucketName).withReplicationRuleID(repRuleID));
        Assert.assertEquals(process.getReplicationRuleID(), repRuleID);
        Assert.assertEquals(process.getTargetBucketName(), targetBucketName);
        Assert.assertEquals(process.getTargetBucketLocation(), targetBucketLoc);
        Assert.assertEquals(process.getReplicationStatus(), ReplicationStatus.Starting);
        Assert.assertEquals(process.getHistoricalObjectProgress(), Float.valueOf(0));
        Assert.assertEquals(process.isEnableHistoricalObjectReplication(), false);
        Assert.assertEquals(process.getNewObjectProgress(), null);
        // Assert.assertEquals(diffSecond(process.getNewObjectProgress(), now) < 5, true);
        ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, repRuleID));
    } catch (OSSException e) {
        Assert.fail(e.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : BucketReplicationProgress(com.aliyun.oss.model.BucketReplicationProgress) AddBucketReplicationRequest(com.aliyun.oss.model.AddBucketReplicationRequest) OSSException(com.aliyun.oss.OSSException) GetBucketReplicationProgressRequest(com.aliyun.oss.model.GetBucketReplicationProgressRequest) DeleteBucketReplicationRequest(com.aliyun.oss.model.DeleteBucketReplicationRequest) ReplicationRule(com.aliyun.oss.model.ReplicationRule) Test(org.junit.Test)

Aggregations

OSSException (com.aliyun.oss.OSSException)2 AddBucketReplicationRequest (com.aliyun.oss.model.AddBucketReplicationRequest)2 DeleteBucketReplicationRequest (com.aliyun.oss.model.DeleteBucketReplicationRequest)2 GetBucketReplicationProgressRequest (com.aliyun.oss.model.GetBucketReplicationProgressRequest)2 Test (org.junit.Test)2 BucketReplicationProgress (com.aliyun.oss.model.BucketReplicationProgress)1 ReplicationRule (com.aliyun.oss.model.ReplicationRule)1