`
kabike
  • 浏览: 608567 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

使用HBaseTestingUtility进行本地调试

 
阅读更多
要想测试hbase的功能,不一定非要启动hbase集群,可以用HBaseTestingUtility在本地进行hbase的部分功能调试

		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 < 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<Result> resultList = new ArrayList<Result>();

			Scan scan = new Scan();
			RegionScanner scanner = region.getScanner(scan);
			while (true) {
				List<Cell> cellList = new ArrayList<Cell>();
				boolean hasNext = scanner.next(cellList);
				if (cellList.size() > 0) {
					resultList.add(Result.create(cellList));
				}
				if (!hasNext) {
					break;
				}
			}
			assertEquals(10, resultList.size());
		} finally {
			region.close();
			region.getLog().closeAndDelete();
		}

	
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics