Search in sources :

Example 1 with MetricPublisher

use of software.amazon.awssdk.metrics.MetricPublisher in project aws-sdk-java-v2 by aws.

the class SyncClientMetricPublisherResolutionTest method testApiCall_publishersSetOnClient_clientPublishersInvoked.

@Test
public void testApiCall_publishersSetOnClient_clientPublishersInvoked() throws IOException {
    MetricPublisher publisher1 = mock(MetricPublisher.class);
    MetricPublisher publisher2 = mock(MetricPublisher.class);
    client = clientWithPublishers(publisher1, publisher2);
    try {
        client.allTypes();
    } catch (Throwable t) {
    // ignored, call fails because our mock HTTP client isn't set up
    } finally {
        verify(publisher1).publish(any(MetricCollection.class));
        verify(publisher2).publish(any(MetricCollection.class));
    }
}
Also used : MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) Test(org.junit.Test)

Example 2 with MetricPublisher

use of software.amazon.awssdk.metrics.MetricPublisher in project aws-sdk-java-v2 by aws.

the class SyncClientMetricPublisherResolutionTest method testApiCall_publishersSetOnClientAndRequest_requestPublishersInvoked.

@Test
public void testApiCall_publishersSetOnClientAndRequest_requestPublishersInvoked() throws IOException {
    MetricPublisher clientPublisher1 = mock(MetricPublisher.class);
    MetricPublisher clientPublisher2 = mock(MetricPublisher.class);
    MetricPublisher requestPublisher1 = mock(MetricPublisher.class);
    MetricPublisher requestPublisher2 = mock(MetricPublisher.class);
    client = clientWithPublishers(clientPublisher1, clientPublisher2);
    try {
        client.allTypes(r -> r.overrideConfiguration(o -> o.addMetricPublisher(requestPublisher1).addMetricPublisher(requestPublisher2)));
    } catch (Throwable t) {
    // ignored, call fails because our mock HTTP client isn't set up
    } finally {
        verify(requestPublisher1).publish(any(MetricCollection.class));
        verify(requestPublisher2).publish(any(MetricCollection.class));
        verifyNoMoreInteractions(clientPublisher1);
        verifyNoMoreInteractions(clientPublisher2);
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Mock(org.mockito.Mock) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) RunWith(org.junit.runner.RunWith) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) ByteArrayInputStream(java.io.ByteArrayInputStream) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) After(org.junit.After) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) Region(software.amazon.awssdk.regions.Region) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) Mockito.verify(org.mockito.Mockito.verify) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) ProtocolRestJsonClientBuilder(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClientBuilder) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) Test(org.junit.Test)

Example 3 with MetricPublisher

use of software.amazon.awssdk.metrics.MetricPublisher in project aws-sdk-java-v2 by aws.

the class SyncClientMetricPublisherResolutionTest method testApiCall_publishersSetOnRequest_requestPublishersInvoked.

@Test
public void testApiCall_publishersSetOnRequest_requestPublishersInvoked() throws IOException {
    MetricPublisher publisher1 = mock(MetricPublisher.class);
    MetricPublisher publisher2 = mock(MetricPublisher.class);
    client = clientWithPublishers();
    try {
        client.allTypes(r -> r.overrideConfiguration(o -> o.addMetricPublisher(publisher1).addMetricPublisher(publisher2)));
    } catch (Throwable t) {
    // ignored, call fails because our mock HTTP client isn't set up
    } finally {
        verify(publisher1).publish(any(MetricCollection.class));
        verify(publisher2).publish(any(MetricCollection.class));
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Mock(org.mockito.Mock) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) RunWith(org.junit.runner.RunWith) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) ByteArrayInputStream(java.io.ByteArrayInputStream) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) After(org.junit.After) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) Region(software.amazon.awssdk.regions.Region) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) Mockito.verify(org.mockito.Mockito.verify) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) ProtocolRestJsonClientBuilder(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClientBuilder) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) Test(org.junit.Test)

Example 4 with MetricPublisher

use of software.amazon.awssdk.metrics.MetricPublisher in project aws-sdk-java-v2 by aws.

the class AsyncCoreMetricsTest method apiCall_publisherOverriddenOnRequest_requestPublisherTakesPrecedence.

@Test
public void apiCall_publisherOverriddenOnRequest_requestPublisherTakesPrecedence() {
    stubSuccessfulResponse();
    MetricPublisher requestMetricPublisher = mock(MetricPublisher.class);
    client.allTypes(r -> r.overrideConfiguration(o -> o.addMetricPublisher(requestMetricPublisher))).join();
    verify(requestMetricPublisher).publish(any(MetricCollection.class));
    verifyNoMoreInteractions(mockPublisher);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) PaginatedOperationWithResultKeyPublisher(software.amazon.awssdk.services.protocolrestjson.paginators.PaginatedOperationWithResultKeyPublisher) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) After(org.junit.After) URI(java.net.URI) Region(software.amazon.awssdk.regions.Region) PaginatedOperationWithResultKeyResponse(software.amazon.awssdk.services.protocolrestjson.model.PaginatedOperationWithResultKeyResponse) Before(org.junit.Before) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PaginatedOperationWithResultKeyIterable(software.amazon.awssdk.services.protocolrestjson.paginators.PaginatedOperationWithResultKeyIterable) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Rule(org.junit.Rule) SimpleStruct(software.amazon.awssdk.services.protocolrestjson.model.SimpleStruct) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) Mockito.mock(org.mockito.Mockito.mock) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) Test(org.junit.Test)

Example 5 with MetricPublisher

use of software.amazon.awssdk.metrics.MetricPublisher in project aws-sdk-java-v2 by aws.

the class AsyncClientMetricPublisherResolutionTest method testApiCall_publishersSetOnClient_clientPublishersInvoked.

@Test
public void testApiCall_publishersSetOnClient_clientPublishersInvoked() throws IOException {
    MetricPublisher publisher1 = mock(MetricPublisher.class);
    MetricPublisher publisher2 = mock(MetricPublisher.class);
    client = clientWithPublishers(publisher1, publisher2);
    try {
        client.allTypes().join();
    } catch (Throwable t) {
    // ignored, call fails because our mock HTTP client isn't set up
    } finally {
        verify(publisher1).publish(any(MetricCollection.class));
        verify(publisher2).publish(any(MetricCollection.class));
    }
}
Also used : MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) Test(org.junit.Test)

Aggregations

MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)80 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)64 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)64 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)59 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)47 List (java.util.List)40 CompletableFuture (java.util.concurrent.CompletableFuture)36 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)36 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)36 CoreMetric (software.amazon.awssdk.core.metrics.CoreMetric)36 JsonOperationMetadata (software.amazon.awssdk.protocols.json.JsonOperationMetadata)35 Collections (java.util.Collections)34 Logger (org.slf4j.Logger)34 LoggerFactory (org.slf4j.LoggerFactory)34 Generated (software.amazon.awssdk.annotations.Generated)34 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)34 AwsAsyncClientHandler (software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler)34 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)34 AsyncClientHandler (software.amazon.awssdk.core.client.handler.AsyncClientHandler)34 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)34