- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一段代码来操作存储在 HBase 中的数据。我还想为这段代码编写一个测试。我想在测试中使用 HBaseTestingUtility,因此,在我的 @BeforeClass 中,我创建 HBaseTestingUtility 的新实例并启动迷你集群:
@BeforeClass
public static void setUpClass() throws Exception {
utility = new HBaseTestingUtility();
utility.startMiniCluster();
}
效果很好。但是,我无法在正在测试的代码中连接到此嵌入式集群。在我的代码中:
Configuration config = HBaseConfiguration.create();
try (HBaseAdmin admin = new HBaseAdmin(config))
{
//code which manipulates the data
}
不幸的是,当创建新的 HBaseAdmin 时,我收到 ConnectionError 异常:
2013-11-21 11:20:35,778 WARN [main-SendThread(0:0:0:0:0:0:0:1:2181)] zookeeper.ClientCnxn (ClientCnxn.java:run(1089)) - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException: Connection refused: no further information at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:692) at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350) at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)
当我尝试另一个方法来创建 HBaseAdmin 时:
try (HBaseAdmin admin = new HBaseAdmin(HBaseCacheTest.utility.getConfiguration()))
{
//code which manipulates the data
}
它可以工作(请注意,这里我通过 HBaseCacheTest.utility 访问 HBaseTestingUtility 的实例)。显然这不是一个好方法,因为我不想拥有依赖于测试代码的生产代码。
我认为在这里可行的一种方法是在我的生产类中设置配置并在我的测试中使用此设置方法。但是,我相信应该有另一种方法来连接到使用 HBaseTestingUtility 创建的嵌入式迷你集群。
有什么想法吗?
最佳答案
您不应创建新的 Configuration 对象,而应使用 HBaseTestingUtility 提供的对象:
HBaseAdmin admin = testingUtility.getHBaseAdmin();
此外,如果您只需要配置,则可以使用这个:
testingUtility.getConfiguration()
刚刚在我的 UT 中重新检查了它。我正在使用 HBase 0.96-hadoop2
希望这有帮助:)
关于java - 创建连接到 HBaseTestingUtility 的 HBaseAdmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20118705/
在 Hbase .98 中,我们使用 .isMasterRunning()查看 HBase 是否正在运行,如果是,我们就可以成功创建表。现在在 1.1.1 中它已被弃用...是否有一个好的解决方法来查
我正在编写一段代码来操作存储在 HBase 中的数据。我还想为这段代码编写一个测试。我想在测试中使用 HBaseTestingUtility,因此,在我的 @BeforeClass 中,我创建 HBa
我的系统环境: Ubuntu 18.04 LTS (64bit) Hadoop 2.7.6 HBase 2.0.1 Sqoop 1.4.7 openjdk version 1.8.0_171 启动h
我是一名优秀的程序员,十分优秀!