From c0c1f5d35cf7876cf2ba2bcfa53a4aa96a08afb6 Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Tue, 16 Apr 2013 15:53:31 -0700 Subject: [PATCH] Move small client tests into hbase-client --- .../hadoop/hbase/client/TestConnectionUtils.java | 56 ++++ .../org/apache/hadoop/hbase/client/TestResult.java | 281 ++++++++++++++++++++ .../hadoop/hbase/HBaseCommonTestingUtility.java | 20 ++ .../org/apache/hadoop/hbase/HBaseTestCase.java | 18 -- .../hadoop/hbase/client/TestConnectionUtils.java | 56 ---- .../org/apache/hadoop/hbase/client/TestResult.java | 281 -------------------- .../hadoop/hbase/regionserver/TestHRegion.java | 38 +-- .../hadoop/hbase/regionserver/TestKeepDeletes.java | 9 +- .../hadoop/hbase/regionserver/TestMinVersions.java | 2 +- .../hadoop/hbase/regionserver/TestStoreFile.java | 4 +- 10 files changed, 389 insertions(+), 376 deletions(-) create mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java create mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestResult.java delete mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java delete mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java diff --git hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java new file mode 100644 index 0000000..4120ec3 --- /dev/null +++ hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java @@ -0,0 +1,56 @@ +/** + * Copyright The Apache Software Foundation + * + * 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 org.apache.hadoop.hbase.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.Set; +import java.util.TreeSet; + +import static org.junit.Assert.assertTrue; + +@Category(SmallTests.class) +public class TestConnectionUtils { + + @Test + public void testRetryTimeJitter() { + long[] retries = new long[200]; + long baseTime = 1000000; //Larger number than reality to help test randomness. + long maxTimeExpected = (long) (baseTime * 1.01f); + for (int i = 0; i < retries.length; i++) { + retries[i] = ConnectionUtils.getPauseTime(baseTime, 0); + } + + Set retyTimeSet = new TreeSet(); + for (long l : retries) { + /*make sure that there is some jitter but only 1%*/ + assertTrue(l >= baseTime); + assertTrue(l <= maxTimeExpected); + // Add the long to the set + retyTimeSet.add(l); + } + + //Make sure that most are unique. some overlap will happen + assertTrue(retyTimeSet.size() > (retries.length * 0.80)); + } + +} diff --git hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestResult.java hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestResult.java new file mode 100644 index 0000000..715f648 --- /dev/null +++ hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestResult.java @@ -0,0 +1,281 @@ +/* + * + * 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 junit.framework.TestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; +import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.SmallTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.experimental.categories.Category; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.List; + +@Category(SmallTests.class) +public class TestResult extends TestCase { + + private static final Log LOG = LogFactory.getLog(TestResult.class.getName()); + + static KeyValue[] genKVs(final byte[] row, final byte[] family, + final byte[] value, + final long timestamp, + final int cols) { + KeyValue [] kvs = new KeyValue[cols]; + + for (int i = 0; i < cols ; i++) { + kvs[i] = new KeyValue( + row, family, Bytes.toBytes(i), + timestamp, + Bytes.add(value, Bytes.toBytes(i))); + } + return kvs; + } + + static final byte [] row = Bytes.toBytes("row"); + static final byte [] family = Bytes.toBytes("family"); + static final byte [] value = Bytes.toBytes("value"); + + public void testBasicGetColumn() throws Exception { + KeyValue [] kvs = genKVs(row, family, value, 1, 100); + + Arrays.sort(kvs, KeyValue.COMPARATOR); + + Result r = new Result(kvs); + + for (int i = 0; i < 100; ++i) { + final byte[] qf = Bytes.toBytes(i); + + List ks = r.getColumn(family, qf); + assertEquals(1, ks.size()); + HBaseCommonTestingUtility.assertByteEquals(qf, ks.get(0).getQualifier()); + assertEquals(ks.get(0), r.getColumnLatest(family, qf)); + } + } + + public void testMultiVersionGetColumn() throws Exception { + KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); + KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); + + KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; + System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); + System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); + + Arrays.sort(kvs, KeyValue.COMPARATOR); + + Result r = new Result(kvs); + for (int i = 0; i < 100; ++i) { + final byte[] qf = Bytes.toBytes(i); + + List ks = r.getColumn(family, qf); + assertEquals(2, ks.size()); + HBaseCommonTestingUtility.assertByteEquals(qf, ks.get(0).getQualifier()); + assertEquals(200, ks.get(0).getTimestamp()); + assertEquals(ks.get(0), r.getColumnLatest(family, qf)); + } + } + + public void testBasicGetValue() throws Exception { + KeyValue [] kvs = genKVs(row, family, value, 1, 100); + + Arrays.sort(kvs, KeyValue.COMPARATOR); + + Result r = new Result(kvs); + + for (int i = 0; i < 100; ++i) { + final byte[] qf = Bytes.toBytes(i); + + HBaseCommonTestingUtility.assertByteEquals(Bytes.add(value, + Bytes.toBytes(i)), + r.getValue(family, qf)); + assertTrue(r.containsColumn(family, qf)); + } + } + + public void testMultiVersionGetValue() throws Exception { + KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); + KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); + + KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; + System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); + System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); + + Arrays.sort(kvs, KeyValue.COMPARATOR); + + Result r = new Result(kvs); + for (int i = 0; i < 100; ++i) { + final byte[] qf = Bytes.toBytes(i); + + HBaseCommonTestingUtility.assertByteEquals(Bytes.add(value, Bytes.toBytes(i)), + r.getValue(family, qf)); + assertTrue(r.containsColumn(family, qf)); + } + } + + public void testBasicLoadValue() throws Exception { + KeyValue [] kvs = genKVs(row, family, value, 1, 100); + + Arrays.sort(kvs, KeyValue.COMPARATOR); + + Result r = new Result(kvs); + ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); + + for (int i = 0; i < 100; ++i) { + final byte[] qf = Bytes.toBytes(i); + + loadValueBuffer.clear(); + r.loadValue(family, qf, loadValueBuffer); + loadValueBuffer.flip(); + assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), loadValueBuffer); + assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), + r.getValueAsByteBuffer(family, qf)); + } + } + + public void testMultiVersionLoadValue() throws Exception { + KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); + KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); + + KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; + System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); + System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); + + Arrays.sort(kvs, KeyValue.COMPARATOR); + + ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); + + Result r = new Result(kvs); + for (int i = 0; i < 100; ++i) { + final byte[] qf = Bytes.toBytes(i); + + loadValueBuffer.clear(); + r.loadValue(family, qf, loadValueBuffer); + loadValueBuffer.flip(); + assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), loadValueBuffer); + assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), + r.getValueAsByteBuffer(family, qf)); + } + } + + /** + * Verify that Result.compareResults(...) behaves correctly. + */ + public void testCompareResults() throws Exception { + byte [] value1 = Bytes.toBytes("value1"); + byte [] qual = Bytes.toBytes("qual"); + + KeyValue kv1 = new KeyValue(row, family, qual, value); + KeyValue kv2 = new KeyValue(row, family, qual, value1); + + Result r1 = new Result(new KeyValue[] {kv1}); + Result r2 = new Result(new KeyValue[] {kv2}); + // no exception thrown + Result.compareResults(r1, r1); + try { + // these are different (HBASE-4800) + Result.compareResults(r1, r2); + fail(); + } catch (Exception x) { + assertTrue(x.getMessage().startsWith("This result was different:")); + } + } + + + /** + * Microbenchmark that compares {@link Result#getValue} and {@link Result#loadValue} performance. + * + * @throws Exception + */ + public void doReadBenchmark() throws Exception { + + final int n = 5; + final int m = 100000000; + + StringBuilder valueSB = new StringBuilder(); + for (int i = 0; i < 100; i++) { + valueSB.append((byte)(Math.random() * 10)); + } + + StringBuilder rowSB = new StringBuilder(); + for (int i = 0; i < 50; i++) { + rowSB.append((byte)(Math.random() * 10)); + } + + KeyValue [] kvs = genKVs(Bytes.toBytes(rowSB.toString()), family, + Bytes.toBytes(valueSB.toString()), 1, n); + Arrays.sort(kvs, KeyValue.COMPARATOR); + ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); + Result r = new Result(kvs); + + byte[][] qfs = new byte[n][Bytes.SIZEOF_INT]; + for (int i = 0; i < n; ++i) { + System.arraycopy(qfs[i], 0, Bytes.toBytes(i), 0, Bytes.SIZEOF_INT); + } + + // warm up + for (int k = 0; k < 100000; k++) { + for (int i = 0; i < n; ++i) { + r.getValue(family, qfs[i]); + loadValueBuffer.clear(); + r.loadValue(family, qfs[i], loadValueBuffer); + loadValueBuffer.flip(); + } + } + + System.gc(); + long start = System.nanoTime(); + for (int k = 0; k < m; k++) { + for (int i = 0; i < n; ++i) { + loadValueBuffer.clear(); + r.loadValue(family, qfs[i], loadValueBuffer); + loadValueBuffer.flip(); + } + } + long stop = System.nanoTime(); + System.out.println("loadValue(): " + (stop - start)); + + System.gc(); + start = System.nanoTime(); + for (int k = 0; k < m; k++) { + for (int i = 0; i < n; i++) { + r.getValue(family, qfs[i]); + } + } + stop = System.nanoTime(); + System.out.println("getValue(): " + (stop - start)); + } + + /** + * Calls non-functional test methods. + * + * @param args + */ + public static void main(String[] args) { + TestResult testResult = new TestResult(); + try { + testResult.doReadBenchmark(); + } catch (Exception e) { + LOG.error("Unexpected exception", e); + } + } +} diff --git hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java index 5033e74..39566d0 100644 --- hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java +++ hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.util.UUID; +import junit.framework.AssertionFailedError; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -29,6 +30,7 @@ import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.util.Bytes; /** * Common helpers for testing HBase that do not depend on specific server/etc. things. @@ -54,6 +56,24 @@ public class HBaseCommonTestingUtility { /** Directory where we put the data for this instance of HBaseTestingUtility*/ private File dataTestDir = null; + public static void assertByteEquals(byte[] expected, + byte[] actual) { + if (Bytes.compareTo(expected, actual) != 0) { + throw new AssertionFailedError("expected:<" + + Bytes.toString(expected) + "> but was:<" + + Bytes.toString(actual) + ">"); + } + } + + public static void assertEquals(byte[] expected, + byte[] actual) { + if (Bytes.compareTo(expected, actual) != 0) { + throw new AssertionFailedError("expected:<" + + Bytes.toStringBinary(expected) + "> but was:<" + + Bytes.toStringBinary(actual) + ">"); + } + } + /** * @return Where to write test data on local filesystem, specific to * the test. Useful for tests that do not use a cluster. diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java index ca6e7f7..5c0fe04 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java @@ -664,22 +664,4 @@ public abstract class HBaseTestCase extends TestCase { HRegion.closeHRegion(meta); } - public static void assertByteEquals(byte[] expected, - byte[] actual) { - if (Bytes.compareTo(expected, actual) != 0) { - throw new AssertionFailedError("expected:<" + - Bytes.toString(expected) + "> but was:<" + - Bytes.toString(actual) + ">"); - } - } - - public static void assertEquals(byte[] expected, - byte[] actual) { - if (Bytes.compareTo(expected, actual) != 0) { - throw new AssertionFailedError("expected:<" + - Bytes.toStringBinary(expected) + "> but was:<" + - Bytes.toStringBinary(actual) + ">"); - } - } - } diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java deleted file mode 100644 index 4120ec3..0000000 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright The Apache Software Foundation - * - * 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 org.apache.hadoop.hbase.SmallTests; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.util.Set; -import java.util.TreeSet; - -import static org.junit.Assert.assertTrue; - -@Category(SmallTests.class) -public class TestConnectionUtils { - - @Test - public void testRetryTimeJitter() { - long[] retries = new long[200]; - long baseTime = 1000000; //Larger number than reality to help test randomness. - long maxTimeExpected = (long) (baseTime * 1.01f); - for (int i = 0; i < retries.length; i++) { - retries[i] = ConnectionUtils.getPauseTime(baseTime, 0); - } - - Set retyTimeSet = new TreeSet(); - for (long l : retries) { - /*make sure that there is some jitter but only 1%*/ - assertTrue(l >= baseTime); - assertTrue(l <= maxTimeExpected); - // Add the long to the set - retyTimeSet.add(l); - } - - //Make sure that most are unique. some overlap will happen - assertTrue(retyTimeSet.size() > (retries.length * 0.80)); - } - -} diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java deleted file mode 100644 index d37b2e2..0000000 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * - * 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 junit.framework.TestCase; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.SmallTests; -import org.apache.hadoop.hbase.util.Bytes; -import org.junit.experimental.categories.Category; - -import static org.apache.hadoop.hbase.HBaseTestCase.assertByteEquals; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.NavigableMap; - -@Category(SmallTests.class) -public class TestResult extends TestCase { - - private static final Log LOG = LogFactory.getLog(TestResult.class.getName()); - - static KeyValue[] genKVs(final byte[] row, final byte[] family, - final byte[] value, - final long timestamp, - final int cols) { - KeyValue [] kvs = new KeyValue[cols]; - - for (int i = 0; i < cols ; i++) { - kvs[i] = new KeyValue( - row, family, Bytes.toBytes(i), - timestamp, - Bytes.add(value, Bytes.toBytes(i))); - } - return kvs; - } - - static final byte [] row = Bytes.toBytes("row"); - static final byte [] family = Bytes.toBytes("family"); - static final byte [] value = Bytes.toBytes("value"); - - public void testBasicGetColumn() throws Exception { - KeyValue [] kvs = genKVs(row, family, value, 1, 100); - - Arrays.sort(kvs, KeyValue.COMPARATOR); - - Result r = new Result(kvs); - - for (int i = 0; i < 100; ++i) { - final byte[] qf = Bytes.toBytes(i); - - List ks = r.getColumn(family, qf); - assertEquals(1, ks.size()); - assertByteEquals(qf, ks.get(0).getQualifier()); - assertEquals(ks.get(0), r.getColumnLatest(family, qf)); - } - } - - public void testMultiVersionGetColumn() throws Exception { - KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); - KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); - - KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; - System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); - System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); - - Arrays.sort(kvs, KeyValue.COMPARATOR); - - Result r = new Result(kvs); - for (int i = 0; i < 100; ++i) { - final byte[] qf = Bytes.toBytes(i); - - List ks = r.getColumn(family, qf); - assertEquals(2, ks.size()); - assertByteEquals(qf, ks.get(0).getQualifier()); - assertEquals(200, ks.get(0).getTimestamp()); - assertEquals(ks.get(0), r.getColumnLatest(family, qf)); - } - } - - public void testBasicGetValue() throws Exception { - KeyValue [] kvs = genKVs(row, family, value, 1, 100); - - Arrays.sort(kvs, KeyValue.COMPARATOR); - - Result r = new Result(kvs); - - for (int i = 0; i < 100; ++i) { - final byte[] qf = Bytes.toBytes(i); - - assertByteEquals(Bytes.add(value, Bytes.toBytes(i)), r.getValue(family, qf)); - assertTrue(r.containsColumn(family, qf)); - } - } - - public void testMultiVersionGetValue() throws Exception { - KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); - KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); - - KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; - System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); - System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); - - Arrays.sort(kvs, KeyValue.COMPARATOR); - - Result r = new Result(kvs); - for (int i = 0; i < 100; ++i) { - final byte[] qf = Bytes.toBytes(i); - - assertByteEquals(Bytes.add(value, Bytes.toBytes(i)), r.getValue(family, qf)); - assertTrue(r.containsColumn(family, qf)); - } - } - - public void testBasicLoadValue() throws Exception { - KeyValue [] kvs = genKVs(row, family, value, 1, 100); - - Arrays.sort(kvs, KeyValue.COMPARATOR); - - Result r = new Result(kvs); - ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); - - for (int i = 0; i < 100; ++i) { - final byte[] qf = Bytes.toBytes(i); - - loadValueBuffer.clear(); - r.loadValue(family, qf, loadValueBuffer); - loadValueBuffer.flip(); - assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), loadValueBuffer); - assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), - r.getValueAsByteBuffer(family, qf)); - } - } - - public void testMultiVersionLoadValue() throws Exception { - KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); - KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); - - KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; - System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); - System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); - - Arrays.sort(kvs, KeyValue.COMPARATOR); - - ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); - - Result r = new Result(kvs); - for (int i = 0; i < 100; ++i) { - final byte[] qf = Bytes.toBytes(i); - - loadValueBuffer.clear(); - r.loadValue(family, qf, loadValueBuffer); - loadValueBuffer.flip(); - assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), loadValueBuffer); - assertEquals(ByteBuffer.wrap(Bytes.add(value, Bytes.toBytes(i))), - r.getValueAsByteBuffer(family, qf)); - } - } - - /** - * Verify that Result.compareResults(...) behaves correctly. - */ - public void testCompareResults() throws Exception { - byte [] value1 = Bytes.toBytes("value1"); - byte [] qual = Bytes.toBytes("qual"); - - KeyValue kv1 = new KeyValue(row, family, qual, value); - KeyValue kv2 = new KeyValue(row, family, qual, value1); - - Result r1 = new Result(new KeyValue[] {kv1}); - Result r2 = new Result(new KeyValue[] {kv2}); - // no exception thrown - Result.compareResults(r1, r1); - try { - // these are different (HBASE-4800) - Result.compareResults(r1, r2); - fail(); - } catch (Exception x) { - assertTrue(x.getMessage().startsWith("This result was different:")); - } - } - - - /** - * Microbenchmark that compares {@link Result#getValue} and {@link Result#loadValue} performance. - * - * @throws Exception - */ - public void doReadBenchmark() throws Exception { - - final int n = 5; - final int m = 100000000; - - StringBuilder valueSB = new StringBuilder(); - for (int i = 0; i < 100; i++) { - valueSB.append((byte)(Math.random() * 10)); - } - - StringBuilder rowSB = new StringBuilder(); - for (int i = 0; i < 50; i++) { - rowSB.append((byte)(Math.random() * 10)); - } - - KeyValue [] kvs = genKVs(Bytes.toBytes(rowSB.toString()), family, - Bytes.toBytes(valueSB.toString()), 1, n); - Arrays.sort(kvs, KeyValue.COMPARATOR); - ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); - Result r = new Result(kvs); - - byte[][] qfs = new byte[n][Bytes.SIZEOF_INT]; - for (int i = 0; i < n; ++i) { - System.arraycopy(qfs[i], 0, Bytes.toBytes(i), 0, Bytes.SIZEOF_INT); - } - - // warm up - for (int k = 0; k < 100000; k++) { - for (int i = 0; i < n; ++i) { - r.getValue(family, qfs[i]); - loadValueBuffer.clear(); - r.loadValue(family, qfs[i], loadValueBuffer); - loadValueBuffer.flip(); - } - } - - System.gc(); - long start = System.nanoTime(); - for (int k = 0; k < m; k++) { - for (int i = 0; i < n; ++i) { - loadValueBuffer.clear(); - r.loadValue(family, qfs[i], loadValueBuffer); - loadValueBuffer.flip(); - } - } - long stop = System.nanoTime(); - System.out.println("loadValue(): " + (stop - start)); - - System.gc(); - start = System.nanoTime(); - for (int k = 0; k < m; k++) { - for (int i = 0; i < n; i++) { - r.getValue(family, qfs[i]); - } - } - stop = System.nanoTime(); - System.out.println("getValue(): " + (stop - start)); - } - - /** - * Calls non-functional test methods. - * - * @param args - */ - public static void main(String[] args) { - TestResult testResult = new TestResult(); - try { - testResult.doReadBenchmark(); - } catch (Exception e) { - LOG.error("Unexpected exception", e); - } - } -} diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index 8c2fe1d..2583941 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -38,6 +38,7 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.CompatibilitySingletonFactory; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.exceptions.FailedSanityCheckException; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestCase; @@ -282,7 +283,8 @@ public class TestHRegion extends HBaseTestCase { for (long i = minSeqId; i <= maxSeqId; i += 10) { List kvs = result.getColumn(family, Bytes.toBytes(i)); assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes(i), kvs.get(0).getValue()); + HBaseCommonTestingUtility.assertEquals(Bytes.toBytes(i), + kvs.get(0).getValue()); } } finally { HRegion.closeHRegion(this.region); @@ -337,7 +339,8 @@ public class TestHRegion extends HBaseTestCase { assertEquals(0, kvs.size()); } else { assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes(i), kvs.get(0).getValue()); + HBaseCommonTestingUtility.assertEquals(Bytes.toBytes(i), + kvs.get(0).getValue()); } } } finally { @@ -1061,8 +1064,8 @@ public class TestHRegion extends HBaseTestCase { get.addColumn(fam2, qf2); Result r = region.get(get); assertEquals(2, r.size()); - assertEquals(val1, r.getValue(fam1, qf1)); - assertEquals(val2, r.getValue(fam2, qf2)); + HBaseCommonTestingUtility.assertEquals(val1, r.getValue(fam1, qf1)); + HBaseCommonTestingUtility.assertEquals(val2, r.getValue(fam2, qf2)); //Family delete delete = new Delete(row1); @@ -1074,7 +1077,7 @@ public class TestHRegion extends HBaseTestCase { get = new Get(row1); r = region.get(get); assertEquals(1, r.size()); - assertEquals(val1, r.getValue(fam1, qf1)); + HBaseCommonTestingUtility.assertEquals(val1, r.getValue(fam1, qf1)); //Row delete delete = new Delete(row1); @@ -1445,7 +1448,8 @@ public class TestHRegion extends HBaseTestCase { Result r = region.get(get); assertEquals(1, r.size()); - assertByteEquals(value2, r.getValue(fam1, qual1)); + HBaseCommonTestingUtility.assertByteEquals(value2, + r.getValue(fam1, qual1)); // next: Scan scan = new Scan(row); @@ -1457,10 +1461,10 @@ public class TestHRegion extends HBaseTestCase { assertEquals(1, results.size()); KeyValue kv = results.get(0); - assertByteEquals(value2, kv.getValue()); - assertByteEquals(fam1, kv.getFamily()); - assertByteEquals(qual1, kv.getQualifier()); - assertByteEquals(row, kv.getRow()); + HBaseCommonTestingUtility.assertByteEquals(value2, kv.getValue()); + HBaseCommonTestingUtility.assertByteEquals(fam1, kv.getFamily()); + HBaseCommonTestingUtility.assertByteEquals(qual1, kv.getQualifier()); + HBaseCommonTestingUtility.assertByteEquals(row, kv.getRow()); } finally { HRegion.closeHRegion(this.region); this.region = null; @@ -3706,7 +3710,7 @@ public class TestHRegion extends HBaseTestCase { KeyValue kv = kvs.get(0); byte[] appendResult = new byte[kv.getValueLength()]; System.arraycopy(kv.getBuffer(), kv.getValueOffset(), appendResult, 0, kv.getValueLength()); - assertEquals(expected, appendResult); + HBaseCommonTestingUtility.assertEquals(expected, appendResult); this.region = null; } @@ -3737,7 +3741,8 @@ public class TestHRegion extends HBaseTestCase { res = this.region.get(get); kvs = res.getColumn(family, qualifier); assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes("value0"), kvs.get(0).getValue()); + HBaseCommonTestingUtility.assertEquals(Bytes.toBytes("value0"), + kvs.get(0).getValue()); region.flushcache(); get = new Get(row); @@ -3746,7 +3751,8 @@ public class TestHRegion extends HBaseTestCase { res = this.region.get(get); kvs = res.getColumn(family, qualifier); assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes("value0"), kvs.get(0).getValue()); + HBaseCommonTestingUtility.assertEquals(Bytes.toBytes("value0"), + kvs.get(0).getValue()); put = new Put(row); value = Bytes.toBytes("value1"); @@ -3758,7 +3764,8 @@ public class TestHRegion extends HBaseTestCase { res = this.region.get(get); kvs = res.getColumn(family, qualifier); assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes("value1"), kvs.get(0).getValue()); + HBaseCommonTestingUtility.assertEquals(Bytes.toBytes("value1"), + kvs.get(0).getValue()); region.flushcache(); get = new Get(row); @@ -3767,7 +3774,8 @@ public class TestHRegion extends HBaseTestCase { res = this.region.get(get); kvs = res.getColumn(family, qualifier); assertEquals(1, kvs.size()); - assertEquals(Bytes.toBytes("value1"), kvs.get(0).getValue()); + HBaseCommonTestingUtility.assertEquals(Bytes.toBytes("value1"), + kvs.get(0).getValue()); } private void putData(int startRow, int numRows, byte [] qf, diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java index ed2274a..2df2582 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseTestCase; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; @@ -319,11 +320,11 @@ public class TestKeepDeletes extends HBaseTestCase { List kvs = new ArrayList(); scan.next(kvs); assertTrue(kvs.get(0).isDeleteFamily()); - assertEquals(kvs.get(1).getValue(), T3); + HBaseCommonTestingUtility.assertEquals(kvs.get(1).getValue(), T3); assertTrue(kvs.get(2).isDelete()); assertTrue(kvs.get(3).isDeleteType()); - assertEquals(kvs.get(4).getValue(), T2); - assertEquals(kvs.get(5).getValue(), T1); + HBaseCommonTestingUtility.assertEquals(kvs.get(4).getValue(), T2); + HBaseCommonTestingUtility.assertEquals(kvs.get(5).getValue(), T1); HRegion.closeHRegion(region); } @@ -767,7 +768,7 @@ public class TestKeepDeletes extends HBaseTestCase { List kvs = r.getColumn(fam, col); assertEquals(kvs.size(), vals.length); for (int i=0;i kvs = r.getColumn(col, col); assertEquals(kvs.size(), vals.length); for (int i=0;i fileInfo = reader.loadFileInfo(); byte[] value = fileInfo.get(HFileDataBlockEncoder.DATA_BLOCK_ENCODING); - assertEquals(dataBlockEncoderAlgo.getNameInBytes(), value); + HBaseCommonTestingUtility.assertEquals(dataBlockEncoderAlgo.getNameInBytes(), + value); } } -- 1.7.10.2 (Apple Git-33)