1   /*
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.client;
21  
22  import org.apache.hadoop.hbase.HBaseTestingUtility;
23  import org.apache.hadoop.hbase.HRegionLocation;
24  import org.apache.hadoop.hbase.util.Bytes;
25  import org.junit.BeforeClass;
26  import org.junit.Test;
27  
28  import static org.junit.Assert.assertNull;
29  import static org.junit.Assert.assertNotNull;
30  
31  /**
32   * This class is for testing HCM features
33   */
34  public class TestHCM {
35  
36    private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
37    private static final byte[] TABLE_NAME = Bytes.toBytes("test");
38    private static final byte[] FAM_NAM = Bytes.toBytes("f");
39    private static final byte[] ROW = Bytes.toBytes("bbb");
40  
41    @BeforeClass
42    public static void setUpBeforeClass() throws Exception {
43      TEST_UTIL.startMiniCluster(1);
44    }
45  
46    /**
47     * Test that when we delete a location using the first row of a region
48     * that we really delete it.
49     * @throws Exception
50     */
51    @Test
52    public void testRegionCaching() throws Exception{
53      HTable table = TEST_UTIL.createTable(TABLE_NAME, FAM_NAM);
54      TEST_UTIL.createMultiRegions(table, FAM_NAM);
55      Put put = new Put(ROW);
56      put.add(FAM_NAM, ROW, ROW);
57      table.put(put);
58      HConnectionManager.TableServers conn =
59          (HConnectionManager.TableServers) table.getConnection();
60      assertNotNull(conn.getCachedLocation(TABLE_NAME, ROW));
61      conn.deleteCachedLocation(TABLE_NAME, ROW);
62      HRegionLocation rl = conn.getCachedLocation(TABLE_NAME, ROW);
63      assertNull("What is this location?? " + rl, rl);
64    }
65  }
66