protected String getTimerAndMeterMapKeyForEndpoint(Endpoint<?> endpoint) { String methodsString = getMatchingHttpMethodsAsCombinedString(endpoint); //TODO: this might be odd for multi-path endpoints return methodsString + "-" + endpoint.requestMatcher().matchingPathTemplates(); }
@Test public void doChannelRead_calls_findSingleEndpointForExecution_then_sets_path_params_and_endpoint_on_state_then_returns_CONTINUE_if_msg_is_HttpRequest() { // given doReturn(Arrays.asList(defaultPath)).when(matcherMock).matchingPathTemplates(); HttpRequest msg = mock(HttpRequest.class); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg); // then verify(handlerSpy).findSingleEndpointForExecution(requestInfoMock); verify(requestInfoMock).setPathParamsBasedOnPathTemplate(defaultPath); verify(stateMock).setEndpointForExecution(endpointMock, defaultPath); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_nothing_if_msg_is_not_HttpRequest() { // given String pathTemplate = "/some/path/with/{id}"; Collection<String> pathTemplates = new ArrayList<String>() {{ add(pathTemplate); }}; doReturn(pathTemplates).when(matcherMock).matchingPathTemplates(); HttpObject msg = mock(HttpObject.class); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg); // then verify(handlerSpy).doChannelRead(ctxMock, msg); verifyNoMoreInteractions(handlerSpy); verifyNoMoreInteractions(requestInfoMock); verifyNoMoreInteractions(stateMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
/** * Adds metrics related to the given ServerConfig - usually gauges so you can inspect how the ServerConfig was setup. * Usually not needed - better to log this info on startup. */ protected void addServerConfigMetrics(ServerConfig config) { // add server config gauges metricsCollector.registerNamedMetric(serverConfigMetricNamingStrategy.nameFor(BOSS_THREADS), (Gauge<Integer>)config::numBossThreads); metricsCollector.registerNamedMetric(serverConfigMetricNamingStrategy.nameFor(WORKER_THREADS), (Gauge<Integer>)config::numWorkerThreads); metricsCollector.registerNamedMetric(serverConfigMetricNamingStrategy.nameFor(MAX_REQUEST_SIZE_IN_BYTES), (Gauge<Integer>)config::maxRequestSizeInBytes); List<String> endpointsList = config.appEndpoints() .stream() .map( endpoint -> endpoint.getClass().getName() + "-" + getMatchingHttpMethodsAsCombinedString(endpoint) + "-" + endpoint.requestMatcher().matchingPathTemplates() ) .collect(Collectors.toList()); metricsCollector.registerNamedMetric(serverConfigMetricNamingStrategy.nameFor(ENDPOINTS), (Gauge<List<String>>)() -> endpointsList); }
logger.info( "Registering endpoint that matches methods and paths: {}\t{}", matchingMethods, endpoint.requestMatcher().matchingPathTemplates() );
logger.info( "Registering endpoint that matches methods and paths: {}\t{}", matchingMethods, endpoint.requestMatcher().matchingPathTemplates() );
endpoint -> endpoint.getClass().getName() + "-" + instance.getMatchingHttpMethodsAsCombinedString(endpoint) + "-" + endpoint.requestMatcher().matchingPathTemplates()