Author: mbautin
Date: Fri Feb 17 02:53:20 2012
New Revision: 1245302

URL: http://svn.apache.org/viewvc?rev=1245302&view=rev
Log:
[jira] [HBASE-4758] [89-fb] Make test methods independent in 
TestMasterTransitions

Summary:
Currently TestMasterTransitions is flaky, and one way to hopefully make it more
stable is to create a separate MiniHBaseCluster for every test method, and get
rid of BeforeClass/AfterClass. So far I have successfully run
TestMasterTransitions a few times with the fix, while it was failing without
the fix.

TestMasterTransitions in trunk is a different story (most of the test is
commented out in the trunk) and is out of scope of this JIRA.

Test Plan: Run TestMasterTransitions

Reviewers: liyintang, kranganathan

Reviewed By: kranganathan

CC: kranganathan, tedyu

Differential Revision: https://reviews.facebook.net/D315

Modified:
    
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java

Modified: 
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java
URL: 
http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java?rev=1245302&r1=1245301&r2=1245302&view=diff
==============================================================================
--- 
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java
 (original)
+++ 
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java
 Fri Feb 17 02:53:20 2012
@@ -51,10 +51,9 @@ import org.apache.hadoop.hbase.regionser
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Threads;
 import org.apache.hadoop.hbase.util.Writables;
-import org.junit.AfterClass;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -63,18 +62,21 @@ import org.junit.Test;
  */
 public class TestMasterTransitions {
   private static final Log LOG = 
LogFactory.getLog(TestMasterTransitions.class);
-  private static final HBaseTestingUtility TEST_UTIL = new 
HBaseTestingUtility();
   private static final String TABLENAME = "master_transitions";
   private static final byte [][] FAMILIES = new byte [][] {Bytes.toBytes("a"),
     Bytes.toBytes("b"), Bytes.toBytes("c")};
+
   static final int SERVER_DURATION = 3 * 1000;
   static final int CLOSE_DURATION = 1 * 1000;
 
+  private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
   /**
    * Start up a mini cluster and put a small table of many empty regions into 
it.
    * @throws Exception
    */
-  @BeforeClass public static void beforeAllTests() throws Exception {
+  @Before
+  public void setUp() throws Exception {
     TEST_UTIL.getConfiguration().setBoolean("dfs.support.append", true);
     // Parcel out the regions, don't give them out in big lumps.  We've only
     // a few in this test.  Let a couple of cycles pass is more realistic and
@@ -90,16 +92,14 @@ public class TestMasterTransitions {
     int countOfRegions = TEST_UTIL.createMultiRegions(t, getTestFamily());
     TEST_UTIL.waitUntilAllRegionsAssigned(countOfRegions);
     addToEachStartKey(countOfRegions);
+    TEST_UTIL.ensureSomeRegionServersAvailable(2);
   }
 
-  @AfterClass public static void afterAllTests() throws IOException {
+  @After
+  public void tearDown() throws IOException {
     TEST_UTIL.shutdownMiniCluster();
   }
 
-  @Before public void setup() throws IOException {
-    TEST_UTIL.ensureSomeRegionServersAvailable(2);
-  }
-
   /**
    * Listener for regionserver events testing hbase-2428 (Infinite loop of
    * region closes if META region is offline).  In particular, listen
@@ -462,8 +462,7 @@ public class TestMasterTransitions {
    * @return Count of regions in meta table.
    * @throws IOException
    */
-  private static int countOfMetaRegions()
-  throws IOException {
+  private int countOfMetaRegions() throws IOException {
     HTable meta = new HTable(TEST_UTIL.getConfiguration(),
       HConstants.META_TABLE_NAME);
     int rows = 0;
@@ -487,7 +486,7 @@ public class TestMasterTransitions {
    * @return
    * @throws IOException
    */
-  private static int addToEachStartKey(final int expected) throws IOException {
+  private int addToEachStartKey(final int expected) throws IOException {
     HTable t = new HTable(TEST_UTIL.getConfiguration(), TABLENAME);
     HTable meta = new HTable(TEST_UTIL.getConfiguration(),
         HConstants.META_TABLE_NAME);
@@ -516,7 +515,7 @@ public class TestMasterTransitions {
    * @return Count of rows in TABLENAME
    * @throws IOException
    */
-  private static int count() throws IOException {
+  private int count() throws IOException {
     HTable t = new HTable(TEST_UTIL.getConfiguration(), TABLENAME);
     int rows = 0;
     Scan scan = new Scan();


Reply via email to