diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml index a961538..9882856 100644 --- a/hbase-common/pom.xml +++ b/hbase-common/pom.xml @@ -67,7 +67,20 @@ - + + skip-common-tests + + + skip-common-tests + + + + true + + + + diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java new file mode 100644 index 0000000..cc080a6 --- /dev/null +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java @@ -0,0 +1,287 @@ +/** + * 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.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Arrays; + +import junit.framework.TestCase; + +public class TestBytes extends TestCase { + public void testNullHashCode() { + byte [] b = null; + Exception ee = null; + try { + Bytes.hashCode(b); + } catch (Exception e) { + ee = e; + } + assertNotNull(ee); + } + + public void testSplit() throws Exception { + byte [] lowest = Bytes.toBytes("AAA"); + byte [] middle = Bytes.toBytes("CCC"); + byte [] highest = Bytes.toBytes("EEE"); + byte [][] parts = Bytes.split(lowest, highest, 1); + for (int i = 0; i < parts.length; i++) { + System.out.println(Bytes.toString(parts[i])); + } + assertEquals(3, parts.length); + assertTrue(Bytes.equals(parts[1], middle)); + // Now divide into three parts. Change highest so split is even. + highest = Bytes.toBytes("DDD"); + parts = Bytes.split(lowest, highest, 2); + for (int i = 0; i < parts.length; i++) { + System.out.println(Bytes.toString(parts[i])); + } + assertEquals(4, parts.length); + // Assert that 3rd part is 'CCC'. + assertTrue(Bytes.equals(parts[2], middle)); + } + + public void testSplit2() throws Exception { + // More split tests. + byte [] lowest = Bytes.toBytes("http://A"); + byte [] highest = Bytes.toBytes("http://z"); + byte [] middle = Bytes.toBytes("http://]"); + byte [][] parts = Bytes.split(lowest, highest, 1); + for (int i = 0; i < parts.length; i++) { + System.out.println(Bytes.toString(parts[i])); + } + assertEquals(3, parts.length); + assertTrue(Bytes.equals(parts[1], middle)); + } + + public void testSplit3() throws Exception { + // Test invalid split cases + byte [] low = { 1, 1, 1 }; + byte [] high = { 1, 1, 3 }; + + // If swapped, should throw IAE + try { + Bytes.split(high, low, 1); + assertTrue("Should not be able to split if low > high", false); + } catch(IllegalArgumentException iae) { + // Correct + } + + // Single split should work + byte [][] parts = Bytes.split(low, high, 1); + for (int i = 0; i < parts.length; i++) { + System.out.println("" + i + " -> " + Bytes.toStringBinary(parts[i])); + } + assertTrue("Returned split should have 3 parts but has " + parts.length, parts.length == 3); + + // If split more than once, this should fail + parts = Bytes.split(low, high, 2); + assertTrue("Returned split but should have failed", parts == null); + + // Split 0 times should throw IAE + try { + parts = Bytes.split(low, high, 0); + assertTrue("Should not be able to split 0 times", false); + } catch(IllegalArgumentException iae) { + // Correct + } + } + + public void testToInt() throws Exception { + int [] ints = {-1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE}; + for (int i = 0; i < ints.length; i++) { + byte [] b = Bytes.toBytes(ints[i]); + assertEquals(ints[i], Bytes.toInt(b)); + byte [] b2 = bytesWithOffset(b); + assertEquals(ints[i], Bytes.toInt(b2, 1)); + assertEquals(ints[i], Bytes.toInt(b2, 1, Bytes.SIZEOF_INT)); + } + } + + public void testToLong() throws Exception { + long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; + for (int i = 0; i < longs.length; i++) { + byte [] b = Bytes.toBytes(longs[i]); + assertEquals(longs[i], Bytes.toLong(b)); + byte [] b2 = bytesWithOffset(b); + assertEquals(longs[i], Bytes.toLong(b2, 1)); + assertEquals(longs[i], Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG)); + } + } + + public void testToFloat() throws Exception { + float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; + for (int i = 0; i < floats.length; i++) { + byte [] b = Bytes.toBytes(floats[i]); + assertEquals(floats[i], Bytes.toFloat(b)); + byte [] b2 = bytesWithOffset(b); + assertEquals(floats[i], Bytes.toFloat(b2, 1)); + } + } + + public void testToDouble() throws Exception { + double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE}; + for (int i = 0; i < doubles.length; i++) { + byte [] b = Bytes.toBytes(doubles[i]); + assertEquals(doubles[i], Bytes.toDouble(b)); + byte [] b2 = bytesWithOffset(b); + assertEquals(doubles[i], Bytes.toDouble(b2, 1)); + } + } + + public void testToBigDecimal() throws Exception { + BigDecimal [] decimals = {new BigDecimal("-1"), new BigDecimal("123.123"), + new BigDecimal("123123123123")}; + for (int i = 0; i < decimals.length; i++) { + byte [] b = Bytes.toBytes(decimals[i]); + assertEquals(decimals[i], Bytes.toBigDecimal(b)); + byte [] b2 = bytesWithOffset(b); + assertEquals(decimals[i], Bytes.toBigDecimal(b2, 1, b.length)); + } + } + + private byte [] bytesWithOffset(byte [] src) { + // add one byte in front to test offset + byte [] result = new byte[src.length + 1]; + result[0] = (byte) 0xAA; + System.arraycopy(src, 0, result, 1, src.length); + return result; + } + + public void testBinarySearch() throws Exception { + byte [][] arr = { + {1}, + {3}, + {5}, + {7}, + {9}, + {11}, + {13}, + {15}, + }; + byte [] key1 = {3,1}; + byte [] key2 = {4,9}; + byte [] key2_2 = {4}; + byte [] key3 = {5,11}; + byte [] key4 = {0}; + byte [] key5 = {2}; + + assertEquals(1, Bytes.binarySearch(arr, key1, 0, 1, + Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(0, Bytes.binarySearch(arr, key1, 1, 1, + Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(-(2+1), Arrays.binarySearch(arr, key2_2, + Bytes.BYTES_COMPARATOR)); + assertEquals(-(2+1), Bytes.binarySearch(arr, key2, 0, 1, + Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(4, Bytes.binarySearch(arr, key2, 1, 1, + Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(2, Bytes.binarySearch(arr, key3, 0, 1, + Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(5, Bytes.binarySearch(arr, key3, 1, 1, + Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(-1, + Bytes.binarySearch(arr, key4, 0, 1, Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(-2, + Bytes.binarySearch(arr, key5, 0, 1, Bytes.BYTES_RAWCOMPARATOR)); + + // Search for values to the left and to the right of each item in the array. + for (int i = 0; i < arr.length; ++i) { + assertEquals(-(i + 1), Bytes.binarySearch(arr, + new byte[] { (byte) (arr[i][0] - 1) }, 0, 1, + Bytes.BYTES_RAWCOMPARATOR)); + assertEquals(-(i + 2), Bytes.binarySearch(arr, + new byte[] { (byte) (arr[i][0] + 1) }, 0, 1, + Bytes.BYTES_RAWCOMPARATOR)); + } + } + + public void testStartsWith() { + assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h"))); + assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes(""))); + assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("hello"))); + assertFalse(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("helloworld"))); + assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello"))); + } + + public void testIncrementBytes() throws IOException { + + assertTrue(checkTestIncrementBytes(10, 1)); + assertTrue(checkTestIncrementBytes(12, 123435445)); + assertTrue(checkTestIncrementBytes(124634654, 1)); + assertTrue(checkTestIncrementBytes(10005460, 5005645)); + assertTrue(checkTestIncrementBytes(1, -1)); + assertTrue(checkTestIncrementBytes(10, -1)); + assertTrue(checkTestIncrementBytes(10, -5)); + assertTrue(checkTestIncrementBytes(1005435000, -5)); + assertTrue(checkTestIncrementBytes(10, -43657655)); + assertTrue(checkTestIncrementBytes(-1, 1)); + assertTrue(checkTestIncrementBytes(-26, 5034520)); + assertTrue(checkTestIncrementBytes(-10657200, 5)); + assertTrue(checkTestIncrementBytes(-12343250, 45376475)); + assertTrue(checkTestIncrementBytes(-10, -5)); + assertTrue(checkTestIncrementBytes(-12343250, -5)); + assertTrue(checkTestIncrementBytes(-12, -34565445)); + assertTrue(checkTestIncrementBytes(-1546543452, -34565445)); + } + + private static boolean checkTestIncrementBytes(long val, long amount) + throws IOException { + byte[] value = Bytes.toBytes(val); + byte [] testValue = {-1, -1, -1, -1, -1, -1, -1, -1}; + if (value[0] > 0) { + testValue = new byte[Bytes.SIZEOF_LONG]; + } + System.arraycopy(value, 0, testValue, testValue.length - value.length, + value.length); + + long incrementResult = Bytes.toLong(Bytes.incrementBytes(value, amount)); + + return (Bytes.toLong(testValue) + amount) == incrementResult; + } + + public void testFixedSizeString() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + Bytes.writeStringFixedSize(dos, "Hello", 5); + Bytes.writeStringFixedSize(dos, "World", 18); + Bytes.writeStringFixedSize(dos, "", 9); + + try { + // Use a long dash which is three bytes in UTF-8. If encoding happens + // using ISO-8859-1, this will fail. + Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9); + fail("Exception expected"); + } catch (IOException ex) { + assertEquals( + "Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " + + "length 9", ex.getMessage()); + } + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + assertEquals("Hello", Bytes.readStringFixedSize(dis, 5)); + assertEquals("World", Bytes.readStringFixedSize(dis, 18)); + assertEquals("", Bytes.readStringFixedSize(dis, 9)); + } +} + diff --git a/hbase-server/pom.xml b/hbase-server/pom.xml index b514a57..f14c6c7 100644 --- a/hbase-server/pom.xml +++ b/hbase-server/pom.xml @@ -465,6 +465,20 @@ + + + skip-server-tests + + + skip-server-tests + + + + true + true + + + hadoop-snappy diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HBaseHomePath.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HBaseHomePath.java index 86089f9..490640e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HBaseHomePath.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/HBaseHomePath.java @@ -18,7 +18,7 @@ package org.apache.hadoop.hbase.util; import java.net.URL; -import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.master.HMaster; /** Determines HBase home path from either class or jar directory */ public class HBaseHomePath { @@ -31,7 +31,7 @@ public class HBaseHomePath { } public static String getHomePath() { - String className = HConstants.class.getName(); // This could have been any HBase class. + String className = HMaster.class.getName(); // This could have been any HBase class. String relPathForClass = className.replace(".", "/") + ".class"; URL url = ClassLoader.getSystemResource(relPathForClass); relPathForClass = "/" + relPathForClass; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java deleted file mode 100644 index e7fea6c..0000000 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java +++ /dev/null @@ -1,298 +0,0 @@ -/** - * Copyright 2009 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.util; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Arrays; - -import junit.framework.TestCase; -import org.apache.hadoop.hbase.SmallTests; -import org.junit.experimental.categories.Category; - -@Category(SmallTests.class) -public class TestBytes extends TestCase { - public void testNullHashCode() { - byte [] b = null; - Exception ee = null; - try { - Bytes.hashCode(b); - } catch (Exception e) { - ee = e; - } - assertNotNull(ee); - } - - public void testSplit() throws Exception { - byte [] lowest = Bytes.toBytes("AAA"); - byte [] middle = Bytes.toBytes("CCC"); - byte [] highest = Bytes.toBytes("EEE"); - byte [][] parts = Bytes.split(lowest, highest, 1); - for (int i = 0; i < parts.length; i++) { - System.out.println(Bytes.toString(parts[i])); - } - assertEquals(3, parts.length); - assertTrue(Bytes.equals(parts[1], middle)); - // Now divide into three parts. Change highest so split is even. - highest = Bytes.toBytes("DDD"); - parts = Bytes.split(lowest, highest, 2); - for (int i = 0; i < parts.length; i++) { - System.out.println(Bytes.toString(parts[i])); - } - assertEquals(4, parts.length); - // Assert that 3rd part is 'CCC'. - assertTrue(Bytes.equals(parts[2], middle)); - } - - public void testSplit2() throws Exception { - // More split tests. - byte [] lowest = Bytes.toBytes("http://A"); - byte [] highest = Bytes.toBytes("http://z"); - byte [] middle = Bytes.toBytes("http://]"); - byte [][] parts = Bytes.split(lowest, highest, 1); - for (int i = 0; i < parts.length; i++) { - System.out.println(Bytes.toString(parts[i])); - } - assertEquals(3, parts.length); - assertTrue(Bytes.equals(parts[1], middle)); - } - - public void testSplit3() throws Exception { - // Test invalid split cases - byte [] low = { 1, 1, 1 }; - byte [] high = { 1, 1, 3 }; - - // If swapped, should throw IAE - try { - Bytes.split(high, low, 1); - assertTrue("Should not be able to split if low > high", false); - } catch(IllegalArgumentException iae) { - // Correct - } - - // Single split should work - byte [][] parts = Bytes.split(low, high, 1); - for (int i = 0; i < parts.length; i++) { - System.out.println("" + i + " -> " + Bytes.toStringBinary(parts[i])); - } - assertTrue("Returned split should have 3 parts but has " + parts.length, parts.length == 3); - - // If split more than once, this should fail - parts = Bytes.split(low, high, 2); - assertTrue("Returned split but should have failed", parts == null); - - // Split 0 times should throw IAE - try { - parts = Bytes.split(low, high, 0); - assertTrue("Should not be able to split 0 times", false); - } catch(IllegalArgumentException iae) { - // Correct - } - } - - public void testToInt() throws Exception { - int [] ints = {-1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE}; - for (int i = 0; i < ints.length; i++) { - byte [] b = Bytes.toBytes(ints[i]); - assertEquals(ints[i], Bytes.toInt(b)); - byte [] b2 = bytesWithOffset(b); - assertEquals(ints[i], Bytes.toInt(b2, 1)); - assertEquals(ints[i], Bytes.toInt(b2, 1, Bytes.SIZEOF_INT)); - } - } - - public void testToLong() throws Exception { - long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; - for (int i = 0; i < longs.length; i++) { - byte [] b = Bytes.toBytes(longs[i]); - assertEquals(longs[i], Bytes.toLong(b)); - byte [] b2 = bytesWithOffset(b); - assertEquals(longs[i], Bytes.toLong(b2, 1)); - assertEquals(longs[i], Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG)); - } - } - - public void testToFloat() throws Exception { - float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; - for (int i = 0; i < floats.length; i++) { - byte [] b = Bytes.toBytes(floats[i]); - assertEquals(floats[i], Bytes.toFloat(b)); - byte [] b2 = bytesWithOffset(b); - assertEquals(floats[i], Bytes.toFloat(b2, 1)); - } - } - - public void testToDouble() throws Exception { - double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE}; - for (int i = 0; i < doubles.length; i++) { - byte [] b = Bytes.toBytes(doubles[i]); - assertEquals(doubles[i], Bytes.toDouble(b)); - byte [] b2 = bytesWithOffset(b); - assertEquals(doubles[i], Bytes.toDouble(b2, 1)); - } - } - - public void testToBigDecimal() throws Exception { - BigDecimal [] decimals = {new BigDecimal("-1"), new BigDecimal("123.123"), - new BigDecimal("123123123123")}; - for (int i = 0; i < decimals.length; i++) { - byte [] b = Bytes.toBytes(decimals[i]); - assertEquals(decimals[i], Bytes.toBigDecimal(b)); - byte [] b2 = bytesWithOffset(b); - assertEquals(decimals[i], Bytes.toBigDecimal(b2, 1, b.length)); - } - } - - private byte [] bytesWithOffset(byte [] src) { - // add one byte in front to test offset - byte [] result = new byte[src.length + 1]; - result[0] = (byte) 0xAA; - System.arraycopy(src, 0, result, 1, src.length); - return result; - } - - public void testBinarySearch() throws Exception { - byte [][] arr = { - {1}, - {3}, - {5}, - {7}, - {9}, - {11}, - {13}, - {15}, - }; - byte [] key1 = {3,1}; - byte [] key2 = {4,9}; - byte [] key2_2 = {4}; - byte [] key3 = {5,11}; - byte [] key4 = {0}; - byte [] key5 = {2}; - - assertEquals(1, Bytes.binarySearch(arr, key1, 0, 1, - Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(0, Bytes.binarySearch(arr, key1, 1, 1, - Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(-(2+1), Arrays.binarySearch(arr, key2_2, - Bytes.BYTES_COMPARATOR)); - assertEquals(-(2+1), Bytes.binarySearch(arr, key2, 0, 1, - Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(4, Bytes.binarySearch(arr, key2, 1, 1, - Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(2, Bytes.binarySearch(arr, key3, 0, 1, - Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(5, Bytes.binarySearch(arr, key3, 1, 1, - Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(-1, - Bytes.binarySearch(arr, key4, 0, 1, Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(-2, - Bytes.binarySearch(arr, key5, 0, 1, Bytes.BYTES_RAWCOMPARATOR)); - - // Search for values to the left and to the right of each item in the array. - for (int i = 0; i < arr.length; ++i) { - assertEquals(-(i + 1), Bytes.binarySearch(arr, - new byte[] { (byte) (arr[i][0] - 1) }, 0, 1, - Bytes.BYTES_RAWCOMPARATOR)); - assertEquals(-(i + 2), Bytes.binarySearch(arr, - new byte[] { (byte) (arr[i][0] + 1) }, 0, 1, - Bytes.BYTES_RAWCOMPARATOR)); - } - } - - public void testStartsWith() { - assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h"))); - assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes(""))); - assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("hello"))); - assertFalse(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("helloworld"))); - assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello"))); - } - - public void testIncrementBytes() throws IOException { - - assertTrue(checkTestIncrementBytes(10, 1)); - assertTrue(checkTestIncrementBytes(12, 123435445)); - assertTrue(checkTestIncrementBytes(124634654, 1)); - assertTrue(checkTestIncrementBytes(10005460, 5005645)); - assertTrue(checkTestIncrementBytes(1, -1)); - assertTrue(checkTestIncrementBytes(10, -1)); - assertTrue(checkTestIncrementBytes(10, -5)); - assertTrue(checkTestIncrementBytes(1005435000, -5)); - assertTrue(checkTestIncrementBytes(10, -43657655)); - assertTrue(checkTestIncrementBytes(-1, 1)); - assertTrue(checkTestIncrementBytes(-26, 5034520)); - assertTrue(checkTestIncrementBytes(-10657200, 5)); - assertTrue(checkTestIncrementBytes(-12343250, 45376475)); - assertTrue(checkTestIncrementBytes(-10, -5)); - assertTrue(checkTestIncrementBytes(-12343250, -5)); - assertTrue(checkTestIncrementBytes(-12, -34565445)); - assertTrue(checkTestIncrementBytes(-1546543452, -34565445)); - } - - private static boolean checkTestIncrementBytes(long val, long amount) - throws IOException { - byte[] value = Bytes.toBytes(val); - byte [] testValue = {-1, -1, -1, -1, -1, -1, -1, -1}; - if (value[0] > 0) { - testValue = new byte[Bytes.SIZEOF_LONG]; - } - System.arraycopy(value, 0, testValue, testValue.length - value.length, - value.length); - - long incrementResult = Bytes.toLong(Bytes.incrementBytes(value, amount)); - - return (Bytes.toLong(testValue) + amount) == incrementResult; - } - - public void testFixedSizeString() throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - Bytes.writeStringFixedSize(dos, "Hello", 5); - Bytes.writeStringFixedSize(dos, "World", 18); - Bytes.writeStringFixedSize(dos, "", 9); - - try { - // Use a long dash which is three bytes in UTF-8. If encoding happens - // using ISO-8859-1, this will fail. - Bytes.writeStringFixedSize(dos, "Too\u2013Long", 9); - fail("Exception expected"); - } catch (IOException ex) { - assertEquals( - "Trying to write 10 bytes (Too\\xE2\\x80\\x93Long) into a field of " + - "length 9", ex.getMessage()); - } - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - assertEquals("Hello", Bytes.readStringFixedSize(dis, 5)); - assertEquals("World", Bytes.readStringFixedSize(dis, 18)); - assertEquals("", Bytes.readStringFixedSize(dis, 9)); - } - - - @org.junit.Rule - public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu = - new org.apache.hadoop.hbase.ResourceCheckerJUnitRule(); -} - diff --git a/hbase-site/src/docbkx/developer.xml b/hbase-site/src/docbkx/developer.xml index a2595dc..6d6e7d1 100644 --- a/hbase-site/src/docbkx/developer.xml +++ b/hbase-site/src/docbkx/developer.xml @@ -276,18 +276,37 @@ What is the new development version for "HBase"? (org.apache.hbase:hbase) 0.92.1
Tests -HBase tests are divided into two groups: and - (As of this writing, Integration tests are little -developed). -Unit tests are run by the Apache Continuous Integration server, Jenkins at -builds.apache.org, and by developers when they are verifying a fix does not cause breakage elsewhere in the code base. -Integration tests are generally long-running tests that are invoked out-of-bound of -the CI server when you want to do more intensive testing beyond the unit test set. -Integration tests, for example, are run proving a release candidate or a production -deploy. Below we go into more detail on each of these test types. Developers at a -minimum should familiarize themselves with the unit test detail; unit tests in + Developers, at a minimum, should familiarize themselves with the unit test detail; unit tests in HBase have a character not usually seen in other projects. +
+HBase Modules +As of 0.96, HBase is split into multiple modules which creates "interesting" rules for +how and where tests are written. If you are writting code for hbase-server, see + for how to write your tests; these tests can spin +up a minicluster and will need to be categorized. For any other module, for example +hbase-common, the tests must be strict unit tests and just test the class +under test - no use of the HBaseTestingUtility or minicluster is allowed (or even possible +given the dependency tree). +
+ Running Tests in other Modules + If the module you are developing in has no other dependencies on other HBase modules, then + you can cd into that module and just run: + mvn test + which will just run the tests IN THAT MODULE. If there are other dependencies on other modules, + then you will have run the command from the ROOT HBASE DIRECTORY. This will run the tests in the other + modules, unless you specify to skip the tests in that module. For instance, to skip the tests in the hbase-server module, + you would run: + mvn clean test -Dskip-server-tests + from the top level directory to run all the tests in modules other than hbase-server. Note that you + can specify to skip tests in multiple modules as well as just for a single module. For example, to skip + the tests in hbase-server and hbase-common, you would run: + mvn clean test -Dskip-server-tests -Dskip-common-tests + Also, keep in mind that if you are running tests in the hbase-server module you will need to + apply the maven profiles discussed in to get the tests to run properly. +
+
+
Unit Tests HBase unit tests are subdivided into three categories: small, medium and large, with @@ -333,8 +352,7 @@ individually. They can use a cluster, and each of them is executed in a separate
<indexterm><primary>LargeTests</primary></indexterm> Large tests are everything else. They are typically integration-like -tests (yes, some large tests should be moved out to be HBase ), -regression tests for specific bugs, timeout tests, performance tests. +tests, regression tests for specific bugs, timeout tests, performance tests. They are executed before a commit on the pre-integration machines. They can be run on the developer machine as well. @@ -491,12 +509,6 @@ mvn compile above in
-
- Running all or individual Integration Tests - See - -
-
Building against various hadoop versions. As of 0.96, HBase supports building against hadoop versions: 1.0.3, 2.0.0-alpha and 3.0.0-SNAPSHOT.