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