Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3574D8CA for ; Thu, 20 Dec 2012 21:47:11 +0000 (UTC) Received: (qmail 32807 invoked by uid 500); 20 Dec 2012 21:47:11 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 32773 invoked by uid 500); 20 Dec 2012 21:47:11 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 32766 invoked by uid 99); 20 Dec 2012 21:47:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Dec 2012 21:47:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Dec 2012 21:47:10 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B68632388AA9; Thu, 20 Dec 2012 21:46:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1424718 - in /hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master: Mocking.java TestAssignmentManager.java Date: Thu, 20 Dec 2012 21:46:49 -0000 To: commits@hbase.apache.org From: enis@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121220214649.B68632388AA9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: enis Date: Thu Dec 20 21:46:49 2012 New Revision: 1424718 URL: http://svn.apache.org/viewvc?rev=1424718&view=rev Log: HBASE-7398 [0.94 UNIT TESTS] TestAssignmentManager fails frequently on CentOS 5 Added: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/Mocking.java Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java Added: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/Mocking.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/Mocking.java?rev=1424718&view=auto ============================================================================== --- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/Mocking.java (added) +++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/Mocking.java Thu Dec 20 21:46:49 2012 @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.master; + +import org.apache.hadoop.hbase.master.AssignmentManager.RegionState; + +/** + * Package scoped mocking utility. + */ +public class Mocking { + + static void waitForRegionPendingOpenInRIT(AssignmentManager am, String encodedName) + throws InterruptedException { + // We used to do a check like this: + //!Mocking.verifyRegionState(this.watcher, REGIONINFO, EventType.M_ZK_REGION_OFFLINE)) { + // There is a race condition with this: because we may do the transition to + // RS_ZK_REGION_OPENING before the RIT is internally updated. We need to wait for the + // RIT to be as we need it to be instead. This cannot happen in a real cluster as we + // update the RIT before sending the openRegion request. + + boolean wait = true; + while (wait) { + RegionState state = am.getRegionsInTransition().get(encodedName); + if (state != null && state.isPendingOpen()){ + wait = false; + } else { + Thread.sleep(1); + } + } + } +} Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java?rev=1424718&r1=1424717&r2=1424718&view=diff ============================================================================== --- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java (original) +++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java Thu Dec 20 21:46:49 2012 @@ -36,9 +36,9 @@ import org.apache.hadoop.hbase.HConstant import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HServerLoad; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.SmallTests; import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.catalog.CatalogTracker; import org.apache.hadoop.hbase.client.Get; @@ -61,12 +61,12 @@ import org.apache.hadoop.hbase.util.Thre import org.apache.hadoop.hbase.util.Writables; import org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper; import org.apache.hadoop.hbase.zookeeper.ZKAssign; +import org.apache.hadoop.hbase.zookeeper.ZKTable.TableState; import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; -import org.apache.hadoop.hbase.zookeeper.ZKTable.TableState; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Watcher; import org.apache.zookeeper.KeeperException.NodeExistsException; +import org.apache.zookeeper.Watcher; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -82,7 +82,7 @@ import com.google.protobuf.ServiceExcept /** * Test {@link AssignmentManager} */ -@Category(SmallTests.class) +@Category(MediumTests.class) public class TestAssignmentManager { private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); private static final ServerName SERVERNAME_A = @@ -162,7 +162,7 @@ public class TestAssignmentManager { /** * Test a balance going on at same time as a master failover - * + * * @throws IOException * @throws KeeperException * @throws InterruptedException @@ -184,10 +184,8 @@ public class TestAssignmentManager { int versionid = ZKAssign.transitionNodeClosed(this.watcher, REGIONINFO, SERVERNAME_A, -1); assertNotSame(versionid, -1); - while (!ZKAssign.verifyRegionState(this.watcher, REGIONINFO, - EventType.M_ZK_REGION_OFFLINE)) { - Threads.sleep(1); - } + Mocking.waitForRegionPendingOpenInRIT(am, REGIONINFO.getEncodedName()); + // Get current versionid else will fail on transition from OFFLINE to // OPENING below versionid = ZKAssign.getVersion(this.watcher, REGIONINFO); @@ -228,10 +226,8 @@ public class TestAssignmentManager { ZKAssign.transitionNodeClosed(this.watcher, REGIONINFO, SERVERNAME_A, -1); assertNotSame(versionid, -1); am.gate.set(false); - while (!ZKAssign.verifyRegionState(this.watcher, REGIONINFO, - EventType.M_ZK_REGION_OFFLINE)) { - Threads.sleep(1); - } + Mocking.waitForRegionPendingOpenInRIT(am, REGIONINFO.getEncodedName()); + // Get current versionid else will fail on transition from OFFLINE to // OPENING below versionid = ZKAssign.getVersion(this.watcher, REGIONINFO); @@ -271,10 +267,8 @@ public class TestAssignmentManager { int versionid = ZKAssign.transitionNodeClosed(this.watcher, REGIONINFO, SERVERNAME_A, -1); assertNotSame(versionid, -1); - while (!ZKAssign.verifyRegionState(this.watcher, REGIONINFO, - EventType.M_ZK_REGION_OFFLINE)) { - Threads.sleep(1); - } + Mocking.waitForRegionPendingOpenInRIT(am, REGIONINFO.getEncodedName()); + am.gate.set(false); // Get current versionid else will fail on transition from OFFLINE to // OPENING below @@ -313,10 +307,11 @@ public class TestAssignmentManager { * from one server to another mocking regionserver responding over zk. * @throws IOException * @throws KeeperException + * @throws InterruptedException */ - @Test + @Test(timeout = 10000) public void testBalance() - throws IOException, KeeperException { + throws IOException, KeeperException, InterruptedException { // Create and startup an executor. This is used by AssignmentManager // handling zk callbacks. ExecutorService executor = startupMasterExecutor("testBalanceExecutor"); @@ -350,11 +345,9 @@ public class TestAssignmentManager { // AM is going to notice above CLOSED and queue up a new assign. The // assign will go to open the region in the new location set by the // balancer. The zk node will be OFFLINE waiting for regionserver to - // transition it through OPENING, OPENED. Wait till we see the OFFLINE - // zk node before we proceed. - while (!ZKAssign.verifyRegionState(this.watcher, REGIONINFO, EventType.M_ZK_REGION_OFFLINE)) { - Threads.sleep(1); - } + // transition it through OPENING, OPENED. Wait till we see the RIT + // before we proceed. + Mocking.waitForRegionPendingOpenInRIT(am, REGIONINFO.getEncodedName()); // Get current versionid else will fail on transition from OFFLINE to OPENING below versionid = ZKAssign.getVersion(this.watcher, REGIONINFO); assertNotSame(-1, versionid); @@ -407,7 +400,7 @@ public class TestAssignmentManager { /** * To test closed region handler to remove rit and delete corresponding znode if region in pending - * close or closing while processing shutdown of a region server.(HBASE-5927). + * close or closing while processing shutdown of a region server.(HBASE-5927). * @throws KeeperException * @throws IOException */ @@ -417,7 +410,7 @@ public class TestAssignmentManager { testCaseWithPartiallyDisabledState(TableState.DISABLING); testCaseWithPartiallyDisabledState(TableState.DISABLED); } - + /** * To test if the split region is removed from RIT if the region was in SPLITTING state * but the RS has actually completed the splitting in META but went down. See HBASE-6070 @@ -451,7 +444,7 @@ public class TestAssignmentManager { am.regionsInTransition.put(REGIONINFO.getEncodedName(), new RegionState(REGIONINFO, State.SPLITTING, System.currentTimeMillis(), SERVERNAME_A)); am.getZKTable().setEnabledTable(REGIONINFO.getTableNameAsString()); - + RegionTransitionData data = new RegionTransitionData(EventType.RS_ZK_REGION_SPLITTING, REGIONINFO.getRegionName(), SERVERNAME_A); String node = ZKAssign.getNodeName(this.watcher, REGIONINFO.getEncodedName()); @@ -459,11 +452,11 @@ public class TestAssignmentManager { ZKUtil.createAndWatch(this.watcher, node, data.getBytes()); try { - + processServerShutdownHandler(ct, am, regionSplitDone); // check znode deleted or not. // In both cases the znode should be deleted. - + if(regionSplitDone){ assertTrue("Region state of region in SPLITTING should be removed from rit.", am.regionsInTransition.isEmpty()); @@ -506,7 +499,7 @@ public class TestAssignmentManager { } else { am.getZKTable().setDisabledTable(REGIONINFO.getTableNameAsString()); } - + RegionTransitionData data = new RegionTransitionData(EventType.M_ZK_REGION_CLOSING, REGIONINFO.getRegionName(), SERVERNAME_A); String node = ZKAssign.getNodeName(this.watcher, REGIONINFO.getEncodedName()); @@ -581,7 +574,7 @@ public class TestAssignmentManager { * @param hri Region to serialize into HRegionInfo * @return A mocked up Result that fakes a Get on a row in the * .META. table. - * @throws IOException + * @throws IOException */ private Result getMetaTableRowResult(final HRegionInfo hri, final ServerName sn) @@ -600,13 +593,13 @@ public class TestAssignmentManager { Bytes.toBytes(sn.getStartcode()))); return new Result(kvs); } - + /** * @param sn ServerName to use making startcode and server in meta * @param hri Region to serialize into HRegionInfo * @return A mocked up Result that fakes a Get on a row in the * .META. table. - * @throws IOException + * @throws IOException */ private Result getMetaTableRowResultAsSplitRegion(final HRegionInfo hri, final ServerName sn) throws IOException { @@ -668,12 +661,12 @@ public class TestAssignmentManager { am.shutdown(); } } - + /** * Tests the processDeadServersAndRegionsInTransition should not fail with NPE * when it failed to get the children. Let's abort the system in this * situation - * @throws ServiceException + * @throws ServiceException */ @Test(timeout = 5000) public void testProcessDeadServersAndRegionsInTransitionShouldNotFailWithNPE() @@ -713,8 +706,8 @@ public class TestAssignmentManager { * @param region region to be created as offline * @param serverName server event originates from * @return Version of znode created. - * @throws KeeperException - * @throws IOException + * @throws KeeperException + * @throws IOException */ // Copied from SplitTransaction rather than open the method over there in // the regionserver package. @@ -807,9 +800,9 @@ public class TestAssignmentManager { server, manager, ct, balancer, executor); return am; } - + /** - * TestCase verifies that the regionPlan is updated whenever a region fails to open + * TestCase verifies that the regionPlan is updated whenever a region fails to open * and the master tries to process RS_ZK_FAILED_OPEN state.(HBASE-5546). */ @Test @@ -857,17 +850,18 @@ public class TestAssignmentManager { assertNotSame("Same region plan should not come", regionPlan, newRegionPlan); assertTrue("Destnation servers should be different.", !(regionPlan.getDestination().equals( newRegionPlan.getDestination()))); + Mocking.waitForRegionPendingOpenInRIT(am, REGIONINFO.getEncodedName()); } finally { this.server.getConfiguration().setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, DefaultLoadBalancer.class, LoadBalancer.class); am.shutdown(); } } - + /** * Test verifies whether assignment is skipped for regions of tables in DISABLING state during * clean cluster startup. See HBASE-6281. - * + * * @throws KeeperException * @throws IOException * @throws Exception @@ -973,7 +967,7 @@ public class TestAssignmentManager { this.gate.set(true); return randomServerName; } - + @Override public Map> retainAssignment( Map regions, List servers) {