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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jrt;
public class InvokeVoidTest extends junit.framework.TestCase {
Test.Orb server;
Acceptor acceptor;
Test.Orb client;
Target target;
public InvokeVoidTest(String name) {
super(name);
}
public void setUp() throws ListenFailedException {
server = new Test.Orb(new Transport());
client = new Test.Orb(new Transport());
acceptor = server.listen(new Spec(Test.PORT));
target = client.connect(new Spec("localhost", Test.PORT));
server.addMethod(new Method("set", "i", "", this, "rpc_set")
.methodDesc("Set the stored value")
.paramDesc(0, "value", "the new value"));
server.addMethod(new Method("inc", "", "", this, "rpc_inc")
.methodDesc("Increase the stored value"));
server.addMethod(new Method("get", "", "i", this, "rpc_get")
.methodDesc("Get the stored value")
.returnDesc(0, "value", "the stored value"));
}
public void tearDown() {
target.close();
acceptor.shutdown().join();
client.transport().shutdown().join();
server.transport().shutdown().join();
}
private int value = 0;
public void rpc_set(Request req) {
value = req.parameters().get(0).asInt32();
}
public void rpc_inc(Request req) {
value++;
}
public void rpc_get(Request req) {
req.returnValues().add(new Int32Value(value));
}
public void testInvokeVoid() {
Request req = new Request("set");
req.parameters().add(new Int32Value(40));
target.invokeSync(req, 5.0);
assertTrue(!req.isError());
assertEquals(0, req.returnValues().size());
target.invokeVoid(new Request("inc"));
target.invokeVoid(new Request("inc"));
req = new Request("get");
target.invokeSync(req, 5.0);
assertTrue(!req.isError());
assertEquals(42, req.returnValues().get(0).asInt32());
assertTrue(server.checkReadCounts(4, 0, 0));
assertTrue(server.checkWriteCounts(0, 2, 0));
assertTrue(client.checkReadCounts(0, 2, 0));
assertTrue(client.checkWriteCounts(4, 0, 0));
assertTrue(server.readBytes == client.writeBytes);
assertTrue(client.readBytes == server.writeBytes);
}
}
|