I have a simple unit test I want to run against the HBaseTestingUtility
MiniCluster. The transitive dependencies needed to run a test with HBaseTestingUtility
are missing. I've been tracking down NoClassDefFoundErrors
and have run into something that may be an error in the packaging of one of the jar files. Here's the error:
java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/test/MetricsAssertHelper
at org.apache.hadoop.hbase.MiniHBaseCluster.<init>(MiniHBaseCluster.java:91)
When I search for MetricsAssertHelper in the .jar files in my project I find that file under the META-INF/services directory:
jar tvf org/apache/hbase/hbase-hadoop2-compat/1.0.0/hbase-hadoop2-compat-1.0.0-tests.jar | grep MetricsAssertHelper
53 Sat Feb 14 19:43:40 MST 2015 META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper
1337 Sat Feb 14 19:43:40 MST 2015 org/apache/hadoop/hbase/test/MetricsAssertHelperImpl$MockMetricsBuilder.class
3743 Sat Feb 14 19:43:40 MST 2015 org/apache/hadoop/hbase/test/MetricsAssertHelperImpl$MockRecordBuilder.class
6689 Sat Feb 14 19:43:40 MST 2015 org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.class
This is not a .class file, however. I wonder if theMetricsAssertHelper.class
file is missing from the .jar file since there is a 'MetricsAssertHelperImpl.class file` there.
Here is my code and mvn dependencies. The Error happens on the HBaseTestingUtility.startMiniCluster()
call.
private static HBaseTestingUtility utility;
@Before
public void setUp() throws Exception {
utility = new HBaseTestingUtility();
utility.startMiniCluster();
}
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.0.0</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-hadoop2-compat</artifactId>
<version>1.0.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>
The problem was that I also needed a dependency for hbase-hadoop-compat
in addition to hbase-hadoop2-compat
. Here is the complete list of dependencies needed to run JUnit tests with HBaseTestingUtility MiniCluster.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.0.0</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-hadoop-compat</artifactId>
<version>1.0.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-hadoop2-compat</artifactId>
<version>1.0.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>