---
title: "使用HBaseTestingUtility进行本地调试"
author: "kabike"
date: "2015-02-01T15:14:43Z"
tags: []
categories: ["开源软件"]
slug: "hbasetestingutility"
draft: false
lastmod: "2015-02-01T15:14:43Z"
id: 2182105
url: "https://kabike.iteye.com/blog/2182105"
---

要想测试hbase的功能,不一定非要启动hbase集群,可以用HBaseTestingUtility在本地进行hbase的部分功能调试 \[code="java"] TableName tableName = TableName.valueOf("testBar"); String family = "cf"; HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(family)); HRegionInfo info = new HRegionInfo(tableName); HRegion region = HRegion.createHRegion(info, TEST\_UTIL.getDataTestDir(), TEST\_UTIL.getConfiguration(), htd); try { String valueString = "ValueString"; for (int i = 0; i &lt; 10; i++) { String key = "row" + i; Put p = new Put(Bytes.toBytes(key)); p.setDurability(Durability.SKIP\_WAL); p.add(Bytes.toBytes(family), Bytes.toBytes("c"), Bytes.toBytes(valueString)); region.put(p); } List resultList = new ArrayList(); Scan scan = new Scan(); RegionScanner scanner = region.getScanner(scan); while (true) { List cellList = new ArrayList(); boolean hasNext = scanner.next(cellList); if (cellList.size() &gt; 0) { resultList.add(Result.create(cellList)); } if (!hasNext) { break; } } assertEquals(10, resultList.size()); } finally { region.close(); region.getLog().closeAndDelete(); } \[/code]