From a8f0f1d95a6a175dd101e93ee15c8f5dda87bd13 Mon Sep 17 00:00:00 2001 From: tedyu Date: Mon, 1 Oct 2018 15:09:01 -0700 Subject: [PATCH] HBASE-21258 Add resetting of flags for RS Group pre/post hooks in TestRSGroups --- .../hadoop/hbase/rsgroup/TestRSGroups.java | 69 +++----- .../hadoop/hbase/rsgroup/TestRSGroups1.java | 159 ++++++++++++++++++ 2 files changed, 182 insertions(+), 46 deletions(-) create mode 100644 hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups1.java diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java index 4320fea9882..64313f308bc 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java @@ -22,7 +22,6 @@ package org.apache.hadoop.hbase.rsgroup; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.IOException; import java.util.Iterator; @@ -43,7 +42,6 @@ import org.apache.hadoop.hbase.Waiter.Predicate; import org.apache.hadoop.hbase.coprocessor.BaseMasterObserver; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; -import org.apache.hadoop.hbase.coprocessor.MasterObserver; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.MasterCoprocessorHost; @@ -67,10 +65,10 @@ import com.google.common.collect.Sets; @Category({MediumTests.class}) public class TestRSGroups extends TestRSGroupsBase { protected static final Log LOG = LogFactory.getLog(TestRSGroups.class); - private static HMaster master; + static HMaster master; private static boolean init = false; private static RSGroupAdminEndpoint RSGroupAdminEndpoint; - private static CPMasterObserver observer; + static CPMasterObserver observer; @BeforeClass public static void setUp() throws Exception { @@ -123,7 +121,7 @@ public class TestRSGroups extends TestRSGroupsBase { init = true; afterMethod(); } - + observer.resetFlags(); } @After @@ -149,7 +147,6 @@ public class TestRSGroups extends TestRSGroupsBase { } catch (Exception ex) { // ignore } - assertTrue(observer.preMoveServersCalled); TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate() { @Override public boolean evaluate() throws Exception { @@ -216,46 +213,6 @@ public class TestRSGroups extends TestRSGroupsBase { }); } - @Test - public void testNamespaceConstraint() throws Exception { - String nsName = tablePrefix+"_foo"; - String groupName = tablePrefix+"_foo"; - LOG.info("testNamespaceConstraint"); - rsGroupAdmin.addRSGroup(groupName); - assertTrue(observer.preAddRSGroupCalled); - assertTrue(observer.postAddRSGroupCalled); - - admin.createNamespace(NamespaceDescriptor.create(nsName) - .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, groupName) - .build()); - //test removing a referenced group - try { - rsGroupAdmin.removeRSGroup(groupName); - fail("Expected a constraint exception"); - } catch (IOException ex) { - } - //test modify group - //changing with the same name is fine - admin.modifyNamespace( - NamespaceDescriptor.create(nsName) - .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, groupName) - .build()); - String anotherGroup = tablePrefix+"_anotherGroup"; - rsGroupAdmin.addRSGroup(anotherGroup); - //test add non-existent group - admin.deleteNamespace(nsName); - rsGroupAdmin.removeRSGroup(groupName); - assertTrue(observer.preRemoveRSGroupCalled); - assertTrue(observer.postRemoveRSGroupCalled); - try { - admin.createNamespace(NamespaceDescriptor.create(nsName) - .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, "foo") - .build()); - fail("Expected a constraint exception"); - } catch (IOException ex) { - } - } - @Test public void testGroupInfoMultiAccessing() throws Exception { RSGroupInfoManager manager = RSGroupAdminEndpoint.getGroupInfoManager(); @@ -283,6 +240,24 @@ public class TestRSGroups extends TestRSGroupsBase { boolean preMoveServersAndTables = false; boolean postMoveServersAndTables = false; + void resetFlags() { + LOG.debug("calling resetFlags"); + preBalanceRSGroupCalled = false; + postBalanceRSGroupCalled = false; + preMoveServersCalled = false; + postMoveServersCalled = false; + preMoveTablesCalled = false; + postMoveTablesCalled = false; + preAddRSGroupCalled = false; + postAddRSGroupCalled = false; + preRemoveRSGroupCalled = false; + postRemoveRSGroupCalled = false; + preRemoveServersCalled = false; + postRemoveServersCalled = false; + preMoveServersAndTables = false; + postMoveServersAndTables = false; + } + @Override public void preMoveServersAndTables(final ObserverContext ctx, Set
servers, Set tables, String targetGroup) throws IOException { @@ -318,6 +293,7 @@ public class TestRSGroups extends TestRSGroupsBase { @Override public void preAddRSGroup(final ObserverContext ctx, String name) throws IOException { + LOG.debug("setting preAddRSGroupCalled"); preAddRSGroupCalled = true; } @Override @@ -338,6 +314,7 @@ public class TestRSGroups extends TestRSGroupsBase { @Override public void preMoveServers(final ObserverContext ctx, Set
servers, String targetGroup) throws IOException { + LOG.debug("setting preMoveServersCalled"); preMoveServersCalled = true; } diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups1.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups1.java new file mode 100644 index 00000000000..12a0b811f90 --- /dev/null +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups1.java @@ -0,0 +1,159 @@ +/** + * Copyright The Apache Software Foundation + * + * 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.rsgroup; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.NamespaceDescriptor; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/* + * The two tests in this class are separated from TestRSGroups + * so that the observer pre/post hook called checks are stable. + * There are some tests from TestRSGroupsBase which are empty since + * they would be run by TestRSGroups. + */ +@Category({MediumTests.class}) +public class TestRSGroups1 extends TestRSGroups { + protected static final Log LOG = LogFactory.getLog(TestRSGroups1.class); + + @Test + public void testNamespaceConstraint() throws Exception { + String nsName = tablePrefix+"_foo"; + String groupName = tablePrefix+"_foo"; + LOG.info("testNamespaceConstraint"); + rsGroupAdmin.addRSGroup(groupName); + assertTrue(observer.preAddRSGroupCalled); + assertTrue(observer.postAddRSGroupCalled); + + admin.createNamespace(NamespaceDescriptor.create(nsName) + .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, groupName) + .build()); + //test removing a referenced group + try { + rsGroupAdmin.removeRSGroup(groupName); + fail("Expected a constraint exception"); + } catch (IOException ex) { + } + //test modify group + //changing with the same name is fine + admin.modifyNamespace( + NamespaceDescriptor.create(nsName) + .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, groupName) + .build()); + String anotherGroup = tablePrefix+"_anotherGroup"; + rsGroupAdmin.addRSGroup(anotherGroup); + //test add non-existent group + admin.deleteNamespace(nsName); + rsGroupAdmin.removeRSGroup(groupName); + assertTrue(observer.preRemoveRSGroupCalled); + assertTrue(observer.postRemoveRSGroupCalled); + try { + admin.createNamespace(NamespaceDescriptor.create(nsName) + .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, "foo") + .build()); + fail("Expected a constraint exception"); + } catch (IOException ex) { + } + } + + @Test + public void testMoveServers() throws Exception { + super.testMoveServers(); + assertTrue(observer.preMoveServersCalled); + assertTrue(observer.postMoveServersCalled); + } + + @Ignore @Test + public void testBogusArgs() throws Exception { + } + @Ignore @Test + public void testCreateMultiRegion() throws IOException { + } + @Ignore @Test + public void testCreateAndDrop() throws Exception { + } + @Ignore @Test + public void testSimpleRegionServerMove() throws IOException, + InterruptedException { + } + @Ignore @Test + public void testTableMoveTruncateAndDrop() throws Exception { + } + @Ignore @Test + public void testGroupBalance() throws Exception { + } + @Ignore @Test + public void testRegionMove() throws Exception { + } + @Ignore @Test + public void testFailRemoveGroup() throws IOException, InterruptedException { + } + @Ignore @Test + public void testKillRS() throws Exception { + } + @Ignore @Test + public void testValidGroupNames() throws IOException { + } + @Ignore @Test + public void testMultiTableMove() throws Exception { + } + @Ignore @Test + public void testMoveServersAndTables() throws Exception { + } + @Ignore @Test + public void testDisabledTableMove() throws Exception { + } + @Ignore @Test + public void testClearDeadServers() throws Exception { + } + @Ignore @Test + public void testRemoveServers() throws Exception { + } + @Ignore @Test + public void testBasicStartUp() throws IOException { + } + @Ignore @Test + public void testNamespaceCreateAndAssign() throws Exception { + } + @Ignore @Test + public void testDefaultNamespaceCreateAndAssign() throws Exception { + } + @Ignore @Test + public void testGroupInfoMultiAccessing() throws Exception { + } + @Ignore @Test + public void testMisplacedRegions() throws Exception { + } + @Ignore @Test + public void testRSGroupBalancerSwitch() throws IOException { + } + @Ignore @Test + public void testCloneSnapshot() throws Exception { + } +}