예제 #1
0
  @Test
  public void mdcIsCleanedAfterCall() throws Exception {
    outputWriter.doWrite(server, query, results);

    assertThat(MDC.get("server")).isNull();
    assertThat(MDC.get("metric")).isNull();
    assertThat(MDC.get("value")).isNull();
    assertThat(MDC.get("attributeName")).isNull();
    assertThat(MDC.get("key")).isNull();
    assertThat(MDC.get("epoch")).isNull();
  }
예제 #2
0
  @Test
  public void metricsAreSentToLoggerViaMDC() throws Exception {
    doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                assertThat(MDC.get("server")).isEqualTo("localhost_9876");
                assertThat(MDC.get("metric"))
                    .isEqualTo("localhost_9876.className.attributeName_key");
                assertThat(MDC.get("value")).isEqualTo("1");
                assertThat(MDC.get("attributeName")).isEqualTo("attributeName");
                assertThat(MDC.get("key")).isEqualTo("key");
                assertThat(MDC.get("epoch")).isEqualTo("1");
                return null;
              }
            })
        .when(logger)
        .info("");

    outputWriter.doWrite(server, query, results);
  }