TpsLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (!tpsLimiter.isAllowable(invoker.getUrl(), invocation)) { throw new RpcException( new StringBuilder(64) .append("Failed to invoke service ") .append(invoker.getInterface().getName()) .append(".") .append(invocation.getMethodName()) .append(" because exceed max service tps.") .toString()); } return invoker.invoke(invocation); }  Result invoke(Invoker<?> invoker, Invocation invocation);  }
@Test public void testWithoutCount() throws Exception { URL url = URL.valueOf("test: url = url.addParameter(Constants.INTERFACE_KEY, "com.alibaba.dubbo.rpc.file.TpsService"); url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5); Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url); Invocation invocation = new MockInvocation(); filter.invoke(invoker, invocation); }
@Test(expected = RpcException.class) public void testFail() throws Exception { URL url = URL.valueOf("test: url = url.addParameter(Constants.INTERFACE_KEY, "com.alibaba.dubbo.rpc.file.TpsService"); url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5); Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url); Invocation invocation = new MockInvocation(); for (int i = 0; i < 10; i++) { try { filter.invoke(invoker, invocation); } catch (Exception e) { assertTrue(i >= 5); throw e; } } }