use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.
the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPublicReadWrite.
@Test
public void testCreateDeleteBucketPublicReadWrite() throws Exception {
if (!judgeUserInfoValid()) {
return;
}
try {
String bucketName = String.format("java-pubrw-%s", appid);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicReadWrite);
AccessControlList accessControlList = new AccessControlList();
Grantee grantee = new UinGrantee("730123456");
accessControlList.grantPermission(grantee, Permission.Write);
createBucketRequest.setAccessControlList(accessControlList);
Bucket bucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, bucket.getName());
assertTrue(cosclient.doesBucketExist(bucketName));
BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
cosclient.deleteBucket(bucketName);
// 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
Thread.sleep(5000L);
assertFalse(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.
the class BatchDeleteTest method batchDeleteAllExistFileForVersionEnabled.
@Test
public void batchDeleteAllExistFileForVersionEnabled() throws IOException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
Thread.sleep(5000L);
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucket);
ArrayList<KeyVersion> keyList = new ArrayList<>();
long deleteFileCount = 30;
for (long fileIndex = 0; fileIndex < deleteFileCount; ++fileIndex) {
File localFile = buildTestFile(fileIndex * 1024);
String key = "ut/" + localFile.getName();
PutObjectResult putObjectResult = putObjectFromLocalFile(localFile, key);
keyList.add(new KeyVersion(key, putObjectResult.getVersionId()));
}
deleteObjectsRequest.setKeys(keyList);
DeleteObjectsResult deleteObjectsResult = cosclient.deleteObjects(deleteObjectsRequest);
assertEquals(deleteFileCount, deleteObjectsResult.getDeletedObjects().size());
}
use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.
the class BatchDeleteTest method batchDeletePartExistFileForVersionSuspended.
@Test
public void batchDeletePartExistFileForVersionSuspended() throws IOException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.SUSPENDED);
cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
Thread.sleep(5000L);
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucket);
ArrayList<KeyVersion> keyList = new ArrayList<>();
long deleteFileCount = 5;
for (long fileIndex = 0; fileIndex < deleteFileCount; ++fileIndex) {
File localFile = buildTestFile(fileIndex * 1024);
String key = "ut/" + localFile.getName();
PutObjectResult putObjectResult = putObjectFromLocalFile(localFile, key);
keyList.add(new KeyVersion(key, "null"));
}
keyList.add(new KeyVersion("ut/not_exist_key.txt", "null"));
deleteObjectsRequest.setKeys(keyList);
try {
DeleteObjectsResult deleteObjectsResult = cosclient.deleteObjects(deleteObjectsRequest);
List<DeletedObject> deleteObjectResultArray = deleteObjectsResult.getDeletedObjects();
} catch (MultiObjectDeleteException mde) {
List<DeletedObject> deleteObjects = mde.getDeletedObjects();
List<DeleteError> deleteErrors = mde.getErrors();
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
}
use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.
the class BucketReplicationTest method setGetDelBucketReplicationTest.
@Test
public void setGetDelBucketReplicationTest() {
if (!judgeUserInfoValid()) {
return;
}
BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
fail(e.toString());
}
ReplicationRule replicationRule = new ReplicationRule();
String prefix = "copy1_folder/";
replicationRule.setPrefix(prefix);
replicationRule.setStatus(ReplicationRuleStatus.Enabled);
ReplicationDestinationConfig replicationDestinationConfig = new ReplicationDestinationConfig();
String bucketQCS = "qcs:id/0:cos:ap-chengdu:appid/1251668577:chengwus3cd";
replicationDestinationConfig.setBucketQCS(bucketQCS);
replicationDestinationConfig.setStorageClass(StorageClass.Standard);
replicationRule.setDestinationConfig(replicationDestinationConfig);
BucketReplicationConfiguration bucketReplicationConfiguration = new BucketReplicationConfiguration();
String ruleName = "qcs::cam::uin/123456789:uin/987654543";
bucketReplicationConfiguration.setRoleName(ruleName);
String ruleId = "cctest1";
replicationRule.setID(ruleId);
bucketReplicationConfiguration.addRule(replicationRule);
cosclient.setBucketReplicationConfiguration(bucket, bucketReplicationConfiguration);
// replication设置后, 立刻获取会需要一段时间
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
fail(e.toString());
}
BucketReplicationConfiguration replicaConfigGet = cosclient.getBucketReplicationConfiguration(bucket);
assertEquals(ruleName, replicaConfigGet.getRoleName());
assertEquals(1, replicaConfigGet.getRules().size());
ReplicationRule replicationRule2 = replicaConfigGet.getRules().get(0);
assertEquals(bucketQCS, replicationRule2.getDestinationConfig().getBucketQCS());
assertEquals(StorageClass.Standard.toString(), replicationRule2.getDestinationConfig().getStorageClass());
assertEquals(ReplicationRuleStatus.Enabled.toString(), replicationRule2.getStatus());
assertEquals(prefix, replicationRule2.getPrefix());
cosclient.deleteBucketReplicationConfiguration(bucket);
}
use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.
the class PutGetLifeCycleConfigTest method testPutGetDelLifeCycleForBucketWithVersions.
@Ignore
public void testPutGetDelLifeCycleForBucketWithVersions() {
if (!judgeUserInfoValid()) {
return;
}
BucketVersioningConfiguration bucketVersionConfig = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
SetBucketVersioningConfigurationRequest setBucketVersionReq = new SetBucketVersioningConfigurationRequest(bucket, bucketVersionConfig);
cosclient.setBucketVersioningConfiguration(setBucketVersionReq);
List<Rule> rules = new ArrayList<>();
Rule standardIaRule = new Rule();
standardIaRule.setId("standard_ia transition for version");
standardIaRule.setFilter(new LifecycleFilter(new LifecyclePrefixPredicate("standard_ia/")));
List<Transition> standardIaTransitions = new ArrayList<>();
Transition standardTransition = new Transition();
standardTransition.setDays(20);
standardTransition.setStorageClass(StorageClass.Standard_IA.toString());
standardIaTransitions.add(standardTransition);
standardIaRule.setTransitions(standardIaTransitions);
standardIaRule.setStatus(BucketLifecycleConfiguration.DISABLED);
standardIaRule.setNoncurrentVersionExpirationInDays(360);
List<NoncurrentVersionTransition> noncurrentVersionTransitions = new ArrayList<>();
NoncurrentVersionTransition noncurrentVersionTransition = new NoncurrentVersionTransition();
noncurrentVersionTransition.setDays(30);
noncurrentVersionTransition.setStorageClass(StorageClass.Standard_IA);
standardIaRule.setNoncurrentVersionTransitions(noncurrentVersionTransitions);
standardIaRule.setExpirationInDays(120);
rules.add(standardIaRule);
testPutGetDelRules(rules);
bucketVersionConfig.setStatus(BucketVersioningConfiguration.SUSPENDED);
SetBucketVersioningConfigurationRequest closeBucketVersionReq = new SetBucketVersioningConfigurationRequest(bucket, bucketVersionConfig);
cosclient.setBucketVersioningConfiguration(closeBucketVersionReq);
}
Aggregations