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.RetriesExhaustedWithDetailsException;
29 import org.apache.hadoop.hbase.client.Durability;
30 import org.apache.hadoop.hbase.regionserver.HRegionServer;
31 import org.apache.hadoop.hbase.util.Bytes;
32 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37
38 import static org.junit.Assert.*;
39
40
41
42
43
44
45
46
47 @Category(MediumTests.class)
48 public class TestRegionServerCoprocessorExceptionWithRemove {
49 public static class BuggyRegionObserver extends SimpleRegionObserver {
50 @SuppressWarnings("null")
51 @Override
52 public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c,
53 final Put put, final WALEdit edit,
54 final Durability durability) {
55 String tableName =
56 c.getEnvironment().getRegion().getRegionInfo()
57 .getTableName().getNameAsString();
58 if (tableName.equals("observed_table")) {
59 Integer i = null;
60 i = i + 1;
61 }
62 }
63 }
64
65 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
66
67 @BeforeClass
68 public static void setupBeforeClass() throws Exception {
69
70 Configuration conf = TEST_UTIL.getConfiguration();
71 conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
72 BuggyRegionObserver.class.getName());
73 TEST_UTIL.startMiniCluster(2);
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
105
106
107
108
109
110
111 boolean threwDNRE = false;
112 try {
113 final byte[] ROW = Bytes.toBytes("aaa");
114 Put put = new Put(ROW);
115 put.add(TEST_FAMILY, ROW, ROW);
116 table.put(put);
117 } catch (RetriesExhaustedWithDetailsException e) {
118
119
120
121
122 assertTrue(e.getMessage().contains("DoNotRetryIOException"));
123 threwDNRE = true;
124 } finally {
125 assertTrue(threwDNRE);
126 }
127
128
129
130 for (int i = 0; i < 3; i++) {
131 assertFalse(regionServer.isAborted());
132 try {
133 Thread.sleep(1000);
134 } catch (InterruptedException e) {
135 fail("InterruptedException while waiting for regionserver " +
136 "zk node to be deleted.");
137 }
138 }
139 table.close();
140 }
141
142 }
143