use of io.gravitee.reporter.api.http.Metrics in project gravitee-gateway by gravitee-io.
the class DefaultInvokerTest method shouldInvokeEndpointWithEncodedTargetURI.
@Test
public void shouldInvokeEndpointWithEncodedTargetURI() {
final String targetUri = "http://host:8080/test toto tété/titi";
final String expectedTargetUri = "http://host:8080/test%20toto%20%20t%C3%A9t%C3%A9/titi";
when(executionContext.getAttribute(ExecutionContext.ATTR_REQUEST_ENDPOINT)).thenReturn(targetUri);
when(endpoint.available()).thenReturn(true);
when(endpoint.target()).thenReturn("/test");
when(endpoint.headers()).thenReturn(httpHeaders);
when(endpoint.available()).thenReturn(true);
when(endpoint.connector()).thenReturn(connector);
when(connector.request(any(ProxyRequest.class))).thenReturn(proxyConnection);
when(endpointManager.endpoints()).thenReturn(singleton(endpoint));
final Metrics metrics = Metrics.on(System.currentTimeMillis()).build();
when(serverRequest.metrics()).thenReturn(metrics);
when(serverRequest.headers()).thenReturn(httpHeaders);
when(api.getProxy()).thenReturn(proxy);
when(proxy.getLoggingMode()).thenReturn(LoggingMode.NONE);
when(stream.bodyHandler(any(Handler.class))).thenReturn(stream);
invoker.invoke(executionContext, serverRequest, stream, connectionHandler);
Assert.assertEquals(expectedTargetUri, metrics.getEndpoint());
}
use of io.gravitee.reporter.api.http.Metrics in project gravitee-gateway by gravitee-io.
the class TransactionHandlerTest method shouldHaveTransactionId.
@Test
public void shouldHaveTransactionId() throws InterruptedException {
final CountDownLatch lock = new CountDownLatch(1);
when(request.id()).thenReturn(UUID.toString(UUID.random()));
new TransactionHandler(request1 -> {
assertNotNull(request1.transactionId());
assertEquals(request1.transactionId(), request1.headers().getFirst(TransactionHandler.DEFAULT_TRANSACTIONAL_ID_HEADER));
assertEquals(request1.transactionId(), request1.metrics().getTransactionId());
assertEquals(request1.transactionId(), response.headers().getFirst(TransactionHandler.DEFAULT_TRANSACTIONAL_ID_HEADER));
lock.countDown();
}, response).handle(request);
assertEquals(true, lock.await(10000, TimeUnit.MILLISECONDS));
}
use of io.gravitee.reporter.api.http.Metrics in project gravitee-gateway by gravitee-io.
the class TransactionHandlerTest method shouldPropagateSameTransactionIdWithCustomHeader.
@Test
public void shouldPropagateSameTransactionIdWithCustomHeader() throws InterruptedException {
final CountDownLatch lock = new CountDownLatch(1);
String transactionId = UUID.toString(UUID.random());
request.headers().set(CUSTOM_TRANSACTION_ID_HEADER, transactionId);
new TransactionHandler(CUSTOM_TRANSACTION_ID_HEADER, request1 -> {
assertNotNull(request1.transactionId());
assertEquals(transactionId, request1.transactionId());
assertEquals(transactionId, request1.headers().getFirst(CUSTOM_TRANSACTION_ID_HEADER));
assertEquals(transactionId, request1.metrics().getTransactionId());
assertEquals(request1.transactionId(), response.headers().getFirst(CUSTOM_TRANSACTION_ID_HEADER));
lock.countDown();
}, response).handle(request);
assertEquals(true, lock.await(10000, TimeUnit.MILLISECONDS));
}
use of io.gravitee.reporter.api.http.Metrics in project gravitee-gateway by gravitee-io.
the class RequestPolicyChainTest method doNext_multiplePolicy_throwError.
@Test
public void doNext_multiplePolicy_throwError() throws Exception {
ExecutionContext executionContext = mock(ExecutionContext.class);
Request request = mock(Request.class);
Metrics metrics = Metrics.on(System.currentTimeMillis()).build();
when(request.metrics()).thenReturn(metrics);
PolicyChain chain = RequestPolicyChain.create(policies3(), executionContext);
chain.setResultHandler(result -> {
});
chain.doNext(request, null);
verify(request, atLeastOnce()).metrics();
verify(policy3, atLeastOnce()).onRequest(request, null, chain, executionContext);
verify(policy2, never()).onRequest(request, null, chain);
}
use of io.gravitee.reporter.api.http.Metrics in project gravitee-gateway by gravitee-io.
the class ResponsePolicyChainTest method doNext_multiplePolicy_throwError.
@Test
public void doNext_multiplePolicy_throwError() throws Exception {
ExecutionContext executionContext = mock(ExecutionContext.class);
Request request = mock(Request.class);
Metrics metrics = Metrics.on(System.currentTimeMillis()).build();
when(request.metrics()).thenReturn(metrics);
PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy2, policy3), executionContext);
chain.setResultHandler(result -> {
});
chain.doNext(request, null);
verify(request, atLeastOnce()).metrics();
verify(policy3, atLeastOnce()).onResponse(request, null, chain, executionContext);
verify(policy2, never()).onResponse(request, null, chain, executionContext);
}
Aggregations