1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.coprocessor;
19
20 import java.io.IOException;
21 import java.util.concurrent.ExecutorService;
22
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.hbase.Abortable;
25 import org.apache.hadoop.hbase.Coprocessor;
26 import org.apache.hadoop.hbase.CoprocessorEnvironment;
27 import org.apache.hadoop.hbase.HBaseConfiguration;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.client.HTableInterface;
30 import org.apache.hadoop.hbase.testclassification.SmallTests;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
34
35 @Category({SmallTests.class})
36 public class TestCoprocessorHost {
37
38
39
40 class TestAbortable implements Abortable {
41 private volatile boolean aborted = false;
42
43 @Override
44 public void abort(String why, Throwable e) {
45 this.aborted = true;
46 Assert.fail();
47 }
48
49 @Override
50 public boolean isAborted() {
51 return this.aborted;
52 }
53 }
54
55 @Test
56 public void testDoubleLoading() {
57 final Configuration conf = HBaseConfiguration.create();
58 CoprocessorHost<CoprocessorEnvironment> host =
59 new CoprocessorHost<CoprocessorEnvironment>(new TestAbortable()) {
60 final Configuration cpHostConf = conf;
61
62 @Override
63 public CoprocessorEnvironment createEnvironment(Class<?> implClass,
64 final Coprocessor instance, int priority, int sequence, Configuration conf) {
65 return new CoprocessorEnvironment() {
66 final Coprocessor envInstance = instance;
67
68 @Override
69 public int getVersion() {
70 return 0;
71 }
72
73 @Override
74 public String getHBaseVersion() {
75 return "0.0.0";
76 }
77
78 @Override
79 public Coprocessor getInstance() {
80 return envInstance;
81 }
82
83 @Override
84 public int getPriority() {
85 return 0;
86 }
87
88 @Override
89 public int getLoadSequence() {
90 return 0;
91 }
92
93 @Override
94 public Configuration getConfiguration() {
95 return cpHostConf;
96 }
97
98 @Override
99 public HTableInterface getTable(TableName tableName) throws IOException {
100 return null;
101 }
102
103 @Override
104 public HTableInterface getTable(TableName tableName, ExecutorService service)
105 throws IOException {
106 return null;
107 }
108
109 @Override
110 public ClassLoader getClassLoader() {
111 return null;
112 }
113 };
114 }
115 };
116 final String key = "KEY";
117 final String coprocessor = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
118
119 conf.setStrings(key, coprocessor, coprocessor, coprocessor);
120 host.loadSystemCoprocessors(conf, key);
121
122 Assert.assertEquals(1, host.coprocessors.size());
123 }
124 }