Search in sources :

Example 6 with MetricPublisher

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

the class AsyncClientMetricPublisherResolutionTest 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))).join();
    } 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) Mock(org.mockito.Mock) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) RunWith(org.junit.runner.RunWith) 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) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) ProtocolRestJsonAsyncClientBuilder(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClientBuilder) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) ProtocolRestJsonException(software.amazon.awssdk.services.protocolrestjson.model.ProtocolRestJsonException) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Rule(org.junit.Rule) 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 7 with MetricPublisher

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

the class CoreMetricsTest method testApiCall_publisherOverriddenOnRequest_requestPublisherTakesPrecedence.

@Test
public void testApiCall_publisherOverriddenOnRequest_requestPublisherTakesPrecedence() {
    MetricPublisher requestMetricPublisher = mock(MetricPublisher.class);
    client.allTypes(r -> r.overrideConfiguration(o -> o.addMetricPublisher(requestMetricPublisher)));
    verify(requestMetricPublisher).publish(any(MetricCollection.class));
    verifyNoMoreInteractions(mockPublisher);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Mock(org.mockito.Mock) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) EmptyModeledException(software.amazon.awssdk.services.protocolrestjson.model.EmptyModeledException) Duration(java.time.Duration) After(org.junit.After) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) Region(software.amazon.awssdk.regions.Region) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) HttpMetric(software.amazon.awssdk.http.HttpMetric) 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) PaginatedOperationWithResultKeyIterable(software.amazon.awssdk.services.protocolrestjson.paginators.PaginatedOperationWithResultKeyIterable) Collectors(java.util.stream.Collectors) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) Mockito.verify(org.mockito.Mockito.verify) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) List(java.util.List) Rule(org.junit.Rule) SimpleStruct(software.amazon.awssdk.services.protocolrestjson.model.SimpleStruct) 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 8 with MetricPublisher

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

the class CoreMetricsTest method testPaginatingApiCall_publisherOverriddenOnRequest_requestPublisherTakesPrecedence.

@Test
public void testPaginatingApiCall_publisherOverriddenOnRequest_requestPublisherTakesPrecedence() {
    MetricPublisher requestMetricPublisher = mock(MetricPublisher.class);
    PaginatedOperationWithResultKeyIterable iterable = client.paginatedOperationWithResultKeyPaginator(r -> r.overrideConfiguration(o -> o.addMetricPublisher(requestMetricPublisher)));
    List<SimpleStruct> resultingItems = iterable.items().stream().collect(Collectors.toList());
    verify(requestMetricPublisher).publish(any(MetricCollection.class));
    verifyNoMoreInteractions(mockPublisher);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Mock(org.mockito.Mock) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) EmptyModeledException(software.amazon.awssdk.services.protocolrestjson.model.EmptyModeledException) Duration(java.time.Duration) After(org.junit.After) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) Region(software.amazon.awssdk.regions.Region) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) HttpMetric(software.amazon.awssdk.http.HttpMetric) 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) PaginatedOperationWithResultKeyIterable(software.amazon.awssdk.services.protocolrestjson.paginators.PaginatedOperationWithResultKeyIterable) Collectors(java.util.stream.Collectors) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) Mockito.verify(org.mockito.Mockito.verify) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) List(java.util.List) Rule(org.junit.Rule) SimpleStruct(software.amazon.awssdk.services.protocolrestjson.model.SimpleStruct) 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) PaginatedOperationWithResultKeyIterable(software.amazon.awssdk.services.protocolrestjson.paginators.PaginatedOperationWithResultKeyIterable) SimpleStruct(software.amazon.awssdk.services.protocolrestjson.model.SimpleStruct) Test(org.junit.Test)

Example 9 with MetricPublisher

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

the class ClientOverrideConfigurationTest method metricPublishers_overwritesPreviouslyAdded.

@Test
public void metricPublishers_overwritesPreviouslyAdded() {
    MetricPublisher firstAdded = mock(MetricPublisher.class);
    List<MetricPublisher> publishers = new ArrayList<>();
    publishers.add(mock(MetricPublisher.class));
    publishers.add(mock(MetricPublisher.class));
    ClientOverrideConfiguration.Builder builder = ClientOverrideConfiguration.builder();
    builder.addMetricPublisher(firstAdded);
    builder.metricPublishers(publishers);
    ClientOverrideConfiguration overrideConfig = builder.build();
    assertThat(overrideConfig.metricPublishers()).isEqualTo(publishers);
}
Also used : ArrayList(java.util.ArrayList) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) Test(org.junit.jupiter.api.Test)

Example 10 with MetricPublisher

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

the class ClientOverrideConfigurationTest method addMetricPublisher_listPreviouslyAdded_appendedToList.

@Test
public void addMetricPublisher_listPreviouslyAdded_appendedToList() {
    List<MetricPublisher> publishers = new ArrayList<>();
    publishers.add(mock(MetricPublisher.class));
    publishers.add(mock(MetricPublisher.class));
    MetricPublisher thirdAdded = mock(MetricPublisher.class);
    ClientOverrideConfiguration.Builder builder = ClientOverrideConfiguration.builder();
    builder.metricPublishers(publishers);
    builder.addMetricPublisher(thirdAdded);
    ClientOverrideConfiguration overrideConfig = builder.build();
    assertThat(overrideConfig.metricPublishers()).containsExactly(publishers.get(0), publishers.get(1), thirdAdded);
}
Also used : ArrayList(java.util.ArrayList) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) Test(org.junit.jupiter.api.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