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 4320fea..b0b64cd 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 @@ -43,7 +43,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 +66,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 +122,7 @@ public class TestRSGroups extends TestRSGroupsBase { init = true; afterMethod(); } - + observer.resetFlags(); } @After @@ -149,7 +148,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 { @@ -217,46 +215,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(); final RSGroupInfo defaultGroup = manager.getRSGroup("default"); @@ -283,6 +241,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 +294,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 +315,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 0000000..c98ff34 --- /dev/null +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups1.java @@ -0,0 +1,90 @@ +/** + * 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.master.MasterCoprocessorHost; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@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); + MasterCoprocessorHost host = master.getMasterCoprocessorHost(); + CPMasterObserver obs = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName()); + if (!observer.preAddRSGroupCalled && !obs.preAddRSGroupCalled) { + LOG.debug("both preAddRSGroupCalled were false"); + } + 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); + } +}