-
Notifications
You must be signed in to change notification settings - Fork 63
/
RpcRequestResponse.java
executable file
·190 lines (138 loc) · 6.3 KB
/
RpcRequestResponse.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.messagebus.client.api;
import com.messagebus.client.Messagebus;
import com.messagebus.client.MessagebusSinglePool;
import com.messagebus.client.core.BaseTestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.concurrent.TimeUnit;
/**
* Created by yanghua on 4/8/15.
*/
public class RpcRequestResponse extends BaseTestCase {
private static final Log logger = LogFactory.getLog(RpcRequestResponse.class);
@Override
public void setUp() throws Exception {
super.setUp();
}
@Override
public void tearDown() throws Exception {
super.tearDown();
}
public void testSimpleRpc() throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
String secret = "jhliquwdlaisudfqbjhasdfulquias";
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
final Messagebus client = singlePool.getResource();
client.callback(secret, TestInterface.class, new HelloServiceProvider(), 10, TimeUnit.SECONDS);
singlePool.returnResource(client);
singlePool.destroy();
}
}).start();
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
Messagebus client = singlePool.getResource();
String secret = "kliwhiduhaiucvarkjajksdbfkjabw";
String targetQueue = "erpDemoRpcResponse";
String token = "klasehnfkljashdnflhkjahwlekdjf";
String methodName = "sayHello";
Object responseObj = client.call(secret, targetQueue, methodName, new Object[0], token, 10000);
assertNull(responseObj);
singlePool.returnResource(client);
singlePool.destroy();
}
public void testReturnValueRpc() throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
String secret = "jhliquwdlaisudfqbjhasdfulquias";
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
final Messagebus client = singlePool.getResource();
client.callback(secret, TestInterface.class, new HelloServiceProvider(), 10, TimeUnit.SECONDS);
singlePool.returnResource(client);
singlePool.destroy();
}
}).start();
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
Messagebus client = singlePool.getResource();
String secret = "kliwhiduhaiucvarkjajksdbfkjabw";
String targetQueue = "erpDemoRpcResponse";
String token = "klasehnfkljashdnflhkjahwlekdjf";
String methodName = "returnValueMethod";
Object responseObj = client.call(secret, targetQueue, methodName, new Object[0], token, 10000);
assertNotNull(responseObj);
assertEquals("hello world", responseObj.toString());
singlePool.returnResource(client);
singlePool.destroy();
}
public void testParamNoReturnValueRpc() throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
String secret = "jhliquwdlaisudfqbjhasdfulquias";
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
final Messagebus client = singlePool.getResource();
client.callback(secret, TestInterface.class, new HelloServiceProvider(), 10, TimeUnit.SECONDS);
singlePool.returnResource(client);
singlePool.destroy();
}
}).start();
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
Messagebus client = singlePool.getResource();
String secret = "kliwhiduhaiucvarkjajksdbfkjabw";
String targetQueue = "erpDemoRpcResponse";
String token = "klasehnfkljashdnflhkjahwlekdjf";
String methodName = "printParam";
Object responseObj = client.call(secret, targetQueue, methodName, new Object[]{"hello world"}, token, 10000);
singlePool.returnResource(client);
singlePool.destroy();
}
public void testReturnParamValueRpc() throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
String secret = "jhliquwdlaisudfqbjhasdfulquias";
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
final Messagebus client = singlePool.getResource();
client.callback(secret, TestInterface.class, new HelloServiceProvider(), 10, TimeUnit.SECONDS);
singlePool.returnResource(client);
singlePool.destroy();
}
}).start();
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
Messagebus client = singlePool.getResource();
String secret = "kliwhiduhaiucvarkjajksdbfkjabw";
String targetQueue = "erpDemoRpcResponse";
String token = "klasehnfkljashdnflhkjahwlekdjf";
String methodName = "returnParam";
Object responseObj = client.call(secret, targetQueue, methodName, new Object[]{"hello world"}, token, 10000);
assertNotNull(responseObj);
assertEquals("hello world", responseObj.toString());
singlePool.returnResource(client);
singlePool.destroy();
}
public static interface TestInterface {
public void sayHello();
public String returnValueMethod();
public void printParam(String arg1);
public String returnParam(String arg1);
}
public static class HelloServiceProvider implements TestInterface {
@Override
public void sayHello() {
logger.info("hello...");
}
@Override
public String returnValueMethod() {
return "hello world";
}
@Override
public void printParam(String arg1) {
System.out.println(arg1);
}
@Override
public String returnParam(String arg1) {
return arg1;
}
}
}