Search in sources :

Example 1 with BuilderTagger

use of com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method ChainedMetricDimensionConfigurator_setupMetricWithDimensions_chains_calls_as_expected.

@Test
public void ChainedMetricDimensionConfigurator_setupMetricWithDimensions_chains_calls_as_expected() {
    // given
    MetricDimensionConfigurator first = mock(MetricDimensionConfigurator.class);
    MetricDimensionConfigurator second = mock(MetricDimensionConfigurator.class);
    ChainedMetricDimensionConfigurator instance = new ChainedMetricDimensionConfigurator(first, second);
    int responseStatusCode = 242;
    int responseStatusCodeXXValue = 2;
    long elapsedTimeMillis = 42;
    String endpointClass = UUID.randomUUID().toString();
    String method = UUID.randomUUID().toString();
    BuilderTagger origBuilderMock = mock(BuilderTagger.class);
    BuilderTagger firstResultBuilderMock = mock(BuilderTagger.class);
    BuilderTagger secondResultBuilderMock = mock(BuilderTagger.class);
    doReturn(firstResultBuilderMock).when(first).setupMetricWithDimensions(any(BuilderTagger.class), any(RequestInfo.class), any(ResponseInfo.class), any(HttpProcessingState.class), anyInt(), anyInt(), anyLong(), any(Endpoint.class), anyString(), anyString(), anyString());
    doReturn(secondResultBuilderMock).when(second).setupMetricWithDimensions(any(BuilderTagger.class), any(RequestInfo.class), any(ResponseInfo.class), any(HttpProcessingState.class), anyInt(), anyInt(), anyLong(), any(Endpoint.class), anyString(), anyString(), anyString());
    // when
    BuilderTagger finalResult = instance.setupMetricWithDimensions(origBuilderMock, requestInfoMock, responseInfoMock, httpStateMock, responseStatusCode, responseStatusCodeXXValue, elapsedTimeMillis, endpointMock, endpointClass, method, matchingPathTemplate);
    // then
    verify(first).setupMetricWithDimensions(origBuilderMock, requestInfoMock, responseInfoMock, httpStateMock, responseStatusCode, responseStatusCodeXXValue, elapsedTimeMillis, endpointMock, endpointClass, method, matchingPathTemplate);
    verify(second).setupMetricWithDimensions(firstResultBuilderMock, requestInfoMock, responseInfoMock, httpStateMock, responseStatusCode, responseStatusCodeXXValue, elapsedTimeMillis, endpointMock, endpointClass, method, matchingPathTemplate);
    assertThat(finalResult).isSameAs(secondResultBuilderMock);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) Endpoint(com.nike.riposte.server.http.Endpoint) MetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.MetricDimensionConfigurator) DefaultMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChainedMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator) Matchers.anyString(org.mockito.Matchers.anyString) RequestInfo(com.nike.riposte.server.http.RequestInfo) BuilderTagger(com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger) Endpoint(com.nike.riposte.server.http.Endpoint) Test(org.junit.Test)

Example 2 with BuilderTagger

use of com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method DefaultMetricDimensionConfigurator_setupMetricWithDimensions_works_as_expected.

@Test
public void DefaultMetricDimensionConfigurator_setupMetricWithDimensions_works_as_expected() {
    // given
    BuilderTagger builderMock = mock(BuilderTagger.class);
    doReturn(builderMock).when(builderMock).withMetricName(anyString());
    doReturn(builderMock).when(builderMock).withDimension(anyString(), anyString());
    String metricName = UUID.randomUUID().toString();
    String responseCodeDimKey = UUID.randomUUID().toString();
    String uriDimKey = UUID.randomUUID().toString();
    String methodDimKey = UUID.randomUUID().toString();
    String endpointDimKey = UUID.randomUUID().toString();
    DefaultMetricDimensionConfigurator instance = new DefaultMetricDimensionConfigurator(metricName, responseCodeDimKey, uriDimKey, methodDimKey, endpointDimKey);
    int responseStatusCode = 242;
    int responseStatusCodeXXValue = 2;
    long elapsedTimeMillis = 42;
    String endpointClass = UUID.randomUUID().toString();
    String method = UUID.randomUUID().toString();
    // when
    BuilderTagger result = instance.setupMetricWithDimensions(builderMock, requestInfoMock, responseInfoMock, httpStateMock, responseStatusCode, responseStatusCodeXXValue, elapsedTimeMillis, endpointMock, endpointClass, method, matchingPathTemplate);
    // then
    assertThat(result).isSameAs(builderMock);
    verify(builderMock).withMetricName(metricName);
    verify(builderMock).withDimension(responseCodeDimKey, String.valueOf(responseStatusCode));
    verify(builderMock).withDimension(uriDimKey, matchingPathTemplate);
    verify(builderMock).withDimension(methodDimKey, method);
    verify(builderMock).withDimension(endpointDimKey, endpointClass);
    verifyNoMoreInteractions(builderMock);
}
Also used : DefaultMetricDimensionConfigurator(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator) Matchers.anyString(org.mockito.Matchers.anyString) BuilderTagger(com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger) Endpoint(com.nike.riposte.server.http.Endpoint) Test(org.junit.Test)

Aggregations

DefaultMetricDimensionConfigurator (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.DefaultMetricDimensionConfigurator)2 Endpoint (com.nike.riposte.server.http.Endpoint)2 BuilderTagger (com.signalfx.codahale.reporter.MetricMetadata.BuilderTagger)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ChainedMetricDimensionConfigurator (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.ChainedMetricDimensionConfigurator)1 MetricDimensionConfigurator (com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.MetricDimensionConfigurator)1 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)1 RequestInfo (com.nike.riposte.server.http.RequestInfo)1 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)1