Skip to content

Commit

Permalink
Fix bug apache#4374 for AccessLogFilter not working (apache#4566)
Browse files Browse the repository at this point in the history
which introduced by apache#4038
  • Loading branch information
lonre authored and beiwei30 committed Jul 15, 2019
1 parent 843e2ee commit 05e44db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -179,7 +179,7 @@ private void processWithServiceLogger(Set<AccessLogData> 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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AccessLogFilterTest> invoker = new MyInvoker<AccessLogFilterTest>(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<String, Set<AccessLogData>> logs = (Map<String, Set<AccessLogData>>) 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
Expand Down

0 comments on commit 05e44db

Please sign in to comment.