http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/TokenProvider.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/TokenProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/TokenProvider.java index 0588138..e355752 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/TokenProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/TokenProvider.java @@ -27,6 +27,8 @@ import java.util.Collections; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.CoprocessorEnvironment; +import org.apache.hadoop.hbase.coprocessor.CoreCoprocessor; +import org.apache.hadoop.hbase.coprocessor.HasRegionServerServices; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; import org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils; @@ -46,6 +48,7 @@ import org.apache.yetus.audience.InterfaceAudience; * Provides a service for obtaining authentication tokens via the * {@link AuthenticationProtos} AuthenticationService coprocessor service. */ +@CoreCoprocessor @InterfaceAudience.Private public class TokenProvider implements AuthenticationProtos.AuthenticationService.Interface, RegionCoprocessor { @@ -59,11 +62,13 @@ public class TokenProvider implements AuthenticationProtos.AuthenticationService public void start(CoprocessorEnvironment env) { // if running at region if (env instanceof RegionCoprocessorEnvironment) { - RegionCoprocessorEnvironment regionEnv = - (RegionCoprocessorEnvironment)env; - assert regionEnv.getCoprocessorRegionServerServices() instanceof RegionServerServices; - RpcServerInterface server = ((RegionServerServices) regionEnv - .getCoprocessorRegionServerServices()).getRpcServer(); + RegionCoprocessorEnvironment regionEnv = (RegionCoprocessorEnvironment)env; + /* Getting the RpcServer from a RegionCE is wrong. There cannot be an expectation that Region + is hosted inside a RegionServer. If you need RpcServer, then pass in a RegionServerCE. + TODO: FIX. + */ + RegionServerServices rss = ((HasRegionServerServices)regionEnv).getRegionServerServices(); + RpcServerInterface server = rss.getRpcServer(); SecretManager<?> mgr = ((RpcServer)server).getSecretManager(); if (mgr instanceof AuthenticationTokenSecretManager) { secretManager = (AuthenticationTokenSecretManager)mgr;
http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java index 8a5265d..5bd7c3f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -46,11 +46,11 @@ import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.AuthUtil; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants.OperationStatusCode; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagType; import org.apache.hadoop.hbase.TagUtil; +import org.apache.hadoop.hbase.coprocessor.HasRegionServerServices; import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Mutation; @@ -62,7 +62,6 @@ import org.apache.hadoop.hbase.io.util.StreamUtils; import org.apache.hadoop.hbase.regionserver.OperationStatus; import org.apache.hadoop.hbase.regionserver.Region; import org.apache.hadoop.hbase.regionserver.RegionScanner; -import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.security.Superusers; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.util.Bytes; @@ -112,9 +111,15 @@ public class DefaultVisibilityLabelServiceImpl implements VisibilityLabelService @Override public void init(RegionCoprocessorEnvironment e) throws IOException { - assert e.getCoprocessorRegionServerServices() instanceof RegionServerServices; - ZooKeeperWatcher zk = ((RegionServerServices) e.getCoprocessorRegionServerServices()) - .getZooKeeper(); + /* So, presumption that the RegionCE has a ZK Connection is too much. Why would a RCE have + * a ZK instance? This is cheating presuming we have access to the RS ZKW. TODO: Fix. + * + * And what is going on here? This ain't even a Coprocessor? And its being passed a CP Env? + */ + // This is a CoreCoprocessor. On creation, we should have gotten an environment that + // implements HasRegionServerServices so we can get at RSS. FIX!!!! Integrate this CP as + // native service. + ZooKeeperWatcher zk = ((HasRegionServerServices)e).getRegionServerServices().getZooKeeper(); try { labelsCache = VisibilityLabelsCache.createAndGet(zk, this.conf); } catch (IOException ioe) { http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java index 102d5f3..b5ff3db 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -56,6 +56,7 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagType; import org.apache.hadoop.hbase.TagUtil; +import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.Delete; @@ -70,6 +71,7 @@ import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.constraint.ConstraintException; import org.apache.hadoop.hbase.coprocessor.CoprocessorException; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; +import org.apache.hadoop.hbase.coprocessor.CoreCoprocessor; import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor; import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; import org.apache.hadoop.hbase.coprocessor.MasterObserver; @@ -85,7 +87,6 @@ import org.apache.hadoop.hbase.filter.FilterList; import org.apache.hadoop.hbase.io.hfile.HFile; import org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils; import org.apache.hadoop.hbase.ipc.RpcServer; -import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionActionResult; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameBytesPair; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos; @@ -122,6 +123,7 @@ import org.apache.hadoop.hbase.shaded.com.google.common.collect.MapMaker; * Coprocessor that has both the MasterObserver and RegionObserver implemented that supports in * visibility labels */ +@CoreCoprocessor @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG) // TODO: break out Observer functions into separate class/sub-class. public class VisibilityController implements MasterCoprocessor, RegionCoprocessor, @@ -212,8 +214,7 @@ public class VisibilityController implements MasterCoprocessor, RegionCoprocesso @Override public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { // Need to create the new system table for labels here - MasterServices master = ctx.getEnvironment().getMasterServices(); - if (!MetaTableAccessor.tableExists(master.getConnection(), LABELS_TABLE_NAME)) { + if (!MetaTableAccessor.tableExists(ctx.getEnvironment().getConnection(), LABELS_TABLE_NAME)) { HTableDescriptor labelsTable = new HTableDescriptor(LABELS_TABLE_NAME); HColumnDescriptor labelsColumn = new HColumnDescriptor(LABELS_TABLE_FAMILY); labelsColumn.setBloomFilterType(BloomType.NONE); @@ -226,7 +227,9 @@ public class VisibilityController implements MasterCoprocessor, RegionCoprocesso DisabledRegionSplitPolicy.class.getName()); labelsTable.setValue(Bytes.toBytes(HConstants.DISALLOW_WRITES_IN_RECOVERING), Bytes.toBytes(true)); - master.createSystemTable(labelsTable); + try (Admin admin = ctx.getEnvironment().getConnection().getAdmin()) { + admin.createTable(labelsTable); + } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelServiceManager.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelServiceManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelServiceManager.java index 65b731f..16eff84 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelServiceManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelServiceManager.java @@ -1,4 +1,4 @@ -/** +/* * 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/MockRegionServerServices.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/MockRegionServerServices.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/MockRegionServerServices.java index 4d2a8cc..c739715 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/MockRegionServerServices.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/MockRegionServerServices.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -111,11 +111,6 @@ public class MockRegionServerServices implements RegionServerServices { } @Override - public Set<TableName> getOnlineTables() { - return null; - } - - @Override public List<Region> getRegions() { return null; } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java index d580b42..12a50ce 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -46,6 +46,8 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; +import org.apache.hadoop.hbase.coprocessor.CoreCoprocessor; +import org.apache.hadoop.hbase.coprocessor.HasRegionServerServices; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; @@ -126,6 +128,7 @@ public class TestReplicaWithCluster { /** * This copro is used to simulate region server down exception for Get and Scan */ + @CoreCoprocessor public static class RegionServerStoppedCopro implements RegionCoprocessor, RegionObserver { public RegionServerStoppedCopro() { @@ -145,8 +148,7 @@ public class TestReplicaWithCluster { // Fail for the primary replica and replica 1 if (e.getEnvironment().getRegion().getRegionInfo().getReplicaId() <= 1) { LOG.info("Throw Region Server Stopped Exceptoin for replica id " + replicaId); - throw new RegionServerStoppedException("Server " + - e.getEnvironment().getCoprocessorRegionServerServices().getServerName() + throw new RegionServerStoppedException("Server " + e.getEnvironment().getServerName() + " not running"); } else { LOG.info("We're replica region " + replicaId); @@ -162,8 +164,7 @@ public class TestReplicaWithCluster { // Fail for the primary replica and replica 1 if (e.getEnvironment().getRegion().getRegionInfo().getReplicaId() <= 1) { LOG.info("Throw Region Server Stopped Exceptoin for replica id " + replicaId); - throw new RegionServerStoppedException("Server " + - e.getEnvironment().getCoprocessorRegionServerServices().getServerName() + throw new RegionServerStoppedException("Server " + e.getEnvironment().getServerName() + " not running"); } else { LOG.info("We're replica region " + replicaId); @@ -197,8 +198,8 @@ public class TestReplicaWithCluster { if (!e.getEnvironment().getRegion().getRegionInfo().isMetaRegion() && (replicaId == 0)) { LOG.info("Get, throw Region Server Stopped Exceptoin for region " + e.getEnvironment() .getRegion().getRegionInfo()); - throw new RegionServerStoppedException( - "Server " + e.getEnvironment().getCoprocessorRegionServerServices().getServerName() + throw new RegionServerStoppedException("Server " + + ((HasRegionServerServices)e.getEnvironment()).getRegionServerServices().getServerName() + " not running"); } } else { @@ -228,9 +229,9 @@ public class TestReplicaWithCluster { LOG.info("Scan, throw Region Server Stopped Exceptoin for replica " + e.getEnvironment() .getRegion().getRegionInfo()); - throw new RegionServerStoppedException( - "Server " + e.getEnvironment().getCoprocessorRegionServerServices().getServerName() - + " not running"); + throw new RegionServerStoppedException("Server " + + ((HasRegionServerServices)e.getEnvironment()).getRegionServerServices().getServerName() + + " not running"); } else { LOG.info("Scan, We're replica region " + replicaId); } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java index 9fa9aa8..22ecd2f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -58,6 +58,7 @@ import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.MemStoreLABImpl; import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; import org.apache.hadoop.hbase.regionserver.RegionScanner; +import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.regionserver.ScanType; import org.apache.hadoop.hbase.regionserver.ScannerContext; import org.apache.hadoop.hbase.regionserver.Store; @@ -70,6 +71,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.TestName; +import org.mockito.Mockito; @Category({CoprocessorTests.class, SmallTests.class}) public class TestCoprocessorInterface { @@ -387,7 +389,8 @@ public class TestCoprocessorInterface { // start a region server here, so just manually create cphost // and set it to region. Configuration conf = TEST_UTIL.getConfiguration(); - RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf); + RegionCoprocessorHost host = new RegionCoprocessorHost(r, + Mockito.mock(RegionServerServices.class), conf); r.setCoprocessorHost(host); for (Class<?> implClass : implClasses) { @@ -421,7 +424,8 @@ public class TestCoprocessorInterface { HRegion r = HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd); // this following piece is a hack. - RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf); + RegionCoprocessorHost host = + new RegionCoprocessorHost(r, Mockito.mock(RegionServerServices.class), conf); r.setCoprocessorHost(host); for (Class<?> implClass : implClasses) { http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java new file mode 100644 index 0000000..7972a93 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java @@ -0,0 +1,114 @@ +/* + * 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.coprocessor; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.CategoryBasedTimeout; +import org.apache.hadoop.hbase.CoprocessorEnvironment; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionUtils; +import org.apache.hadoop.hbase.testclassification.CoprocessorTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.AfterClass; +import org.junit.BeforeClass; +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 java.io.IOException; + +import static org.junit.Assert.assertTrue; + +/** + * Ensure Coprocessors get ShortCircuit Connections when they get a Connection from their + * CoprocessorEnvironment. + */ +@Category({CoprocessorTests.class, SmallTests.class}) +public class TestCoprocessorShortCircuitRPC { + @Rule + public TestName name = new TestName(); + @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()). + withLookingForStuckThread(true).build(); + private static final HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU(); + + /** + * Start up a mini cluster with my three CPs loaded. + */ + @BeforeClass + public static void beforeClass() throws Exception { + // Set my test Coprocessors into the Configuration before we start up the cluster. + Configuration conf = HTU.getConfiguration(); + conf.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, + TestMasterCoprocessor.class.getName()); + conf.setStrings(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, + TestRegionServerCoprocessor.class.getName()); + conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, + TestRegionCoprocessor.class.getName()); + HTU.startMiniCluster(); + } + + @AfterClass + public static void afterClass() throws Exception { + HTU.shutdownMiniCluster(); + } + + // Three test coprocessors, one of each type that has a Connection in its environment + // (WALCoprocessor does not). + public static class TestMasterCoprocessor implements MasterCoprocessor { + public TestMasterCoprocessor() {} + + @Override + public void start(CoprocessorEnvironment env) throws IOException { + // At start, we get base CoprocessorEnvironment Type, not MasterCoprocessorEnvironment, + check(((MasterCoprocessorEnvironment)env).getConnection()); + } + } + + public static class TestRegionServerCoprocessor implements RegionServerCoprocessor { + public TestRegionServerCoprocessor() {} + + @Override + public void start(CoprocessorEnvironment env) throws IOException { + // At start, we get base CoprocessorEnvironment Type, not RegionServerCoprocessorEnvironment, + check(((RegionServerCoprocessorEnvironment)env).getConnection()); + } + } + + public static class TestRegionCoprocessor implements RegionCoprocessor { + public TestRegionCoprocessor() {} + + @Override + public void start(CoprocessorEnvironment env) throws IOException { + // At start, we get base CoprocessorEnvironment Type, not RegionCoprocessorEnvironment, + check(((RegionCoprocessorEnvironment)env).getConnection()); + } + } + + private static void check(Connection connection) { + assertTrue(connection instanceof ConnectionUtils.ShortCircuitingClusterConnection); + } + + @Test + public void test() throws IOException { + // Nothing to do in here. The checks are done as part of the cluster spinup when CPs get + // loaded. Need this here so this class looks like a test. + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java new file mode 100644 index 0000000..a0c831e --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java @@ -0,0 +1,99 @@ +/* + * 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.coprocessor; + +import org.apache.hadoop.hbase.CategoryBasedTimeout; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.master.MasterCoprocessorHost; +import org.apache.hadoop.hbase.master.MasterServices; +import org.apache.hadoop.hbase.master.assignment.MockMasterServices; +import org.apache.hadoop.hbase.testclassification.CoprocessorTests; +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 java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Test CoreCoprocessor Annotation works giving access to facility not usually available. + * Test MasterCoprocessor. + */ +@Category({CoprocessorTests.class, SmallTests.class}) +public class TestCoreMasterCoprocessor { + @Rule public TestName name = new TestName(); + @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()). + withLookingForStuckThread(true).build(); + private static final HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU(); + private MasterServices ms; + private MasterCoprocessorHost mch; + + @Before + public void before() throws IOException { + String methodName = this.name.getMethodName(); + this.ms = new MockMasterServices(HTU.getConfiguration(), null); + this.mch = new MasterCoprocessorHost(this.ms, HTU.getConfiguration()); + this.mch.preMasterInitialization(); + } + + @After + public void after() throws IOException { + this.mch.preStopMaster(); + } + + /** + * No annotation with CoreCoprocessor. This should make it so I can NOT get at instance of a + * MasterServices instance after some gymnastics. + */ + public static class NotCoreMasterCoprocessor implements MasterCoprocessor { + public NotCoreMasterCoprocessor() {} + } + + /** + * Annotate with CoreCoprocessor. This should make it so I can get at instance of a + * MasterServices instance after some gymnastics. + */ + @CoreCoprocessor + public static class CoreMasterCoprocessor implements MasterCoprocessor { + public CoreMasterCoprocessor() {} + } + + /** + * Assert that when a Coprocessor is annotated with CoreCoprocessor, then it is possible to + * access a MasterServices instance. Assert the opposite too. + * Do it to MasterCoprocessors. + * @throws IOException + */ + @Test + public void testCoreRegionCoprocessor() throws IOException { + MasterCoprocessorEnvironment env = + this.mch.load(null, NotCoreMasterCoprocessor.class.getName(), 0, HTU.getConfiguration()); + assertFalse(env instanceof HasMasterServices); + env = this.mch.load(null, CoreMasterCoprocessor.class.getName(), 1, HTU.getConfiguration()); + assertTrue(env instanceof HasMasterServices); + assertEquals(this.ms, ((HasMasterServices)env).getMasterServices()); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java new file mode 100644 index 0000000..daf489c --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java @@ -0,0 +1,113 @@ +/* + * 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.coprocessor; + +import org.apache.hadoop.hbase.CategoryBasedTimeout; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.MockRegionServerServices; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.RegionInfoBuilder; +import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; +import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; +import org.apache.hadoop.hbase.regionserver.HRegion; +import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; +import org.apache.hadoop.hbase.regionserver.RegionServerServices; +import org.apache.hadoop.hbase.testclassification.CoprocessorTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.hbase.util.Bytes; +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 java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Test CoreCoprocessor Annotation works giving access to facility not usually available. + * Test RegionCoprocessor. + */ +@Category({CoprocessorTests.class, SmallTests.class}) +public class TestCoreRegionCoprocessor { + @Rule public TestName name = new TestName(); + @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()). + withLookingForStuckThread(true).build(); + HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU(); + private HRegion region = null; + private RegionServerServices rss; + + @Before + public void before() throws IOException { + String methodName = this.name.getMethodName(); + TableName tn = TableName.valueOf(methodName); + ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(methodName)).build(); + TableDescriptor td = TableDescriptorBuilder.newBuilder(tn).addColumnFamily(cfd).build(); + RegionInfo ri = RegionInfoBuilder.newBuilder(tn).build(); + this.rss = new MockRegionServerServices(HTU.getConfiguration()); + this.region = HRegion.openHRegion(ri, td, null, HTU.getConfiguration(), this.rss, null); + } + + @After + public void after() throws IOException { + this.region.close(); + } + + /** + * No annotation with CoreCoprocessor. This should make it so I can NOT get at instance of a + * RegionServerServices instance after some gymnastics. + */ + public static class NotCoreRegionCoprocessor implements RegionCoprocessor { + public NotCoreRegionCoprocessor() {} + } + + /** + * Annotate with CoreCoprocessor. This should make it so I can get at instance of a + * RegionServerServices instance after some gymnastics. + */ + @org.apache.hadoop.hbase.coprocessor.CoreCoprocessor + public static class CoreRegionCoprocessor implements RegionCoprocessor { + public CoreRegionCoprocessor() {} + } + + /** + * Assert that when a Coprocessor is annotated with CoreCoprocessor, then it is possible to + * access a RegionServerServices instance. Assert the opposite too. + * Do it to RegionCoprocessors. + * @throws IOException + */ + @Test + public void testCoreRegionCoprocessor() throws IOException { + RegionCoprocessorHost rch = region.getCoprocessorHost(); + RegionCoprocessorEnvironment env = + rch.load(null, NotCoreRegionCoprocessor.class.getName(), 0, HTU.getConfiguration()); + assertFalse(env instanceof HasRegionServerServices); + env = rch.load(null, CoreRegionCoprocessor.class.getName(), 1, HTU.getConfiguration()); + assertTrue(env instanceof HasRegionServerServices); + assertEquals(this.rss, ((HasRegionServerServices)env).getRegionServerServices()); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java new file mode 100644 index 0000000..6834982 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java @@ -0,0 +1,99 @@ +/* + * 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.coprocessor; + +import org.apache.hadoop.hbase.CategoryBasedTimeout; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.MockRegionServerServices; +import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost; +import org.apache.hadoop.hbase.regionserver.RegionServerServices; +import org.apache.hadoop.hbase.testclassification.CoprocessorTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.hbase.util.Bytes; +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 java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Test CoreCoprocessor Annotation works giving access to facility not usually available. + * Test RegionServerCoprocessor. + */ +@Category({CoprocessorTests.class, SmallTests.class}) +public class TestCoreRegionServerCoprocessor { + @Rule public TestName name = new TestName(); + @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()). + withLookingForStuckThread(true).build(); + private static final HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU(); + private RegionServerServices rss; + private RegionServerCoprocessorHost rsch; + + @Before + public void before() throws IOException { + String methodName = this.name.getMethodName(); + this.rss = new MockRegionServerServices(HTU.getConfiguration()); + this.rsch = new RegionServerCoprocessorHost(this.rss, HTU.getConfiguration()); + } + + @After + public void after() throws IOException { + this.rsch.preStop("Stopping", null); + } + + /** + * No annotation with CoreCoprocessor. This should make it so I can NOT get at instance of a + * RegionServerServices instance after some gymnastics. + */ + public static class NotCoreRegionServerCoprocessor implements RegionServerCoprocessor { + public NotCoreRegionServerCoprocessor() {} + } + + /** + * Annotate with CoreCoprocessor. This should make it so I can get at instance of a + * RegionServerServices instance after some gymnastics. + */ + @CoreCoprocessor + public static class CoreRegionServerCoprocessor implements RegionServerCoprocessor { + public CoreRegionServerCoprocessor() {} + } + + /** + * Assert that when a Coprocessor is annotated with CoreCoprocessor, then it is possible to + * access a RegionServerServices instance. Assert the opposite too. + * Do it to RegionServerCoprocessors. + * @throws IOException + */ + @Test + public void testCoreRegionCoprocessor() throws IOException { + RegionServerCoprocessorEnvironment env = + rsch.load(null, NotCoreRegionServerCoprocessor.class.getName(), 0, HTU.getConfiguration()); + assertFalse(env instanceof HasRegionServerServices); + env = rsch.load(null, CoreRegionServerCoprocessor.class.getName(), 1, HTU.getConfiguration()); + assertTrue(env instanceof HasRegionServerServices); + assertEquals(this.rss, ((HasRegionServerServices)env).getRegionServerServices()); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java index 71b4209..b2f7d1a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -74,7 +74,7 @@ public class TestOpenTableInCoprocessor { @Override public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, final Put put, final WALEdit edit, final Durability durability) throws IOException { - try (Table table = e.getEnvironment().getCoprocessorRegionServerServices().getConnection(). + try (Table table = e.getEnvironment().getConnection(). getTable(otherTable)) { table.put(put); completed[0] = true; @@ -112,8 +112,7 @@ public class TestOpenTableInCoprocessor { @Override public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, final Put put, final WALEdit edit, final Durability durability) throws IOException { - try (Table table = e.getEnvironment().getCoprocessorRegionServerServices(). - getConnection().getTable(otherTable, getPool())) { + try (Table table = e.getEnvironment().getConnection().getTable(otherTable, getPool())) { Put p = new Put(new byte[]{'a'}); p.addColumn(family, null, new byte[]{'a'}); try { http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java index 1277ccc..8470116 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -32,6 +32,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.MockRegionServerServices; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Durability; @@ -39,11 +40,13 @@ import org.apache.hadoop.hbase.regionserver.ChunkCreator; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.MemStoreLABImpl; import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; +import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.testclassification.CoprocessorTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category({CoprocessorTests.class, SmallTests.class}) public class TestRegionObserverStacking extends TestCase { @@ -128,7 +131,8 @@ public class TestRegionObserverStacking extends TestCase { // is secretly loaded at OpenRegionHandler. we don't really // start a region server here, so just manually create cphost // and set it to region. - RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf); + RegionCoprocessorHost host = new RegionCoprocessorHost(r, + Mockito.mock(RegionServerServices.class), conf); r.setCoprocessorHost(host); return r; } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java index b4644cb..aea09bb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java @@ -162,4 +162,4 @@ public class TestRegionServerCoprocessorExceptionWithAbort { } } } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java index 4f544e4..85d2b0b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.List; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.Server; @@ -454,4 +455,9 @@ public class MockNoopMasterServices implements MasterServices, Server { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockRegionServer.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockRegionServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockRegionServer.java index ca5a83b..6ca7076 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockRegionServer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockRegionServer.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -536,12 +536,6 @@ ClientProtos.ClientService.BlockingInterface, RegionServerServices { } @Override - public Set<TableName> getOnlineTables() { - // TODO Auto-generated method stub - return null; - } - - @Override public Leases getLeases() { // TODO Auto-generated method stub return null; http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java index 418216c..f1feef5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -28,6 +28,7 @@ import java.util.concurrent.Semaphore; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.HBaseTestingUtility; @@ -332,5 +333,15 @@ public class TestActiveMasterManager { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java index 1c135b9..572816d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -199,7 +199,6 @@ public class TestHFileCleaner { } static class DummyServer implements Server { - @Override public Configuration getConfiguration() { return UTIL.getConfiguration(); @@ -263,6 +262,16 @@ public class TestHFileCleaner { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } @Test http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java index 4ef3196..773d0fc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -201,5 +201,15 @@ public class TestHFileLinkCleaner { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java index 547f72e..b5ca894 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -309,6 +309,16 @@ public class TestLogsCleaner { public ClusterConnection getClusterConnection() { return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } static class FaultyZooKeeperWatcher extends ZooKeeperWatcher { http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java index e7a2588..be7f35e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -320,6 +320,16 @@ public class TestReplicationHFileCleaner { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } static class FaultyZooKeeperWatcher extends ZooKeeperWatcher { http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java index d4f1dfb..739519f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -27,6 +27,7 @@ import java.lang.management.ManagementFactory; import java.util.Iterator; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.HBaseConfiguration; @@ -897,6 +898,16 @@ public class TestHeapMemoryManager { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } static class CustomHeapMemoryTuner implements HeapMemoryTuner { http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java index 6ff9f75..39339aa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -40,6 +40,8 @@ import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; +import org.apache.hadoop.hbase.coprocessor.CoreCoprocessor; +import org.apache.hadoop.hbase.coprocessor.HasRegionServerServices; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; @@ -168,6 +170,7 @@ public class TestRegionServerAbort { assertFalse(cluster.getRegionServer(0).isStopped()); } + @CoreCoprocessor public static class StopBlockingRegionObserver implements RegionServerCoprocessor, RegionCoprocessor, RegionServerObserver, RegionObserver { public static final String DO_ABORT = "DO_ABORT"; @@ -187,9 +190,12 @@ public class TestRegionServerAbort { public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit, Durability durability) throws IOException { if (put.getAttribute(DO_ABORT) != null) { - HRegionServer rs = (HRegionServer) c.getEnvironment().getCoprocessorRegionServerServices(); - LOG.info("Triggering abort for regionserver " + rs.getServerName()); - rs.abort("Aborting for test"); + // TODO: Change this so it throws a CP Abort Exception instead. + RegionServerServices rss = + ((HasRegionServerServices)c.getEnvironment()).getRegionServerServices(); + String str = "Aborting for test"; + LOG.info(str + " " + rss.getServerName()); + rss.abort(str, new Throwable(str)); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java index 1d2b038..a01c75d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java @@ -32,6 +32,7 @@ import java.util.concurrent.atomic.LongAdder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.CoordinatedStateManagerFactory; @@ -149,6 +150,16 @@ public class TestSplitLogWorker { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } private void waitForCounter(LongAdder ctr, long oldval, long newval, long timems) http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestWALLockup.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestWALLockup.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestWALLockup.java index a8a60ab..2e5c552 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestWALLockup.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestWALLockup.java @@ -1,4 +1,4 @@ -/** +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -560,6 +560,15 @@ public class TestWALLockup { return null; } + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } static class DummyWALActionsListener extends WALActionsListener.Base { http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java index 3685d6d..2fe09af 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.replication; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.HBaseTestingUtility; @@ -474,5 +475,14 @@ public class TestReplicationStateHBaseImpl { abortCount = 0; } + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java index 36f762e..7d586ad 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java @@ -26,6 +26,7 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.ClusterId; import org.apache.hadoop.hbase.CoordinatedStateManager; @@ -205,5 +206,15 @@ public class TestReplicationStateZKImpl extends TestReplicationStateBasic { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java index f4ae59e..1e6e153 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.ClusterId; import org.apache.hadoop.hbase.CoordinatedStateManager; @@ -302,5 +303,15 @@ public class TestReplicationTrackerZKImpl { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java index 5712146..8451d69 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java @@ -57,7 +57,6 @@ import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.ClusterConnection; @@ -722,5 +721,15 @@ public abstract class TestReplicationSourceManager { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java index a7b8972..11af0de 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java @@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.ClusterId; import org.apache.hadoop.hbase.CoordinatedStateManager; @@ -57,7 +58,6 @@ import org.apache.hadoop.hbase.ipc.ServerRpcController; import org.apache.hadoop.hbase.ipc.SimpleRpcServer; import org.apache.hadoop.hbase.metrics.MetricRegistry; import org.apache.hadoop.hbase.protobuf.generated.AuthenticationProtos; -import org.apache.hadoop.hbase.regionserver.CoprocessorRegionServerServices; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.security.SecurityInfo; @@ -239,6 +239,16 @@ public class TestTokenAuthentication { } @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return this.stopped; + } + + @Override public void abort(String reason, Throwable error) { LOG.fatal("Aborting on: "+reason, error); this.aborted = true; @@ -268,10 +278,6 @@ public class TestTokenAuthentication { @Override public void shutdown() {} - public CoprocessorRegionServerServices getCoprocessorRegionServerServices() { - return mockServices; - } - @Override public ConcurrentMap<String, Object> getSharedData() { return null; } @@ -307,6 +313,16 @@ public class TestTokenAuthentication { public HRegionInfo getRegionInfo() { return null; } + + @Override + public ServerName getServerName() { + return null; + } + + @Override + public Connection getConnection() { + return null; + } }); started = true; http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java index 90fb521..db44219 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -22,6 +22,7 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.HBaseTestingUtility; @@ -133,4 +134,14 @@ public class MockServer implements Server { // TODO Auto-generated method stub return null; } + + @Override + public FileSystem getFileSystem() { + return null; + } + + @Override + public boolean isStopping() { + return false; + } } http://git-wip-us.apache.org/repos/asf/hbase/blob/38879fb3/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/ErrorThrowingGetObserver.java ---------------------------------------------------------------------- diff --git a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/ErrorThrowingGetObserver.java b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/ErrorThrowingGetObserver.java index 3eec2a6..019eb61 100644 --- a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/ErrorThrowingGetObserver.java +++ b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/ErrorThrowingGetObserver.java @@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.RegionTooBusyException; import org.apache.hadoop.hbase.UnknownScannerException; import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.coprocessor.CoreCoprocessor; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; @@ -44,6 +45,7 @@ import java.util.Optional; /** * Simple test coprocessor for injecting exceptions on Get requests. */ +@CoreCoprocessor public class ErrorThrowingGetObserver implements RegionCoprocessor, RegionObserver { @Override public Optional<RegionObserver> getRegionObserver() { @@ -68,8 +70,7 @@ public class ErrorThrowingGetObserver implements RegionCoprocessor, RegionObserv case NOT_SERVING_REGION: throw new NotServingRegionException("Failing for test"); case REGION_MOVED: - throw new RegionMovedException( - e.getEnvironment().getCoprocessorRegionServerServices().getServerName(), 1); + throw new RegionMovedException(e.getEnvironment().getServerName(), 1); case SCANNER_RESET: throw new ScannerResetException("Failing for test"); case UNKNOWN_SCANNER: