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 @SuppressWarnings("null")
54 @Override
55 public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c,
56 final Put put, final WALEdit edit,
57 final Durability durability) {
58 String tableName =
59 c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString();
60 if (tableName.equals("observed_table")) {
61
62 Integer i = null;
63 i = i + 1;
64 }
65 }
66 }
67
68 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
69
70 @BeforeClass
71 public static void setupBeforeClass() throws Exception {
72
73 Configuration conf = TEST_UTIL.getConfiguration();
74 conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
75 BuggyRegionObserver.class.getName());
76 TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false);
77 TEST_UTIL.startMiniCluster();
78 }
79
80 @AfterClass
81 public static void teardownAfterClass() throws Exception {
82 TEST_UTIL.shutdownMiniCluster();
83 }
84
85 @Test(timeout=60000)
86 public void testExceptionFromCoprocessorDuringPut()
87 throws IOException, InterruptedException {
88
89
90
91
92
93
94
95
96 TableName TEST_TABLE = TableName.valueOf("observed_table");
97 byte[] TEST_FAMILY = Bytes.toBytes("aaa");
98
99 HTable table = TEST_UTIL.createMultiRegionTable(TEST_TABLE, TEST_FAMILY);
100 TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE);
101
102
103 HRegionServer regionServer =
104 TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
105
106 boolean threwIOE = false;
107 try {
108 final byte[] ROW = Bytes.toBytes("aaa");
109 Put put = new Put(ROW);
110 put.add(TEST_FAMILY, ROW, ROW);
111 table.put(put);
112 table.flushCommits();
113
114 table.put(put);
115 table.flushCommits();
116 } catch (IOException e) {
117 threwIOE = true;
118 } finally {
119 assertTrue("The regionserver should have thrown an exception", threwIOE);
120 }
121
122
123
124 for (int i = 0; i < 10; i++) {
125 assertFalse(regionServer.isAborted());
126 try {
127 Thread.sleep(1000);
128 } catch (InterruptedException e) {
129 fail("InterruptedException while waiting for regionserver " +
130 "zk node to be deleted.");
131 }
132 }
133 table.close();
134 }
135
136 }
137