@Test public void withKeyExtractor() { final RequestLog log = mock(RequestLog.class); when(log.authority()).thenReturn("kawamuray"); when(log.decodedPath()).thenReturn("kyuto"); final KafkaAccessLogWriter<String, String> service = new KafkaAccessLogWriter<>(producer, TOPIC_NAME, RequestLog::decodedPath, RequestLog::authority); service.log(log); verify(producer, times(1)).send(captor.capture(), any(Callback.class)); final ProducerRecord<String, String> record = captor.getValue(); assertThat(record.key()).isEqualTo("kyuto"); assertThat(record.value()).isEqualTo("kawamuray"); }
@Test public void withoutKeyExtractor() { final RequestLog log = mock(RequestLog.class); when(log.authority()).thenReturn("kawamuray"); final KafkaAccessLogWriter<String, String> service = new KafkaAccessLogWriter<>(producer, TOPIC_NAME, RequestLog::authority); service.log(log); verify(producer, times(1)).send(captor.capture(), any(Callback.class)); final ProducerRecord<String, String> record = captor.getValue(); assertThat(record.key()).isNull(); assertThat(record.value()).isEqualTo("kawamuray"); }
final String authority = log.authority(); if (!"?".equals(authority)) { out.put(REQ_AUTHORITY.mdcKey, authority);
final String authority = log.authority(); if (!"?".equals(authority)) { out.put(REQ_AUTHORITY.mdcKey, authority);
final String authority = log.authority(); if (!"?".equals(authority)) { out.put(REQ_AUTHORITY.mdcKey, authority);