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 org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseTestingUtility;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.After;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.fail;
36
37
38
39
40 public class TestScannerTimeout {
41
42 private final static HBaseTestingUtility
43 TEST_UTIL = new HBaseTestingUtility();
44
45 final Log LOG = LogFactory.getLog(getClass());
46 private final static byte[] SOME_BYTES = Bytes.toBytes("f");
47 private final static byte[] TABLE_NAME = Bytes.toBytes("t");
48 private final static int NB_ROWS = 10;
49 private final static int SCANNER_TIMEOUT = 1000;
50 private static HTable table;
51
52
53
54
55 @BeforeClass
56 public static void setUpBeforeClass() throws Exception {
57 Configuration c = TEST_UTIL.getConfiguration();
58 c.setInt("hbase.regionserver.lease.period", SCANNER_TIMEOUT);
59 TEST_UTIL.startMiniCluster(2);
60 table = TEST_UTIL.createTable(Bytes.toBytes("t"), SOME_BYTES);
61 for (int i = 0; i < NB_ROWS; i++) {
62 Put put = new Put(Bytes.toBytes(i));
63 put.add(SOME_BYTES, SOME_BYTES, SOME_BYTES);
64 table.put(put);
65 }
66 }
67
68
69
70
71 @AfterClass
72 public static void tearDownAfterClass() throws Exception {
73 TEST_UTIL.shutdownMiniCluster();
74 }
75
76
77
78
79 @Before
80 public void setUp() throws Exception {
81 TEST_UTIL.ensureSomeRegionServersAvailable(2);
82 }
83
84
85
86
87
88 @Test
89 public void test2481() throws Exception {
90 Scan scan = new Scan();
91 ResultScanner r = table.getScanner(scan);
92 int count = 0;
93 try {
94 Result res = r.next();
95 while (res != null) {
96 count++;
97 if (count == 5) {
98
99 Thread.sleep(SCANNER_TIMEOUT+100);
100 }
101 res = r.next();
102 }
103 } catch (ScannerTimeoutException e) {
104 LOG.info("Got the timeout " + e.getMessage(), e);
105 return;
106 }
107 fail("We should be timing out");
108 }
109
110
111
112
113
114
115 @Test
116 public void test2772() throws Exception {
117 int rs = TEST_UTIL.getHBaseCluster().getServerWith(
118 TEST_UTIL.getHBaseCluster().getRegions(
119 TABLE_NAME).get(0).getRegionName());
120 Scan scan = new Scan();
121
122
123
124
125 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
126 conf.setInt(
127 HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, SCANNER_TIMEOUT*100);
128 HTable higherScanTimeoutTable = new HTable(conf, TABLE_NAME);
129 ResultScanner r = higherScanTimeoutTable.getScanner(scan);
130
131 TEST_UTIL.getHBaseCluster().getRegionServer(rs).abort("die!");
132 Result[] results = r.next(NB_ROWS);
133 assertEquals(NB_ROWS, results.length);
134 r.close();
135
136 }
137 }