diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java index 55633719eda..ae2bc066d9b 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java @@ -68,7 +68,7 @@ public class AccessLogFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(AccessLogFilter.class); - private static final String ACCESS_LOG_KEY = "dubbo.accesslog"; + private static final String LOG_KEY = "dubbo.accesslog"; private static final int LOG_MAX_BUFFER = 5000; @@ -179,7 +179,7 @@ private void processWithServiceLogger(Set logSet) { iterator.hasNext(); iterator.remove()) { AccessLogData logData = iterator.next(); - LoggerFactory.getLogger(ACCESS_LOG_KEY + "." + logData.getServiceName()).info(logData.getLogMessage()); + LoggerFactory.getLogger(LOG_KEY + "." + logData.getServiceName()).info(logData.getLogMessage()); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java index ca84381ff5d..3fc463fbadb 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java @@ -16,17 +16,23 @@ */ package org.apache.dubbo.rpc.filter; +import java.lang.reflect.Field; +import java.util.Map; +import java.util.Set; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.LogUtil; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.support.AccessLogData; import org.apache.dubbo.rpc.support.MockInvocation; import org.apache.dubbo.rpc.support.MyInvoker; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * AccessLogFilterTest.java @@ -48,11 +54,23 @@ public void testInvokeException() { // TODO how to assert thread action @Test - public void testDefault() { + @SuppressWarnings("unchecked") + public void testDefault() throws NoSuchFieldException, IllegalAccessException { URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1"); Invoker invoker = new MyInvoker(url); Invocation invocation = new MockInvocation(); + + Field field = AccessLogFilter.class.getDeclaredField("LOG_ENTRIES"); + field.setAccessible(true); + assertTrue(((Map) field.get(AccessLogFilter.class)).isEmpty()); + accessLogFilter.invoke(invoker, invocation); + + Map> logs = (Map>) field.get(AccessLogFilter.class); + assertFalse(logs.isEmpty()); + assertFalse(logs.get("true").isEmpty()); + AccessLogData log = logs.get("true").iterator().next(); + assertEquals("org.apache.dubbo.rpc.support.DemoService", log.getServiceName()); } @Test