|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. 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, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertNotNull; |
| 22 | +import static org.junit.Assert.assertNull; |
| 23 | +import static org.junit.Assert.assertTrue; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | +import org.apache.hadoop.conf.Configuration; |
| 27 | +import org.apache.hadoop.hbase.client.Connection; |
| 28 | +import org.apache.hadoop.hbase.client.ConnectionFactory; |
| 29 | +import org.apache.hadoop.hbase.client.RegionInfo; |
| 30 | +import org.apache.hadoop.hbase.master.HMaster; |
| 31 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 32 | +import org.apache.hadoop.hbase.testclassification.MiscTests; |
| 33 | +import org.apache.hadoop.hbase.util.Bytes; |
| 34 | +import org.apache.hadoop.hbase.util.Pair; |
| 35 | +import org.junit.AfterClass; |
| 36 | +import org.junit.BeforeClass; |
| 37 | +import org.junit.ClassRule; |
| 38 | +import org.junit.Rule; |
| 39 | +import org.junit.Test; |
| 40 | +import org.junit.experimental.categories.Category; |
| 41 | +import org.junit.rules.TestName; |
| 42 | +import org.slf4j.Logger; |
| 43 | +import org.slf4j.LoggerFactory; |
| 44 | + |
| 45 | +/** |
| 46 | + * Test {@link org.apache.hadoop.hbase.TestMetaTableForReplica}. |
| 47 | + */ |
| 48 | +@Category({ MiscTests.class, MediumTests.class }) |
| 49 | +@SuppressWarnings("deprecation") |
| 50 | +public class TestMetaTableForReplica { |
| 51 | + @ClassRule |
| 52 | + public static final HBaseClassTestRule CLASS_RULE = |
| 53 | + HBaseClassTestRule.forClass(TestMetaTableForReplica.class); |
| 54 | + |
| 55 | + private static final Logger LOG = LoggerFactory.getLogger(TestMetaTableForReplica.class); |
| 56 | + private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); |
| 57 | + private static Connection connection; |
| 58 | + |
| 59 | + @Rule |
| 60 | + public TestName name = new TestName(); |
| 61 | + |
| 62 | + @BeforeClass |
| 63 | + public static void beforeClass() throws Exception { |
| 64 | + Configuration c = UTIL.getConfiguration(); |
| 65 | + // quicker heartbeat interval for faster DN death notification |
| 66 | + c.setInt("hbase.ipc.client.connect.max.retries", 1); |
| 67 | + c.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000); |
| 68 | + // Start cluster having non-default hbase meta table name |
| 69 | + c.setStrings(HConstants.HBASE_META_TABLE_SUFFIX, "test"); |
| 70 | + UTIL.startMiniCluster(3); |
| 71 | + connection = ConnectionFactory.createConnection(c); |
| 72 | + } |
| 73 | + |
| 74 | + @AfterClass |
| 75 | + public static void afterClass() throws Exception { |
| 76 | + connection.close(); |
| 77 | + UTIL.shutdownMiniCluster(); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testStateOfMetaForReplica() { |
| 82 | + HMaster m = UTIL.getMiniHBaseCluster().getMaster(); |
| 83 | + assertTrue(m.waitForMetaOnline()); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testNameOfMetaForReplica() { |
| 88 | + // Check the correctness of the meta table for replica |
| 89 | + String metaTableName = TableName.META_TABLE_NAME.getNameWithNamespaceInclAsString(); |
| 90 | + assertNotNull(metaTableName); |
| 91 | + |
| 92 | + // Check if name of the meta table for replica is not same as default table |
| 93 | + assertEquals(0, |
| 94 | + TableName.META_TABLE_NAME.compareTo(TableName.getDefaultNameOfMetaForReplica())); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testGetNonExistentRegionFromMetaFromReplica() throws IOException { |
| 99 | + final String name = this.name.getMethodName(); |
| 100 | + LOG.info("Started " + name); |
| 101 | + Pair<RegionInfo, ServerName> pair = |
| 102 | + MetaTableAccessor.getRegion(connection, Bytes.toBytes("nonexistent-region")); |
| 103 | + assertNull(pair); |
| 104 | + LOG.info("Finished " + name); |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + public void testGetExistentRegionFromMetaFromReplica() throws IOException { |
| 109 | + final TableName tableName = TableName.valueOf(name.getMethodName()); |
| 110 | + LOG.info("Started " + tableName); |
| 111 | + UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); |
| 112 | + assertEquals(1, MetaTableAccessor.getTableRegions(connection, tableName).size()); |
| 113 | + } |
| 114 | +} |
0 commit comments