You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by en...@apache.org on 2015/02/28 03:09:39 UTC

hbase git commit: HBASE-13119 FileLink should implement equals

Repository: hbase
Updated Branches:
  refs/heads/master 21f12ce8e -> bec2b0d32


HBASE-13119 FileLink should implement equals


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

Branch: refs/heads/master
Commit: bec2b0d320554b0af8c891fddc147a953f35765f
Parents: 21f12ce
Author: Enis Soztutar <en...@apache.org>
Authored: Fri Feb 27 17:19:56 2015 -0800
Committer: Enis Soztutar <en...@apache.org>
Committed: Fri Feb 27 18:09:29 2015 -0800

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/io/FileLink.java    | 20 ++++++++++-
 .../apache/hadoop/hbase/io/TestFileLink.java    | 36 ++++++++++++++++++++
 .../hbase/regionserver/TestStoreFileInfo.java   | 28 +++++++++++++--
 3 files changed, 81 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/bec2b0d3/hbase-server/src/main/java/org/apache/hadoop/hbase/io/FileLink.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/FileLink.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/FileLink.java
index 7d96920..67153ae 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/FileLink.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/FileLink.java
@@ -19,8 +19,8 @@
 package org.apache.hadoop.hbase.io;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.FileNotFoundException;
@@ -336,6 +336,7 @@ public class FileLink {
     return locations;
   }
 
+  @Override
   public String toString() {
     StringBuilder str = new StringBuilder(getClass().getName());
     str.append(" locations=[");
@@ -472,5 +473,22 @@ public class FileLink {
     if (dirPath == null) return false;
     return dirPath.getName().startsWith(BACK_REFERENCES_DIRECTORY_PREFIX);
   }
+
+  @Override
+  public boolean equals(Object obj) {
+    // Assumes that the ordering of locations between objects are the same. This is true for the
+    // current subclasses already (HFileLink, WALLink). Otherwise, we may have to sort the locations
+    // or keep them presorted
+    if (this.getClass().equals(obj.getClass())) {
+      return Arrays.equals(this.locations, ((FileLink) obj).locations);
+    }
+
+    return false;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(locations);
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/bec2b0d3/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
index 777b3cd..0da685f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.io;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.io.FileNotFoundException;
@@ -46,6 +47,41 @@ import org.junit.experimental.categories.Category;
  */
 @Category({IOTests.class, MediumTests.class})
 public class TestFileLink {
+
+  @Test
+  public void testEquals() {
+    Path p1 = new Path("/p1");
+    Path p2 = new Path("/p2");
+    Path p3 = new Path("/p3");
+
+    assertEquals(new FileLink(), new FileLink());
+    assertEquals(new FileLink(p1), new FileLink(p1));
+    assertEquals(new FileLink(p1, p2), new FileLink(p1, p2));
+    assertEquals(new FileLink(p1, p2, p3), new FileLink(p1, p2, p3));
+
+    assertNotEquals(new FileLink(p1), new FileLink(p3));
+    assertNotEquals(new FileLink(p1, p2), new FileLink(p1));
+    assertNotEquals(new FileLink(p1, p2), new FileLink(p2));
+    assertNotEquals(new FileLink(p1, p2), new FileLink(p2, p1)); // ordering important!
+  }
+
+  @Test
+  public void testHashCode() {
+    Path p1 = new Path("/p1");
+    Path p2 = new Path("/p2");
+    Path p3 = new Path("/p3");
+
+    assertEquals(new FileLink().hashCode(), new FileLink().hashCode());
+    assertEquals(new FileLink(p1).hashCode(), new FileLink(p1).hashCode());
+    assertEquals(new FileLink(p1, p2).hashCode(), new FileLink(p1, p2).hashCode());
+    assertEquals(new FileLink(p1, p2, p3).hashCode(), new FileLink(p1, p2, p3).hashCode());
+
+    assertNotEquals(new FileLink(p1).hashCode(), new FileLink(p3).hashCode());
+    assertNotEquals(new FileLink(p1, p2).hashCode(), new FileLink(p1).hashCode());
+    assertNotEquals(new FileLink(p1, p2).hashCode(), new FileLink(p2).hashCode());
+    assertNotEquals(new FileLink(p1, p2).hashCode(), new FileLink(p2, p1).hashCode()); // ordering
+  }
+
   /**
    * Test, on HDFS, that the FileLink is still readable
    * even when the current file gets renamed.

http://git-wip-us.apache.org/repos/asf/hbase/blob/bec2b0d3/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFileInfo.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFileInfo.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFileInfo.java
index da39f59..1125d11 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFileInfo.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFileInfo.java
@@ -18,7 +18,11 @@
  */
 package org.apache.hadoop.hbase.regionserver;
 
-import org.apache.hadoop.hbase.HBaseTestCase;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
@@ -30,7 +34,7 @@ import org.junit.experimental.categories.Category;
  * Test HStoreFile
  */
 @Category({RegionServerTests.class, SmallTests.class})
-public class TestStoreFileInfo extends HBaseTestCase {
+public class TestStoreFileInfo {
   private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
 
   /**
@@ -59,5 +63,25 @@ public class TestStoreFileInfo extends HBaseTestCase {
       assertFalse("should not be a valid link: " + name, HFileLink.isHFileLink(name));
     }
   }
+
+  @Test
+  public void testEqualsWithLink() throws IOException {
+    Path origin = new Path("/origin");
+    Path tmp = new Path("/tmp");
+    Path archive = new Path("/archive");
+    HFileLink link1 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
+      new Path(archive, "f1"));
+    HFileLink link2 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
+      new Path(archive, "f1"));
+
+
+    StoreFileInfo info1 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
+      TEST_UTIL.getTestFileSystem(), null, link1);
+    StoreFileInfo info2 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
+      TEST_UTIL.getTestFileSystem(), null, link2);
+
+    assertEquals(info1, info2);
+    assertEquals(info1.hashCode(), info2.hashCode());
+  }
 }