use of com.aliyun.oss.model.ListBucketsRequest in project aliyun-oss-java-sdk by aliyun.
the class BucketInfoTest method testListBucketWithEndpoint.
@Test
public void testListBucketWithEndpoint() {
try {
ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
listBucketsRequest.setPrefix(bucketName);
listBucketsRequest.setMaxKeys(1);
BucketList buckets = ossClient.listBuckets(listBucketsRequest);
Assert.assertEquals(buckets.getBucketList().size(), 1);
Assert.assertNotNull(buckets.getBucketList().get(0).getExtranetEndpoint());
Assert.assertNotNull(buckets.getBucketList().get(0).getIntranetEndpoint());
Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.ListBucketsRequest in project aliyun-oss-java-sdk by aliyun.
the class BucketInfoTest method testListBucketWithBid.
@Test
public void testListBucketWithBid() {
try {
ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
listBucketsRequest.setPrefix(bucketName);
listBucketsRequest.setMaxKeys(1);
listBucketsRequest.setBid("26842");
BucketList buckets = ossClient.listBuckets(listBucketsRequest);
Assert.assertEquals(buckets.getBucketList().size(), 1);
Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.ListBucketsRequest in project aliyun-oss-java-sdk by aliyun.
the class TestBase method listAllBuckets.
protected static List<String> listAllBuckets(OSSClient client, String bucketPrefix) {
List<String> bkts = new ArrayList<String>();
String nextMarker = null;
BucketList bucketList = null;
do {
ListBucketsRequest listBucketsRequest = new ListBucketsRequest(bucketPrefix, nextMarker, ListBucketsRequest.MAX_RETURNED_KEYS);
bucketList = client.listBuckets(listBucketsRequest);
nextMarker = bucketList.getNextMarker();
for (Bucket b : bucketList.getBucketList()) {
bkts.add(b.getName());
}
} while (bucketList.isTruncated());
return bkts;
}
use of com.aliyun.oss.model.ListBucketsRequest in project aliyun-oss-java-sdk by aliyun.
the class ListBucketsTest method testNormalListBuckets.
@Test
public void testNormalListBuckets() {
final String bucketNamePrefix = BUCKET_NAME_PREFIX + "normal-list-buckets-";
try {
List<Bucket> returnedBuckets = ossClient.listBuckets();
for (Bucket bkt : returnedBuckets) {
if (bkt.getName().startsWith(bucketNamePrefix)) {
ossClient.deleteBucket(bkt.getName());
}
}
waitForCacheExpiration(5);
List<String> existingBuckets = new ArrayList<String>();
returnedBuckets = ossClient.listBuckets();
for (Bucket bkt : returnedBuckets) {
if (bkt.getName().startsWith(bucketNamePrefix)) {
existingBuckets.add(bkt.getName());
}
}
int remaindingAllowed = MAX_BUCKETS_ALLOWED - existingBuckets.size();
List<String> newlyBuckets = new ArrayList<String>();
for (int i = 0; i < remaindingAllowed; i++) {
String bucketName = bucketNamePrefix + i;
try {
ossClient.createBucket(bucketName);
newlyBuckets.add(bucketName);
waitForCacheExpiration(5);
String loc = ossClient.getBucketLocation(bucketName);
Assert.assertEquals(OSS_TEST_REGION, loc);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
waitForCacheExpiration(5);
// List all existing buckets
returnedBuckets = ossClient.listBuckets();
existingBuckets.clear();
for (Bucket bkt : returnedBuckets) {
if (bkt.getName().startsWith(bucketNamePrefix)) {
existingBuckets.add(bkt.getName());
}
}
Assert.assertEquals(MAX_BUCKETS_ALLOWED, existingBuckets.size());
// List all existing buckets prefix with 'normal-list-buckets-'
BucketList bucketList = ossClient.listBuckets(bucketNamePrefix, null, null);
Assert.assertEquals(remaindingAllowed, bucketList.getBucketList().size());
for (Bucket bkt : bucketList.getBucketList()) {
Assert.assertTrue(bkt.getName().startsWith(bucketNamePrefix));
}
// List 'max-keys' buckets each time
final int maxKeys = 3;
bucketList = ossClient.listBuckets(bucketNamePrefix, null, maxKeys);
Assert.assertTrue(bucketList.getBucketList().size() <= 3);
returnedBuckets.clear();
returnedBuckets.addAll(bucketList.getBucketList());
while (bucketList.isTruncated()) {
bucketList = ossClient.listBuckets(new ListBucketsRequest(bucketNamePrefix, bucketList.getNextMarker(), maxKeys));
Assert.assertTrue(bucketList.getBucketList().size() <= 3);
returnedBuckets.addAll(bucketList.getBucketList());
}
Assert.assertEquals(remaindingAllowed, returnedBuckets.size());
for (Bucket bkt : returnedBuckets) {
Assert.assertTrue(bkt.getName().startsWith(bucketNamePrefix));
}
for (String bkt : newlyBuckets) {
ossClient.deleteBucket(bkt);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.ListBucketsRequest in project aliyun-oss-java-sdk by aliyun.
the class OSSBucketOperation method listBuckets.
/**
* List all my buckets.
*/
public List<Bucket> listBuckets() throws OSSException, ClientException {
BucketList bucketList = listBuckets(new ListBucketsRequest(null, null, null));
List<Bucket> buckets = bucketList.getBucketList();
while (bucketList.isTruncated()) {
bucketList = listBuckets(new ListBucketsRequest(null, bucketList.getNextMarker(), null));
buckets.addAll(bucketList.getBucketList());
}
return buckets;
}
Aggregations