1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.ipc;
20
21 import java.io.IOException;
22 import java.net.InetSocketAddress;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.SmallTests;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31
32 @Category(SmallTests.class)
33 public class TestProtocolExtension {
34 private static final String ADDRESS = "0.0.0.0";
35
36 public static final Log LOG =
37 LogFactory.getLog(TestProtocolExtension.class);
38
39 private static Configuration conf = new Configuration();
40
41 public interface ProtocolExtention {
42 void logClassName();
43 }
44
45 public interface TestProtocol extends VersionedProtocol, ProtocolExtention {
46 public static final long VERSION = 7L;
47
48 void ping() throws IOException;
49
50
51
52 }
53
54 public static class TestImpl implements TestProtocol {
55 public long getProtocolVersion(String protocol, long clientVersion) {
56 return TestProtocol.VERSION;
57 }
58
59 @Override
60 public void ping() {}
61
62 @Override
63 public void logClassName() {
64 LOG.info(this.getClass().getName());
65 }
66
67 @Override
68 public ProtocolSignature getProtocolSignature(String protocol,
69 long clientVersion, int clientMethodsHash) throws IOException {
70 return new ProtocolSignature(VERSION, null);
71 }
72 }
73
74 @Test
75 public void testCalls() throws Exception {
76 RpcServer server = HBaseRPC.getServer(TestProtocol.class,
77 new TestImpl(),
78 new Class<?>[]{ProtocolExtention.class},
79 ADDRESS,
80 6016,
81 10, 10, false,
82 conf, 10);
83 RpcEngine rpcEngine = null;
84 try {
85 server.start();
86 rpcEngine = HBaseRPC.getProtocolEngine(conf);
87
88 InetSocketAddress addr = server.getListenerAddress();
89 TestProtocol proxy = rpcEngine.getProxy(
90 TestProtocol.class, TestProtocol.VERSION, addr, conf, 10000);
91
92 proxy.ping();
93
94 proxy.logClassName();
95 } finally {
96 server.stop();
97 if (rpcEngine != null) {
98 rpcEngine.close();
99 }
100 }
101 }
102
103 @org.junit.Rule
104 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
105 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
106 }