Search in sources :

Example 1 with BlockMyInvoker

use of com.alibaba.dubbo.rpc.support.BlockMyInvoker in project dubbo by alibaba.

the class ActiveLimitFilterTest method testInvokeGreaterActives.

@Test
public void testInvokeGreaterActives() {
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=1&timeout=1");
    final Invoker<ActiveLimitFilterTest> invoker = new BlockMyInvoker<ActiveLimitFilterTest>(url, 100);
    final Invocation invocation = new MockInvocation();
    final CountDownLatch latch = new CountDownLatch(1);
    for (int i = 0; i < 100; i++) {
        Thread thread = new Thread(new Runnable() {

            public void run() {
                try {
                    latch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                for (int i = 0; i < 100; i++) {
                    try {
                        activeLimitFilter.invoke(invoker, invocation);
                    } catch (RpcException expected) {
                        count++;
                    }
                }
            }
        });
        thread.start();
    }
    latch.countDown();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertNotSame(0, count);
}
Also used : BlockMyInvoker(com.alibaba.dubbo.rpc.support.BlockMyInvoker) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) RpcException(com.alibaba.dubbo.rpc.RpcException) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) CountDownLatch(java.util.concurrent.CountDownLatch) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

URL (com.alibaba.dubbo.common.URL)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 BlockMyInvoker (com.alibaba.dubbo.rpc.support.BlockMyInvoker)1 MockInvocation (com.alibaba.dubbo.rpc.support.MockInvocation)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1