1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.coprocessor;
21
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25
26 import java.io.IOException;
27
28 import org.apache.hadoop.conf.Configuration;
29 import org.apache.hadoop.hbase.HBaseTestingUtility;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.client.Durability;
32 import org.apache.hadoop.hbase.client.HTable;
33 import org.apache.hadoop.hbase.client.Put;
34 import org.apache.hadoop.hbase.regionserver.HRegionServer;
35 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
36 import org.apache.hadoop.hbase.testclassification.MediumTests;
37 import org.apache.hadoop.hbase.util.Bytes;
38 import org.junit.AfterClass;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41 import org.junit.experimental.categories.Category;
42
43
44
45
46
47
48
49
50 @Category(MediumTests.class)
51 public class TestRegionServerCoprocessorExceptionWithRemove {
52 public static class BuggyRegionObserver extends SimpleRegionObserver {
53 @Override
54 @SuppressWarnings("null")
55 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_NULL_ON_SOME_PATH",
56 justification="Preconditions checks insure we are not going to dereference a null value")
57 public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c,
58 final Put put, final WALEdit edit,
59 final Durability durability) {
60 String tableName =
61 c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString();
62 if (tableName.equals("observed_table")) {
63
64 Integer i = null;
65 i = i + 1;
66 }
67 }
68 }
69
70 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
71
72 @BeforeClass
73 public static void setupBeforeClass() throws Exception {
74
75 Configuration conf = TEST_UTIL.getConfiguration();
76 conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
77 BuggyRegionObserver.class.getName());
78 TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false);
79 TEST_UTIL.startMiniCluster();
80 }
81
82 @AfterClass
83 public static void teardownAfterClass() throws Exception {
84 TEST_UTIL.shutdownMiniCluster();
85 }
86
87 @Test(timeout=60000)
88 public void testExceptionFromCoprocessorDuringPut()
89 throws IOException, InterruptedException {
90
91
92
93
94
95
96
97
98 TableName TEST_TABLE = TableName.valueOf("observed_table");
99 byte[] TEST_FAMILY = Bytes.toBytes("aaa");
100
101 HTable table = TEST_UTIL.createMultiRegionTable(TEST_TABLE, TEST_FAMILY);
102 TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE);
103
104
105 HRegionServer regionServer =
106 TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
107
108 boolean threwIOE = false;
109 try {
110 final byte[] ROW = Bytes.toBytes("aaa");
111 Put put = new Put(ROW);
112 put.add(TEST_FAMILY, ROW, ROW);
113 table.put(put);
114 table.flushCommits();
115
116 table.put(put);
117 table.flushCommits();
118 } catch (IOException e) {
119 threwIOE = true;
120 } finally {
121 assertTrue("The regionserver should have thrown an exception", threwIOE);
122 }
123
124
125
126 for (int i = 0; i < 10; i++) {
127 assertFalse(regionServer.isAborted());
128 try {
129 Thread.sleep(1000);
130 } catch (InterruptedException e) {
131 fail("InterruptedException while waiting for regionserver " +
132 "zk node to be deleted.");
133 }
134 }
135 table.close();
136 }
137
138 }
139