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.MediumTests;
34  import org.junit.Test;
35  import org.junit.experimental.categories.Category;
36  
37  /**
38   * A basic unit test that spins up a local HBase cluster.
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    // DISABLED BECAUSE FLAKEY @Test(timeout=300 * 1000)
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        // These numbers are deterministic, seeded by table name.
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  }