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.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37
38
39
40 @Category(MediumTests.class)
41 public class TestProcessBasedCluster {
42
43 private static final Log LOG = LogFactory.getLog(TestProcessBasedCluster.class);
44
45 private static final int COLS_PER_ROW = 5;
46 private static final int FLUSHES = 5;
47 private static final int NUM_REGIONS = 5;
48 private static final int ROWS_PER_FLUSH = 5;
49
50 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
51
52
53 public void testProcessBasedCluster() throws Exception {
54 ProcessBasedLocalHBaseCluster cluster = new ProcessBasedLocalHBaseCluster(
55 TEST_UTIL.getConfiguration(), 2, 3);
56 cluster.startMiniDFS();
57 cluster.startHBase();
58 try {
59 TEST_UTIL.createRandomTable(HTestConst.DEFAULT_TABLE_STR,
60 HTestConst.DEFAULT_CF_STR_SET,
61 HColumnDescriptor.DEFAULT_VERSIONS, COLS_PER_ROW, FLUSHES, NUM_REGIONS,
62 ROWS_PER_FLUSH);
63 HTable table = new HTable(TEST_UTIL.getConfiguration(), HTestConst.DEFAULT_TABLE_BYTES);
64 ResultScanner scanner = table.getScanner(HTestConst.DEFAULT_CF_BYTES);
65 Result result;
66 int rows = 0;
67 int cols = 0;
68 while ((result = scanner.next()) != null) {
69 ++rows;
70 cols += result.getFamilyMap(HTestConst.DEFAULT_CF_BYTES).size();
71 }
72 LOG.info("Read " + rows + " rows, " + cols + " columns");
73 scanner.close();
74 table.close();
75
76
77 assertEquals(19, rows);
78 assertEquals(35, cols);
79 } catch (Exception ex) {
80 LOG.error(ex);
81 throw ex;
82 } finally {
83 cluster.shutdown();
84 }
85 }
86
87 @Test
88 public void testHomePath() {
89 File pom = new File(HBaseHomePath.getHomePath(), "pom.xml");
90 assertTrue(pom.getPath() + " does not exist", pom.exists());
91 }
92
93 }