com.amazonaws.http.ExecutionContext.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中com.amazonaws.http.ExecutionContext.<init>()方法的一些代码示例,展示了ExecutionContext.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExecutionContext.<init>()方法的具体详情如下:
包路径:com.amazonaws.http.ExecutionContext
类名称:ExecutionContext
方法名:<init>

ExecutionContext.<init>介绍

[英]For testing purposes.
[中]用于测试目的。

代码示例

代码示例来源:origin: aws/aws-sdk-java

public ExecutionContext build() {
  return new ExecutionContext(this);
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

public ExecutionContext build() {
  return new ExecutionContext(this);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * @deprecated by {@link #createExecutionContext(AmazonWebServiceRequest)}.
 *             This method exists only for backward compatiblity reason, so
 *             that clients compiled against the older version of this class
 *             won't get {@link NoSuchMethodError} at runtime. However,
 *             calling this methods would effectively ignore and disable the
 *             request metric collector, if any, specified at the request
 *             level. Request metric collector specified at the service
 *             client or AWS SDK level will still be honored.
 */
@Deprecated
protected final ExecutionContext createExecutionContext() {
  final boolean isMetricsEnabled = isRMCEnabledAtClientOrSdkLevel() || isProfilingEnabled();
  return new ExecutionContext(requestHandler2s, isMetricsEnabled, this);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

protected ExecutionContext createExecutionContext(final AmazonWebServiceRequest req) {
  final boolean isMetricsEnabled = isRequestMetricsEnabled(req) || isProfilingEnabled();
  return new ExecutionContext(requestHandler2s, isMetricsEnabled, this);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * Build a {@link HttpRequest} object for the given method.
 *
 * @param method method that annotated with {@link Operation}
 * @param args arguments of the method
 * @return a {@link HttpRequest} object
 */
HttpRequest createHttpRequest(Method method, Object[] args) {
  final Request<?> request = buildRequest(method, args);
  final ExecutionContext context = new ExecutionContext();
  String userAgent = apiName;
  if (request.getHeaders().containsKey("User-Agent")) {
    // append it to execution context
    userAgent += " " + request.getHeaders().get("User-Agent");
  }
  context.setContextUserAgent(userAgent);
  return requestFactory.createHttpRequest(request, clientConfiguration, context);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Before
public void setup() {
  factory = new HttpRequestFactory();
  request = new DefaultRequest<Object>("dummy");
  request.setEndpoint(URI.create("https://s3.amazonaws.com"));
  clientConfiguration = new ClientConfiguration();
  context = new ExecutionContext();
}

代码示例来源:origin: aws-amplify/aws-sdk-android

HttpRequest invokeExecuteMethod(Object[] args) {
  final ExecutionContext context = new ExecutionContext();
  final Request<?> request = ((ApiRequest) args[0]).getRequest();
  if (request.getEndpoint() == null) {
    request.setEndpoint(URI.create(endpoint));
  }
  String userAgent = apiName;
  if (request.getHeaders().containsKey("User-Agent")) {
    // append it to execution context
    userAgent += " " + request.getHeaders().get("User-Agent");
  }
  context.setContextUserAgent(userAgent);
  // add the api key
  if (apiKey != null) {
    request.addHeader("x-api-key", apiKey);
  }
  // sign the request
  if (provider != null && signer != null) {
    signer.sign(request, provider.getCredentials());
  }
  return requestFactory.createHttpRequest(request, clientConfiguration, context);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

ExecutionContext ec = new ExecutionContext(handlers, false, null);
client.requestHandler2s(testRequest, ec);
assertEquals(calls.size(), 2);

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
   * Verifies the request is actually retried for the expected times.
   */
  private static void testActualRetries(int expectedRetryAttempts) {
    // The ExecutionContext should collect the expected RequestCount
    ExecutionContext context = new ExecutionContext(true);

    try {
      testedClient.execute(getSampleRequestWithRepeatableContent(originalRequest),
          null,
          errorResponseHandler,
          context);
      Assert.fail("AmazonServiceException is expected.");
    } catch (AmazonServiceException ase) {
    }

    // Check the RequestCount metric equals the expected value.
    Assert.assertEquals(
        expectedRetryAttempts + 1, // request count = retries + 1
        context.getAwsRequestMetrics()
            .getTimingInfo()
            .getCounter(AWSRequestMetrics.Field.RequestCount.toString()).intValue());
  }
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testRetryIOExceptionFromExecute() throws IOException {
  IOException exception = new IOException("BOOM");
  EasyMock
      .expect(httpClient.execute(EasyMock.<HttpRequest> anyObject()))
      .andThrow(exception)
      .times(4);
  EasyMock.replay(httpClient);
  ExecutionContext context = new ExecutionContext();
  Request<?> request = new DefaultRequest<Object>("testsvc");
  request.setEndpoint(java.net.URI.create(
      "http://testsvc.region.amazonaws.com"));
  request.addHeader(HttpHeader.CONTENT_LENGTH, "0");
  request.setContent(new ByteArrayInputStream(new byte[0]));
  try {
    client.execute(request, null, null, context);
    Assert.fail("No exception when request repeatedly fails!");
  } catch (AmazonClientException e) {
    Assert.assertSame(exception, e.getCause());
  }
  // Verify that we called execute 4 times.
  EasyMock.verify(httpClient);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

ExecutionContext context = new ExecutionContext();

代码示例来源:origin: aws-amplify/aws-sdk-android

ExecutionContext context = new ExecutionContext(true);

代码示例来源:origin: aws-amplify/aws-sdk-android

ExecutionContext context = new ExecutionContext(true);

代码示例来源:origin: aws-amplify/aws-sdk-android

ExecutionContext context = new ExecutionContext(true);

代码示例来源:origin: aws-amplify/aws-sdk-android

ExecutionContext context = new ExecutionContext(true);

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test(expected = RuntimeException.class)
public void testHandleResponseWithNullResult() throws IOException {
  Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse")
      .statusCode(200).build();
  HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() {
    @Override
    public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      return null;
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  client.handleResponse(request, responseHandler, httpResponse,
      new ExecutionContext());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test(expected = Exception.class)
public void testHandleResponseThrowsGenericException() throws IOException {
  Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse")
      .statusCode(200).build();
  HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() {
    @Override
    public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      throw new Exception("test");
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  client.handleResponse(request, responseHandler, httpResponse,
      new ExecutionContext());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test(expected = CRC32MismatchException.class)
public void testHandleResponseThrowsCRC32MisMatch() throws IOException {
  Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse")
      .statusCode(200).build();
  HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() {
    @Override
    public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      throw new CRC32MismatchException("test");
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  client.handleResponse(request, responseHandler, httpResponse,
      new ExecutionContext());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test(expected = IOException.class)
public void testHandleResponseThrowsIOException() throws IOException {
  Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse")
      .statusCode(200).build();
  HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() {
    @Override
    public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      throw new IOException("test");
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  client.handleResponse(request, responseHandler, httpResponse,
      new ExecutionContext());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testHandleResponse() throws IOException {
  Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse")
      .statusCode(200).build();
  HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() {
    @Override
    public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      AmazonWebServiceResponse<String> awsResponse = new AmazonWebServiceResponse<String>();
      awsResponse.setResult("Result");
      return awsResponse;
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  assertEquals("Result", client.handleResponse(request, responseHandler, httpResponse,
      new ExecutionContext()));
}

相关文章