1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22
23 import java.io.File;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.hbase.HBaseTestingUtility;
28 import org.apache.hadoop.hbase.HColumnDescriptor;
29 import org.apache.hadoop.hbase.HTestConst;
30 import org.apache.hadoop.hbase.client.HTable;
31 import org.apache.hadoop.hbase.client.Result;
32 import org.apache.hadoop.hbase.client.ResultScanner;
33 import org.apache.hadoop.hbase.testclassification.MediumTests;
34 import org.apache.hadoop.hbase.client.Table;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37
38
39
40
41 @Category(MediumTests.class)
42 public class TestProcessBasedCluster {
43
44 private static final Log LOG = LogFactory.getLog(TestProcessBasedCluster.class);
45
46 private static final int COLS_PER_ROW = 5;
47 private static final int FLUSHES = 5;
48 private static final int NUM_REGIONS = 5;
49 private static final int ROWS_PER_FLUSH = 5;
50
51 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
52
53
54 public void testProcessBasedCluster() throws Exception {
55 ProcessBasedLocalHBaseCluster cluster = new ProcessBasedLocalHBaseCluster(
56 TEST_UTIL.getConfiguration(), 2, 3);
57 cluster.startMiniDFS();
58 cluster.startHBase();
59 try {
60 TEST_UTIL.createRandomTable(HTestConst.DEFAULT_TABLE_STR,
61 HTestConst.DEFAULT_CF_STR_SET,
62 HColumnDescriptor.DEFAULT_VERSIONS, COLS_PER_ROW, FLUSHES, NUM_REGIONS,
63 ROWS_PER_FLUSH);
64 Table table = new HTable(TEST_UTIL.getConfiguration(), HTestConst.DEFAULT_TABLE);
65 ResultScanner scanner = table.getScanner(HTestConst.DEFAULT_CF_BYTES);
66 Result result;
67 int rows = 0;
68 int cols = 0;
69 while ((result = scanner.next()) != null) {
70 ++rows;
71 cols += result.getFamilyMap(HTestConst.DEFAULT_CF_BYTES).size();
72 }
73 LOG.info("Read " + rows + " rows, " + cols + " columns");
74 scanner.close();
75 table.close();
76
77
78 assertEquals(19, rows);
79 assertEquals(35, cols);
80 } catch (Exception ex) {
81 LOG.error(ex);
82 throw ex;
83 } finally {
84 cluster.shutdown();
85 }
86 }
87
88 @Test
89 public void testHomePath() {
90 File pom = new File(HBaseHomePath.getHomePath(), "pom.xml");
91 assertTrue(pom.getPath() + " does not exist", pom.exists());
92 }
93
94 }