Repository: hbase
Updated Branches:
  refs/heads/branch-1 95d290bc5 -> b09c4fead


HBASE-13119 FileLink should implement equals

Conflicts:
        
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFileInfo.java


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

Branch: refs/heads/branch-1
Commit: b09c4feade0c86c284c814322971c3b8e0279a5e
Parents: 95d290b
Author: Enis Soztutar <[email protected]>
Authored: Fri Feb 27 17:19:56 2015 -0800
Committer: Enis Soztutar <[email protected]>
Committed: Fri Feb 27 18:13:45 2015 -0800

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


http://git-wip-us.apache.org/repos/asf/hbase/blob/b09c4fea/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/b09c4fea/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 c0d62fd..da2c7a0 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;
@@ -45,6 +46,41 @@ import org.junit.experimental.categories.Category;
  */
 @Category(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/b09c4fea/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 955996c..5aa96c1 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,22 +18,28 @@
  */
 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.SmallTests;
 import org.apache.hadoop.hbase.io.HFileLink;
+import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 /**
  * Test HStoreFile
  */
 @Category(SmallTests.class)
-public class TestStoreFileInfo extends HBaseTestCase {
+public class TestStoreFileInfo {
   private static final HBaseTestingUtility TEST_UTIL = new 
HBaseTestingUtility();
 
   /**
    * Validate that we can handle valid tables with '.', '_', and '-' chars.
    */
+  @Test
   public void testStoreFileNames() {
     String[] legalHFileLink = { "MyTable_02=abc012-def345", 
"MyTable_02.300=abc012-def345",
       "MyTable_02-400=abc012-def345", "MyTable_02-400.200=abc012-def345",
@@ -56,5 +62,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());
+  }
 }
 

Reply via email to