1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging;
17
18 import org.junit.Test;
19 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
20 import org.kuali.rice.ksb.messaging.bam.BAMTargetEntry;
21 import org.kuali.rice.ksb.messaging.bam.service.BAMService;
22 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
23 import org.kuali.rice.ksb.service.KSBServiceLocator;
24 import org.kuali.rice.ksb.test.KSBTestCase;
25
26 import javax.xml.namespace.QName;
27 import java.util.List;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertTrue;
31
32
33
34
35
36
37
38
39 public class DelayedAsynchronousServiceTest extends KSBTestCase {
40
41 public boolean startClient1() {
42 return true;
43 }
44
45 public boolean startClient2() {
46 return true;
47 }
48
49 @Test public void testDelayedAsynchronousServiceCall() throws Exception {
50 KSBTestUtils.setMessagingToAsync();
51
52 QName serviceName = new QName("testAppsSharedQueue", "sharedQueue");
53
54
55 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, "context", "value1", "value2", 5000);
56 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
57 verifyServiceCalls(serviceName, false);
58
59
60 Thread.sleep(1000);
61 verifyServiceCalls(serviceName, false);
62
63
64 Thread.sleep(1000);
65 verifyServiceCalls(serviceName, false);
66
67
68 Thread.sleep(1000);
69 verifyServiceCalls(serviceName, false);
70
71 Thread.sleep(1000);
72 verifyServiceCalls(serviceName, false);
73
74
75
76
77
78
79
80 Thread.sleep(3000);
81 verifyServiceCalls(serviceName, true);
82
83 }
84
85 private void verifyServiceCalls(QName serviceName, boolean shouldHaveBeenCalled) throws Exception {
86 BAMService bamService = KSBServiceLocator.getBAMService();
87 List<BAMTargetEntry> bamCalls = bamService.getCallsForService(serviceName);
88 if (!shouldHaveBeenCalled) {
89 assertTrue("A service call should not have been recorded yet.", bamCalls.size() == 0);
90 } else {
91 assertTrue("No service call recorded", bamCalls.size() > 0);
92 boolean foundClientCall = false;
93 boolean foundServiceCall = false;
94 for (BAMTargetEntry bamEntry : bamCalls) {
95 if (bamEntry.getServerInvocation()) {
96 foundServiceCall = true;
97 } else {
98 foundClientCall = true;
99 }
100 }
101 assertTrue("No client call recorded", foundClientCall);
102 assertTrue("No service call recorded", foundServiceCall);
103 assertEquals("Wrong number of calls recorded", 2, bamCalls.size());
104 }
105 }
106
107 }