hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-13381 Expand TestSizeFailures to include small scans (Josh Elser)
Date Fri, 10 Apr 2015 00:59:02 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 69bbf839b -> 3f097d951


HBASE-13381 Expand TestSizeFailures to include small scans (Josh Elser)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3f097d95
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3f097d95
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3f097d95

Branch: refs/heads/0.98
Commit: 3f097d9518dc937446b9c4247b1aa505fba9f330
Parents: 69bbf83
Author: tedyu <yuzhihong@gmail.com>
Authored: Thu Apr 9 17:58:52 2015 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Thu Apr 9 17:58:52 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/client/TestSizeFailures.java   | 114 ++++++++++---------
 1 file changed, 62 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/3f097d95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSizeFailures.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSizeFailures.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSizeFailures.java
index 1be0e43..f8b0ec1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSizeFailures.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSizeFailures.java
@@ -20,12 +20,10 @@ package org.apache.hadoop.hbase.client;
 
 import static org.junit.Assert.assertEquals;
 
-import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.TreeSet;
+import java.util.Map.Entry;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -41,16 +39,17 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import com.google.common.collect.Maps;
+
 @Category(LargeTests.class)
 public class TestSizeFailures {
-  final Log LOG = LogFactory.getLog(getClass());
+  static final Log LOG = LogFactory.getLog(TestSizeFailures.class);
   protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
   private static byte[] FAMILY = Bytes.toBytes("testFamily");
   protected static int SLAVES = 1;
+  private static HTable table;
+  private static final int NUM_ROWS = 1000 * 1000, NUM_COLS = 10;
 
-  /**
-   * @throws java.lang.Exception
-   */
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
     // Uncomment the following lines if more verbosity is needed for
@@ -61,23 +60,9 @@ public class TestSizeFailures {
     Configuration conf = TEST_UTIL.getConfiguration();
     conf.setBoolean("hbase.table.sanity.checks", true); // ignore sanity checks in the server
     TEST_UTIL.startMiniCluster(SLAVES);
-  }
-
-  /**
-   * @throws java.lang.Exception
-   */
-  @AfterClass
-  public static void tearDownAfterClass() throws Exception {
-    TEST_UTIL.shutdownMiniCluster();
-  }
 
-  /**
-   * Basic client side validation of HBASE-13262
-   */
-  @Test
-  public void testScannerSeesAllRecords() throws Exception {
-    final int NUM_ROWS = 1000 * 1000, NUM_COLS = 10;
-    final TableName TABLENAME = TableName.valueOf("testScannerSeesAllRecords");
+    // Write a bunch of data
+    final TableName TABLENAME = TableName.valueOf("testSizeFailures");
     List<byte[]> qualifiers = new ArrayList<byte[]>();
     for (int i = 1; i <= 10; i++) {
       qualifiers.add(Bytes.toBytes(Integer.toString(i)));
@@ -93,7 +78,7 @@ public class TestSizeFailures {
       splits[i - 1][0] = (byte) (split);
     }
 
-    HTable table = TEST_UTIL.createTable(desc, splits);
+    table = TEST_UTIL.createTable(desc, splits);
 
     List<Put> puts = new LinkedList<Put>();
     for (int i = 0; i < NUM_ROWS; i++) {
@@ -106,53 +91,78 @@ public class TestSizeFailures {
       puts.add(p);
 
       if (puts.size() == 1000) {
-        Object[] results = new Object[1000];
-        try {
-          table.batch(puts, results);
-        } catch (IOException e) {
-          LOG.error("Failed to write data", e);
-          LOG.debug("Errors: " + Arrays.toString(results));
-        }
-
+        table.batch(puts, new Object[1000]);
         puts.clear();
       }
     }
 
     if (puts.size() > 0) {
-      Object[] results = new Object[puts.size()];
-      try {
-        table.batch(puts, results);
-      } catch (IOException e) {
-        LOG.error("Failed to write data", e);
-        LOG.debug("Errors: " + Arrays.toString(results));
-      }
+      table.batch(puts, new Object[puts.size()]);
     }
+  }
 
-    // Flush the memstore to disk
-    TEST_UTIL.flush(TABLENAME);
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
 
-    TreeSet<Integer> rows = new TreeSet<Integer>();
-    long rowsObserved = 0l;
-    long entriesObserved = 0l;
+  /**
+   * Basic client side validation of HBASE-13262
+   */
+  @Test
+  public void testScannerSeesAllRecords() throws Exception {
+   Scan s = new Scan();
+   s.addFamily(FAMILY);
+   s.setMaxResultSize(-1);
+   s.setBatch(-1);
+   s.setCaching(500);
+   Entry<Long,Long> entry = sumTable(table.getScanner(s));
+   long rowsObserved = entry.getKey();
+   long entriesObserved = entry.getValue();
+
+   // Verify that we see 1M rows and 10M cells
+   assertEquals(NUM_ROWS, rowsObserved);
+   assertEquals(NUM_ROWS * NUM_COLS, entriesObserved);
+ }
+
+ /**
+  * Basic client side validation of HBASE-13262
+  */
+  @Test
+  public void testSmallScannerSeesAllRecords() throws Exception {
     Scan s = new Scan();
+    s.setSmall(true);
     s.addFamily(FAMILY);
     s.setMaxResultSize(-1);
     s.setBatch(-1);
     s.setCaching(500);
-    ResultScanner scanner = table.getScanner(s);
+    Entry<Long,Long> entry = sumTable(table.getScanner(s));
+    long rowsObserved = entry.getKey();
+    long entriesObserved = entry.getValue();
+
+    // Verify that we see 1M rows and 10M cells
+    assertEquals(NUM_ROWS, rowsObserved);
+    assertEquals(NUM_ROWS * NUM_COLS, entriesObserved);
+  }
+
+  /**
+   * Count the number of rows and the number of entries from a scanner
+   *
+   * @param scanner
+   *          The Scanner
+   * @return An entry where the first item is rows observed and the second is entries observed.
+   */
+  private Entry<Long,Long> sumTable(ResultScanner scanner) {
+    long rowsObserved = 0l;
+    long entriesObserved = 0l;
+
     // Read all the records in the table
     for (Result result : scanner) {
       rowsObserved++;
-      String row = new String(result.getRow());
-      rows.add(Integer.parseInt(row));
       while (result.advance()) {
         entriesObserved++;
-        // result.current();
       }
     }
-
-    // Verify that we see 1M rows and 10M cells
-    assertEquals(NUM_ROWS, rowsObserved);
-    assertEquals(NUM_ROWS * NUM_COLS, entriesObserved);
+    return Maps.immutableEntry(rowsObserved,entriesObserved);
   }
 }


Mime
View raw message