use of com.aliyun.oss.ClientConfiguration in project alluxio by Alluxio.
the class OSSUnderFileSystem method initializeOSSClientConfig.
/**
* Creates an OSS {@code ClientConfiguration} using an Alluxio Configuration.
*
* @return the OSS {@link ClientConfiguration}
*/
private static ClientConfiguration initializeOSSClientConfig() {
ClientConfiguration ossClientConf = new ClientConfiguration();
ossClientConf.setConnectionTimeout(Configuration.getInt(PropertyKey.UNDERFS_OSS_CONNECT_TIMEOUT));
ossClientConf.setSocketTimeout(Configuration.getInt(PropertyKey.UNDERFS_OSS_SOCKET_TIMEOUT));
ossClientConf.setConnectionTTL(Configuration.getLong(PropertyKey.UNDERFS_OSS_CONNECT_TTL));
ossClientConf.setMaxConnections(Configuration.getInt(PropertyKey.UNDERFS_OSS_CONNECT_MAX));
return ossClientConf;
}
use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class RequestTimeoutTest method setUp.
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
long ticks = new Date().getTime() / 1000 + new Random().nextInt(5000);
bucketName = BUCKET_NAME_PREFIX + ticks;
if (ossClient == null) {
ClientConfiguration config = new ClientConfiguration();
config.setRequestTimeout(requestTimeout);
config.setRequestTimeoutEnabled(true);
// config.setMaxConnections(1);
ossClient = new OSSClient(endpoint, accessId, accessKey, config);
ossClient.createBucket(bucketName);
}
}
use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ServiceClientTest method testRetryWithServiceException.
@Test
public void testRetryWithServiceException() throws Exception {
// This request will fail after 1 retries
ClientConfiguration config = new ClientConfiguration();
config.setMaxErrorRetry(1);
// It should be always successful.
int maxFailures = 0;
String content = "Let's retry!";
byte[] contentBytes = content.getBytes(OSSConstants.DEFAULT_CHARSET_NAME);
ByteArrayInputStream contentStream = new ByteArrayInputStream(contentBytes);
RequestMessage request = new RequestMessage(null, null);
request.setEndpoint(new URI("http://localhost"));
request.setMethod(HttpMethod.GET);
request.setContent(contentStream);
request.setContentLength(contentBytes.length);
ExecutionContext context = new ExecutionContext();
context.getResponseHandlers().add(new ResponseHandler() {
@Override
public void handle(ResponseMessage responseData) throws ServiceException, ClientException {
throw new ServiceException();
}
});
// This request will succeed after 2 retries
ServiceClientImpl client = new ServiceClientImpl(config, maxFailures, null, 500, content);
// Fix the max error retry count to 3
try {
client.sendRequest(request, context);
fail("ServiceException has not been thrown.");
} catch (ServiceException e) {
assertEquals(2, client.getRequestAttempts());
}
}
use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ServiceClientTest method testRetryWillSucceed.
@Test
public void testRetryWillSucceed() throws Exception {
// Fix the max error retry count to 3
final int MAX_RETRIES = 3;
ClientConfiguration config = new ClientConfiguration();
config.setMaxErrorRetry(MAX_RETRIES);
int maxFailures = 3;
final long skipBeforeSend = 3;
String content = "Let's retry!";
byte[] contentBytes = content.getBytes(OSSConstants.DEFAULT_CHARSET_NAME);
ByteArrayInputStream contentStream = new ByteArrayInputStream(contentBytes);
contentStream.skip(skipBeforeSend);
RequestMessage request = new RequestMessage(null, null);
request.setEndpoint(new URI("http://localhost"));
request.setMethod(HttpMethod.GET);
request.setContent(contentStream);
request.setContentLength(contentBytes.length - skipBeforeSend);
ExecutionContext context = new ExecutionContext();
ClientException exceptionToThrow = createRetryableException();
// This request will succeed after 2 retries
ServiceClientImpl client = new ServiceClientImpl(config, maxFailures, exceptionToThrow, 200, content.substring((int) skipBeforeSend));
client.sendRequest(request, context);
assertEquals(MAX_RETRIES + 1, client.getRequestAttempts());
}
use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ServiceClientTest method retryButFail.
private void retryButFail(final int maxRetries) throws UnsupportedEncodingException, URISyntaxException, ServiceException {
// This request will fail after 3 retries
ClientConfiguration config = new ClientConfiguration();
config.setMaxErrorRetry(maxRetries);
int maxFailures = 4;
String content = "Let's retry!";
byte[] contentBytes = content.getBytes(OSSConstants.DEFAULT_CHARSET_NAME);
ByteArrayInputStream contentStream = new ByteArrayInputStream(contentBytes);
RequestMessage request = new RequestMessage(null, null);
request.setEndpoint(new URI("http://localhost"));
request.setMethod(HttpMethod.GET);
request.setContent(contentStream);
request.setContentLength(contentBytes.length);
ExecutionContext context = new ExecutionContext();
ClientException exceptionToThrown = createRetryableException();
ServiceClientImpl client = new ServiceClientImpl(config, maxFailures, exceptionToThrown, 200, content);
try {
client.sendRequest(request, context);
fail("ClientException has not been thrown.");
} catch (ClientException e) {
assertEquals(exceptionToThrown, e);
assertEquals(maxRetries + 1, client.getRequestAttempts());
}
}
Aggregations