Search in sources :

Example 6 with ExecutionContext

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());
    }
}
Also used : ExecutionContext(com.aliyun.oss.common.comm.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) ClientException(com.aliyun.oss.ClientException) File(java.io.File) URI(java.net.URI) FileInputStream(java.io.FileInputStream) ClientConfiguration(com.aliyun.oss.ClientConfiguration) Test(org.junit.Test)

Aggregations

ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)6 ClientConfiguration (com.aliyun.oss.ClientConfiguration)4 ClientException (com.aliyun.oss.ClientException)4 RequestMessage (com.aliyun.oss.common.comm.RequestMessage)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 URI (java.net.URI)4 Test (org.junit.Test)3 ResponseHandler (com.aliyun.oss.common.comm.ResponseHandler)2 ResponseMessage (com.aliyun.oss.common.comm.ResponseMessage)2 OSSException (com.aliyun.oss.OSSException)1 ServiceException (com.aliyun.oss.ServiceException)1 RequestSigner (com.aliyun.oss.common.auth.RequestSigner)1 RequestChecksumHanlder (com.aliyun.oss.common.comm.RequestChecksumHanlder)1 RequestHandler (com.aliyun.oss.common.comm.RequestHandler)1 RequestProgressHanlder (com.aliyun.oss.common.comm.RequestProgressHanlder)1 ResponseChecksumHandler (com.aliyun.oss.common.comm.ResponseChecksumHandler)1 ResponseProgressHandler (com.aliyun.oss.common.comm.ResponseProgressHandler)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 WebServiceRequest (com.aliyun.oss.model.WebServiceRequest)1 File (java.io.File)1