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.client;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.fail;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.hbase.HBaseTestingUtility;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.hbase.LargeTests;
31 import org.apache.hadoop.hbase.catalog.MetaReader;
32 import org.apache.hadoop.hbase.regionserver.HRegionServer;
33 import org.apache.hadoop.hbase.util.Bytes;
34 import org.junit.AfterClass;
35 import org.junit.Before;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.junit.experimental.categories.Category;
39
40
41
42
43 @Category(LargeTests.class)
44 public class TestScannerTimeout {
45
46 private final static HBaseTestingUtility
47 TEST_UTIL = new HBaseTestingUtility();
48
49 final Log LOG = LogFactory.getLog(getClass());
50 private final static byte[] SOME_BYTES = Bytes.toBytes("f");
51 private final static byte[] TABLE_NAME = Bytes.toBytes("t");
52 private final static int NB_ROWS = 10;
53
54
55 private final static int SCANNER_TIMEOUT = 15000;
56 private final static int SCANNER_CACHING = 5;
57
58
59
60
61 @BeforeClass
62 public static void setUpBeforeClass() throws Exception {
63 Configuration c = TEST_UTIL.getConfiguration();
64 c.setInt("hbase.regionserver.lease.period", SCANNER_TIMEOUT);
65
66 TEST_UTIL.startMiniCluster(2);
67 HTable table = TEST_UTIL.createTable(TABLE_NAME, SOME_BYTES);
68 for (int i = 0; i < NB_ROWS; i++) {
69 Put put = new Put(Bytes.toBytes(i));
70 put.add(SOME_BYTES, SOME_BYTES, SOME_BYTES);
71 table.put(put);
72 }
73 table.close();
74 }
75
76
77
78
79 @AfterClass
80 public static void tearDownAfterClass() throws Exception {
81 TEST_UTIL.shutdownMiniCluster();
82 }
83
84
85
86
87 @Before
88 public void setUp() throws Exception {
89 TEST_UTIL.ensureSomeNonStoppedRegionServersAvailable(2);
90 }
91
92
93
94
95
96 @Test(timeout=300000)
97 public void test2481() throws Exception {
98 LOG.info("START ************ test2481");
99 Scan scan = new Scan();
100 HTable table =
101 new HTable(new Configuration(TEST_UTIL.getConfiguration()), TABLE_NAME);
102 ResultScanner r = table.getScanner(scan);
103 int count = 0;
104 try {
105 Result res = r.next();
106 while (res != null) {
107 count++;
108 if (count == 5) {
109
110 Thread.sleep(SCANNER_TIMEOUT+100);
111 }
112 res = r.next();
113 }
114 } catch (ScannerTimeoutException e) {
115 LOG.info("Got the timeout " + e.getMessage(), e);
116 return;
117 } finally {
118 table.close();
119 }
120 fail("We should be timing out");
121 LOG.info("END ************ test2481");
122 }
123
124
125
126
127
128
129 @Test(timeout=300000)
130 public void test2772() throws Exception {
131 LOG.info("START************ test2772");
132 HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
133 Scan scan = new Scan();
134
135
136
137
138 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
139 conf.setInt(
140 HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, SCANNER_TIMEOUT*100);
141 HTable higherScanTimeoutTable = new HTable(conf, TABLE_NAME);
142 ResultScanner r = higherScanTimeoutTable.getScanner(scan);
143
144 rs.abort("die!");
145 Result[] results = r.next(NB_ROWS);
146 assertEquals(NB_ROWS, results.length);
147 r.close();
148 higherScanTimeoutTable.close();
149 LOG.info("END ************ test2772");
150
151 }
152
153
154
155
156
157
158 @Test(timeout=300000)
159 public void test3686a() throws Exception {
160 LOG.info("START ************ TEST3686A---1");
161 HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
162 LOG.info("START ************ TEST3686A---1111");
163
164 Scan scan = new Scan();
165 scan.setCaching(SCANNER_CACHING);
166 LOG.info("************ TEST3686A");
167 MetaReader.fullScanMetaAndPrint(TEST_UTIL.getHBaseCluster().getMaster().getCatalogTracker());
168
169
170
171
172 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
173 conf.setInt(
174 HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, SCANNER_TIMEOUT*100);
175 HTable table = new HTable(conf, TABLE_NAME);
176 LOG.info("START ************ TEST3686A---22");
177
178 ResultScanner r = table.getScanner(scan);
179 LOG.info("START ************ TEST3686A---33");
180
181 int count = 1;
182 r.next();
183 LOG.info("START ************ TEST3686A---44");
184
185
186 rs.abort("die!");
187 while(r.next() != null) {
188 count ++;
189 }
190 assertEquals(NB_ROWS, count);
191 r.close();
192 table.close();
193 LOG.info("************ END TEST3686A");
194 }
195
196
197
198
199
200
201
202 @Test(timeout=300000)
203 public void test3686b() throws Exception {
204 LOG.info("START ************ test3686b");
205 HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
206 Scan scan = new Scan();
207 scan.setCaching(SCANNER_CACHING);
208
209
210
211
212 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
213 conf.setInt(
214 HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, SCANNER_TIMEOUT*100);
215 HTable higherScanTimeoutTable = new HTable(conf, TABLE_NAME);
216 ResultScanner r = higherScanTimeoutTable.getScanner(scan);
217 int count = 1;
218 r.next();
219
220 Thread.sleep(SCANNER_TIMEOUT+2000);
221 while(r.next() != null) {
222 count ++;
223 }
224 assertEquals(NB_ROWS, count);
225 r.close();
226 higherScanTimeoutTable.close();
227 LOG.info("END ************ END test3686b");
228
229 }
230
231 @org.junit.Rule
232 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
233 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
234 }
235