Search in sources :

Example 6 with Metrics

use of io.gravitee.reporter.api.http.Metrics in project gravitee-gateway by gravitee-io.

the class TransactionHandlerTest method shouldHaveTransactionIdWithCustomHeader.

@Test
public void shouldHaveTransactionIdWithCustomHeader() throws InterruptedException {
    final CountDownLatch lock = new CountDownLatch(1);
    when(request.id()).thenReturn(UUID.toString(UUID.random()));
    new TransactionHandler(CUSTOM_TRANSACTION_ID_HEADER, request1 -> {
        assertNotNull(request1.transactionId());
        assertEquals(request1.transactionId(), request1.headers().getFirst(CUSTOM_TRANSACTION_ID_HEADER));
        assertEquals(request1.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));
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Mock(org.mockito.Mock) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Metrics(io.gravitee.reporter.api.http.Metrics) TimeUnit(java.util.concurrent.TimeUnit) MockitoAnnotations(org.mockito.MockitoAnnotations) CountDownLatch(java.util.concurrent.CountDownLatch) Response(io.gravitee.gateway.api.Response) UUID(io.gravitee.common.utils.UUID) Request(io.gravitee.gateway.api.Request) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with Metrics

use of io.gravitee.reporter.api.http.Metrics in project gravitee-gateway by gravitee-io.

the class TransactionHandlerTest method shouldPropagateSameTransactionId.

@Test
public void shouldPropagateSameTransactionId() throws InterruptedException {
    final CountDownLatch lock = new CountDownLatch(1);
    String transactionId = UUID.toString(UUID.random());
    request.headers().set(TransactionHandler.DEFAULT_TRANSACTIONAL_ID_HEADER, transactionId);
    new TransactionHandler(request1 -> {
        assertNotNull(request1.transactionId());
        assertEquals(transactionId, request1.transactionId());
        assertEquals(transactionId, request1.headers().getFirst(TransactionHandler.DEFAULT_TRANSACTIONAL_ID_HEADER));
        assertEquals(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));
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Mock(org.mockito.Mock) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Metrics(io.gravitee.reporter.api.http.Metrics) TimeUnit(java.util.concurrent.TimeUnit) MockitoAnnotations(org.mockito.MockitoAnnotations) CountDownLatch(java.util.concurrent.CountDownLatch) Response(io.gravitee.gateway.api.Response) UUID(io.gravitee.common.utils.UUID) Request(io.gravitee.gateway.api.Request) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Metrics (io.gravitee.reporter.api.http.Metrics)7 Test (org.junit.Test)7 Request (io.gravitee.gateway.api.Request)6 HttpHeaders (io.gravitee.common.http.HttpHeaders)4 UUID (io.gravitee.common.utils.UUID)4 Response (io.gravitee.gateway.api.Response)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 TimeUnit (java.util.concurrent.TimeUnit)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)4 Before (org.junit.Before)4 Mock (org.mockito.Mock)4 Mockito.when (org.mockito.Mockito.when)4 MockitoAnnotations (org.mockito.MockitoAnnotations)4 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)2 PolicyChain (io.gravitee.gateway.policy.impl.PolicyChain)2 Handler (io.gravitee.gateway.api.handler.Handler)1 ProxyRequest (io.gravitee.gateway.api.proxy.ProxyRequest)1 RequestPolicyChain (io.gravitee.gateway.policy.impl.RequestPolicyChain)1 ResponsePolicyChain (io.gravitee.gateway.policy.impl.ResponsePolicyChain)1