1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.coprocessor;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import java.io.IOException;
28
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.HBaseTestingUtility;
31 import org.apache.hadoop.hbase.MediumTests;
32 import org.apache.hadoop.hbase.client.HTable;
33 import org.apache.hadoop.hbase.client.Put;
34 import org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException;
35 import org.apache.hadoop.hbase.regionserver.HRegionServer;
36 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
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 boolean writeToWAL) {
58 String tableName =
59 c.getEnvironment().getRegion().getRegionInfo().getTableNameAsString();
60 if (tableName.equals("observed_table")) {
61 Integer i = null;
62 i = i + 1;
63 }
64 }
65 }
66
67 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
68
69 @BeforeClass
70 public static void setupBeforeClass() throws Exception {
71
72 Configuration conf = TEST_UTIL.getConfiguration();
73 conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
74 BuggyRegionObserver.class.getName());
75 TEST_UTIL.startMiniCluster(2);
76 }
77
78 @AfterClass
79 public static void teardownAfterClass() throws Exception {
80 TEST_UTIL.shutdownMiniCluster();
81 }
82
83 @Test(timeout=60000)
84 public void testExceptionFromCoprocessorDuringPut()
85 throws IOException {
86
87
88
89
90
91
92
93
94 byte[] TEST_TABLE = Bytes.toBytes("observed_table");
95 byte[] TEST_FAMILY = Bytes.toBytes("aaa");
96
97 HTable table = TEST_UTIL.createTable(TEST_TABLE, TEST_FAMILY);
98 TEST_UTIL.createMultiRegions(table, TEST_FAMILY);
99 TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE);
100
101
102 HRegionServer regionServer =
103 TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
104
105
106
107
108
109
110
111
112 boolean threwDNRE = false;
113 try {
114 final byte[] ROW = Bytes.toBytes("aaa");
115 Put put = new Put(ROW);
116 put.add(TEST_FAMILY, ROW, ROW);
117 table.put(put);
118 } catch (RetriesExhaustedWithDetailsException e) {
119
120
121
122
123 assertTrue(e.getMessage().contains("DoNotRetryIOException"));
124 threwDNRE = true;
125 } finally {
126 assertTrue(threwDNRE);
127 }
128
129
130
131 for (int i = 0; i < 3; i++) {
132 assertFalse(regionServer.isAborted());
133 try {
134 Thread.sleep(1000);
135 } catch (InterruptedException e) {
136 fail("InterruptedException while waiting for regionserver " +
137 "zk node to be deleted.");
138 }
139 }
140 table.close();
141 }
142
143 @org.junit.Rule
144 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
145 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
146 }
147