1
2
3
4
5 package org.neo.swarm.interceptor.asyncQueue;
6
7 import junit.framework.TestCase;
8
9 import org.aopalliance.intercept.MethodInvocation;
10 import org.neo.swarm.core.aop.silc.comp.Invocation;
11
12 import com.mockobjects.dynamic.Mock;
13
14 public class AsyncInterceptorTest extends TestCase {
15
16 int calls = 0;
17
18 public void testAsyncQueueHandlesLoad() throws Exception, Throwable {
19
20 AsyncInterceptor asyncInterceptor = new AsyncInterceptor(10);
21 Mock invocation = new Mock(MethodInvocation.class);
22 invocation.expectAndReturn("proceed", calls++);
23 invocation.expectAndReturn("proceed", calls++);
24 invocation.expectAndReturn("proceed", calls++);
25 invocation.expectAndReturn("proceed", calls++);
26 invocation.expectAndReturn("proceed", calls++);
27 invocation.expectAndReturn("proceed", calls++);
28 invocation.expectAndReturn("proceed", calls++);
29 invocation.expectAndReturn("proceed", calls++);
30 invocation.expectAndReturn("proceed", calls++);
31 invocation.expectAndReturn("proceed", calls++);
32
33 for (int i = 0; i < 10; i++) {
34 asyncInterceptor.invoke((MethodInvocation) invocation.proxy());
35 }
36
37 Thread.sleep(1000);
38 assertEquals(10, calls);
39 invocation.verify();
40 }
41 }