use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithStorageType.
@Ignore
public void testPutWithStorageType() {
final String bucketName = "bucket-with-storage-type";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setStorageClass(StorageClass.IA);
try {
ossClient.createBucket(createBucketRequest);
AccessControlList returnedAcl = ossClient.getBucketAcl(bucketName);
Set<Grant> grants = returnedAcl.getGrants();
Assert.assertEquals(0, grants.size());
BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
Assert.assertEquals(1, buckets.getBucketList().size());
Assert.assertEquals(StorageClass.IA, buckets.getBucketList().get(0).getStorageClass());
} catch (Exception ex) {
Assert.fail(ex.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithInconsistentLocation.
@Test
public void testPutWithInconsistentLocation() {
final String bucketName = "bucket-with-inconsistent-location";
CreateBucketRequest request = new CreateBucketRequest(bucketName);
// Make location constraint inconsistent with endpoint
request.setLocationConstraint("oss-ap-southeast-1");
try {
ossClient.createBucket(request);
Assert.fail("Create bucket should not be successful.");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_LOCATION_CONSTRAINT, e.getErrorCode());
Assert.assertTrue(e.getMessage().startsWith(INVALID_LOCATION_CONSTRAINT_ERR));
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithStorageTypeModify.
@Ignore
public void testPutWithStorageTypeModify() {
final String bucketName = "bucket-with-storage-type-modify";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
try {
ossClient.createBucket(createBucketRequest);
BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
Assert.assertEquals(1, buckets.getBucketList().size());
Assert.assertEquals(StorageClass.Standard, buckets.getBucketList().get(0).getStorageClass());
try {
createBucketRequest.setStorageClass(StorageClass.IA);
ossClient.createBucket(createBucketRequest);
Assert.fail("Create bucket should not be successful.");
} catch (OSSException oe) {
Assert.assertEquals(OSSErrorCode.BUCKET_ALREADY_EXISTS, oe.getErrorCode());
Assert.assertTrue(oe.getMessage().startsWith(MODIFY_STORAGE_TYPE_ERR));
}
} catch (Exception ex) {
Assert.fail(ex.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithUnsupportedLocation.
@Test
public void testPutWithUnsupportedLocation() {
final String bucketName = "bucket-with-unsupported-location";
final String unsupportedLocation = "oss-cn-zhengzhou";
CreateBucketRequest request = new CreateBucketRequest(bucketName);
request.setLocationConstraint(unsupportedLocation);
try {
ossClient.createBucket(request);
Assert.fail("Create bucket should not be successful.");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_LOCATION_CONSTRAINT, e.getErrorCode());
Assert.assertTrue(e.getMessage().startsWith(INVALID_LOCATION_CONSTRAINT_ERR));
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class ArchiveTest method testNormalRestoreObject.
@Ignore
public void testNormalRestoreObject() {
String bucketName = "restore-object-test-bucket";
String key = "normal-restore-object.txt";
String filePath = null;
try {
// create archive bucket
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setStorageClass(StorageClass.Archive);
ossClient.createBucket(createBucketRequest);
// put archive object
filePath = genFixedLengthFile(1024);
ossClient.putObject(bucketName, key, new File(filePath));
ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, key);
// check whether the object is archive class
StorageClass storageClass = objectMetadata.getObjectStorageClass();
if (storageClass == StorageClass.Archive) {
// restore object
ossClient.restoreObject(bucketName, key);
// wait for restore completed
do {
Thread.sleep(1000);
objectMetadata = ossClient.getObjectMetadata(bucketName, key);
System.out.println("x-oss-restore:" + objectMetadata.getObjectRawRestore());
} while (!objectMetadata.isRestoreCompleted());
}
// get restored object
OSSObject ossObject = ossClient.getObject(bucketName, key);
ossObject.getObjectContent().close();
// restore repeatedly
ossClient.restoreObject(bucketName, key);
// delete object
ossClient.deleteObject(bucketName, key);
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
removeFile(filePath);
ossClient.deleteBucket(bucketName);
}
}
Aggregations