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.callbacks.SimpleCallback;
23 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
24 import org.kuali.rice.ksb.service.KSBServiceLocator;
25 import org.kuali.rice.ksb.test.KSBTestCase;
26
27 import javax.xml.namespace.QName;
28 import java.util.List;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32
33
34
35
36
37
38
39 public class DistributedQueueTest extends KSBTestCase {
40
41 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DistributedQueueTest.class);
42
43 public boolean startClient1() {
44 return true;
45 }
46
47 public boolean startClient2() {
48 return true;
49 }
50
51
52
53
54
55
56 @Test
57 public void testSuccessfullyCallingQueueOnce() throws Exception {
58 QName serviceName = new QName("testAppsSharedQueue", "sharedQueue");
59 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
60 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
61 verifyServiceCalls(serviceName);
62
63 }
64
65 @Test
66 public void testCallingQueueAsnyc() throws Exception {
67 KSBTestUtils.setMessagingToAsync();
68
69
70
71 for (int i = 0; i < 100; i++) {
72 LOG.info("testCallingQueueAsnyc, iteration: " + i);
73 QName serviceName = new QName("testAppsSharedQueue", "sharedQueue");
74 SimpleCallback callback = new SimpleCallback();
75 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback);
76 synchronized (callback) {
77 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
78 callback.waitForAsyncCall();
79 }
80 verifyServiceCalls(serviceName);
81 KSBServiceLocator.getBAMService().clearBAMTables();
82 }
83 }
84
85 private void verifyServiceCalls(QName serviceName) throws Exception {
86 BAMService bamService = KSBServiceLocator.getBAMService();
87 List<BAMTargetEntry> bamCalls = bamService.getCallsForService(serviceName);
88 assertTrue("No service call recorded", bamCalls.size() > 0);
89 boolean foundClientCall = false;
90 boolean foundServiceCall = false;
91 for (BAMTargetEntry bamEntry : bamCalls) {
92 if (bamEntry.getServerInvocation()) {
93 foundServiceCall = true;
94 } else {
95 foundClientCall = true;
96 }
97 }
98 assertTrue("No client call recorded", foundClientCall);
99 assertTrue("No service call recorded", foundServiceCall);
100 assertEquals("Wrong number of calls recorded", 2, bamCalls.size());
101 }
102
103 }