HBaseTestingUtility是否适用于MiniCluster?

时间:2015-04-15 18:13:41

标签: hbase hbasetestingutility

我想对HBaseTestingUtility MiniCluster运行一个简单的单元测试。缺少使用HBaseTestingUtility运行测试所需的传递依赖项。我一直在跟踪NoClassDefFoundErrors,并且在其中一个jar文件的打包中遇到了一些错误。这是错误:

java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/test/MetricsAssertHelper at org.apache.hadoop.hbase.MiniHBaseCluster.<init>(MiniHBaseCluster.java:91)

当我在项目的.jar文件中搜索MetricsAssertHelper时,我在META-INF / services目录下找到该文件:

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

但这不是.class文件。我想知道.jar文件中是否缺少MetricsAssertHelper.class文件,因为那里有一个&#39; MetricsAssertHelperImpl.class文件。

这是我的代码和mvn依赖项。错误发生在HBaseTestingUtility.startMiniCluster()电话上。

    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>

1 个答案:

答案 0 :(得分:4)

问题是除了hbase-hadoop-compat之外,我还需要hbase-hadoop2-compat的依赖关系。以下是使用HBaseTestingUtility MiniCluster运行JUnit测试所需的完整依赖项列表。

    <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>