Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC29511F57 for ; Fri, 4 Jul 2014 04:54:40 +0000 (UTC) Received: (qmail 43002 invoked by uid 500); 4 Jul 2014 04:54:40 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 42959 invoked by uid 500); 4 Jul 2014 04:54:40 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 42948 invoked by uid 99); 4 Jul 2014 04:54:40 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jul 2014 04:54:40 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B16E0999F9D; Fri, 4 Jul 2014 04:54:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stack@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: HBASE-11463 (findbugs) HE: Class defines equals() and uses Object.hashCode() Date: Fri, 4 Jul 2014 04:54:39 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/master 80f1271ee -> 6da1a485f HBASE-11463 (findbugs) HE: Class defines equals() and uses Object.hashCode() Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/6da1a485 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/6da1a485 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/6da1a485 Branch: refs/heads/master Commit: 6da1a485fc50f8b75ebce2b582f718dcce0845af Parents: 80f1271 Author: stack Authored: Thu Jul 3 21:54:03 2014 -0700 Committer: stack Committed: Thu Jul 3 21:54:28 2014 -0700 ---------------------------------------------------------------------- .../regionserver/MetricsRegionSourceImpl.java | 5 ++ .../TestMetricsRegionSourceImpl.java | 5 +- .../hadoop/hbase/io/hfile/LruCachedBlock.java | 5 ++ .../apache/hadoop/hbase/mapred/TableSplit.java | 10 ++++ .../apache/hadoop/hbase/master/RegionPlan.java | 5 ++ .../hbase/master/balancer/ServerAndLoad.java | 7 +++ .../hbase/regionserver/MemStoreFlusher.java | 5 ++ .../hbase/security/token/AuthenticationKey.java | 10 ++++ .../hbase/io/hfile/TestLruCachedBlock.java | 57 +++++++++++++++++++ .../hadoop/hbase/mapred/TestSplitTable.java | 53 +++++++++-------- .../hadoop/hbase/master/TestRegionPlan.java | 52 +++++++++++++++++ .../master/balancer/TestServerAndLoad.java | 48 ++++++++++++++++ .../regionserver/TestFlushRegionEntry.java | 47 +++++++++++++++ .../security/token/TestAuthenticationKey.java | 60 ++++++++++++++++++++ 14 files changed, 343 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java ---------------------------------------------------------------------- diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java index 09f877d..4ca792e 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java @@ -158,6 +158,11 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { } @Override + public int hashCode() { + return this.regionWrapper.getRegionName().hashCode(); + } + + @Override public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof MetricsRegionSourceImpl)) return false; http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java ---------------------------------------------------------------------- diff --git a/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java index 30beb8a..eb5c814 100644 --- a/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java +++ b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java @@ -22,12 +22,13 @@ import org.apache.hadoop.hbase.CompatibilitySingletonFactory; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; public class TestMetricsRegionSourceImpl { @Test - public void testCompareTo() throws Exception { + public void testCompareToHashCodeEquals() throws Exception { MetricsRegionServerSourceFactory fact = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class); MetricsRegionSource one = fact.createRegion(new RegionWrapperStub("TEST")); @@ -35,6 +36,8 @@ public class TestMetricsRegionSourceImpl { MetricsRegionSource two = fact.createRegion(new RegionWrapperStub("TWO")); assertEquals(0, one.compareTo(oneClone)); + assertEquals(one.hashCode(), oneClone.hashCode()); + assertNotEquals(one, two); assertTrue( one.compareTo(two) < 0); assertTrue( two.compareTo(one) > 0); http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruCachedBlock.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruCachedBlock.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruCachedBlock.java index 25cfb2e..1b53eb0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruCachedBlock.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruCachedBlock.java @@ -102,6 +102,11 @@ public class LruCachedBlock implements HeapSize, Comparable { } @Override + public int hashCode() { + return (int)(accessTime ^ (accessTime >>> 32)); + } + + @Override public boolean equals(Object obj) { if (this == obj) { return true; http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java index 9083586..b3c8b82 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java @@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.mapred; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.util.Arrays; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -138,4 +139,13 @@ public class TableSplit implements InputSplit, Comparable { Bytes.equals(m_endRow, other.m_endRow) && m_regionLocation.equals(other.m_regionLocation); } + + @Override + public int hashCode() { + int result = m_tableName != null ? m_tableName.hashCode() : 0; + result = 31 * result + Arrays.hashCode(m_startRow); + result = 31 * result + Arrays.hashCode(m_endRow); + result = 31 * result + (m_regionLocation != null ? m_regionLocation.hashCode() : 0); + return result; + } } http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java index 6fb3edf..31b4be2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java @@ -117,6 +117,11 @@ public class RegionPlan implements Comparable { } @Override + public int hashCode() { + return getRegionName().hashCode(); + } + + @Override public boolean equals(Object obj) { if (this == obj) { return true; http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ServerAndLoad.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ServerAndLoad.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ServerAndLoad.java index 93298d8..22082e8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ServerAndLoad.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/ServerAndLoad.java @@ -51,6 +51,13 @@ class ServerAndLoad implements Comparable, Serializable { } @Override + public int hashCode() { + int result = load; + result = 31 * result + ((sn == null) ? 0 : sn.hashCode()); + return result; + } + + @Override public boolean equals(Object o) { if (o instanceof ServerAndLoad) { ServerAndLoad sl = (ServerAndLoad) o; http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java index 5bf3a19..165176f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java @@ -733,6 +733,11 @@ class MemStoreFlusher implements FlushRequester { } @Override + public int hashCode() { + return (int) getDelay(TimeUnit.MILLISECONDS); + } + + @Override public boolean equals(Object obj) { if (this == obj) { return true; http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/AuthenticationKey.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/AuthenticationKey.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/AuthenticationKey.java index c68af4e..5f4378f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/AuthenticationKey.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/AuthenticationKey.java @@ -19,9 +19,11 @@ package org.apache.hadoop.hbase.security.token; import javax.crypto.SecretKey; + import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.util.Arrays; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.Writable; @@ -63,6 +65,14 @@ public class AuthenticationKey implements Writable { } @Override + public int hashCode() { + int result = id; + result = 31 * result + (int) (expirationDate ^ (expirationDate >>> 32)); + result = 31 * result + ((secret == null) ? 0 : Arrays.hashCode(secret.getEncoded())); + return result; + } + + @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof AuthenticationKey)) { return false; http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java new file mode 100644 index 0000000..a2baf55 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java @@ -0,0 +1,57 @@ +/** + * 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.io.hfile; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.apache.hadoop.hbase.SmallTests; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.mockito.Mockito; + +@Category(SmallTests.class) +public class TestLruCachedBlock { + + LruCachedBlock block; + LruCachedBlock blockEqual; + LruCachedBlock blockNotEqual; + + @Before + public void setUp() throws Exception { + BlockCacheKey cacheKey = new BlockCacheKey("name", 0); + BlockCacheKey otherKey = new BlockCacheKey("name2", 1); + + Cacheable cacheable = Mockito.mock(Cacheable.class); + Cacheable otheCacheable = Mockito.mock(Cacheable.class); + + block = new LruCachedBlock(cacheKey, cacheable, 0); + blockEqual = new LruCachedBlock(otherKey, otheCacheable, 0); + blockNotEqual = new LruCachedBlock(cacheKey, cacheable, 1); + } + + @Test + public void testEquality() { + assertEquals(block.hashCode(), blockEqual.hashCode()); + assertNotEquals(block.hashCode(), blockNotEqual.hashCode()); + + assertEquals(block, blockEqual); + assertNotEquals(block, blockNotEqual); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java index 68d2fe0..86f6272 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java @@ -18,7 +18,8 @@ */ package org.apache.hadoop.hbase.mapred; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import org.apache.hadoop.hbase.SmallTests; @@ -60,29 +61,31 @@ public class TestSplitTable { @Test @SuppressWarnings("deprecation") public void testSplitTableEquals() { - assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"), - Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes - .toBytes("tableB"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"), - "locationA"))); - - assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"), - Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes - .toBytes("tableA"), Bytes.toBytes("bbb"), Bytes.toBytes("ddd"), - "locationA"))); - - assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"), - Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes - .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("eee"), - "locationA"))); - - assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"), - Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes - .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"), - "locationB"))); - - assertTrue(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"), - Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes - .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"), - "locationA"))); + byte[] tableA = Bytes.toBytes("tableA"); + byte[] aaa = Bytes.toBytes("aaa"); + byte[] ddd = Bytes.toBytes("ddd"); + String locationA = "locationA"; + + TableSplit tablesplit = new TableSplit(tableA, aaa, ddd, locationA); + + TableSplit tableB = new TableSplit(Bytes.toBytes("tableB"), aaa, ddd, locationA); + assertNotEquals(tablesplit.hashCode(), tableB.hashCode()); + assertNotEquals(tablesplit, tableB); + + TableSplit startBbb = new TableSplit(tableA, Bytes.toBytes("bbb"), ddd, locationA); + assertNotEquals(tablesplit.hashCode(), startBbb.hashCode()); + assertNotEquals(tablesplit, startBbb); + + TableSplit endEee = new TableSplit(tableA, aaa, Bytes.toBytes("eee"), locationA); + assertNotEquals(tablesplit.hashCode(), endEee.hashCode()); + assertNotEquals(tablesplit, endEee); + + TableSplit locationB = new TableSplit(tableA, aaa, ddd, "locationB"); + assertNotEquals(tablesplit.hashCode(), locationB.hashCode()); + assertNotEquals(tablesplit, locationB); + + TableSplit same = new TableSplit(tableA, aaa, ddd, locationA); + assertEquals(tablesplit.hashCode(), same.hashCode()); + assertEquals(tablesplit, same); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlan.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlan.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlan.java new file mode 100644 index 0000000..a42a04c --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlan.java @@ -0,0 +1,52 @@ +/** + * 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.master; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.SmallTests; +import org.apache.hadoop.hbase.TableName; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(SmallTests.class) +public class TestRegionPlan { + @Test + public void test() { + HRegionInfo hri = new HRegionInfo(TableName.valueOf("table")); + ServerName source = ServerName.valueOf("source", 1234, 2345); + ServerName dest = ServerName.valueOf("dest", 1234, 2345); + + // Identiy equality + RegionPlan plan = new RegionPlan(hri, source, dest); + assertEquals(plan.hashCode(), new RegionPlan(hri, source, dest).hashCode()); + assertEquals(plan, new RegionPlan(hri, source, dest)); + + // Source and destination not used for equality + assertEquals(plan.hashCode(), new RegionPlan(hri, dest, source).hashCode()); + assertEquals(plan, new RegionPlan(hri, dest, source)); + + // HRI is used for equality + HRegionInfo other = new HRegionInfo(TableName.valueOf("other")); + assertNotEquals(plan.hashCode(), new RegionPlan(other, source, dest).hashCode()); + assertNotEquals(plan, new RegionPlan(other, source, dest)); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestServerAndLoad.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestServerAndLoad.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestServerAndLoad.java new file mode 100644 index 0000000..c067f9d --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestServerAndLoad.java @@ -0,0 +1,48 @@ +/** + * 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.master.balancer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(SmallTests.class) +public class TestServerAndLoad { + + @Test + public void test() { + ServerName server = ServerName.valueOf("host", 12345, 112244); + int startcode = 12; + + ServerAndLoad sal = new ServerAndLoad(server, startcode); + assertEquals(sal.hashCode(), new ServerAndLoad(server, startcode).hashCode()); + assertEquals(sal, new ServerAndLoad(server, startcode)); + + assertNotEquals(sal.hashCode(), new ServerAndLoad(server, startcode + 1).hashCode()); + assertNotEquals(sal, new ServerAndLoad(server, startcode + 1)); + + ServerName other = ServerName.valueOf("other", 12345, 112244); + assertNotEquals(sal.hashCode(), new ServerAndLoad(other, startcode).hashCode()); + assertNotEquals(sal, new ServerAndLoad(other, startcode)); + } + +} http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java new file mode 100644 index 0000000..33c5c8f --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java @@ -0,0 +1,47 @@ +/** + * 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.regionserver; + +import static org.junit.Assert.*; + +import org.apache.hadoop.hbase.SmallTests; +import org.apache.hadoop.hbase.regionserver.MemStoreFlusher.FlushRegionEntry; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; +import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.mockito.Mockito; + +@Category(SmallTests.class) +public class TestFlushRegionEntry { + @Before + public void setUp() throws Exception { + ManualEnvironmentEdge edge = new ManualEnvironmentEdge(); + edge.setValue(12345); + EnvironmentEdgeManager.injectEdge(edge); + } + + @Test + public void test() { + FlushRegionEntry entry = new FlushRegionEntry(Mockito.mock(HRegion.class)); + FlushRegionEntry other = new FlushRegionEntry(Mockito.mock(HRegion.class)); + + assertEquals(entry.hashCode(), other.hashCode()); + assertEquals(entry, other); + } + + @After + public void teardown() { + EnvironmentEdgeManager.reset(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/6da1a485/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestAuthenticationKey.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestAuthenticationKey.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestAuthenticationKey.java new file mode 100644 index 0000000..50d5095 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestAuthenticationKey.java @@ -0,0 +1,60 @@ +/** + * 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.security.token; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.io.UnsupportedEncodingException; + +import javax.crypto.SecretKey; + +import org.apache.hadoop.hbase.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.mockito.Mockito; + +@Category(SmallTests.class) +public class TestAuthenticationKey { + + @Test + public void test() throws UnsupportedEncodingException { + SecretKey secret = Mockito.mock(SecretKey.class); + Mockito.when(secret.getEncoded()).thenReturn("secret".getBytes("UTF-8")); + + AuthenticationKey key = new AuthenticationKey(0, 1234, secret); + assertEquals(key.hashCode(), new AuthenticationKey(0, 1234, secret).hashCode()); + assertEquals(key, new AuthenticationKey(0, 1234, secret)); + + AuthenticationKey otherID = new AuthenticationKey(1, 1234, secret); + assertNotEquals(key.hashCode(), otherID.hashCode()); + assertNotEquals(key, otherID); + + AuthenticationKey otherExpiry = new AuthenticationKey(0, 8765, secret); + assertNotEquals(key.hashCode(), otherExpiry.hashCode()); + assertNotEquals(key, otherExpiry); + + SecretKey other = Mockito.mock(SecretKey.class); + Mockito.when(secret.getEncoded()).thenReturn("other".getBytes("UTF-8")); + + AuthenticationKey otherSecret = new AuthenticationKey(0, 1234, other); + assertNotEquals(key.hashCode(), otherSecret.hashCode()); + assertNotEquals(key, otherSecret); + } + +}