hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject git commit: HBASE-12156 TableName cache doesn't used for once of valueOf methods (Andrey Stepachev)
Date Thu, 02 Oct 2014 16:46:36 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 5aea36d4d -> 0dfe556f3


HBASE-12156 TableName cache doesn't used for once of valueOf methods (Andrey Stepachev)


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

Branch: refs/heads/branch-1
Commit: 0dfe556f31c6dedc3d57501de0f0e0be9d3ce0a2
Parents: 5aea36d
Author: stack <stack@apache.org>
Authored: Thu Oct 2 09:45:02 2014 -0700
Committer: stack <stack@apache.org>
Committed: Thu Oct 2 09:46:30 2014 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/TableName.java |  2 +-
 .../apache/hadoop/hbase/util/TestTableName.java | 90 +++++++++++++++++++-
 2 files changed, 90 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/0dfe556f/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
index eb0f7a9..802319e 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
@@ -446,7 +446,7 @@ public final class TableName implements Comparable<TableName> {
     }
 
     for (TableName tn : tableCache) {
-      if (Arrays.equals(tn.getQualifier(), namespace) &&
+      if (Arrays.equals(tn.getQualifier(), qualifier) &&
           Arrays.equals(tn.getNamespace(), namespace)) {
         return tn;
       }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0dfe556f/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
index 04f4aa9..80d84f9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestTableName.java
@@ -17,6 +17,14 @@
  */
 package org.apache.hadoop.hbase.util;
 
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 
 import org.apache.hadoop.hbase.SmallTests;
@@ -91,5 +99,85 @@ public class TestTableName extends TestWatcher {
       }
     }
   }
-  
+
+  class Names {
+    String ns;
+    byte[] nsb;
+    String tn;
+    byte[] tnb;
+    String nn;
+    byte[] nnb;
+
+    Names(String ns, String tn) {
+      this.ns = ns;
+      nsb = ns.getBytes();
+      this.tn = tn;
+      tnb = tn.getBytes();
+      nn = this.ns + ":" + this.tn;
+      nnb = nn.getBytes();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      Names names = (Names) o;
+
+      if (!ns.equals(names.ns)) return false;
+      if (!tn.equals(names.tn)) return false;
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      int result = ns.hashCode();
+      result = 31 * result + tn.hashCode();
+      return result;
+    }
+  }
+
+  Names[] names = new Names[] {
+      new Names("n1", "n1"),
+      new Names("n2", "n2"),
+      new Names("table1", "table1"),
+      new Names("table2", "table2"),
+      new Names("table2", "table1"),
+      new Names("table1", "table2"),
+      new Names("n1", "table1"),
+      new Names("n1", "table1"),
+      new Names("n2", "table2"),
+      new Names("n2", "table2")
+  };
+
+  @Test
+  public void testValueOf() {
+
+    Map<String, TableName> inCache = new HashMap<>();
+    // fill cache
+    for (Names name : names) {
+      inCache.put(name.nn, TableName.valueOf(name.ns, name.tn));
+    }
+    for (Names name : names) {
+      assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.ns, name.tn),
name));
+      assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.nsb, name.tnb),
name));
+      assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.nn), name));
+      assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.nnb), name));
+      assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(
+          ByteBuffer.wrap(name.nsb), ByteBuffer.wrap(name.tnb)), name));
+    }
+
+  }
+
+  private TableName validateNames(TableName expected, Names names) {
+    assertEquals(expected.getNameAsString(), names.nn);
+    assertArrayEquals(expected.getName(), names.nnb);
+    assertEquals(expected.getQualifierAsString(), names.tn);
+    assertArrayEquals(expected.getQualifier(), names.tnb);
+    assertEquals(expected.getNamespaceAsString(), names.ns);
+    assertArrayEquals(expected.getNamespace(), names.nsb);
+    return expected;
+  }
+
 }


Mime
View raw message