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