commit 916dcf557054f6a3b7cb556638fa33cb8166710e Author: stack Date: Mon Jan 4 21:28:56 2016 -0800 test diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/Server.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/Server.java index 365c0b8..26454f0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/Server.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/Server.java @@ -22,6 +22,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceStability; import org.apache.hadoop.hbase.client.ClusterConnection; +import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; @@ -43,12 +44,20 @@ public interface Server extends Abortable, Stoppable { ZooKeeperWatcher getZooKeeper(); /** - * Returns a reference to the servers' cluster connection. + * Returns a reference to the servers' connection. * * Important note: this method returns a reference to Connection which is managed * by Server itself, so callers must NOT attempt to close connection obtained. */ - ClusterConnection getConnection(); + Connection getConnection(); + + /** + * Returns a reference to the servers' cluster connection. Prefer {@link #getConnection()}. + * + * Important note: this method returns a reference to Connection which is managed + * by Server itself, so callers must NOT attempt to close connection obtained. + */ + ClusterConnection getClusterConnection(); /** * Returns instance of {@link org.apache.hadoop.hbase.zookeeper.MetaTableLocator} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java index 50f07c1..a95279c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java @@ -215,7 +215,7 @@ public class ServerManager { Configuration c = master.getConfiguration(); maxSkew = c.getLong("hbase.master.maxclockskew", 30000); warningSkew = c.getLong("hbase.master.warningclockskew", 10000); - this.connection = connect ? master.getConnection() : null; + this.connection = connect ? master.getClusterConnection() : null; int pingMaxAttempts = Math.max(1, master.getConfiguration().getInt( "hbase.master.maximum.ping.server.attempts", 10)); int pingSleepInterval = Math.max(1, master.getConfiguration().getInt( diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 1255fa4..90cf4a9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -79,6 +79,7 @@ import org.apache.hadoop.hbase.YouAreDeadException; import org.apache.hadoop.hbase.ZNodeClearer; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.client.ClusterConnection; +import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionUtils; import org.apache.hadoop.hbase.client.RpcRetryingCallerFactory; import org.apache.hadoop.hbase.conf.ConfigurationManager; @@ -1866,7 +1867,7 @@ public class HRegionServer extends HasThread implements RegionServerServices, La } @Override - public ClusterConnection getConnection() { + public Connection getConnection() { return this.clusterConnection; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterSchema.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterSchema.java new file mode 100644 index 0000000..0a16967 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterSchema.java @@ -0,0 +1,102 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.master; + + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.hadoop.hbase.CategoryBasedTimeout; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.MetaTableAccessor; +import org.apache.hadoop.hbase.NamespaceDescriptor; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.client.TableState; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CellScanner; +import org.apache.hadoop.hbase.testclassification.MasterTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; +import org.junit.rules.TestRule; +import org.mockito.Mockito; + + +/** + * Test ClusterSchema standalone outside Master. + */ +@Category({MasterTests.class, SmallTests.class}) +public class TestClusterSchema { + @Rule public TestName testName = new TestName(); + @Rule public final TestRule timeout = CategoryBasedTimeout.builder(). + withTimeout(this.getClass()). + withLookingForStuckThread(true).build(); + private ClusterSchemaService css; + + @Before + public void setUp() throws Exception { + MasterServices masterServices = Mockito.mock(MasterServices.class); + Mockito.when(masterServices.getConfiguration()).thenReturn(HBaseConfiguration.create()); + Connection connection = Mockito.mock(Connection.class); + Table table = Mockito.mock(Table.class); + Mockito.when(table.get((Get)Mockito.any())).thenReturn(getNamespaceTableStateEnabledResult()); + Mockito.when(connection.getTable((TableName)Mockito.any())).thenReturn(table); + Mockito.when(masterServices.getConnection()).thenReturn(connection); + ClusterSchemaService css = new ClusterSchemaServiceImpl(masterServices); + css.startAndWait(); + } + + /** + * This is + * @return A Result that has in it serialized enable state for the namespace table. + */ + private static Result getNamespaceTableStateEnabledResult() throws IOException { + // Get a TableState for the Namespace table that shows it as Enabled. + TableState state = new TableState(TableName.NAMESPACE_TABLE_NAME, TableState.State.ENABLED); + // Now, get Put with this TableState in it... then get the Cell out of the Put with cellScanner. + CellScanner cellScanner = MetaTableAccessor.makePutFromTableState(state).cellScanner(); + cellScanner.advance(); + List cells = new ArrayList(); + // Add the Cell from Put to the Cell List + cells.add(cellScanner.current()); + // Wrap the cell list in a Result. + return Result.create(cells); + } + + + @After + public void tearDown() throws Exception { + css.stopAndWait(); + } + + @Test + public void testNamespaces() throws IOException { + NamespaceDescriptor nsd = NamespaceDescriptor.create(this.testName.getMethodName()).build(); + css.createNamespace(nsd, HConstants.NO_NONCE, HConstants.NO_NONCE); + } +} \ No newline at end of file