You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2013/03/15 18:23:04 UTC

svn commit: r1457027 [2/2] - in /hbase/branches/0.95: hbase-client/src/main/java/org/apache/hadoop/hbase/catalog/ hbase-client/src/main/java/org/apache/hadoop/hbase/client/ hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ hbase-client/src...

Added: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java?rev=1457027&view=auto
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java (added)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java Fri Mar 15 17:23:02 2013
@@ -0,0 +1,149 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.ConcurrentModificationException;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellScanner;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test that I can Iterate Client Actions that hold Cells (Get does not have Cells).
+ */
+@Category(SmallTests.class)
+public class TestPutDeleteEtcCellIteration {
+  private static final byte [] ROW = new byte [] {'r'};
+  private static final long TIMESTAMP = System.currentTimeMillis();
+  private static final int COUNT = 10;
+
+  @Test
+  public void testPutIteration() {
+    Put p = new Put(ROW);
+    for (int i = 0; i < COUNT; i++) {
+      byte [] bytes = Bytes.toBytes(i);
+      p.add(bytes, bytes, TIMESTAMP, bytes);
+    }
+    int index = 0;
+    for (CellScanner cellScanner = p.cellScanner(); cellScanner.advance();) {
+      Cell cell = cellScanner.current();
+      byte [] bytes = Bytes.toBytes(index++);
+      cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes));
+    }
+    assertEquals(COUNT, index);
+  }
+
+  @Test (expected = ConcurrentModificationException.class)
+  public void testPutConcurrentModificationOnIteration() {
+    Put p = new Put(ROW);
+    for (int i = 0; i < COUNT; i++) {
+      byte [] bytes = Bytes.toBytes(i);
+      p.add(bytes, bytes, TIMESTAMP, bytes);
+    }
+    int index = 0;
+    int trigger = 3;
+    for (CellScanner cellScanner = p.cellScanner(); cellScanner.advance();) {
+      Cell cell = cellScanner.current();
+      byte [] bytes = Bytes.toBytes(index++);
+      // When we hit the trigger, try inserting a new KV; should trigger exception
+      if (trigger == 3) p.add(bytes, bytes, TIMESTAMP, bytes);
+      cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes));
+    }
+    assertEquals(COUNT, index);
+  }
+
+  @Test
+  public void testDeleteIteration() {
+    Delete d = new Delete(ROW);
+    for (int i = 0; i < COUNT; i++) {
+      byte [] bytes = Bytes.toBytes(i);
+      d.deleteColumn(bytes, bytes, TIMESTAMP);
+    }
+    int index = 0;
+    for (CellScanner cellScanner = d.cellScanner(); cellScanner.advance();) {
+      Cell cell = cellScanner.current();
+      byte [] bytes = Bytes.toBytes(index++);
+      cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, KeyValue.Type.DeleteColumn));
+    }
+    assertEquals(COUNT, index);
+  }
+
+  @Test
+  public void testAppendIteration() {
+    Append a = new Append(ROW);
+    for (int i = 0; i < COUNT; i++) {
+      byte [] bytes = Bytes.toBytes(i);
+      a.add(bytes, bytes, bytes);
+    }
+    int index = 0;
+    for (CellScanner cellScanner = a.cellScanner(); cellScanner.advance();) {
+      Cell cell = cellScanner.current();
+      byte [] bytes = Bytes.toBytes(index++);
+      KeyValue kv = (KeyValue)cell;
+      assertTrue(Bytes.equals(kv.getFamily(), bytes));
+      assertTrue(Bytes.equals(kv.getValue(), bytes));
+    }
+    assertEquals(COUNT, index);
+  }
+
+  @Test
+  public void testIncrementIteration() {
+    Increment increment = new Increment(ROW);
+    for (int i = 0; i < COUNT; i++) {
+      byte [] bytes = Bytes.toBytes(i);
+      increment.addColumn(bytes, bytes, i);
+    }
+    int index = 0;
+    for (CellScanner cellScanner = increment.cellScanner(); cellScanner.advance();) {
+      Cell cell = cellScanner.current();
+      int value = index;
+      byte [] bytes = Bytes.toBytes(index++);
+      KeyValue kv = (KeyValue)cell;
+      assertTrue(Bytes.equals(kv.getFamily(), bytes));
+      long a = Bytes.toLong(kv.getValue());
+      assertEquals(value, a);
+    }
+    assertEquals(COUNT, index);
+  }
+
+  @Test
+  public void testResultIteration() {
+    Cell [] cells = new Cell[COUNT];
+    for(int i = 0; i < COUNT; i++) {
+      byte [] bytes = Bytes.toBytes(i);
+      cells[i] = new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes);
+    }
+    Result r = new Result(Arrays.asList(cells));
+    int index = 0;
+    for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance();) {
+      Cell cell = cellScanner.current();
+      byte [] bytes = Bytes.toBytes(index++);
+      cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes));
+    }
+    assertEquals(COUNT, index);
+  }
+}
\ No newline at end of file

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java?rev=1457027&r1=1457026&r2=1457027&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java (original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java Fri Mar 15 17:23:02 2013
@@ -318,7 +318,12 @@ public class TestCoprocessorInterface ex
     // now have all Environments fail
     for (int i = 0; i < regions.length; i++) {
       try {
-        Get g = new Get(regions[i].getStartKey());
+        byte [] r = regions[i].getStartKey();
+        if (r == null || r.length <= 0) {
+          // Its the start row.  Can't ask for null.  Ask for minimal key instead.
+          r = new byte [] {0};
+        }
+        Get g = new Get(r);
         regions[i].get(g);
         fail();
       } catch (org.apache.hadoop.hbase.exceptions.DoNotRetryIOException xc) {
@@ -342,7 +347,8 @@ public class TestCoprocessorInterface ex
         findCoprocessor(CoprocessorII.class.getName());
     // new map and object created, hence the reference is different
     // hence the old entry was indeed removed by the GC and new one has been created
-    assertFalse(((CoprocessorII)c2).getSharedData().get("test2") == o2);
+    Object o3 = ((CoprocessorII)c2).getSharedData().get("test2");
+    assertFalse(o3 == o2);
   }
 
   public void testCoprocessorInterface() throws IOException {

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java?rev=1457027&r1=1457026&r2=1457027&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java (original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java Fri Mar 15 17:23:02 2013
@@ -20,10 +20,12 @@
 package org.apache.hadoop.hbase.io;
 
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.TreeMap;
 import java.util.Map;
+import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -44,14 +46,11 @@ import org.apache.hadoop.hbase.io.hfile.
 import org.apache.hadoop.hbase.io.hfile.CachedBlock;
 import org.apache.hadoop.hbase.io.hfile.LruBlockCache;
 import org.apache.hadoop.hbase.regionserver.HRegion;
-import org.apache.hadoop.hbase.regionserver.MemStore;
 import org.apache.hadoop.hbase.regionserver.HStore;
-import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.regionserver.MemStore;
 import org.apache.hadoop.hbase.util.ClassSize;
-import org.junit.experimental.categories.Category;
 import org.junit.BeforeClass;
-import java.lang.management.ManagementFactory;
-import java.lang.management.RuntimeMXBean;
+import org.junit.experimental.categories.Category;
 
 /**
  * Testing the sizing that HeapSize offers and compares to the size given by
@@ -252,10 +251,10 @@ public class TestHeapSize extends TestCa
     cl = Put.class;
     expected = ClassSize.estimateBase(cl, false);
     //The actual TreeMap is not included in the above calculation
-    expected += ClassSize.TREEMAP;
-    Put put = new Put(Bytes.toBytes(""));
+    expected += ClassSize.align(ClassSize.TREEMAP + ClassSize.REFERENCE);
+    Put put = new Put(new byte [] {'0'});
     actual = put.heapSize();
-    if(expected != actual) {
+    if (expected != actual) {
       ClassSize.estimateBase(cl, true);
       assertEquals(expected, actual);
     }

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java?rev=1457027&r1=1457026&r2=1457027&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java (original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java Fri Mar 15 17:23:02 2013
@@ -477,7 +477,10 @@ public class TestEndToEndSplitTransactio
     HTable table = new HTable(conf, hri.getTableName());
 
     try {
-      Get get = new Get(hri.getStartKey());
+      byte [] row = hri.getStartKey();
+      // Check for null/empty row.  If we find one, use a key that is likely to be in first region.
+      if (row == null || row.length <= 0) row = new byte [] {'0'};
+      Get get = new Get(row);
       while (System.currentTimeMillis() - start < timeout) {
         try {
           table.get(get);

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java?rev=1457027&r1=1457026&r2=1457027&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java (original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java Fri Mar 15 17:23:02 2013
@@ -164,8 +164,9 @@ public class TestMemStore extends TestCa
   /**
    * A simple test which verifies the 3 possible states when scanning across snapshot.
    * @throws IOException
+   * @throws CloneNotSupportedException 
    */
-  public void testScanAcrossSnapshot2() throws IOException {
+  public void testScanAcrossSnapshot2() throws IOException, CloneNotSupportedException {
     // we are going to the scanning across snapshot with two kvs
     // kv1 should always be returned before kv2
     final byte[] one = Bytes.toBytes(1);

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java?rev=1457027&r1=1457026&r2=1457027&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java (original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java Fri Mar 15 17:23:02 2013
@@ -32,7 +32,6 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.IOException;
 
 @Category(MediumTests.class)
 public class TestRegionServerMetrics {