Search in sources :

Example 1 with MonitorFilter

use of com.alibaba.dubbo.monitor.support.MonitorFilter in project dubbo by alibaba.

the class MonitorFilterTest method testFilter.

@Test
public void testFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("aaa", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) MonitorService(com.alibaba.dubbo.monitor.MonitorService) MonitorFilter(com.alibaba.dubbo.monitor.support.MonitorFilter) Test(org.junit.Test)

Example 2 with MonitorFilter

use of com.alibaba.dubbo.monitor.support.MonitorFilter in project dubbo by alibaba.

the class MonitorFilterTest method testGenericFilter.

@Test
public void testGenericFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("$invoke", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "xxx", new String[] {}, new Object[] {} });
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) MonitorService(com.alibaba.dubbo.monitor.MonitorService) MonitorFilter(com.alibaba.dubbo.monitor.support.MonitorFilter) Test(org.junit.Test)

Aggregations

MonitorService (com.alibaba.dubbo.monitor.MonitorService)2 MonitorFilter (com.alibaba.dubbo.monitor.support.MonitorFilter)2 Invocation (com.alibaba.dubbo.rpc.Invocation)2 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)2 Test (org.junit.Test)2