From c3f046633676f80bdf37bb407039be6c8fef9799 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Sun, 10 Feb 2019 18:21:24 +0800 Subject: [PATCH] HBASE-21857 Addendum fix broken UTs --- .../replication/ReplicationPeerManager.java | 2 +- .../replication/TestReplicationAdmin.java | 6 +- .../replication/DummyReplicationEndpoint.java | 68 +++++++++++++++++++ .../test/ruby/hbase/replication_admin_test.rb | 6 +- 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/replication/DummyReplicationEndpoint.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java index af00aaed9cc..17bbb82abdc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java @@ -252,7 +252,7 @@ public class ReplicationPeerManager { try { endpoint = Class.forName(replicationEndpointImpl) .asSubclass(ReplicationEndpoint.class).getDeclaredConstructor().newInstance(); - } catch (Exception e) { + } catch (Throwable e) { throw new DoNotRetryIOException( "Can not instantiate configured replication endpoint class=" + replicationEndpointImpl, e); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java index a753d235bf1..3f5b6bc5c39 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java @@ -41,6 +41,7 @@ import org.apache.hadoop.hbase.ReplicationPeerNotFoundException; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.replication.DummyReplicationEndpoint; import org.apache.hadoop.hbase.replication.ReplicationException; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder; @@ -48,7 +49,6 @@ import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; import org.apache.hadoop.hbase.replication.ReplicationQueueStorage; import org.apache.hadoop.hbase.replication.ReplicationStorageFactory; import org.apache.hadoop.hbase.replication.TestReplicationEndpoint.InterClusterReplicationEndpointForTest; -import org.apache.hadoop.hbase.replication.TestReplicationEndpoint.ReplicationEndpointForTest; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.junit.After; @@ -874,7 +874,7 @@ public class TestReplicationAdmin { public void testPeerReplicationEndpointImpl() throws Exception { ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(); builder.setClusterKey(KEY_ONE); - builder.setReplicationEndpointImpl(ReplicationEndpointForTest.class.getName()); + builder.setReplicationEndpointImpl(DummyReplicationEndpoint.class.getName()); hbaseAdmin.addReplicationPeer(ID_ONE, builder.build()); try { @@ -899,7 +899,7 @@ public class TestReplicationAdmin { hbaseAdmin.addReplicationPeer(ID_SECOND, builder.build()); try { - builder.setReplicationEndpointImpl(ReplicationEndpointForTest.class.getName()); + builder.setReplicationEndpointImpl(DummyReplicationEndpoint.class.getName()); hbaseAdmin.updateReplicationPeerConfig(ID_SECOND, builder.build()); fail("Change replication endpoint implementation class on an existing peer is not allowed"); } catch (Exception e) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/DummyReplicationEndpoint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/DummyReplicationEndpoint.java new file mode 100644 index 00000000000..38f0dbe6103 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/DummyReplicationEndpoint.java @@ -0,0 +1,68 @@ +/** + * 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.replication; + +import java.util.UUID; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * A dummy replication endpoint that does nothing, for test use only. + */ +@InterfaceAudience.Private +public class DummyReplicationEndpoint extends BaseReplicationEndpoint { + + @Override + public boolean canReplicateToSameCluster() { + return true; + } + + @Override + public UUID getPeerUUID() { + return ctx.getClusterId(); + } + + @Override + public WALEntryFilter getWALEntryfilter() { + return null; + } + + @Override + public boolean replicate(ReplicateContext replicateContext) { + return true; + } + + @Override + public void start() { + startAsync(); + } + + @Override + public void stop() { + stopAsync(); + } + + @Override + protected void doStart() { + notifyStarted(); + } + + @Override + protected void doStop() { + notifyStopped(); + } +} diff --git a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb index d8a6302402e..17ab98be9c6 100644 --- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb @@ -601,7 +601,7 @@ module Hbase define_test "get_peer_config: works with replicationendpointimpl peer and config params" do cluster_key = 'localhost:2181:/hbase-test' - repl_impl = 'org.apache.hadoop.hbase.replication.ReplicationEndpointForTest' + repl_impl = 'org.apache.hadoop.hbase.replication.DummyReplicationEndpoint' config_params = { "config1" => "value1", "config2" => "value2" } args = { CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params } @@ -621,7 +621,7 @@ module Hbase peer_id_second = '2' command(:add_peer, @peer_id, args) - repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest" + repl_impl = "org.apache.hadoop.hbase.replication.DummyReplicationEndpoint" config_params = { "config1" => "value1", "config2" => "value2" } args2 = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params} command(:add_peer, peer_id_second, args2) @@ -636,7 +636,7 @@ module Hbase end define_test "update_peer_config: can update peer config and data" do - repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest" + repl_impl = "org.apache.hadoop.hbase.replication.DummyReplicationEndpoint" config_params = { "config1" => "value1", "config2" => "value2" } data_params = {"data1" => "value1", "data2" => "value2"} args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params, DATA => data_params}