Index: src/test/org/apache/hadoop/hbase/client/TestScannerTimeout.java =================================================================== --- src/test/org/apache/hadoop/hbase/client/TestScannerTimeout.java (revision 0) +++ src/test/org/apache/hadoop/hbase/client/TestScannerTimeout.java (revision 0) @@ -0,0 +1,102 @@ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClusterTestCase; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Test various scanner timeout issues. + */ +public class TestScannerTimeout extends HBaseClusterTestCase { + final Log LOG = LogFactory.getLog(getClass()); + private final byte[] someBytes = Bytes.toBytes("f"); + + @Override + protected void preHBaseClusterSetup() throws Exception { + this.conf.setInt("hbase.regionserver.lease.period", 1000); + super.preHBaseClusterSetup(); + } + + private HTable createTable(byte [] tableName, byte [][] families, + int numVersions) + throws IOException { + HTableDescriptor desc = new HTableDescriptor(tableName); + for(byte [] family : families) { + HColumnDescriptor hcd = new HColumnDescriptor(family, numVersions, + HColumnDescriptor.DEFAULT_COMPRESSION, + HColumnDescriptor.DEFAULT_IN_MEMORY, + HColumnDescriptor.DEFAULT_BLOCKCACHE, + Integer.MAX_VALUE, HColumnDescriptor.DEFAULT_TTL, false); + desc.addFamily(hcd); + } + HBaseAdmin admin = new HBaseAdmin(conf); + admin.createTable(desc); + return new HTable(conf, tableName); + } + + /** + * Test that we do get a ScannerTimeoutException + * @throws Exception + */ + @Test + public void test2481() throws Exception { + int initialCount = 10; + HTable t = createTable(Bytes.toBytes("t"), new byte [][] {someBytes}, 1); + for (int i = 0; i < initialCount; i++) { + Put put = new Put(Bytes.toBytes(i)); + put.add(someBytes, someBytes, someBytes); + t.put(put); + } + // Scan. + Scan scan = new Scan(); + ResultScanner r = t.getScanner(scan); + int count = 0; + boolean exception = false; + try { + Result res = r.next(); + while (res != null) { + count++; + if (count == 5) { + Thread.sleep(1500); + } + res = r.next(); + } + } catch (ScannerTimeoutException e) { + LOG.info("Got the timeout " + e.getMessage(), e); + exception = true; + } + assertTrue(exception); + // Try with iterator. + exception = false; + scan = new Scan(); + r = t.getScanner(scan); + try { + count = 0; + for (Result rr: r) { + count++; + if (count == 5) { + Thread.sleep(1500); + } + } + } catch (java.lang.RuntimeException e) { + LOG.info("Got the timeout " + e.getMessage(), e); + exception = true; + } + assertTrue(exception); + } +}