use of com.aliyun.oss.common.comm.ExecutionContext in project aliyun-oss-java-sdk by aliyun.
the class ServiceClientTest method testRetryWithNoneMarkSupportedStream.
@Test
public void testRetryWithNoneMarkSupportedStream() throws Exception {
String filename = ResourceUtils.getTestFilename("oss/listBucket.xml");
File file = new File(filename);
InputStream contentStream = new FileInputStream(file);
RequestMessage request = new RequestMessage(null, null);
request.setEndpoint(new URI("http://localhost"));
request.setMethod(HttpMethod.GET);
request.setContent(contentStream);
request.setContentLength(file.length());
ExecutionContext context = new ExecutionContext();
ClientException exceptionToThrown = createRetryableException();
String content = "";
InputStream contentStream2 = new FileInputStream(file);
try {
content = StreamUtils.readContent(contentStream2, "utf-8");
} finally {
contentStream2.close();
}
// This request will succeed after 2 retries
ServiceClientImpl client = new ServiceClientImpl(new ClientConfiguration(), 3, exceptionToThrown, 400, content);
// Fix the max error retry count to 3
try {
client.sendRequest(request, context);
fail("ClientException has not been thrown.");
} catch (ClientException e) {
assertEquals(exceptionToThrown, e);
assertEquals(1, client.getRequestAttempts());
}
}
Aggregations