|
@@ -314,8 +314,9 @@ public class TestRPC {
|
|
|
|
|
|
@Test
|
|
|
public void testConfRpc() throws Exception {
|
|
|
- Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 1, false, conf, null);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(1).setVerbose(false).build();
|
|
|
// Just one handler
|
|
|
int confQ = conf.getInt(
|
|
|
CommonConfigurationKeys.IPC_SERVER_HANDLER_QUEUE_SIZE_KEY,
|
|
@@ -328,8 +329,11 @@ public class TestRPC {
|
|
|
assertEquals(confReaders, server.getNumReaders());
|
|
|
server.stop();
|
|
|
|
|
|
- server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 1, 3, 200, false, conf, null);
|
|
|
+ server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(1).setnumReaders(3).setQueueSizePerHandler(200)
|
|
|
+ .setVerbose(false).build();
|
|
|
+
|
|
|
assertEquals(3, server.getNumReaders());
|
|
|
assertEquals(200, server.getMaxQueueSize());
|
|
|
server.stop();
|
|
@@ -337,8 +341,8 @@ public class TestRPC {
|
|
|
|
|
|
@Test
|
|
|
public void testProxyAddress() throws Exception {
|
|
|
- Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, conf);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0).build();
|
|
|
TestProtocol proxy = null;
|
|
|
|
|
|
try {
|
|
@@ -362,8 +366,10 @@ public class TestRPC {
|
|
|
public void testSlowRpc() throws Exception {
|
|
|
System.out.println("Testing Slow RPC");
|
|
|
// create a server with two handlers
|
|
|
- Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 2, false, conf, null);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(2).setVerbose(false).build();
|
|
|
+
|
|
|
TestProtocol proxy = null;
|
|
|
|
|
|
try {
|
|
@@ -409,8 +415,8 @@ public class TestRPC {
|
|
|
}
|
|
|
|
|
|
private void testCallsInternal(Configuration conf) throws Exception {
|
|
|
- Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, conf);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0).build();
|
|
|
TestProtocol proxy = null;
|
|
|
try {
|
|
|
server.start();
|
|
@@ -528,8 +534,9 @@ public class TestRPC {
|
|
|
}
|
|
|
|
|
|
private void doRPCs(Configuration conf, boolean expectFailure) throws Exception {
|
|
|
- Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 5, true, conf, null);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(5).setVerbose(true).build();
|
|
|
|
|
|
server.refreshServiceAcl(conf, new TestPolicyProvider());
|
|
|
|
|
@@ -573,8 +580,9 @@ public class TestRPC {
|
|
|
|
|
|
@Test
|
|
|
public void testServerAddress() throws IOException {
|
|
|
- Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 5, true, conf, null);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(5).setVerbose(true).build();
|
|
|
InetSocketAddress bindAddr = null;
|
|
|
try {
|
|
|
bindAddr = NetUtils.getConnectAddress(server);
|
|
@@ -668,8 +676,9 @@ public class TestRPC {
|
|
|
|
|
|
@Test
|
|
|
public void testErrorMsgForInsecureClient() throws Exception {
|
|
|
- final Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 5, true, conf, null);
|
|
|
+ final Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(5).setVerbose(true).build();
|
|
|
server.enableSecurity();
|
|
|
server.start();
|
|
|
boolean succeeded = false;
|
|
@@ -693,8 +702,10 @@ public class TestRPC {
|
|
|
|
|
|
conf.setInt(CommonConfigurationKeys.IPC_SERVER_RPC_READ_THREADS_KEY, 2);
|
|
|
|
|
|
- final Server multiServer = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 5, true, conf, null);
|
|
|
+ final Server multiServer = new RPC.Builder(conf)
|
|
|
+ .setProtocol(TestProtocol.class).setInstance(new TestImpl())
|
|
|
+ .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true)
|
|
|
+ .build();
|
|
|
multiServer.enableSecurity();
|
|
|
multiServer.start();
|
|
|
succeeded = false;
|
|
@@ -748,8 +759,9 @@ public class TestRPC {
|
|
|
assertEquals("Expect no Reader threads running before test",
|
|
|
0, threadsBefore);
|
|
|
|
|
|
- final Server server = RPC.getServer(TestProtocol.class,
|
|
|
- new TestImpl(), ADDRESS, 0, 5, true, conf, null);
|
|
|
+ final Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(5).setVerbose(true).build();
|
|
|
server.start();
|
|
|
try {
|
|
|
int threadsRunning = countThreads("Server$Listener$Reader");
|
|
@@ -762,6 +774,42 @@ public class TestRPC {
|
|
|
0, threadsAfter);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testRPCBuilder() throws Exception {
|
|
|
+ // Test mandatory field conf
|
|
|
+ try {
|
|
|
+ new RPC.Builder(null).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(5).setVerbose(true).build();
|
|
|
+ fail("Didn't throw HadoopIllegalArgumentException");
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (!(e instanceof HadoopIllegalArgumentException)) {
|
|
|
+ fail("Expecting HadoopIllegalArgumentException but caught " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Test mandatory field protocol
|
|
|
+ try {
|
|
|
+ new RPC.Builder(conf).setInstance(new TestImpl()).setBindAddress(ADDRESS)
|
|
|
+ .setPort(0).setNumHandlers(5).setVerbose(true).build();
|
|
|
+ fail("Didn't throw HadoopIllegalArgumentException");
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (!(e instanceof HadoopIllegalArgumentException)) {
|
|
|
+ fail("Expecting HadoopIllegalArgumentException but caught " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Test mandatory field instance
|
|
|
+ try {
|
|
|
+ new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5)
|
|
|
+ .setVerbose(true).build();
|
|
|
+ fail("Didn't throw HadoopIllegalArgumentException");
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (!(e instanceof HadoopIllegalArgumentException)) {
|
|
|
+ fail("Expecting HadoopIllegalArgumentException but caught " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
new TestRPC().testCallsInternal(conf);
|
|
|
|