Search in sources :

Example 1 with DefaultLogService

use of com.weibo.api.motan.log.DefaultLogService in project motan by weibocom.

the class AccessLogFilterTest method testSwitcher.

public void testSwitcher() {
    final Request request = mockery.mock(Request.class);
    final Caller<IHello> caller = mockery.mock(Caller.class);
    URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
    url.addParameter(URLParamType.accessLog.getName(), String.valueOf(false));
    final Map<String, String> attachments = new HashMap<>();
    attachments.put(URLParamType.host.getName(), URLParamType.host.getValue());
    attachments.put(URLParamType.application.getName(), URLParamType.application.getValue());
    attachments.put(URLParamType.module.getName(), URLParamType.module.getValue());
    final LogService logService = mockery.mock(LogService.class);
    LoggerUtil.setLogService(logService);
    mockery.checking(new Expectations() {

        {
            atLeast(1).of(caller).getUrl();
            will(returnValue(url));
            atLeast(1).of(caller).call(request);
        }
    });
    accessLogFilter.filter(caller, request);
    mockery.assertIsSatisfied();
    MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, true);
    mockery.checking(new Expectations() {

        {
            exactly(1).of(request).getInterfaceName();
            will(returnValue(IHello.class.getName()));
            exactly(1).of(request).getMethodName();
            will(returnValue("get"));
            exactly(1).of(request).getParamtersDesc();
            will(returnValue("param_desc"));
            atLeast(1).of(request).getAttachments();
            will(returnValue(attachments));
            exactly(1).of(logService).accessLog(with(any(String.class)));
            allowing(request).getRequestId();
        }
    });
    accessLogFilter.filter(caller, request);
    mockery.assertIsSatisfied();
    MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, false);
    accessLogFilter.filter(caller, request);
    mockery.assertIsSatisfied();
    LoggerUtil.setLogService(new DefaultLogService());
}
Also used : Expectations(org.jmock.Expectations) HashMap(java.util.HashMap) DefaultLogService(com.weibo.api.motan.log.DefaultLogService) Request(com.weibo.api.motan.rpc.Request) RegistryService(com.weibo.api.motan.registry.RegistryService) IHello(com.weibo.api.motan.protocol.example.IHello) URL(com.weibo.api.motan.rpc.URL) DefaultLogService(com.weibo.api.motan.log.DefaultLogService) LogService(com.weibo.api.motan.log.LogService)

Aggregations

DefaultLogService (com.weibo.api.motan.log.DefaultLogService)1 LogService (com.weibo.api.motan.log.LogService)1 IHello (com.weibo.api.motan.protocol.example.IHello)1 RegistryService (com.weibo.api.motan.registry.RegistryService)1 Request (com.weibo.api.motan.rpc.Request)1 URL (com.weibo.api.motan.rpc.URL)1 HashMap (java.util.HashMap)1 Expectations (org.jmock.Expectations)1