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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jrt;
import org.junit.After;
import org.junit.Before;
import java.time.Duration;
import java.util.HashSet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class MandatoryMethodsTest {
Supervisor server;
Acceptor acceptor;
Supervisor client;
Target target;
@Before
public void setUp() throws ListenFailedException {
server = new Supervisor(new Transport());
client = new Supervisor(new Transport());
acceptor = server.listen(new Spec(0));
target = client.connect(new Spec("localhost", acceptor.port()));
}
@After
public void tearDown() {
target.close();
acceptor.shutdown().join();
client.transport().shutdown().join();
server.transport().shutdown().join();
}
@org.junit.Test
public void testPing() {
Request req = new Request("frt.rpc.ping");
target.invokeSync(req, Duration.ofSeconds(5));
assertFalse(req.isError());
assertEquals(0, req.returnValues().size());
}
@org.junit.Test
public void testGetMethodList() {
Request req = new Request("frt.rpc.getMethodList");
target.invokeSync(req, Duration.ofSeconds(5));
assertFalse(req.isError());
assertTrue(req.checkReturnTypes("SSS"));
String[] names = req.returnValues().get(0).asStringArray();
String[] param = req.returnValues().get(1).asStringArray();
String[] ret = req.returnValues().get(2).asStringArray();
assertEquals(3, names.length);
assertTrue(names.length == param.length);
assertTrue(names.length == ret.length);
HashSet<String> foundSet = new HashSet<String>();
for (int i = 0; i < names.length; i++) {
if (names[i].equals("frt.rpc.ping")) {
assertEquals("", param[i]);
assertEquals("", ret[i]);
} else if (names[i].equals("frt.rpc.getMethodList")) {
assertEquals("", param[i]);
assertEquals("SSS", ret[i]);
} else if (names[i].equals("frt.rpc.getMethodInfo")) {
assertEquals("s", param[i]);
assertEquals("sssSSSS", ret[i]);
}
foundSet.add(names[i]);
}
assertEquals(3, foundSet.size());
assertTrue(foundSet.contains("frt.rpc.ping"));
assertTrue(foundSet.contains("frt.rpc.getMethodList"));
assertTrue(foundSet.contains("frt.rpc.getMethodInfo"));
}
@org.junit.Test
public void testGetMethodInfo() {
Request req = new Request("frt.rpc.getMethodInfo");
req.parameters().add(new StringValue("frt.rpc.getMethodInfo"));
target.invokeSync(req, Duration.ofSeconds(5));
assertFalse(req.isError());
assertTrue(req.checkReturnTypes("sssSSSS"));
String desc = req.returnValues().get(0).asString();
String param = req.returnValues().get(1).asString();
String ret = req.returnValues().get(2).asString();
String[] paramName = req.returnValues().get(3).asStringArray();
String[] paramDesc = req.returnValues().get(4).asStringArray();
String[] retName = req.returnValues().get(5).asStringArray();
String[] retDesc = req.returnValues().get(6).asStringArray();
assertEquals("s", param);
assertEquals("sssSSSS", ret);
assertEquals(1, paramName.length);
assertTrue(paramName.length == paramDesc.length);
assertEquals(7, retName.length);
assertTrue(retName.length == retDesc.length);
}
}
|