View Javadoc

1   /*
2   
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements. See the NOTICE file distributed with this
5    * work for additional information regarding copyright ownership. The ASF
6    * licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15   * License for the specific language governing permissions and limitations
16   * under the License.
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   * A basic unit test that spins up a local HBase cluster.
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    // DISABLED BECAUSE FLAKEY @Test(timeout=300 * 1000)
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        // These numbers are deterministic, seeded by table name.
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  }