com.ibm.cloud.objectstorage.ClientConfiguration Java Examples
The following examples show how to use
com.ibm.cloud.objectstorage.ClientConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DummyResponseServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = TEST_TIMEOUT) public void requestTimeoutEnabled_ServerRespondsWithRetryableError_RetriesUpToLimitThenThrowsServerException() throws IOException { int maxRetries = 2; ClientConfiguration config = new ClientConfiguration().withRequestTimeout(25 * 1000) .withClientExecutionTimeout(25 * 1000).withMaxErrorRetry(maxRetries); HttpClientFactory<ConnectionManagerAwareHttpClient> httpClientFactory = new ApacheHttpClientFactory(); ConnectionManagerAwareHttpClient rawHttpClient = spy(httpClientFactory.create(HttpClientSettings.adapt(config))); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { httpClient.execute(newGetRequest(), new ErrorDuringUnmarshallingResponseHandler(), new NullErrorResponseHandler(), new ExecutionContext()); fail("Exception expected"); } catch (AmazonServiceException e) { assertEquals(e.getStatusCode(), STATUS_CODE); int expectedNumberOfRequests = 1 + maxRetries; assertNumberOfRetries(rawHttpClient, expectedNumberOfRequests); assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 0); assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 0); } }
Example #2
Source File: UnresponsiveServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = TEST_TIMEOUT) public void clientExecutionTimeoutEnabled_WithShorterRequestTimeout_ThrowsHttpRequestTimeoutException() throws IOException { httpClient = new AmazonHttpClient(new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT) .withRequestTimeout(SHORTER_REQUEST_TIMEOUT).withMaxErrorRetry(0)); try { httpClient.requestExecutionBuilder().request(newGetRequest()).execute(); fail("Exception expected"); } catch (AmazonClientException e) { assertThat(e.getCause(), instanceOf(HttpRequestTimeoutException.class)); // Completed tasks means the client execution was aborted by the timer assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 0); assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 1); } }
Example #3
Source File: MockedClientTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test public void clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse() throws Exception { ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT); ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config); HttpResponseProxy responseProxy = createHttpResponseProxySpy(); doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { httpClient.requestExecutionBuilder().request(createMockGetRequest()).execute(new ErrorDuringUnmarshallingResponseHandler().leaveConnectionOpen()); fail("Exception expected"); } catch (AmazonClientException e) { } assertResponseWasNotBuffered(responseProxy); }
Example #4
Source File: AmazonHttpClient.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
private AmazonHttpClient(ClientConfiguration clientConfig, RetryPolicy retryPolicy, RequestMetricCollector requestMetricCollector, HttpClientSettings httpClientSettings) { this.config = clientConfig; this.retryPolicy = retryPolicy == null ? new RetryPolicyAdapter(clientConfig.getRetryPolicy(), clientConfig) : retryPolicy; this.httpClientSettings = httpClientSettings; this.requestMetricCollector = requestMetricCollector; this.responseMetadataCache = clientConfig.getCacheResponseMetadata() ? new ResponseMetadataCache(clientConfig.getResponseMetadataCacheSize()) : new NullResponseMetadataCache(); this.httpRequestTimer = new HttpRequestTimer(); this.clientExecutionTimer = new ClientExecutionTimer(); // When enabled, total retry capacity is computed based on retry cost // and desired number of retries. int throttledRetryMaxCapacity = clientConfig.useThrottledRetries() ? THROTTLED_RETRY_COST * config.getMaxConsecutiveRetriesBeforeThrottling() : -1; this.retryCapacity = new CapacityManager(throttledRetryMaxCapacity); }
Example #5
Source File: MockedClientTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test public void clientExecutionTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered() throws Exception { ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(0); ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config); HttpResponseProxy responseProxy = createHttpResponseProxySpy(); doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { execute(httpClient, createMockGetRequest()); fail("Exception expected"); } catch (AmazonClientException e) { } assertResponseWasNotBuffered(responseProxy); }
Example #6
Source File: DummySuccessfulResponseServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
/** * Tests that a streaming operation has it's request properly cleaned up if the client is interrupted after the * response is received. * * @see TT0070103230 */ @Test public void clientInterruptedDuringResponseHandlers_DoesNotLeakConnection() throws IOException { ClientConfiguration config = new ClientConfiguration(); ConnectionManagerAwareHttpClient rawHttpClient = new ApacheHttpClientFactory().create(HttpClientSettings.adapt(config)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); interruptCurrentThreadAfterDelay(1000); List<RequestHandler2> requestHandlers = RequestHandlerTestUtils .buildRequestHandlerList(new SlowRequestHandler().withAfterResponseWaitInSeconds(10)); try { requestBuilder().executionContext(withHandlers(requestHandlers)).execute(new DummyResponseHandler().leaveConnectionOpen()); fail("Expected exception"); } catch (AmazonClientException e) { assertThat(e.getCause(), instanceOf(InterruptedException.class)); } @SuppressWarnings("deprecation") int leasedConnections = ((ConnPoolControl<?>) ((SdkHttpClient)rawHttpClient).getHttpClientConnectionManager()).getTotalStats().getLeased(); assertEquals(0, leasedConnections); }
Example #7
Source File: AmazonS3EncryptionClient.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
/** * @deprecated use {@link AmazonS3EncryptionClientBuilder#withEncryptionMaterials(EncryptionMaterialsProvider)} and * {@link AmazonS3EncryptionClientBuilder#withCredentials(AWSCredentialsProvider)} and * {@link AmazonS3EncryptionClientBuilder#withCryptoConfiguration(CryptoConfiguration)} and * {@link AmazonS3EncryptionClientBuilder#withClientConfiguration(ClientConfiguration)} and * {@link AmazonS3EncryptionClientBuilder#withMetricsCollector(RequestMetricCollector)} and * {@link AmazonS3EncryptionClientBuilder#withKmsClient(AWSKMS)} */ @Deprecated public AmazonS3EncryptionClient(AWSKMSClient kms, AWSCredentialsProvider credentialsProvider, EncryptionMaterialsProvider kekMaterialsProvider, ClientConfiguration clientConfig, CryptoConfiguration cryptoConfig, RequestMetricCollector requestMetricCollector) { super(credentialsProvider, clientConfig, requestMetricCollector); assertParameterNotNull(kekMaterialsProvider, "EncryptionMaterialsProvider parameter must not be null."); assertParameterNotNull(cryptoConfig, "CryptoConfiguration parameter must not be null."); this.isKMSClientInternal = kms == null; this.kms = isKMSClientInternal ? newAWSKMSClient(credentialsProvider, clientConfig, cryptoConfig, requestMetricCollector) : kms; this.crypto = new CryptoModuleDispatcher(this.kms, new S3DirectImpl(), credentialsProvider, kekMaterialsProvider, cryptoConfig); }
Example #8
Source File: UnresponsiveServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
/** * The client execution timer uses interrupts to abort the client but if another thread * interrupts the current thread for another reason we don't want to squash the * {@link InterruptedException}. We should set the thread's interrupted status and throw the * exception back out (we can't throw the actual {@link InterruptedException} because it's * checked) */ @Test(timeout = TEST_TIMEOUT) public void interruptCausedBySomethingOtherThanTimer_PropagatesInterruptToCaller() { final int socketTimeoutInMillis = 100; httpClient = new AmazonHttpClient(new ClientConfiguration().withSocketTimeout(socketTimeoutInMillis) .withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT) .withRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, new FixedTimeBackoffStrategy(CLIENT_EXECUTION_TIMEOUT), 1, false))); // We make sure the first connection has failed due to the socket timeout before // interrupting so we know that we are sleeping per the backoff strategy. Apache HTTP // client doesn't seem to honor interrupts reliably but Thread.sleep does interruptCurrentThreadAfterDelay(socketTimeoutInMillis * 2); try { httpClient.requestExecutionBuilder().request(newGetRequest()).execute(); fail("Exception expected"); } catch (AmazonClientException e) { assertTrue(Thread.currentThread().isInterrupted()); assertThat(e.getCause(), instanceOf(InterruptedException.class)); } }
Example #9
Source File: UnresponsiveServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = TEST_TIMEOUT) public void clientExecutionTimeoutEnabled_WithShorterRequestTimeoutAndRetry_ThrowsClientExecutionTimeoutException() throws IOException { final int clientExecutionTimeout = 1500; final int requestTimeout = 1000; final int backoffTime = 300; httpClient = new AmazonHttpClient(new ClientConfiguration().withClientExecutionTimeout(clientExecutionTimeout) .withRequestTimeout(requestTimeout) .withRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, new FixedTimeBackoffStrategy(backoffTime), Integer.MAX_VALUE, false))); try { httpClient.requestExecutionBuilder().request(newGetRequest()).execute(); fail("Exception expected"); } catch (AmazonClientException e) { assertThat(e, instanceOf(ClientExecutionTimeoutException.class)); // Completed tasks means the client execution was aborted by the timer assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 1); assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 1); } }
Example #10
Source File: AbortedExceptionClientExecutionTimerIntegrationTest.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(expected = ClientExecutionTimeoutException.class) public void clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_expired() throws Exception { ClientConfiguration config = new ClientConfiguration() .withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT) .withMaxErrorRetry(0); ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config); httpClient = new AmazonHttpClient(config, rawHttpClient, null); execute(httpClient, new EmptyHttpRequest(server.getEndpoint(), HttpMethodName.PUT, new SdkBufferedInputStream(new InputStream() { @Override public int read() throws IOException { // Sleeping here to avoid OOM issues from a limitless InputStream try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return 1; } }))); }
Example #11
Source File: UnresponsiveServerTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = TEST_TIMEOUT) public void requestTimeoutDisabledInRequestObject_TakesPrecedenceOverClientConfiguration() { final int socketTimeout = REQUEST_TIMEOUT; // Client configuration is set arbitrarily low so that the request will be aborted if // the client configuration is incorrectly honored over the request config httpClient = new AmazonHttpClient( new ClientConfiguration().withSocketTimeout(socketTimeout).withRequestTimeout(1).withMaxErrorRetry(0)); try { EmptyHttpRequest request = newGetRequest(); request.setOriginalRequest(new EmptyAmazonWebServiceRequest().withSdkRequestTimeout(0)); execute(httpClient, request); fail("Exception expected"); } catch (AmazonClientException e) { assertThat(e.getCause(), instanceOf(SocketTimeoutException.class)); } }
Example #12
Source File: ConnectionPoolMaxConnectionsIntegrationTest.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = 60 * 1000) public void leasing_a_new_connection_fails_with_connection_pool_timeout() throws Exception { String localhostEndpoint = "http://localhost:" + server.getPort(); AmazonHttpClient httpClient = new AmazonHttpClient( new ClientConfiguration() .withMaxConnections(1) .withConnectionTimeout(100) .withMaxErrorRetry(0)); Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET); // Block the first connection in the pool with this request. httpClient.requestExecutionBuilder().request(request).execute(new EmptyAWSResponseHandler()); try { // A new connection will be leased here which would fail in // ConnectionPoolTimeoutException. httpClient.requestExecutionBuilder().request(request).execute(); Assert.fail("Connection pool timeout exception is expected!"); } catch (AmazonClientException e) { Assert.assertTrue(e.getCause() instanceof ConnectionPoolTimeoutException); } }
Example #13
Source File: UnresponsiveServerTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = TEST_TIMEOUT) public void requestTimeoutSetInRequestObject_TakesPrecedenceOverClientConfiguration() { // Client configuration is set arbitrarily high so that the test will timeout if the // client configuration is incorrectly honored over the request config httpClient = new AmazonHttpClient(new ClientConfiguration().withSocketTimeout(LONGER_SOCKET_TIMEOUT) .withRequestTimeout(REQUEST_TIMEOUT * 1000).withMaxErrorRetry(0)); try { EmptyHttpRequest request = newGetRequest(); request.setOriginalRequest(new EmptyAmazonWebServiceRequest().withSdkRequestTimeout(REQUEST_TIMEOUT)); execute(httpClient, request); fail("Exception expected"); } catch (AmazonClientException e) { assertThat(e.getCause(), instanceOf(HttpRequestTimeoutException.class)); } }
Example #14
Source File: AwsClientBuilderTest.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
/** * If a custom executor is set then the Max Connections in Client Configuration should be * ignored and the executor should be used as is. */ @Test public void customMaxConnsAndExplicitExecutor_UsesExplicitExecutor() throws Exception { final int clientConfigMaxConns = 10; final int customExecutorThreadCount = 15; final ExecutorService customExecutor = Executors .newFixedThreadPool(customExecutorThreadCount); ExecutorService actualExecutor = builderWithRegion().withClientConfiguration( new ClientConfiguration().withMaxConnections(clientConfigMaxConns)) .withExecutorFactory(new StaticExecutorFactory(customExecutor)).build() .getAsyncParams().getExecutor(); assertThat(actualExecutor, instanceOf(ThreadPoolExecutor.class)); assertEquals(customExecutor, actualExecutor); assertEquals(customExecutorThreadCount, ((ThreadPoolExecutor) actualExecutor).getMaximumPoolSize()); }
Example #15
Source File: MockedClientTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test public void requestTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse() throws Exception { ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000); ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config); HttpResponseProxy responseProxy = createHttpResponseProxySpy(); doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { httpClient.requestExecutionBuilder().request(createMockGetRequest()).execute(new ErrorDuringUnmarshallingResponseHandler().leaveConnectionOpen()); fail("Exception expected"); } catch (AmazonClientException e) { } assertResponseWasNotBuffered(responseProxy); }
Example #16
Source File: MockedClientTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test public void requestTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered() throws Exception { ClientConfiguration config = new ClientConfiguration().withRequestTimeout(0); ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config); HttpResponseProxy responseProxy = createHttpResponseProxySpy(); doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { execute(httpClient, createMockGetRequest()); fail("Exception expected"); } catch (AmazonClientException e) { } assertResponseWasNotBuffered(responseProxy); }
Example #17
Source File: RuntimeHttpUtils.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
public static String getUserAgent(final ClientConfiguration config, final String userAgentMarker) { String userDefinedPrefix = config != null ? config.getUserAgentPrefix() : ""; String userDefinedSuffix = config != null ? config.getUserAgentSuffix() : ""; String awsExecutionEnvironment = getEnvironmentVariable(AWS_EXECUTION_ENV_NAME); StringBuilder userAgent = new StringBuilder(userDefinedPrefix.trim()); if(!ClientConfiguration.DEFAULT_USER_AGENT.equals(userDefinedPrefix)) { userAgent.append(COMMA).append(ClientConfiguration.DEFAULT_USER_AGENT); } if(StringUtils.hasValue(userDefinedSuffix)) { userAgent.append(COMMA).append(userDefinedSuffix.trim()); } if(StringUtils.hasValue(awsExecutionEnvironment)) { userAgent.append(SPACE).append(AWS_EXECUTION_ENV_PREFIX).append(awsExecutionEnvironment.trim()); } if(StringUtils.hasValue(userAgentMarker)) { userAgent.append(SPACE).append(userAgentMarker.trim()); } return userAgent.toString(); }
Example #18
Source File: MockedClientTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
/** * Response to HEAD requests don't have an entity so we shouldn't try to wrap the response in a * {@link BufferedHttpEntity}. */ @Test public void requestTimeoutEnabled_HeadRequestCompletesWithinTimeout_EntityNotBuffered() throws Exception { ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000).withMaxErrorRetry(0); ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config); HttpResponseProxy responseProxy = createHttpHeadResponseProxy(); doReturn(responseProxy).when(rawHttpClient).execute(any(HttpHead.class), any(HttpContext.class)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { execute(httpClient, createMockHeadRequest()); fail("Exception expected"); } catch (AmazonClientException e) { NullResponseHandler.assertIsUnmarshallingException(e); } assertNull(responseProxy.getEntity()); }
Example #19
Source File: ApacheDefaultHttpRequestFactoryTest.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test public void request_has_proxy_config_when_proxy_auth_enabled() throws Exception { List<ProxyAuthenticationMethod> authMethods = Arrays.asList(ProxyAuthenticationMethod.BASIC, ProxyAuthenticationMethod.DIGEST, ProxyAuthenticationMethod.KERBEROS, ProxyAuthenticationMethod.NTLM, ProxyAuthenticationMethod.SPNEGO); List<String> expectedAuthMethods = Arrays.asList(AuthSchemes.BASIC, AuthSchemes.DIGEST, AuthSchemes.KERBEROS, AuthSchemes.NTLM, AuthSchemes.SPNEGO); ClientConfiguration configuration = new ClientConfiguration().withProxyHost("localhost") .withProxyPort(80) .withProxyUsername("user") .withProxyPassword("password") .withProxyAuthenticationMethods(authMethods); HttpClientSettings settings = HttpClientSettings.adapt(configuration); HttpRequestBase requestBase = requestFactory.create(newDefaultRequest(HttpMethodName.POST), settings); Assert.assertEquals(expectedAuthMethods, requestBase.getConfig().getProxyPreferredAuthSchemes()); }
Example #20
Source File: AmazonHttpClientSslHandshakeTimeoutIntegrationTest.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = 60 * 1000) public void testSslHandshakeTimeout() { AmazonHttpClient httpClient = new AmazonHttpClient(new ClientConfiguration() .withSocketTimeout(CLIENT_SOCKET_TO).withMaxErrorRetry(0)); System.out.println("Sending request to localhost..."); try { httpClient.requestExecutionBuilder() .request(new EmptyHttpRequest(server.getHttpsEndpoint(), HttpMethodName.GET)) .execute(); fail("Client-side socket read timeout is expected!"); } catch (AmazonClientException e) { /** * Http client catches the SocketTimeoutException and throws a * ConnectTimeoutException. * {@link org.apache.http.impl.conn.DefaultHttpClientConnectionOperator#connect(ManagedHttpClientConnection, HttpHost, InetSocketAddress, int, SocketConfig, HttpContext)} */ Assert.assertTrue(e.getCause() instanceof ConnectTimeoutException); ConnectTimeoutException cte = (ConnectTimeoutException) e.getCause(); Assert.assertThat(cte.getMessage(), org.hamcrest.Matchers .containsString("Read timed out")); } }
Example #21
Source File: OverloadedServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Test(timeout = TEST_TIMEOUT) public void requestTimeoutEnabled_HonorsRetryPolicy() throws IOException { int maxRetries = 2; ClientConfiguration config = new ClientConfiguration().withRequestTimeout(1 * 1000) .withMaxErrorRetry(maxRetries); HttpClientFactory<ConnectionManagerAwareHttpClient> httpClientFactory = new ApacheHttpClientFactory(); ConnectionManagerAwareHttpClient rawHttpClient = spy(httpClientFactory.create(HttpClientSettings.adapt(config))); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { execute(httpClient, newGetRequest()); fail("Exception expected"); } catch (AmazonClientException e) { /* the expected exception and number of requests. */ assertThat(e.getCause(), instanceOf(HttpRequestTimeoutException.class)); int expectedNumberOfRequests = 1 + maxRetries; assertNumberOfRetries(rawHttpClient, expectedNumberOfRequests); assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), expectedNumberOfRequests); } }
Example #22
Source File: MockedClientTests.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
@Test public void clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_TaskCanceledAndEntityBuffered() throws Exception { ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT) .withMaxErrorRetry(0); ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config); HttpResponseProxy responseProxy = createHttpResponseProxySpy(); doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class)); httpClient = new AmazonHttpClient(config, rawHttpClient, null); try { execute(httpClient, createMockGetRequest()); fail("Exception expected"); } catch (AmazonClientException e) { NullResponseHandler.assertIsUnmarshallingException(e); } assertResponseIsBuffered(responseProxy); ScheduledThreadPoolExecutor requestTimerExecutor = httpClient.getClientExecutionTimer().getExecutor(); assertTimerNeverTriggered(requestTimerExecutor); assertCanceledTasksRemoved(requestTimerExecutor); // Core threads should be spun up on demand. Since only one task was submitted only one // thread should exist assertEquals(1, requestTimerExecutor.getPoolSize()); assertCoreThreadsShutDownAfterBeingIdle(requestTimerExecutor); }
Example #23
Source File: DummySuccessfulResponseServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
@Test(timeout = TEST_TIMEOUT, expected = ClientExecutionTimeoutException.class) public void clientExecutionTimeoutEnabled_SlowAfterResponseRequestHandler_ThrowsClientExecutionTimeoutException() throws Exception { httpClient = new AmazonHttpClient( new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT)); List<RequestHandler2> requestHandlers = RequestHandlerTestUtils.buildRequestHandlerList( new SlowRequestHandler().withAfterResponseWaitInSeconds(SLOW_REQUEST_HANDLER_TIMEOUT)); requestBuilder().executionContext(withHandlers(requestHandlers)).execute(new DummyResponseHandler()); }
Example #24
Source File: UnresponsiveServerIntegrationTests.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
@Test(timeout = TEST_TIMEOUT) public void clientExecutionTimeoutEnabled_WithShorterClientExecutionTimeout_ThrowsClientExecutionTimeoutException() throws IOException { httpClient = new AmazonHttpClient(new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT) .withRequestTimeout(LONGER_REQUEST_TIMEOUT).withMaxErrorRetry(0)); try { httpClient.requestExecutionBuilder().request(newGetRequest()).execute(); fail("Exception expected"); } catch (AmazonClientException e) { assertThat(e, instanceOf(ClientExecutionTimeoutException.class)); assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 1); assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 0); } }
Example #25
Source File: AmazonS3EncryptionClient.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
/** * @deprecated use {@link AmazonS3EncryptionClientBuilder#withEncryptionMaterials(EncryptionMaterialsProvider)} and * {@link AmazonS3EncryptionClientBuilder#withCredentials(AWSCredentialsProvider)} and * {@link AmazonS3EncryptionClientBuilder#withCryptoConfiguration(CryptoConfiguration)} and * {@link AmazonS3EncryptionClientBuilder#withClientConfiguration(ClientConfiguration)} and * {@link AmazonS3EncryptionClientBuilder#withMetricsCollector(RequestMetricCollector)} */ @Deprecated public AmazonS3EncryptionClient( AWSCredentialsProvider credentialsProvider, EncryptionMaterialsProvider kekMaterialsProvider, ClientConfiguration clientConfig, CryptoConfiguration cryptoConfig, RequestMetricCollector requestMetricCollector) { this(null, // KMS client credentialsProvider, kekMaterialsProvider, clientConfig, cryptoConfig, requestMetricCollector); }
Example #26
Source File: ClientSideMonitoringRequestHandler.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
/** * Get the default user agent and append the user agent marker if there are any. */ private String getDefaultUserAgent(Request<?> request) { String userAgentMarker = request.getOriginalRequest().getRequestClientOptions().getClientMarker(RequestClientOptions .Marker.USER_AGENT); String userAgent = ClientConfiguration.DEFAULT_USER_AGENT; if (StringUtils.hasValue(userAgentMarker)) { userAgent += " " + userAgentMarker; } return userAgent; }
Example #27
Source File: ApacheDefaultHttpRequestFactoryTest.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
@Test public void request_has_no_proxy_config_when_proxy_auth_disabled() throws Exception { List<ProxyAuthenticationMethod> authMethods = Collections.singletonList(ProxyAuthenticationMethod.BASIC); ClientConfiguration configuration = new ClientConfiguration().withProxyHost("localhost") .withProxyPort(80) .withProxyAuthenticationMethods(authMethods); HttpClientSettings settings = HttpClientSettings.adapt(configuration); HttpRequestBase requestBase = requestFactory.create(newDefaultRequest(HttpMethodName.POST), settings); Assert.assertThat(requestBase.getConfig().getProxyPreferredAuthSchemes(), Matchers.nullValue()); }
Example #28
Source File: AmazonHttpClientIntegrationTest.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
@Test public void canHandleOptionsRequest() throws Exception { Request<?> request = newRequest(OPERATION); request.setHttpMethod(HttpMethodName.OPTIONS); AmazonHttpClient sut = new AmazonHttpClient(new ClientConfiguration()); sut.requestExecutionBuilder().request(request).execute(); verify(optionsRequestedFor(urlPathEqualTo(OPERATION))); }
Example #29
Source File: AwsClientBuilderTest.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
@Test public void customMaxConnsAndNoExplicitExecutor_UsesDefaultExecutorBasedOnMaxConns() { final int maxConns = 10; ExecutorService executor = builderWithRegion() .withClientConfiguration(new ClientConfiguration().withMaxConnections(maxConns)) .build().getAsyncParams().getExecutor(); assertThat(executor, instanceOf(ThreadPoolExecutor.class)); assertEquals(maxConns, ((ThreadPoolExecutor) executor).getMaximumPoolSize()); }
Example #30
Source File: AmazonS3EncryptionClient.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
/** * @deprecated use {@link AmazonS3EncryptionClientBuilder#withEncryptionMaterials(EncryptionMaterialsProvider)} and * {@link AmazonS3EncryptionClientBuilder#withCredentials(AWSCredentialsProvider)} and * {@link AmazonS3EncryptionClientBuilder#withCryptoConfiguration(CryptoConfiguration)} and * {@link AmazonS3EncryptionClientBuilder#withClientConfiguration(ClientConfiguration)} */ @Deprecated public AmazonS3EncryptionClient( AWSCredentialsProvider credentialsProvider, EncryptionMaterialsProvider kekMaterialsProvider, ClientConfiguration clientConfig, CryptoConfiguration cryptoConfig) { this(credentialsProvider, kekMaterialsProvider, clientConfig, cryptoConfig, null // request metric collector ); }