use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class RequestTimeoutTest method testMultiOssClientIndependent.
/**
* Multiple OSSClient instances test.
* Each instance should work independently without being impacted by other instances.
* So one timeout instance should not make other instances timeout.
*/
@Test
public void testMultiOssClientIndependent() throws Exception {
String key = "test-multi-client-independent";
try {
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setRequestTimeout(1);
config.setRequestTimeoutEnabled(true);
config.setMaxConnections(1);
OSS client = new OSSClientBuilder().build(endpoint, accessId, accessKey, config);
Thread[] threads = new Thread[10];
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
threads[i] = new TimeoutOperationThread(client, key + i);
} else {
threads[i] = new OperationThread(key + i);
}
}
for (int i = 0; i < 10; i++) {
threads[i].start();
}
for (int i = 0; i < 10; i++) {
threads[i].join();
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class RequestTimeoutTest method testExitNormalAfterTimeout.
/**
* Testing grace exist after connection timeout
*/
@Test
public void testExitNormalAfterTimeout() throws Exception {
String key = "test-exit-after-timeout";
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setRequestTimeout(requestTimeout);
config.setRequestTimeoutEnabled(true);
config.setMaxConnections(1);
OSS client = new OSSClientBuilder().build(endpoint, accessId, accessKey, config);
try {
client.putObject(bucketName, key, TestUtils.genFixedLengthInputStream(1024 * 10));
Assert.fail("Put object should not be successful");
} catch (ClientException e) {
Assert.assertEquals(OSSErrorCode.REQUEST_TIMEOUT, e.getErrorCode());
}
}
use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithSTS.
@Test
public void testClientBuilderWithSTS() {
try {
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setSupportCname(true);
config.setConnectionTimeout(10000);
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET, "TOKEN"), config);
Assert.assertTrue(ossClient.getClientConfiguration().isSupportCname());
Assert.assertEquals(ossClient.getClientConfiguration().getConnectionTimeout(), 10000);
Credentials cred = ossClient.getCredentialsProvider().getCredentials();
Assert.assertEquals(cred.getAccessKeyId(), TestConfig.OSS_TEST_ACCESS_KEY_ID);
Assert.assertEquals(cred.getSecretAccessKey(), TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
Assert.assertEquals(cred.getSecurityToken(), "TOKEN");
Assert.assertTrue(cred.useSecurityToken());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithBuilderConfiguration.
@Test
public void testClientBuilderWithBuilderConfiguration() {
try {
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET), new ClientBuilderConfiguration());
Assert.assertFalse(ossClient.getClientConfiguration().isSupportCname());
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class CnameTest method testCnameExcludeList.
@Test
@SuppressWarnings("unused")
public void testCnameExcludeList() {
ClientBuilderConfiguration cc = new ClientBuilderConfiguration();
// Defalut CNAME Exclude List: [aliyuncs.com, aliyun-inc.com, aliyun.com]
List<String> currentExcludeList = cc.getCnameExcludeList();
Assert.assertEquals(currentExcludeList.size(), 3);
Assert.assertTrue(currentExcludeList.contains("aliyuncs.com"));
Assert.assertTrue(currentExcludeList.contains("aliyun-inc.com"));
Assert.assertTrue(currentExcludeList.contains("aliyun.com"));
List<String> cnameExcludeList = new ArrayList<String>();
String excludeItem = "http://oss-cn-hangzhou.aliyuncs.gd";
// Add your customized host name here
cnameExcludeList.add(excludeItem);
cc.setCnameExcludeList(cnameExcludeList);
currentExcludeList = cc.getCnameExcludeList();
Assert.assertEquals(currentExcludeList.size(), 4);
Assert.assertTrue(currentExcludeList.contains(excludeItem));
Assert.assertTrue(currentExcludeList.contains("aliyuncs.com"));
Assert.assertTrue(currentExcludeList.contains("aliyun-inc.com"));
Assert.assertTrue(currentExcludeList.contains("aliyun.com"));
OSS client = new OSSClientBuilder().build(OSS_TEST_ENDPOINT, OSS_TEST_ACCESS_KEY_ID, OSS_TEST_ACCESS_KEY_SECRET, cc);
// Do some operations with client here...
}
Aggregations