use of io.airlift.event.client.InMemoryEventClient in project airlift by airlift.
the class TestDelimitedRequestLog method testTraceTokenHeader.
@Test
public void testTraceTokenHeader() throws Exception {
Request request = mock(Request.class);
Response response = mock(Response.class);
TraceTokenManager tokenManager = new TraceTokenManager();
InMemoryEventClient eventClient = new InMemoryEventClient();
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, tokenManager, eventClient, new SystemCurrentTimeMillisProvider(), false);
String token = "test-trace-token";
when(request.getHttpVersion()).thenReturn(HTTP_2);
when(request.getHeader(TRACETOKEN_HEADER)).thenReturn(token);
// log a request without a token set by tokenManager
logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
// create and set a new token with tokenManager
tokenManager.createAndRegisterNewRequestToken();
logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
// clear the token HTTP header
when(request.getHeader(TRACETOKEN_HEADER)).thenReturn(null);
logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
logger.stop();
List<Object> events = eventClient.getEvents();
assertEquals(events.size(), 3);
// first two events should have the token set from the header
for (int i = 0; i < 2; i++) {
assertEquals(((HttpRequestEvent) events.get(i)).getTraceToken(), token);
}
// last event should have the token set by the tokenManager
assertEquals(((HttpRequestEvent) events.get(2)).getTraceToken(), tokenManager.getCurrentRequestToken());
}
use of io.airlift.event.client.InMemoryEventClient in project airlift by airlift.
the class TestDelimitedRequestLog method testXForwardedForSkipPrivateAddresses.
@Test
public void testXForwardedForSkipPrivateAddresses() throws Exception {
Request request = mock(Request.class);
Response response = mock(Response.class);
String clientIp = "1.1.1.1";
when(request.getRemoteAddr()).thenReturn("9.9.9.9");
when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of(clientIp, "192.168.1.2, 172.16.0.1", "169.254.1.2, 127.1.2.3", "10.1.2.3")));
when(request.getHttpVersion()).thenReturn(HTTP_2);
InMemoryEventClient eventClient = new InMemoryEventClient();
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, null, eventClient, false);
logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
logger.stop();
List<Object> events = eventClient.getEvents();
assertEquals(events.size(), 1);
HttpRequestEvent event = (HttpRequestEvent) events.get(0);
assertEquals(event.getClientAddress(), clientIp);
}
use of io.airlift.event.client.InMemoryEventClient in project airlift by airlift.
the class TestDelimitedRequestLog method testNoXForwardedFor.
@Test
public void testNoXForwardedFor() throws Exception {
Request request = mock(Request.class);
Response response = mock(Response.class);
String clientIp = "1.1.1.1";
when(request.getRemoteAddr()).thenReturn(clientIp);
when(request.getHttpVersion()).thenReturn(HTTP_2);
InMemoryEventClient eventClient = new InMemoryEventClient();
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, null, eventClient, false);
logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
logger.stop();
List<Object> events = eventClient.getEvents();
assertEquals(events.size(), 1);
HttpRequestEvent event = (HttpRequestEvent) events.get(0);
assertEquals(event.getClientAddress(), clientIp);
}
use of io.airlift.event.client.InMemoryEventClient in project airlift by airlift.
the class TestPersonStore method testPut.
@Test
public void testPut() {
InMemoryEventClient eventClient = new InMemoryEventClient();
PersonStore store = new PersonStore(new StoreConfig(), eventClient);
store.put("foo", new Person("foo@example.com", "Mr Foo"));
assertEquals(new Person("foo@example.com", "Mr Foo"), store.get("foo"));
assertEquals(store.getAll().size(), 1);
assertEquals(eventClient.getEvents(), ImmutableList.of(personAdded("foo", new Person("foo@example.com", "Mr Foo"))));
}
use of io.airlift.event.client.InMemoryEventClient in project airlift by airlift.
the class TestPersonStore method testGetAll.
@Test
public void testGetAll() {
PersonStore store = new PersonStore(new StoreConfig(), new InMemoryEventClient());
store.put("foo", new Person("foo@example.com", "Mr Foo"));
store.put("bar", new Person("bar@example.com", "Mr Bar"));
assertEquals(store.getAll().size(), 2);
assertEquals(store.getAll(), asList(new Person("foo@example.com", "Mr Foo"), new Person("bar@example.com", "Mr Bar")));
}
Aggregations