Table of Contents
This chapter will be of interest only to those building and developing HBase (i.e., as opposed to just downloading the latest distribution).
See HBASE-3678 Add Eclipse-based Apache Formatter to HBase Wiki for an Eclipse formatter to help ensure your code conforms to HBase'y coding convention. The issue includes instructions for loading the attached formatter.
Also, no @author tags - that's a rule. Quality Javadoc comments are appreciated. And include the Apache license.
Download and install the Subversive plugin.
Set up an SVN Repository target from Section 1.1.1, “SVN”, then check out the code.
mvn eclipse:eclipse... from your local HBase project directory in your workspace to generate some new
.project
and .classpath
files. Then reopen Eclipse.
Download and install the Maven plugin. For example, Help -> Install New Software -> (search for Maven Plugin)
The M2_REPO
classpath variable needs to be set up for the project. This needs to be set to
your local Maven repository, which is usually ~/.m2/repository
Description Resource Path Location Type The project cannot be built until build path errors are resolved hbase Unknown Java Problem Unbound classpath variable: 'M2_REPO/asm/asm/3.1/asm-3.1.jar' in project 'hbase' hbase Build path Build Path Problem Unbound classpath variable: 'M2_REPO/com/github/stephenc/high-scale-lib/high-scale-lib/1.1.1/high-scale-lib-1.1.1.jar' in project 'hbase' hbase Build path Build Path Problem Unbound classpath variable: 'M2_REPO/com/google/guava/guava/r09/guava-r09.jar' in project 'hbase' hbase Build path Build Path Problem Unbound classpath variable: 'M2_REPO/com/google/protobuf/protobuf-java/2.3.0/protobuf-java-2.3.0.jar' in project 'hbase' hbase Build path Build Path Problem Unbound classpath variable:
If you install the m2eclipse and import the HBase pom.xml in your workspace, you will have to fix your eclipse Build Path.
Remove target
folder, add target/generated-jamon
and target/generated-sources/java
folders. You may also remove from your Build Path
the exclusions on the src/main/resources
and src/test/resources
to avoid error message in the console 'Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project hbase:
'An Ant BuildException has occured: Replace: source file .../target/classes/hbase-default.xml doesn't exist'. This will also
reduce the eclipse build cycles and make your life easier when developing.
Eclipse will currently complain about Bytes.java
. It is not possible to turn these errors off.
Description Resource Path Location Type Access restriction: The method arrayBaseOffset(Class) from the type Unsafe is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar Bytes.java /hbase/src/main/java/org/apache/hadoop/hbase/util line 1061 Java Problem Access restriction: The method arrayIndexScale(Class) from the type Unsafe is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar Bytes.java /hbase/src/main/java/org/apache/hadoop/hbase/util line 1064 Java Problem Access restriction: The method getLong(Object, long) from the type Unsafe is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar Bytes.java /hbase/src/main/java/org/apache/hadoop/hbase/util line 1111 Java Problem
For additional information on setting up Eclipse for HBase development on Windows, see Michael Morello's blog on the topic.
This section will be of interest only to those building HBase from source.
Pass -Dsnappy
to trigger the snappy maven profile for building
snappy native libs into hbase.
Do the following to build the HBase tarball. Passing the -Drelease will generate javadoc and run the RAT plugin to verify licenses on source.
% MAVEN_OPTS="-Xmx2g" mvn clean site install assembly:single -Dmaven.test.skip -Prelease
Follow the instructions at
Publishing Maven Artifacts.
The 'trick' to making it all work is answering the questions put to you by the mvn release plugin properly,
making sure it is using the actual branch AND before doing the mvn release:perform step,
VERY IMPORTANT, hand edit the release.properties file that was put under ${HBASE_HOME}
by the previous step, release:perform. You need to edit it to make it point at
right locations in SVN.
If you see run into the below, its because you need to edit version in the pom.xml and add
-SNAPSHOT
to the version (and commit).
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'release'. [INFO] ------------------------------------------------------------------------ [INFO] Building HBase [INFO] task-segment: [release:prepare] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] [release:prepare {execution: default-cli}] [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] You don't have a SNAPSHOT project in the reactor projects list. [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Sat Mar 26 18:11:07 PDT 2011 [INFO] Final Memory: 35M/423M [INFO] -----------------------------------------------------------------------
If you see Unable to find resource 'VM_global_library.vm'
, ignore it.
Its not an error. It is officially ugly though.
HBase tests are divided into two groups: Section 1.4.1, “Unit Tests” and Section 1.4.2, “Integration Tests”. Unit tests are run by the Apache Continuous Integration server 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 HBase have a character not usually seen in other projects.
HBase unit tests are subdivided into three categories: small, medium and large, with
corresponding JUnit categories:
SmallTests
, MediumTests
,
LargeTests
. JUnit categories are denoted using java annotations
and look like this in your unit test code.
... @Category(SmallTests.class) public class TestHRegionInfo { @Test public void testCreateHRegionInfoName() throws Exception { // ... } }
The above example shows how to mark a test as belonging to the small category.
Small tests are executed in a shared JVM. We put in this category all the tests that can be executed quickly in a shared JVM. The maximum execution time for a test is 15 seconds, and they do not use a cluster. Medium tests represent tests that must be executed before proposing a patch. They are designed to run in less than 30 minutes altogether, and are quite stable in their results. They are designed to last less than 50 seconds individually. They can use a cluster, and each of them is executed in a separate JVM. Large tests are everything else. They are typically integration-like tests (yes, some large tests should be moved out to be HBase Section 1.4.2, “Integration 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.
HBase uses a patched maven surefire plugin and maven profiles to implement its unit test characterizations.
Below we describe how to run the HBase junit categories.
Running
mvn test
will execute all small tests in a single JVM and medium tests in a separate JVM for each test instance. Medium tests are NOT executed if there is an error in a small test. Large tests are NOT executed. There is one report for small tests, and one report for medium tests if they are executed. To run small and medium tests with the security profile enabled, do
mvn test -P security
Running
mvn test -P runAllTests
will execute small tests in a single JVM then medium and large tests in a separate JVM for each test. Medium and large tests are NOT executed if there is an error in a small test. Large tests are NOT executed if there is an error in a small or medium test. There is one report for small tests, and one report for medium and large tests if they are executed
To run an individual test, e.g. MyTest
, do
mvn test -P localTests -Dtest=MyTest
You can also pass multiple, individual tests as a comma-delimited list:
mvn test -P localTests -Dtest=MyTest1,MyTest2,MyTest3
You can also pass a package, which will run all tests under the package:
mvn test -P localTests -Dtest=org.apache.hadoop.hbase.client.*
To run a single test with the security profile enabled:
mvn test -P security,localTests -Dtest=TestGet
The -P localTests
will remove the JUnit category effect (without this specific profile,
the profiles are taken into account). It will actually use the official release of surefire
and the old connector (The HBase build uses a patched version of the maven surefire plugin).
junit tests are executed in separated JVM. You will see a new message at the end of the
report: "[INFO] Tests are skipped". It's harmless.
Running
mvn test -P runSmallTests
will execute small tests only, in a single JVM.
Running
mvn test -P runMediumTests
will execute medium tests in a single JVM.
Running
mvn test -P runLargeTests
execute medium tests in a single JVM.
It's also possible to use the script hbasetests.sh. This script runs the medium and
large tests in parallel with two maven instances, and provide a single report.
It must be executed from the directory which contains the pom.xml
.
For example running
./dev-support/hbasetests.sh
will execute small and medium tests. Running
./dev-support/hbasetests.sh runAllTests
will execute all tests. Running
./dev-support/hbasetests.sh replayFailed
will rerun the failed tests a second time, in a separate jvm and without parallelisation.
HBaseTestingUtility
.
This class offers helper functions to create a temp directory and do the cleanup, or to start a cluster.
Categories and execution time
Whenever possible, tests should not use Thread.sleep
, but rather waiting for the real event they need. This is faster and clearer for the reader.
Tests should not do a Thread.sleep
without testing an ending condition. This allows understanding what the test is waiting for. Moreover, the test will work whatever the machine performance is.
Sleep should be minimal to be as fast as possible. Waiting for a variable should be done in a 40ms sleep loop. Waiting for a socket operation should be done in a 200 ms sleep loop.
Tests using a HRegion do not have to start a cluster: A region can use the local file system.
Start/stopping a cluster cost around 10 seconds. They should not be started per test method but per test class.
Started cluster must be shutdown using HBaseTestingUtility#shutdownMiniCluster
, which cleans the directories.
As most as possible, tests should use the default settings for the cluster. When they don't, they should document it. This will allow to share the cluster later.
HBase integration Tests are tests that are beyond HBase unit tests. They are generally long-lasting, sizeable (the test can be asked to 1M rows or 1B rows), targetable (they can take configuration that will point them at the ready-made cluster they are to run against; integration tests do not include cluster start/stop code), and verifying success, integration tests rely on public APIs only; they do not attempt to examine server internals asserring success/fail. Integration tests are what you would run when you need to more elaborate proofing of a release candidate beyond what unit tests can do. They are not generally run on the Apache Continuous Integration build server.
Integration tests currently live under the src/test
directory and
will match the regex: **/IntegrationTest*.java
.
HBase 0.92 added a verify
maven target.
Invoking it, for example by doing mvn verify
, will
run all the phases up to and including the verify phase via the
maven failsafe plugin,
running all the above mentioned HBase unit tests as well as tests that are in the HBase integration test group.
If you just want to run the integration tests, you need to run two commands. First:
mvn failsafe:integration-test
This actually runs ALL the integration tests.
This command will always output BUILD SUCCESS
even if there are test failures.
At this point, you could grep the output by hand looking for failed tests. However, maven will do this for us; just use:
mvn failsafe:verify
The above command basically looks at all the test results (so don't remove the 'target' directory) for test failures and reports the results.
This is very similar to how you specify running a subset of unit tests (see above).
To just run IntegrationTestClassXYZ.java
, use:
mvn failsafe:integration-test -Dtest=IntegrationTestClassXYZ
Pretty similar, right? The next thing you might want to do is run groups of integration tests, say all integration tests that are named IntegrationTestClassX*.java:
mvn failsafe:integration-test -Dtest=*ClassX*
This runs everything that is an integration test that matches *ClassX*. This means anything matching: "**/IntegrationTest*ClassX*". You can also run multiple groups of integration tests using comma-delimited lists (similar to unit tests). Using a list of matches still supports full regex matching for each of the groups.This would look something like:
mvn failsafe:integration-test -Dtest=*ClassX*, *ClassY
All commands executed from the local HBase project directory.
Note: use Maven 3 (Maven 2 may work but we suggest you use Maven 3).
See the Section 1.4.1.1, “Running tests” section above in Section 1.4.1, “Unit Tests”
mvn -Dhadoop.profile=22 ...
That is, designate build with hadoop.profile 22. Pass 23 for hadoop.profile to build against hadoop 0.23.
Tests do not all pass as of this writing so you may need ot pass -DskipTests
unless you are inclined
to fix the failing tests.
HBase gets better only when people contribute!
As HBase is an Apache Software Foundation project, see ??? for more information about how the ASF functions.
Sign up for the dev-list and the user-list. See the mailing lists page. Posing questions - and helping to answer other people's questions - is encouraged! There are varying levels of experience on both lists so patience and politeness are encouraged (and please stay on topic.)
Check for existing issues in Jira. If it's either a new feature request, enhancement, or a bug, file a ticket.
The following is a guideline on setting Jira issue priorities:
Most development is done on TRUNK. However, there are branches for minor releases (e.g., 0.90.1, 0.90.2, and 0.90.3 are on the 0.90 branch).
If you have any questions on this just send an email to the dev dist-list.
In HBase we use JUnit 4.
If you need to run miniclusters of HDFS, ZooKeeper, HBase, or MapReduce testing,
be sure to checkout the HBaseTestingUtility
.
Alex Baranau of Sematext describes how it can be used in
HBase Case-Study: Using HBaseTestingUtility for Local Testing and Development (2010).
Sometimes you don't need a full running server
unit testing. For example, some methods can make do with a
a org.apache.hadoop.hbase.Server
instance
or a org.apache.hadoop.hbase.master.MasterServices
Interface reference rather than a full-blown
org.apache.hadoop.hbase.master.HMaster
.
In these cases, you maybe able to get away with a mocked
Server
instance. For example:
TODO...
Patch files can be easily generated from Eclipse, for example by selecting "Team -> Create Patch". Patches can also be created by git diff and svn diff.
Please submit one patch-file per Jira. For example, if multiple files are changed make sure the selected resource when generating the patch is a directory. Patch files can reflect changes in multiple files.
Make sure you review Section 1.2.1.1, “Code Formatting” for code style.
The patch file should have the HBase Jira ticket in the name. For example, if a patch was submitted for Foo.java
, then
a patch file called Foo_HBASE_XXXX.patch
would be acceptable where XXXX is the HBase Jira number.
If you generating from a branch, then including the target branch in the filename is advised, e.g., HBASE-XXXX-0.90.patch
.
Yes, please. Please try to include unit tests with every code patch (and especially new classes and large changes). Make sure unit tests pass locally before submitting the patch.
Also, see Section 1.7.2.1, “Mockito”.
The patch should be attached to the associated Jira ticket "More Actions -> Attach Files". Make sure you click the ASF license inclusion, otherwise the patch can't be considered for inclusion.
Once attached to the ticket, click "Submit Patch" and the status of the ticket will change. Committers will review submitted patches for inclusion into the codebase. Please understand that not every patch may get committed, and that feedback will likely be provided on the patch. Fear not, though, because the HBase community is helpful!
The following items are representative of common patch feedback. Your patch process will go faster if these are taken into account before submission.
See the Java coding standards for more information on coding conventions in Java.
Rather than do this...
if ( foo.equals( bar ) ) { // don't do this
... do this instead...
if (foo.equals(bar)) {
Also, rather than do this...
foo = barArray[ i ]; // don't do this
... do this instead...
foo = barArray[i];
Auto-generated code in Eclipse often looks like this...
public void readFields(DataInput arg0) throws IOException { // don't do this foo = arg0.readUTF(); // don't do this
... do this instead ...
public void readFields(DataInput di) throws IOException { foo = di.readUTF();
See the difference? 'arg0' is what Eclipse uses for arguments by default.
Keep lines less than 80 characters.
Bar bar = foo.veryLongMethodWithManyArguments(argument1, argument2, argument3, argument4, argument5); // don't do this
... do this instead ...
Bar bar = foo.veryLongMethodWithManyArguments(argument1, argument2, argument3,argument4, argument5);
... or this, whichever looks better ...
Bar bar = foo.veryLongMethodWithManyArguments( argument1, argument2, argument3,argument4, argument5);
This happens more than people would imagine.
Bar bar = foo.getBar(); <--- imagine there's an extra space(s) after the semicolon instead of a line break.
Make sure there's a line-break after the end of your code, and also avoid lines that have nothing but whitespace.
Every class returned by RegionServers must implement Writable
. If you
are creating a new class that needs to implement this interface, don't forget the default constructor.
Don't just leave the @param arguments the way your IDE generated them. Don't do this...
/** * * @param bar <---- don't do this!!!! * @return <---- or this!!!! */ public Foo getFoo(Bar bar);
... either add something descriptive to the @param and @return lines, or just remove them. But the preference is to add something descriptive and useful.
If you submit a patch for one thing, don't do auto-reformatting or unrelated reformatting of code on a completely different area of code.
Likewise, don't add unrelated cleanup or refactorings outside the scope of your Jira.
Larger patches should go through ReviewBoard.
For more information on how to use ReviewBoard, see the ReviewBoard documentation.
Committers do this. See How To Commit in the HBase wiki.
Commiters will also resolve the Jira, typically after the patch passes a build.