1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.ipc;
19
20 import static org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl.SERVICE;
21 import static org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl.newBlockingStub;
22 import static org.mockito.Mockito.mock;
23
24 import com.google.common.collect.Lists;
25 import com.google.protobuf.BlockingService;
26
27 import java.io.IOException;
28 import java.net.InetSocketAddress;
29
30 import org.apache.hadoop.conf.Configuration;
31 import org.apache.hadoop.hbase.Abortable;
32 import org.apache.hadoop.hbase.HBaseConfiguration;
33 import org.apache.hadoop.hbase.ipc.protobuf.generated.TestProtos.EchoRequestProto;
34 import org.apache.hadoop.hbase.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface;
35 import org.apache.hadoop.hbase.testclassification.RPCTests;
36 import org.apache.hadoop.hbase.testclassification.SmallTests;
37 import org.junit.Ignore;
38 import org.junit.Test;
39 import org.junit.experimental.categories.Category;
40
41 @Category({ RPCTests.class, SmallTests.class })
42 public class TestRpcHandlerException {
43
44 private final static Configuration CONF = HBaseConfiguration.create();
45
46
47
48
49
50 private static class TestRpcServer extends RpcServer {
51
52 TestRpcServer(RpcScheduler scheduler) throws IOException {
53 super(null, "testRpcServer",
54 Lists.newArrayList(new BlockingServiceAndInterface((BlockingService) SERVICE, null)),
55 new InetSocketAddress("localhost", 0), CONF, scheduler);
56 }
57 }
58
59
60
61
62
63
64 private class AbortServer implements Abortable {
65 private boolean aborted = false;
66
67 @Override
68 public void abort(String why, Throwable e) {
69 aborted = true;
70 }
71
72 @Override
73 public boolean isAborted() {
74 return aborted;
75 }
76 }
77
78
79
80
81
82 @Ignore
83 @Test
84 public void testRpcScheduler() throws IOException, InterruptedException {
85 PriorityFunction qosFunction = mock(PriorityFunction.class);
86 Abortable abortable = new AbortServer();
87 RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0);
88 RpcServer rpcServer = new TestRpcServer(scheduler);
89 try (BlockingRpcClient client = new BlockingRpcClient(CONF)) {
90 rpcServer.start();
91 BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
92 stub.echo(null, EchoRequestProto.newBuilder().setMessage("hello").build());
93 } catch (Throwable e) {
94 assert (abortable.isAborted() == true);
95 } finally {
96 rpcServer.stop();
97 }
98 }
99
100 }