Search in sources :

Example 11 with AddBucketReplicationRequest

use of com.aliyun.oss.model.AddBucketReplicationRequest 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)

Example 12 with AddBucketReplicationRequest

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

the class BucketReplicationTest method testNormalAddBucketReplication.

@Test
public void testNormalAddBucketReplication() throws ParseException {
    final String bucketName = "test-bucket-set-replication";
    final String ruleId = "bucket-replication-rule-id";
    try {
        ossClient.createBucket(bucketName);
        AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
        request.setReplicationRuleID(ruleId);
        request.setTargetBucketName(targetBucketName);
        request.setTargetBucketLocation(targetBucketLoc);
        ossClient.addBucketReplication(request);
        List<ReplicationRule> rules = ossClient.getBucketReplication(bucketName);
        Assert.assertEquals(rules.size(), 1);
        ReplicationRule r0 = rules.get(0);
        Assert.assertEquals(r0.getReplicationRuleID(), ruleId);
        Assert.assertEquals(r0.getTargetBucketName(), targetBucketName);
        Assert.assertEquals(r0.getTargetBucketLocation(), targetBucketLoc);
        Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Starting);
        Assert.assertNull(r0.getObjectPrefixList());
        Assert.assertEquals(r0.getReplicationActionList().size(), 1);
        Assert.assertEquals(r0.getReplicationActionList().get(0), ReplicationAction.parse("ALL"));
        BucketReplicationProgress progress = ossClient.getBucketReplicationProgress(bucketName, ruleId);
        Assert.assertEquals(progress.getReplicationRuleID(), ruleId);
        Assert.assertEquals(progress.getTargetBucketName(), targetBucketName);
        Assert.assertEquals(progress.getTargetBucketLocation(), targetBucketLoc);
        Assert.assertEquals(progress.getReplicationStatus(), ReplicationStatus.Starting);
        Assert.assertEquals(progress.getHistoricalObjectProgress(), Float.valueOf(0));
        Assert.assertEquals(progress.isEnableHistoricalObjectReplication(), true);
        Assert.assertEquals(progress.getNewObjectProgress(), null);
        ossClient.deleteBucketReplication(new DeleteBucketReplicationRequest(bucketName, ruleId));
        rules = ossClient.getBucketReplication(bucketName);
        Assert.assertEquals(rules.size(), 1);
        r0 = rules.get(0);
        Assert.assertEquals(r0.getReplicationRuleID(), ruleId);
        Assert.assertEquals(r0.getTargetBucketName(), targetBucketName);
        Assert.assertEquals(r0.getTargetBucketLocation(), targetBucketLoc);
        Assert.assertEquals(r0.getReplicationStatus(), ReplicationStatus.Closing);
        List<String> locations = ossClient.getBucketReplicationLocation(bucketName);
        Assert.assertEquals(locations.size() > 0, true);
    } catch (OSSException e) {
        e.printStackTrace();
        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) DeleteBucketReplicationRequest(com.aliyun.oss.model.DeleteBucketReplicationRequest) ReplicationRule(com.aliyun.oss.model.ReplicationRule) Test(org.junit.Test)

Example 13 with AddBucketReplicationRequest

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

the class BucketReplicationTest method testUnormalSetBucketReplicationInvalidParam.

@Test
public void testUnormalSetBucketReplicationInvalidParam() throws ParseException {
    final String bucketName = "test-unormal-bucket-delete-replication-param";
    try {
        ossClient.createBucket(bucketName);
        AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
        request.setTargetBucketName(targetBucketName);
        try {
            ossClient.addBucketReplication(request);
            Assert.fail("Get bucket replication should not be successful.");
        } catch (NullPointerException e) {
        }
    } catch (OSSException e) {
        Assert.fail(e.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : AddBucketReplicationRequest(com.aliyun.oss.model.AddBucketReplicationRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Aggregations

OSSException (com.aliyun.oss.OSSException)13 AddBucketReplicationRequest (com.aliyun.oss.model.AddBucketReplicationRequest)13 Test (org.junit.Test)13 DeleteBucketReplicationRequest (com.aliyun.oss.model.DeleteBucketReplicationRequest)10 ReplicationRule (com.aliyun.oss.model.ReplicationRule)8 BucketReplicationProgress (com.aliyun.oss.model.BucketReplicationProgress)4 GetBucketReplicationProgressRequest (com.aliyun.oss.model.GetBucketReplicationProgressRequest)2 ReplicationAction (com.aliyun.oss.model.AddBucketReplicationRequest.ReplicationAction)1 ArrayList (java.util.ArrayList)1