You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2010/09/01 01:51:50 UTC

svn commit: r991397 [13/15] - in /hbase/trunk: ./ bin/ conf/ src/main/java/org/apache/hadoop/hbase/ src/main/java/org/apache/hadoop/hbase/avro/ src/main/java/org/apache/hadoop/hbase/catalog/ src/main/java/org/apache/hadoop/hbase/client/ src/main/java/o...

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java Tue Aug 31 23:51:44 2010
@@ -59,7 +59,9 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.hbase.util.Threads;
 import org.apache.hadoop.hbase.util.Writables;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper;
+import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
+import org.apache.hadoop.hbase.zookeeper.ZKConfig;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.hadoop.hdfs.DFSClient;
 import org.apache.hadoop.hdfs.DistributedFileSystem;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
@@ -72,9 +74,9 @@ import org.apache.zookeeper.ZooKeeper;
 import com.google.common.base.Preconditions;
 
 /**
- * Facility for testing HBase. Added as tool to abet junit4 testing.  Replaces
+ * Facility for testing HBase. Replacement for
  * old HBaseTestCase and HBaseCluserTestCase functionality.
- * Create an instance and keep it around doing HBase testing.  This class is
+ * Create an instance and keep it around testing HBase.  This class is
  * meant to be your one-stop shop for anything you might need testing.  Manages
  * one cluster at a time only.  Depends on log4j being on classpath and
  * hbase-site.xml for logging and test-run configuration.  It does not set
@@ -93,13 +95,14 @@ public class HBaseTestingUtility {
 
   /**
    * System property key to get test directory value.
+   * Name is as it is because mini dfs has hard-codings to put test data here.
    */
   public static final String TEST_DIRECTORY_KEY = "test.build.data";
 
   /**
-   * Default parent direccounttory for test output.
+   * Default parent directory for test output.
    */
-  public static final String DEFAULT_TEST_DIRECTORY = "target/build/data";
+  public static final String DEFAULT_TEST_DIRECTORY = "target/test-data";
 
   public HBaseTestingUtility() {
     this(HBaseConfiguration.create());
@@ -120,6 +123,8 @@ public class HBaseTestingUtility {
    * @return Where to write test data on local filesystem; usually
    * {@link #DEFAULT_TEST_DIRECTORY}
    * @see #setupClusterTestBuildDir()
+   * @see #clusterTestBuildDir()
+   * @see #getTestFileSystem()
    */
   public static Path getTestDir() {
     return new Path(System.getProperty(TEST_DIRECTORY_KEY,
@@ -131,22 +136,26 @@ public class HBaseTestingUtility {
    * @return Path to a subdirectory named <code>subdirName</code> under
    * {@link #getTestDir()}.
    * @see #setupClusterTestBuildDir()
+   * @see #clusterTestBuildDir(String)
+   * @see #getTestFileSystem()
    */
   public static Path getTestDir(final String subdirName) {
     return new Path(getTestDir(), subdirName);
   }
 
   /**
-   * Home our cluster in a dir under target/test.  Give it a random name
+   * Home our cluster in a dir under {@link #DEFAULT_TEST_DIRECTORY}.  Give it a
+   * random name
    * so can have many concurrent clusters running if we need to.  Need to
-   * amend the test.build.data System property.  Its what minidfscluster bases
+   * amend the {@link #TEST_DIRECTORY_KEY} System property.  Its what
+   * minidfscluster bases
    * it data dir on.  Moding a System property is not the way to do concurrent
    * instances -- another instance could grab the temporary
    * value unintentionally -- but not anything can do about it at moment;
    * single instance only is how the minidfscluster works.
    * @return The calculated cluster test build directory.
    */
-  File setupClusterTestBuildDir() {
+  public File setupClusterTestBuildDir() {
     String randomStr = UUID.randomUUID().toString();
     String dirStr = getTestDir(randomStr).toString();
     File dir = new File(dirStr).getAbsoluteFile();
@@ -158,8 +167,8 @@ public class HBaseTestingUtility {
   /**
    * @throws IOException If a cluster -- zk, dfs, or hbase -- already running.
    */
-  void isRunningCluster() throws IOException {
-    if (this.clusterTestBuildDir == null) return;
+  void isRunningCluster(String passedBuildPath) throws IOException {
+    if (this.clusterTestBuildDir == null || passedBuildPath != null) return;
     throw new IOException("Cluster already running at " +
       this.clusterTestBuildDir);
   }
@@ -190,8 +199,11 @@ public class HBaseTestingUtility {
     //     base_dir = new File(System.getProperty("test.build.data", "build/test/data"), "dfs/");
     // Some tests also do this:
     //  System.getProperty("test.cache.data", "build/test/cache");
-    if (dir == null) this.clusterTestBuildDir = setupClusterTestBuildDir();
-    else this.clusterTestBuildDir = dir;
+    if (dir == null) {
+      this.clusterTestBuildDir = setupClusterTestBuildDir();
+    } else {
+      this.clusterTestBuildDir = dir;
+    }
     System.setProperty(TEST_DIRECTORY_KEY, this.clusterTestBuildDir.toString());
     System.setProperty("test.cache.data", this.clusterTestBuildDir.toString());
     this.dfsCluster = new MiniDFSCluster(0, this.conf, servers, true, true,
@@ -242,7 +254,10 @@ public class HBaseTestingUtility {
    * @see #startMiniZKCluster()
    */
   public void shutdownMiniZKCluster() throws IOException {
-    if (this.zkCluster != null) this.zkCluster.shutdown();
+    if (this.zkCluster != null) {
+      this.zkCluster.shutdown();
+      this.zkCluster = null;
+    }
   }
 
   /**
@@ -272,10 +287,15 @@ public class HBaseTestingUtility {
   throws Exception {
     LOG.info("Starting up minicluster");
     // If we already put up a cluster, fail.
-    isRunningCluster();
+    String testBuildPath = conf.get(TEST_DIRECTORY_KEY, null);
+    isRunningCluster(testBuildPath);
+    if(testBuildPath != null) {
+      LOG.info("Using passed path: " + testBuildPath);
+    }
     // Make a new random dir to home everything in.  Set it as system property.
     // minidfs reads home from system property.
-    this.clusterTestBuildDir = setupClusterTestBuildDir();
+    this.clusterTestBuildDir = testBuildPath == null?
+      setupClusterTestBuildDir() : new File(testBuildPath);
     System.setProperty(TEST_DIRECTORY_KEY, this.clusterTestBuildDir.getPath());
     // Bring up mini dfs cluster. This spews a bunch of warnings about missing
     // scheme. Complaints are 'Scheme is undefined for build/test/data/dfs/name1'.
@@ -302,12 +322,31 @@ public class HBaseTestingUtility {
     // Don't leave here till we've done a successful scan of the .META.
     HTable t = new HTable(this.conf, HConstants.META_TABLE_NAME);
     ResultScanner s = t.getScanner(new Scan());
-    while (s.next() != null) continue;
+    while (s.next() != null) {
+      continue;
+    }
     LOG.info("Minicluster is up");
     return this.hbaseCluster;
   }
 
   /**
+   * Starts the hbase cluster up again after shutting it down previously in a
+   * test.  Use this if you want to keep dfs/zk up and just stop/start hbase.
+   * @param servers number of region servers
+   * @throws IOException
+   */
+  public void restartHBaseCluster(int servers) throws IOException {
+    this.hbaseCluster = new MiniHBaseCluster(this.conf, servers);
+    // Don't leave here till we've done a successful scan of the .META.
+    HTable t = new HTable(this.conf, HConstants.META_TABLE_NAME);
+    ResultScanner s = t.getScanner(new Scan());
+    while (s.next() != null) {
+      continue;
+    }
+    LOG.info("HBase has been restarted");
+  }
+
+  /**
    * @return Current mini hbase cluster. Only has something in it after a call
    * to {@link #startMiniCluster()}.
    * @see #startMiniCluster()
@@ -339,6 +378,7 @@ public class HBaseTestingUtility {
           new Path(this.clusterTestBuildDir.toString()))) {
         LOG.warn("Failed delete of " + this.clusterTestBuildDir.toString());
       }
+      this.clusterTestBuildDir = null;
     }
     LOG.info("Minicluster is down");
   }
@@ -609,6 +649,7 @@ public class HBaseTestingUtility {
     // and end key. Adding the custom regions below adds those blindly,
     // including the new start region from empty to "bbb". lg
     List<byte[]> rows = getMetaTableRows(htd.getName());
+    List<HRegionInfo> newRegions = new ArrayList<HRegionInfo>(startKeys.length);
     // add custom ones
     int count = 0;
     for (int i = 0; i < startKeys.length; i++) {
@@ -620,6 +661,7 @@ public class HBaseTestingUtility {
         Writables.getBytes(hri));
       meta.put(put);
       LOG.info("createMultiRegions: inserted " + hri.toString());
+      newRegions.add(hri);
       count++;
     }
     // see comment above, remove "old" (or previous) single region
@@ -631,6 +673,10 @@ public class HBaseTestingUtility {
     // flush cache of regions
     HConnection conn = table.getConnection();
     conn.clearRegionCache();
+    // assign all the new regions
+    for(HRegionInfo hri : newRegions) {
+      hbaseCluster.getMaster().assignRegion(hri);
+    }
     return count;
   }
 
@@ -757,7 +803,7 @@ public class HBaseTestingUtility {
    */
   public void expireMasterSession() throws Exception {
     HMaster master = hbaseCluster.getMaster();
-    expireSession(master.getZooKeeperWrapper());
+    expireSession(master.getZooKeeper(), master);
   }
 
   /**
@@ -767,19 +813,16 @@ public class HBaseTestingUtility {
    */
   public void expireRegionServerSession(int index) throws Exception {
     HRegionServer rs = hbaseCluster.getRegionServer(index);
-    expireSession(rs.getZooKeeperWrapper());
+    expireSession(rs.getZooKeeper(), rs);
   }
 
-  public void expireSession(ZooKeeperWrapper nodeZK) throws Exception{
-    ZooKeeperWrapper zkw =
-        ZooKeeperWrapper.createInstance(conf,
-            ZooKeeperWrapper.class.getName());
-    zkw.registerListener(EmptyWatcher.instance);
-    String quorumServers = zkw.getQuorumServers();
+  public void expireSession(ZooKeeperWatcher nodeZK, Server server)
+  throws Exception {
+    String quorumServers = ZKConfig.getZKQuorumServersString(conf);
     int sessionTimeout = 5 * 1000; // 5 seconds
 
-    byte[] password = nodeZK.getSessionPassword();
-    long sessionID = nodeZK.getSessionID();
+    byte[] password = nodeZK.getZooKeeper().getSessionPasswd();
+    long sessionID = nodeZK.getZooKeeper().getSessionId();
 
     ZooKeeper zk = new ZooKeeper(quorumServers,
         sessionTimeout, EmptyWatcher.instance, sessionID, password);
@@ -805,9 +848,10 @@ public class HBaseTestingUtility {
    * Returns a HBaseAdmin instance.
    *
    * @return The HBaseAdmin instance.
-   * @throws MasterNotRunningException
+   * @throws IOException 
    */
-  public HBaseAdmin getHBaseAdmin() throws MasterNotRunningException {
+  public HBaseAdmin getHBaseAdmin()
+  throws IOException {
     if (hbaseAdmin == null) {
       hbaseAdmin = new HBaseAdmin(getConfiguration());
     }
@@ -832,7 +876,7 @@ public class HBaseTestingUtility {
    */
   public void closeRegion(byte[] regionName) throws IOException {
     HBaseAdmin admin = getHBaseAdmin();
-    admin.closeRegion(regionName, (Object[]) null);
+    admin.closeRegion(regionName, null);
   }
 
   /**
@@ -874,8 +918,34 @@ public class HBaseTestingUtility {
     return FileSystem.get(conf);
   }
 
-  public void cleanupTestDir() throws IOException {
-    getTestDir().getFileSystem(conf).delete(getTestDir(), true);
+  /**
+   * @return True if we removed the test dir
+   * @throws IOException
+   */
+  public boolean cleanupTestDir() throws IOException {
+    return deleteDir(getTestDir());
+  }
+
+  /**
+   * @param subdir Test subdir name.
+   * @return True if we removed the test dir
+   * @throws IOException
+   */
+  public boolean cleanupTestDir(final String subdir) throws IOException {
+    return deleteDir(getTestDir(subdir));
+  }
+
+  /**
+   * @param dir Directory to delete
+   * @return True if we deleted it.
+   * @throws IOException 
+   */
+  public boolean deleteDir(final Path dir) throws IOException {
+    FileSystem fs = getTestFileSystem();
+    if (fs.exists(dir)) {
+      return fs.delete(getTestDir(), true);
+    }
+    return false;
   }
 
   public void waitTableAvailable(byte[] table, long timeoutMillis)
@@ -1006,12 +1076,16 @@ public class HBaseTestingUtility {
       for (Result r = null; (r = s.next()) != null;) {
         byte [] b =
           r.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
-        if (b == null || b.length <= 0) break;
+        if (b == null || b.length <= 0) {
+          break;
+        }
         rows++;
       }
       s.close();
       // If I get to here and all rows have a Server, then all have been assigned.
-      if (rows == countOfRegions) break;
+      if (rows == countOfRegions) {
+        break;
+      }
       LOG.info("Found=" + rows);
       Threads.sleep(1000);
     }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java Tue Aug 31 23:51:44 2010
@@ -40,6 +40,7 @@ import org.apache.hadoop.hdfs.Distribute
 import org.apache.hadoop.io.MapWritable;
 import org.apache.hadoop.security.UnixUserGroupInformation;
 import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.zookeeper.KeeperException;
 
 /**
  * This class creates a single process HBase cluster.
@@ -82,7 +83,7 @@ public class MiniHBaseCluster {
       new ConcurrentHashMap<HServerInfo, IOException>();
 
     public MiniHBaseClusterMaster(final Configuration conf)
-    throws IOException {
+    throws IOException, KeeperException, InterruptedException {
       super(conf);
     }
 
@@ -151,7 +152,7 @@ public class MiniHBaseCluster {
     private Thread shutdownThread = null;
 
     public MiniHBaseClusterRegionServer(Configuration conf)
-        throws IOException {
+        throws IOException, InterruptedException {
       super(setDifferentUser(conf));
     }
 
@@ -181,8 +182,8 @@ public class MiniHBaseCluster {
     }
 
     @Override
-    protected void init(MapWritable c) throws IOException {
-      super.init(c);
+    protected void handleReportForDutyResponse(MapWritable c) throws IOException {
+      super.handleReportForDutyResponse(c);
       // Run this thread to shutdown our filesystem on way out.
       this.shutdownThread = new SingleFileSystemShutdownThread(getFileSystem());
     }
@@ -303,7 +304,7 @@ public class MiniHBaseCluster {
     JVMClusterUtil.RegionServerThread server =
       hbaseCluster.getRegionServers().get(serverNumber);
     LOG.info("Stopping " + server.toString());
-    server.getRegionServer().stop();
+    server.getRegionServer().stop("Stopping rs " + serverNumber);
     return server;
   }
 
@@ -342,7 +343,7 @@ public class MiniHBaseCluster {
   public void flushcache() throws IOException {
     for (JVMClusterUtil.RegionServerThread t:
         this.hbaseCluster.getRegionServers()) {
-      for(HRegion r: t.getRegionServer().getOnlineRegions()) {
+      for(HRegion r: t.getRegionServer().getOnlineRegionsLocalContext()) {
         r.flushcache();
       }
     }
@@ -355,7 +356,7 @@ public class MiniHBaseCluster {
   public void flushcache(byte [] tableName) throws IOException {
     for (JVMClusterUtil.RegionServerThread t:
         this.hbaseCluster.getRegionServers()) {
-      for(HRegion r: t.getRegionServer().getOnlineRegions()) {
+      for(HRegion r: t.getRegionServer().getOnlineRegionsLocalContext()) {
         if(Bytes.equals(r.getTableDesc().getName(), tableName)) {
           r.flushcache();
         }
@@ -390,7 +391,7 @@ public class MiniHBaseCluster {
     List<HRegion> ret = new ArrayList<HRegion>();
     for (JVMClusterUtil.RegionServerThread rst : getRegionServerThreads()) {
       HRegionServer hrs = rst.getRegionServer();
-      for (HRegion region : hrs.getOnlineRegions()) {
+      for (HRegion region : hrs.getOnlineRegionsLocalContext()) {
         if (Bytes.equals(region.getTableDesc().getName(), tableName)) {
           ret.add(region);
         }
@@ -481,4 +482,4 @@ public class MiniHBaseCluster {
   throws IOException {
     ((MiniHBaseClusterMaster)getMaster()).addMessage(hrs.getHServerInfo(), msg);
   }
-}
+}
\ No newline at end of file

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java Tue Aug 31 23:51:44 2010
@@ -62,6 +62,7 @@ import org.apache.hadoop.hbase.util.FSUt
 import org.apache.hadoop.hbase.util.Hash;
 import org.apache.hadoop.hbase.util.MurmurHash;
 import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.NullWritable;

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestFullLogReconstruction.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestFullLogReconstruction.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestFullLogReconstruction.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestFullLogReconstruction.java Tue Aug 31 23:51:44 2010
@@ -20,16 +20,19 @@
 
 package org.apache.hadoop.hbase;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import static org.junit.Assert.assertEquals;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.*;
-import static org.junit.Assert.assertEquals;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 public class TestFullLogReconstruction {
 

Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java?rev=991397&view=auto
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java (added)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java Tue Aug 31 23:51:44 2010
@@ -0,0 +1,105 @@
+/**
+ * Copyright 2010 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;
+
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test our testing utility class
+ */
+public class TestHBaseTestingUtility {
+  private final Log LOG = LogFactory.getLog(this.getClass());
+
+  private HBaseTestingUtility hbt;
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    this.hbt = new HBaseTestingUtility();
+    this.hbt.cleanupTestDir();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+  }
+
+  @Test public void testMiniCluster() throws Exception {
+    MiniHBaseCluster cluster = this.hbt.startMiniCluster();
+    try {
+      assertEquals(1, cluster.getLiveRegionServerThreads().size());
+    } finally {
+      cluster.shutdown();
+    }
+  }
+
+  @Test public void testMiniDFSCluster() throws Exception {
+    MiniDFSCluster cluster = this.hbt.startMiniDFSCluster(1);
+    FileSystem dfs = cluster.getFileSystem();
+    Path dir = new Path("dir");
+    Path qualifiedDir = dfs.makeQualified(dir);
+    LOG.info("dir=" + dir + ", qualifiedDir=" + qualifiedDir);
+    assertFalse(dfs.exists(qualifiedDir));
+    assertTrue(dfs.mkdirs(qualifiedDir));
+    assertTrue(dfs.delete(qualifiedDir, true));
+    try {
+    } finally {
+      cluster.shutdown();
+    }
+  }
+
+  @Test public void testSetupClusterTestBuildDir() {
+    File testdir = this.hbt.setupClusterTestBuildDir();
+    LOG.info("uuid-subdir=" + testdir);
+    assertFalse(testdir.exists());
+    assertTrue(testdir.mkdirs());
+    assertTrue(testdir.exists());
+  }
+
+  @Test public void testTestDir() throws IOException {
+    Path testdir = HBaseTestingUtility.getTestDir();
+    LOG.info("testdir=" + testdir);
+    FileSystem fs = this.hbt.getTestFileSystem();
+    assertTrue(!fs.exists(testdir));
+    assertTrue(fs.mkdirs(testdir));
+    assertTrue(this.hbt.cleanupTestDir());
+  }
+}
\ No newline at end of file

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHMsg.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHMsg.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHMsg.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestHMsg.java Tue Aug 31 23:51:44 2010
@@ -35,7 +35,7 @@ public class TestHMsg extends TestCase {
     final int size = 10;
     for (int i = 0; i < size; i++) {
       byte [] b = Bytes.toBytes(i);
-      hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+      hmsg = new HMsg(HMsg.Type.STOP_REGIONSERVER,
         new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), b, b));
       msgs.add(hmsg);
     }
@@ -45,12 +45,12 @@ public class TestHMsg extends TestCase {
     msgs.remove(index);
     assertEquals(size - 1, msgs.size());
     byte [] other = Bytes.toBytes("other");
-    hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+    hmsg = new HMsg(HMsg.Type.STOP_REGIONSERVER,
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), other, other));
     assertEquals(-1, msgs.indexOf(hmsg));
     // Assert that two HMsgs are same if same content.
     byte [] b = Bytes.toBytes(1);
-    hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+    hmsg = new HMsg(HMsg.Type.STOP_REGIONSERVER,
      new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), b, b));
     assertNotSame(-1, msgs.indexOf(hmsg));
   }
@@ -64,7 +64,7 @@ public class TestHMsg extends TestCase {
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("parent")),
       parentbytes, parentbytes);
     // Assert simple HMsg serializes
-    HMsg hmsg = new HMsg(HMsg.Type.MSG_REGION_CLOSE, parent);
+    HMsg hmsg = new HMsg(HMsg.Type.STOP_REGIONSERVER, parent);
     byte [] bytes = Writables.getBytes(hmsg);
     HMsg close = (HMsg)Writables.getWritable(bytes, new HMsg());
     assertTrue(close.equals(hmsg));
@@ -73,8 +73,8 @@ public class TestHMsg extends TestCase {
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("a")), abytes, abytes);
     HRegionInfo daughterb =
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("b")), bbytes, bbytes);
-    HMsg splithmsg = new HMsg(HMsg.Type.MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS,
-      parent, daughtera, daughterb, Bytes.toBytes("split"));
+    HMsg splithmsg = new HMsg(HMsg.Type.REGION_SPLIT,
+      parent, daughtera, daughterb, Bytes.toBytes("REGION_SPLIT"));
     bytes = Writables.getBytes(splithmsg);
     hmsg = (HMsg)Writables.getWritable(bytes, new HMsg());
     assertTrue(splithmsg.equals(hmsg));

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java Tue Aug 31 23:51:44 2010
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2009 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class TestMultiParallelPut extends MultiRegionTable {
+  final Log LOG = LogFactory.getLog(getClass());
+  private static final byte[] VALUE = Bytes.toBytes("value");
+  private static final byte[] QUALIFIER = Bytes.toBytes("qual");
+  private static final String FAMILY = "family";
+  private static final String TEST_TABLE = "test_table";
+  private static final byte[] BYTES_FAMILY = Bytes.toBytes(FAMILY);
+
+
+  public TestMultiParallelPut() {
+    super(2, FAMILY);
+    desc = new HTableDescriptor(TEST_TABLE);
+    desc.addFamily(new HColumnDescriptor(FAMILY));
+    makeKeys();
+  }
+
+  private void makeKeys() {
+    for (byte [] k : KEYS) {
+      byte [] cp = new byte[k.length+1];
+      System.arraycopy(k, 0, cp, 0, k.length);
+      cp[k.length] = 1;
+      keys.add(cp);
+    }
+  }
+
+  List<byte[]> keys = new ArrayList<byte[]>();
+
+  public void testParallelPut() throws Exception {
+    LOG.info("Starting testParallelPut");
+    doATest(false);
+  }
+
+  public void testParallelPutWithRSAbort() throws Exception {
+    LOG.info("Starting testParallelPutWithRSAbort");
+    doATest(true);
+  }
+
+  public void doATest(boolean doAbort) throws Exception {
+    conf.setInt("hbase.client.retries.number", 10);
+    HTable table = new HTable(conf, TEST_TABLE);
+    table.setAutoFlush(false);
+    table.setWriteBufferSize(10 * 1024 * 1024);
+    for ( byte [] k : keys ) {
+      Put put = new Put(k);
+      put.add(BYTES_FAMILY, QUALIFIER, VALUE);
+      table.put(put);
+    }
+    table.flushCommits();
+
+    if (doAbort) {
+      LOG.info("Aborting...");
+      cluster.abortRegionServer(0);
+      // try putting more keys after the abort.
+      for ( byte [] k : keys ) {
+        Put put = new Put(k);
+        put.add(BYTES_FAMILY, QUALIFIER, VALUE);
+        table.put(put);
+      }
+      table.flushCommits();
+    }
+
+    for (byte [] k : keys ) {
+      Get get = new Get(k);
+      get.addColumn(BYTES_FAMILY, QUALIFIER);
+      Result r = table.get(get);
+      assertTrue(r.containsColumn(BYTES_FAMILY, QUALIFIER));
+      assertEquals(0,
+          Bytes.compareTo(VALUE,
+              r.getValue(BYTES_FAMILY, QUALIFIER)));
+    }
+
+    HBaseAdmin admin = new HBaseAdmin(conf);
+    ClusterStatus cs = admin.getClusterStatus();
+    int expectedServerCount = 2;
+    if (doAbort)  expectedServerCount = 1;
+    LOG.info("Clusterstatus servers count " + cs.getServers());
+    assertEquals(expectedServerCount, cs.getServers());
+    for ( HServerInfo info : cs.getServerInfo()) {
+      LOG.info("Info from clusterstatus=" + info);
+      assertTrue(info.getLoad().getNumberOfRegions() > 8);
+    }
+  }
+}
\ No newline at end of file

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java Tue Aug 31 23:51:44 2010
@@ -33,6 +33,7 @@ import org.apache.hadoop.hbase.regionser
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.JVMClusterUtil;
+import org.apache.hadoop.hbase.util.Threads;
 
 /**
  * Test whether region rebalancing works. (HBASE-71)
@@ -103,31 +104,40 @@ public class TestRegionRebalancing exten
 
     LOG.debug("Adding 2nd region server.");
     // add a region server - total of 2
-    cluster.startRegionServer();
+    LOG.info("Started=" +
+      cluster.startRegionServer().getRegionServer().getServerName());
+    cluster.getMaster().balance();
     assertRegionsAreBalanced();
 
     // add a region server - total of 3
     LOG.debug("Adding 3rd region server.");
-    cluster.startRegionServer();
+    LOG.info("Started=" +
+      cluster.startRegionServer().getRegionServer().getServerName());
+    cluster.getMaster().balance();
     assertRegionsAreBalanced();
 
     // kill a region server - total of 2
     LOG.debug("Killing the 3rd region server.");
-    cluster.stopRegionServer(2, false);
+    LOG.info("Stopped=" + cluster.stopRegionServer(2, false));
     cluster.waitOnRegionServer(2);
+    cluster.getMaster().balance();
     assertRegionsAreBalanced();
 
     // start two more region servers - total of 4
     LOG.debug("Adding 3rd region server");
-    cluster.startRegionServer();
+    LOG.info("Started=" +
+      cluster.startRegionServer().getRegionServer().getServerName());
     LOG.debug("Adding 4th region server");
-    cluster.startRegionServer();
+    LOG.info("Started=" +
+      cluster.startRegionServer().getRegionServer().getServerName());
+    cluster.getMaster().balance();
     assertRegionsAreBalanced();
 
     for (int i = 0; i < 6; i++){
       LOG.debug("Adding " + (i + 5) + "th region server");
       cluster.startRegionServer();
     }
+    cluster.getMaster().balance();
     assertRegionsAreBalanced();
   }
 
@@ -157,7 +167,7 @@ public class TestRegionRebalancing exten
 
       int regionCount = getRegionCount();
       List<HRegionServer> servers = getOnlineRegionServers();
-      double avg = cluster.getMaster().getAverageLoad();
+      double avg = cluster.getMaster().getServerManager().getAverageLoad();
       int avgLoadPlusSlop = (int)Math.ceil(avg * (1 + slop));
       int avgLoadMinusSlop = (int)Math.floor(avg * (1 - slop)) - 1;
       LOG.debug("There are " + servers.size() + " servers and " + regionCount
@@ -166,10 +176,10 @@ public class TestRegionRebalancing exten
 
       for (HRegionServer server : servers) {
         int serverLoad = server.getOnlineRegions().size();
-        LOG.debug(server.hashCode() + " Avg: " + avg + " actual: " + serverLoad);
+        LOG.debug(server.getServerName() + " Avg: " + avg + " actual: " + serverLoad);
         if (!(avg > 2.0 && serverLoad <= avgLoadPlusSlop
             && serverLoad >= avgLoadMinusSlop)) {
-          LOG.debug(server.hashCode() + " Isn't balanced!!! Avg: " + avg +
+          LOG.debug(server.getServerName() + " Isn't balanced!!! Avg: " + avg +
               " actual: " + serverLoad + " slop: " + slop);
           success = false;
         }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestSerialization.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestSerialization.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestSerialization.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestSerialization.java Tue Aug 31 23:51:44 2010
@@ -20,6 +20,8 @@
 package org.apache.hadoop.hbase;
 
 
+import static org.junit.Assert.*;
+
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.util.ArrayList;
@@ -44,23 +46,14 @@ import org.apache.hadoop.hbase.io.TimeRa
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Writables;
 import org.apache.hadoop.io.DataInputBuffer;
+import org.junit.Test;
 
 /**
  * Test HBase Writables serializations
  */
-public class TestSerialization extends HBaseTestCase {
-
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();
-  }
+public class TestSerialization {
 
-  @Override
-  protected void tearDown() throws Exception {
-    super.tearDown();
-  }
-
-  public void testCompareFilter() throws Exception {
+  @Test public void testCompareFilter() throws Exception {
     Filter f = new RowFilter(CompareOp.EQUAL,
       new BinaryComparator(Bytes.toBytes("testRowOne-2")));
     byte [] bytes = Writables.getBytes(f);
@@ -68,10 +61,11 @@ public class TestSerialization extends H
     assertNotNull(ff);
   }
 
-  public void testKeyValue() throws Exception {
-    byte [] row = Bytes.toBytes(getName());
-    byte [] family = Bytes.toBytes(getName());
-    byte [] qualifier = Bytes.toBytes(getName());
+  @Test public void testKeyValue() throws Exception {
+    final String name = "testKeyValue";
+    byte [] row = Bytes.toBytes(name);
+    byte [] family = Bytes.toBytes(name);
+    byte [] qualifier = Bytes.toBytes(name);
     KeyValue original = new KeyValue(row, family, qualifier);
     byte [] bytes = Writables.getBytes(original);
     KeyValue newone = (KeyValue)Writables.getWritable(bytes, new KeyValue());
@@ -79,7 +73,7 @@ public class TestSerialization extends H
   }
 
   @SuppressWarnings("unchecked")
-  public void testHbaseMapWritable() throws Exception {
+  @Test public void testHbaseMapWritable() throws Exception {
     HbaseMapWritable<byte [], byte []> hmw =
       new HbaseMapWritable<byte[], byte[]>();
     hmw.put("key".getBytes(), "value".getBytes());
@@ -90,13 +84,14 @@ public class TestSerialization extends H
     assertTrue(Bytes.equals("value".getBytes(), hmw.get("key".getBytes())));
   }
 
-  public void testHMsg() throws Exception {
-    HMsg  m = new HMsg(HMsg.Type.MSG_REGIONSERVER_QUIESCE);
+  @Test public void testHMsg() throws Exception {
+    final String name = "testHMsg";
+    HMsg  m = new HMsg(HMsg.Type.STOP_REGIONSERVER);
     byte [] mb = Writables.getBytes(m);
     HMsg deserializedHMsg = (HMsg)Writables.getWritable(mb, new HMsg());
     assertTrue(m.equals(deserializedHMsg));
-    m = new HMsg(HMsg.Type.MSG_REGIONSERVER_QUIESCE,
-      new HRegionInfo(new HTableDescriptor(getName()),
+    m = new HMsg(HMsg.Type.STOP_REGIONSERVER,
+      new HRegionInfo(new HTableDescriptor(name),
         HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY),
         "Some message".getBytes());
     mb = Writables.getBytes(m);
@@ -104,8 +99,9 @@ public class TestSerialization extends H
     assertTrue(m.equals(deserializedHMsg));
   }
 
-  public void testTableDescriptor() throws Exception {
-    HTableDescriptor htd = createTableDescriptor(getName());
+  @Test public void testTableDescriptor() throws Exception {
+    final String name = "testTableDescriptor";
+    HTableDescriptor htd = createTableDescriptor(name);
     byte [] mb = Writables.getBytes(htd);
     HTableDescriptor deserializedHtd =
       (HTableDescriptor)Writables.getWritable(mb, new HTableDescriptor());
@@ -116,8 +112,9 @@ public class TestSerialization extends H
    * Test RegionInfo serialization
    * @throws Exception
    */
-  public void testRegionInfo() throws Exception {
-    HTableDescriptor htd = new HTableDescriptor(getName());
+  @Test public void testRegionInfo() throws Exception {
+    final String name = "testRegionInfo";
+    HTableDescriptor htd = new HTableDescriptor(name);
     String [] families = new String [] {"info", "anchor"};
     for (int i = 0; i < families.length; i++) {
       htd.addFamily(new HColumnDescriptor(families[i]));
@@ -136,7 +133,7 @@ public class TestSerialization extends H
    * Test ServerInfo serialization
    * @throws Exception
    */
-  public void testServerInfo() throws Exception {
+  @Test public void testServerInfo() throws Exception {
     HServerInfo hsi = new HServerInfo(new HServerAddress("0.0.0.0:123"), -1,
       1245, "default name");
     byte [] b = Writables.getBytes(hsi);
@@ -145,7 +142,7 @@ public class TestSerialization extends H
     assertTrue(hsi.equals(deserializedHsi));
   }
 
-  public void testPut() throws Exception{
+  @Test public void testPut() throws Exception{
     byte[] row = "row".getBytes();
     byte[] fam = "fam".getBytes();
     byte[] qf1 = "qf1".getBytes();
@@ -193,7 +190,7 @@ public class TestSerialization extends H
   }
 
 
-  public void testPut2() throws Exception{
+  @Test public void testPut2() throws Exception{
     byte[] row = "testAbort,,1243116656250".getBytes();
     byte[] fam = "historian".getBytes();
     byte[] qf1 = "creation".getBytes();
@@ -221,7 +218,7 @@ public class TestSerialization extends H
   }
 
 
-  public void testDelete() throws Exception{
+  @Test public void testDelete() throws Exception{
     byte[] row = "row".getBytes();
     byte[] fam = "fam".getBytes();
     byte[] qf1 = "qf1".getBytes();
@@ -248,7 +245,7 @@ public class TestSerialization extends H
     }
   }
 
-  public void testGet() throws Exception{
+  @Test public void testGet() throws Exception{
     byte[] row = "row".getBytes();
     byte[] fam = "fam".getBytes();
     byte[] qf1 = "qf1".getBytes();
@@ -289,7 +286,8 @@ public class TestSerialization extends H
   }
 
 
-  public void testScan() throws Exception{
+  @Test public void testScan() throws Exception {
+    
     byte[] startRow = "startRow".getBytes();
     byte[] stopRow  = "stopRow".getBytes();
     byte[] fam = "fam".getBytes();
@@ -323,7 +321,8 @@ public class TestSerialization extends H
 
       // Test filters are serialized properly.
       scan = new Scan(startRow);
-      byte [] prefix = Bytes.toBytes(getName());
+      final String name = "testScan";
+      byte [] prefix = Bytes.toBytes(name);
       scan.setFilter(new PrefixFilter(prefix));
       sb = Writables.getBytes(scan);
       desScan = (Scan)Writables.getWritable(sb, new Scan());
@@ -338,7 +337,7 @@ public class TestSerialization extends H
     assertEquals(tr.getMin(), desTr.getMin());
   }
 
-  public void testResultEmpty() throws Exception {
+  @Test public void testResultEmpty() throws Exception {
     List<KeyValue> keys = new ArrayList<KeyValue>();
     Result r = new Result(keys);
     assertTrue(r.isEmpty());
@@ -348,7 +347,7 @@ public class TestSerialization extends H
   }
 
 
-  public void testResult() throws Exception {
+  @Test public void testResult() throws Exception {
     byte [] rowA = Bytes.toBytes("rowA");
     byte [] famA = Bytes.toBytes("famA");
     byte [] qfA = Bytes.toBytes("qfA");
@@ -380,7 +379,7 @@ public class TestSerialization extends H
     assertEquals(r.size(), deserialized.size());
   }
 
-  public void testResultDynamicBuild() throws Exception {
+  @Test public void testResultDynamicBuild() throws Exception {
     byte [] rowA = Bytes.toBytes("rowA");
     byte [] famA = Bytes.toBytes("famA");
     byte [] qfA = Bytes.toBytes("qfA");
@@ -421,7 +420,7 @@ public class TestSerialization extends H
 
   }
 
-  public void testResultArray() throws Exception {
+  @Test public void testResultArray() throws Exception {
     byte [] rowA = Bytes.toBytes("rowA");
     byte [] famA = Bytes.toBytes("famA");
     byte [] qfA = Bytes.toBytes("qfA");
@@ -470,7 +469,7 @@ public class TestSerialization extends H
 
   }
 
-  public void testResultArrayEmpty() throws Exception {
+  @Test public void testResultArrayEmpty() throws Exception {
     List<KeyValue> keys = new ArrayList<KeyValue>();
     Result r = new Result(keys);
     Result [] results = new Result [] {r};
@@ -512,7 +511,7 @@ public class TestSerialization extends H
 
   }
 
-  public void testTimeRange(String[] args) throws Exception{
+  @Test public void testTimeRange() throws Exception{
     TimeRange tr = new TimeRange(0,5);
     byte [] mb = Writables.getBytes(tr);
     TimeRange deserializedTr =
@@ -523,8 +522,9 @@ public class TestSerialization extends H
 
   }
 
-  public void testKeyValue2() throws Exception {
-    byte[] row = getName().getBytes();
+  @Test public void testKeyValue2() throws Exception {
+    final String name = "testKeyValue2";
+    byte[] row = name.getBytes();
     byte[] fam = "fam".getBytes();
     byte[] qf = "qf".getBytes();
     long ts = System.currentTimeMillis();
@@ -539,4 +539,48 @@ public class TestSerialization extends H
     assertEquals(kv.getOffset(), deserializedKv.getOffset());
     assertEquals(kv.getLength(), deserializedKv.getLength());
   }
+
+  protected static final int MAXVERSIONS = 3;
+  protected final static byte [] fam1 = Bytes.toBytes("colfamily1");
+  protected final static byte [] fam2 = Bytes.toBytes("colfamily2");
+  protected final static byte [] fam3 = Bytes.toBytes("colfamily3");
+  protected static final byte [][] COLUMNS = {fam1, fam2, fam3};
+
+  /**
+   * Create a table of name <code>name</code> with {@link COLUMNS} for
+   * families.
+   * @param name Name to give table.
+   * @return Column descriptor.
+   */
+  protected HTableDescriptor createTableDescriptor(final String name) {
+    return createTableDescriptor(name, MAXVERSIONS);
+  }
+
+  /**
+   * Create a table of name <code>name</code> with {@link COLUMNS} for
+   * families.
+   * @param name Name to give table.
+   * @param versions How many versions to allow per column.
+   * @return Column descriptor.
+   */
+  protected HTableDescriptor createTableDescriptor(final String name,
+      final int versions) {
+    HTableDescriptor htd = new HTableDescriptor(name);
+    htd.addFamily(new HColumnDescriptor(fam1, versions,
+      HColumnDescriptor.DEFAULT_COMPRESSION, false, false,
+      Integer.MAX_VALUE, HConstants.FOREVER,
+      HColumnDescriptor.DEFAULT_BLOOMFILTER,
+      HConstants.REPLICATION_SCOPE_LOCAL));
+    htd.addFamily(new HColumnDescriptor(fam2, versions,
+        HColumnDescriptor.DEFAULT_COMPRESSION, false, false,
+        Integer.MAX_VALUE, HConstants.FOREVER,
+        HColumnDescriptor.DEFAULT_BLOOMFILTER,
+        HConstants.REPLICATION_SCOPE_LOCAL));
+    htd.addFamily(new HColumnDescriptor(fam3, versions,
+        HColumnDescriptor.DEFAULT_COMPRESSION, false, false,
+        Integer.MAX_VALUE,  HConstants.FOREVER,
+        HColumnDescriptor.DEFAULT_BLOOMFILTER,
+        HConstants.REPLICATION_SCOPE_LOCAL));
+    return htd;
+  }
 }
\ No newline at end of file

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java Tue Aug 31 23:51:44 2010
@@ -19,6 +19,13 @@
  */
 package org.apache.hadoop.hbase;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+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.conf.Configuration;
@@ -29,22 +36,16 @@ import org.apache.hadoop.hbase.client.HC
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper;
+import org.apache.hadoop.hbase.zookeeper.ZKConfig;
+import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
-import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.io.IOException;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
 public class TestZooKeeper {
   private final Log LOG = LogFactory.getLog(this.getClass());
 
@@ -91,15 +92,12 @@ public class TestZooKeeper {
       throws IOException, InterruptedException {
     new HTable(conf, HConstants.META_TABLE_NAME);
 
-    ZooKeeperWrapper zkw =
-        ZooKeeperWrapper.createInstance(conf, TestZooKeeper.class.getName());
-    zkw.registerListener(EmptyWatcher.instance);
-    String quorumServers = zkw.getQuorumServers();
+    String quorumServers = ZKConfig.getZKQuorumServersString(conf);
     int sessionTimeout = 5 * 1000; // 5 seconds
     HConnection connection = HConnectionManager.getConnection(conf);
-    ZooKeeperWrapper connectionZK = connection.getZooKeeperWrapper();
-    long sessionID = connectionZK.getSessionID();
-    byte[] password = connectionZK.getSessionPassword();
+    ZooKeeperWatcher connectionZK = connection.getZooKeeperWatcher();
+    long sessionID = connectionZK.getZooKeeper().getSessionId();
+    byte[] password = connectionZK.getZooKeeper().getSessionPasswd();
 
     ZooKeeper zk = new ZooKeeper(quorumServers, sessionTimeout,
         EmptyWatcher.instance, sessionID, password);
@@ -110,15 +108,18 @@ public class TestZooKeeper {
     System.err.println("ZooKeeper should have timed out");
     connection.relocateRegion(HConstants.ROOT_TABLE_NAME, HConstants.EMPTY_BYTE_ARRAY);
   }
+  
   @Test
-  public void testRegionServerSessionExpired() throws Exception{
+  public void testRegionServerSessionExpired() throws Exception {
     LOG.info("Starting testRegionServerSessionExpired");
     new HTable(conf, HConstants.META_TABLE_NAME);
-    TEST_UTIL.expireRegionServerSession(0);
+    int metaIndex = TEST_UTIL.getMiniHBaseCluster().getServerWithMeta();
+    TEST_UTIL.expireRegionServerSession(metaIndex);
     testSanity();
   }
-  @Test
-  public void testMasterSessionExpired() throws Exception {
+
+  //@Test
+  public void disabledTestMasterSessionExpired() throws Exception {
     LOG.info("Starting testMasterSessionExpired");
     new HTable(conf, HConstants.META_TABLE_NAME);
     TEST_UTIL.expireMasterSession();
@@ -133,13 +134,12 @@ public class TestZooKeeper {
 
     HBaseAdmin admin = new HBaseAdmin(conf);
     String tableName = "test"+System.currentTimeMillis();
-    HTableDescriptor desc =
-        new HTableDescriptor(tableName);
+    HTableDescriptor desc = new HTableDescriptor(tableName);
     HColumnDescriptor family = new HColumnDescriptor("fam");
     desc.addFamily(family);
     admin.createTable(desc);
 
-    HTable table = new HTable(tableName);
+    HTable table = new HTable(conf, tableName);
     Put put = new Put(Bytes.toBytes("testrow"));
     put.add(Bytes.toBytes("fam"),
         Bytes.toBytes("col"), Bytes.toBytes("testdata"));
@@ -160,12 +160,11 @@ public class TestZooKeeper {
       ipMeta.exists(new Get(HConstants.LAST_ROW));
 
       // make sure they aren't the same
-      assertFalse(HConnectionManager.getClientZooKeeperWatcher(conf)
-          .getZooKeeperWrapper() == HConnectionManager.getClientZooKeeperWatcher(
-          otherConf).getZooKeeperWrapper());
+      assertFalse(HConnectionManager.getConnection(conf).getZooKeeperWatcher()
+          == HConnectionManager.getConnection(otherConf).getZooKeeperWatcher());
       assertFalse(HConnectionManager.getConnection(conf)
-          .getZooKeeperWrapper().getQuorumServers().equals(HConnectionManager
-          .getConnection(otherConf).getZooKeeperWrapper().getQuorumServers()));
+          .getZooKeeperWatcher().getQuorum().equals(HConnectionManager
+              .getConnection(otherConf).getZooKeeperWatcher().getQuorum()));
     } catch (Exception e) {
       e.printStackTrace();
       fail();
@@ -179,19 +178,18 @@ public class TestZooKeeper {
    */
   @Test
   public void testZNodeDeletes() throws Exception {
-    ZooKeeperWrapper zkw =
-        ZooKeeperWrapper.createInstance(conf, TestZooKeeper.class.getName());
-    zkw.registerListener(EmptyWatcher.instance);
-    zkw.ensureExists("/l1/l2/l3/l4");
+    ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, 
+        TestZooKeeper.class.getName(), null);
+    ZKUtil.createWithParents(zkw, "/l1/l2/l3/l4");
     try {
-      zkw.deleteZNode("/l1/l2");
+      ZKUtil.deleteNode(zkw, "/l1/l2");
       fail("We should not be able to delete if znode has childs");
     } catch (KeeperException ex) {
-      assertNotNull(zkw.getData("/l1/l2/l3", "l4"));
+      assertNotNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2/l3/l4", null));
     }
-    zkw.deleteZNode("/l1/l2", true);
-    assertNull(zkw.getData("/l1/l2/l3", "l4"));
-    zkw.deleteZNode("/l1");
-    assertNull(zkw.getData("/l1", "l2"));
+    ZKUtil.deleteNodeRecursively(zkw, "/l1/l2");
+    assertNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2/l3/l4", null));
+    ZKUtil.deleteNode(zkw, "/l1");
+    assertNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2", null));
   }
 }
\ No newline at end of file

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/avro/TestAvroServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/avro/TestAvroServer.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/avro/TestAvroServer.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/avro/TestAvroServer.java Tue Aug 31 23:51:44 2010
@@ -22,30 +22,23 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.hadoop.hbase.HBaseClusterTestCase;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
 
 import org.apache.avro.Schema;
 import org.apache.avro.generic.GenericArray;
 import org.apache.avro.generic.GenericData;
-
+import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.avro.generated.AColumn;
 import org.apache.hadoop.hbase.avro.generated.AColumnValue;
 import org.apache.hadoop.hbase.avro.generated.AFamilyDescriptor;
 import org.apache.hadoop.hbase.avro.generated.AGet;
 import org.apache.hadoop.hbase.avro.generated.APut;
-import org.apache.hadoop.hbase.avro.generated.AResult;
 import org.apache.hadoop.hbase.avro.generated.ATableDescriptor;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 /**
  * Unit testing for AvroServer.HBaseImpl, a part of the
@@ -129,7 +122,7 @@ public class TestAvroServer {
 
     tableA.maxFileSize = 123456L;
     impl.modifyTable(tableAname, tableA);
-    assertEquals((long) impl.describeTable(tableAname).maxFileSize, 123456L);
+    assertEquals(123456L, (long) impl.describeTable(tableAname).maxFileSize);
 
     impl.enableTable(tableAname);
     assertTrue(impl.isTableEnabled(tableAname));

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Tue Aug 31 23:51:44 2010
@@ -21,12 +21,13 @@ package org.apache.hadoop.hbase.client;
 
 
 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;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.commons.logging.Log;
@@ -37,9 +38,14 @@ import org.apache.hadoop.hbase.HConstant
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HServerAddress;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.NotServingRegionException;
 import org.apache.hadoop.hbase.TableExistsException;
 import org.apache.hadoop.hbase.TableNotDisabledException;
 import org.apache.hadoop.hbase.TableNotFoundException;
+import org.apache.hadoop.hbase.executor.EventHandler;
+import org.apache.hadoop.hbase.executor.EventHandler.EventType;
+import org.apache.hadoop.hbase.executor.ExecutorService;
+import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -86,7 +92,173 @@ public class TestAdmin {
   }
 
   @Test
-  public void testCreateTableWithRegions() throws IOException {
+  public void testGetTableDescriptor() throws IOException {
+    HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
+    HColumnDescriptor fam2 = new HColumnDescriptor("fam2");
+    HColumnDescriptor fam3 = new HColumnDescriptor("fam3");
+    HTableDescriptor htd = new HTableDescriptor("myTestTable");
+    htd.addFamily(fam1);
+    htd.addFamily(fam2);
+    htd.addFamily(fam3);
+    this.admin.createTable(htd);
+    HTable table = new HTable(TEST_UTIL.getConfiguration(), "myTestTable");
+    HTableDescriptor confirmedHtd = table.getTableDescriptor();
+    assertEquals(htd.compareTo(confirmedHtd), 0);
+  }
+
+  /**
+   * Verify schema modification takes.
+   * @throws IOException
+   */
+  @Test public void testChangeTableSchema() throws IOException {
+    final byte [] tableName = Bytes.toBytes("changeTableSchema");
+    HTableDescriptor [] tables = admin.listTables();
+    int numTables = tables.length;
+    TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY);
+    tables = this.admin.listTables();
+    assertEquals(numTables + 1, tables.length);
+
+    // FIRST, do htabledescriptor changes.
+    HTableDescriptor htd = this.admin.getTableDescriptor(tableName);
+    // Make a copy and assert copy is good.
+    HTableDescriptor copy = new HTableDescriptor(htd);
+    assertTrue(htd.equals(copy));
+    // Now amend the copy. Introduce differences.
+    long newFlushSize = htd.getMemStoreFlushSize() / 2;
+    copy.setMemStoreFlushSize(newFlushSize);
+    final String key = "anyoldkey";
+    assertTrue(htd.getValue(key) == null);
+    copy.setValue(key, key);
+    boolean expectedException = false;
+    try {
+      this.admin.modifyTable(tableName, copy);
+    } catch (TableNotDisabledException re) {
+      expectedException = true;
+    }
+    assertTrue(expectedException);
+    this.admin.disableTable(tableName);
+    assertTrue(this.admin.isTableDisabled(tableName));
+    modifyTable(tableName, copy);
+    HTableDescriptor modifiedHtd = this.admin.getTableDescriptor(tableName);
+    // Assert returned modifiedhcd is same as the copy.
+    assertFalse(htd.equals(modifiedHtd));
+    assertTrue(copy.equals(modifiedHtd));
+    assertEquals(newFlushSize, modifiedHtd.getMemStoreFlushSize());
+    assertEquals(key, modifiedHtd.getValue(key));
+
+    // Reenable table to test it fails if not disabled.
+    this.admin.enableTable(tableName);
+    assertFalse(this.admin.isTableDisabled(tableName));
+
+    // Now work on column family changes.
+    int countOfFamilies = modifiedHtd.getFamilies().size();
+    assertTrue(countOfFamilies > 0);
+    HColumnDescriptor hcd = modifiedHtd.getFamilies().iterator().next();
+    int maxversions = hcd.getMaxVersions();
+    final int newMaxVersions = maxversions + 1;
+    hcd.setMaxVersions(newMaxVersions);
+    final byte [] hcdName = hcd.getName();
+    expectedException = false;
+    try {
+      this.admin.modifyColumn(tableName, hcd);
+    } catch (TableNotDisabledException re) {
+      expectedException = true;
+    }
+    assertTrue(expectedException);
+    this.admin.disableTable(tableName);
+    assertTrue(this.admin.isTableDisabled(tableName));
+    // Modify Column is synchronous
+    this.admin.modifyColumn(tableName, hcd);
+    modifiedHtd = this.admin.getTableDescriptor(tableName);
+    HColumnDescriptor modifiedHcd = modifiedHtd.getFamily(hcdName);
+    assertEquals(newMaxVersions, modifiedHcd.getMaxVersions());
+
+    // Try adding a column
+    // Reenable table to test it fails if not disabled.
+    this.admin.enableTable(tableName);
+    assertFalse(this.admin.isTableDisabled(tableName));
+    final String xtracolName = "xtracol";
+    HColumnDescriptor xtracol = new HColumnDescriptor(xtracolName);
+    xtracol.setValue(xtracolName, xtracolName);
+    try {
+      this.admin.addColumn(tableName, xtracol);
+    } catch (TableNotDisabledException re) {
+      expectedException = true;
+    }
+    assertTrue(expectedException);
+    this.admin.disableTable(tableName);
+    assertTrue(this.admin.isTableDisabled(tableName));
+    this.admin.addColumn(tableName, xtracol);
+    modifiedHtd = this.admin.getTableDescriptor(tableName);
+    hcd = modifiedHtd.getFamily(xtracol.getName());
+    assertTrue(hcd != null);
+    assertTrue(hcd.getValue(xtracolName).equals(xtracolName));
+
+    // Delete the just-added column.
+    this.admin.deleteColumn(tableName, xtracol.getName());
+    modifiedHtd = this.admin.getTableDescriptor(tableName);
+    hcd = modifiedHtd.getFamily(xtracol.getName());
+    assertTrue(hcd == null);
+
+    // Delete the table
+    this.admin.deleteTable(tableName);
+    this.admin.listTables();
+    assertFalse(this.admin.tableExists(tableName));
+  }
+
+  /**
+   * Modify table is async so wait on completion of the table operation in master.
+   * @param tableName
+   * @param htd
+   * @throws IOException
+   */
+  private void modifyTable(final byte [] tableName, final HTableDescriptor htd)
+  throws IOException {
+    MasterServices services = TEST_UTIL.getMiniHBaseCluster().getMaster();
+    ExecutorService executor = services.getExecutorService();
+    AtomicBoolean done = new AtomicBoolean(false);
+    executor.registerListener(EventType.C2M_MODIFY_TABLE, new DoneListener(done));
+    this.admin.modifyTable(tableName, htd);
+    while (!done.get()) {
+      synchronized (done) {
+        try {
+          done.wait(1000);
+        } catch (InterruptedException e) {
+          e.printStackTrace();
+        }
+      }
+    }
+    executor.unregisterListener(EventType.C2M_MODIFY_TABLE);
+  }
+
+  /**
+   * Listens for when an event is done in Master.
+   */
+  static class DoneListener implements EventHandler.EventHandlerListener {
+    private final AtomicBoolean done;
+
+    DoneListener(final AtomicBoolean done) {
+      super();
+      this.done = done;
+    }
+
+    @Override
+    public void afterProcess(EventHandler event) {
+      this.done.set(true);
+      synchronized (this.done) {
+        // Wake anyone waiting on this value to change.
+        this.done.notifyAll();
+      }
+    }
+
+    @Override
+    public void beforeProcess(EventHandler event) {
+      // continue
+    }
+  }
+
+  @Test
+  public void testCreateTableWithRegions() throws IOException, InterruptedException {
 
     byte[] tableName = Bytes.toBytes("testCreateTableWithRegions");
 
@@ -255,19 +427,24 @@ public class TestAdmin {
     Put put = new Put(row);
     put.add(HConstants.CATALOG_FAMILY, qualifier, value);
     ht.put(put);
+    Get get = new Get(row);
+    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
+    ht.get(get);
 
     this.admin.disableTable(table);
 
     // Test that table is disabled
-    Get get = new Get(row);
+    get = new Get(row);
     get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
     boolean ok = false;
     try {
       ht.get(get);
+    } catch (NotServingRegionException e) {
+      ok = true;
     } catch (RetriesExhaustedException e) {
       ok = true;
     }
-    assertEquals(true, ok);
+    assertTrue(ok);
     this.admin.enableTable(table);
 
     //Test that table is enabled
@@ -276,7 +453,7 @@ public class TestAdmin {
     } catch (RetriesExhaustedException e) {
       ok = false;
     }
-    assertEquals(true, ok);
+    assertTrue(ok);
   }
 
   @Test
@@ -361,8 +538,8 @@ public class TestAdmin {
       }
     };
     t.start();
-    // tell the master to split the table
-    admin.split(Bytes.toString(tableName));
+    // Split the table
+    this.admin.split(Bytes.toString(tableName));
     t.join();
 
     // Verify row count
@@ -571,26 +748,13 @@ public class TestAdmin {
     for(int i = 0; i < times; i++) {
       String tableName = "table"+i;
       this.admin.disableTable(tableName);
+      byte [] tableNameBytes = Bytes.toBytes(tableName);
+      assertTrue(this.admin.isTableDisabled(tableNameBytes));
       this.admin.enableTable(tableName);
+      assertFalse(this.admin.isTableDisabled(tableNameBytes));
       this.admin.disableTable(tableName);
+      assertTrue(this.admin.isTableDisabled(tableNameBytes));
       this.admin.deleteTable(tableName);
     }
   }
-
-  @Test
-  public void testGetTableDescriptor() throws IOException {
-    HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
-    HColumnDescriptor fam2 = new HColumnDescriptor("fam2");
-    HColumnDescriptor fam3 = new HColumnDescriptor("fam3");
-    HTableDescriptor htd = new HTableDescriptor("myTestTable");
-    htd.addFamily(fam1);
-    htd.addFamily(fam2);
-    htd.addFamily(fam3);
-    this.admin.createTable(htd);
-    HTable table = new HTable("myTestTable");
-    HTableDescriptor confirmedHtd = table.getTableDescriptor();
-
-    assertEquals(htd.compareTo(confirmedHtd), 0);
-  }
 }
-

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Tue Aug 31 23:51:44 2010
@@ -25,9 +25,9 @@ import static org.junit.Assert.assertSam
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -41,7 +41,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
@@ -51,6 +50,7 @@ import org.apache.hadoop.hbase.HTableDes
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.filter.BinaryComparator;
 import org.apache.hadoop.hbase.filter.CompareFilter;
+import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.filter.Filter;
 import org.apache.hadoop.hbase.filter.FilterList;
 import org.apache.hadoop.hbase.filter.PrefixFilter;
@@ -59,7 +59,6 @@ import org.apache.hadoop.hbase.filter.Re
 import org.apache.hadoop.hbase.filter.RowFilter;
 import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
 import org.apache.hadoop.hbase.filter.WhileMatchFilter;
-import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -262,9 +261,11 @@ public class TestFromClientSide {
    * logs to ensure that we're not scanning more regions that we're supposed to.
    * Related to the TestFilterAcrossRegions over in the o.a.h.h.filter package.
    * @throws IOException
+   * @throws InterruptedException 
    */
   @Test
-  public void testFilterAcrossMutlipleRegions() throws IOException {
+  public void testFilterAcrossMultipleRegions()
+  throws IOException, InterruptedException {
     byte [] name = Bytes.toBytes("testFilterAcrossMutlipleRegions");
     HTable t = TEST_UTIL.createTable(name, FAMILY);
     int rowCount = TEST_UTIL.loadTable(t, FAMILY);
@@ -314,32 +315,6 @@ public class TestFromClientSide {
       CompareFilter.CompareOp.GREATER_OR_EQUAL));
     assertEquals(rowCount - endKeyCount, countGreater);
   }
-  
-  /*
-   * Load table with rows from 'aaa' to 'zzz'.
-   * @param t
-   * @return Count of rows loaded.
-   * @throws IOException
-   */
-  private int loadTable(final HTable t) throws IOException {
-    // Add data to table.
-    byte[] k = new byte[3];
-    int rowCount = 0;
-    for (byte b1 = 'a'; b1 < 'z'; b1++) {
-      for (byte b2 = 'a'; b2 < 'z'; b2++) {
-        for (byte b3 = 'a'; b3 < 'z'; b3++) {
-          k[0] = b1;
-          k[1] = b2;
-          k[2] = b3;
-          Put put = new Put(k);
-          put.add(FAMILY, new byte[0], k);
-          t.put(put);
-          rowCount++;
-        }
-      }
-    }
-    return rowCount;
-  }
 
   /*
    * @param key
@@ -399,7 +374,7 @@ public class TestFromClientSide {
    * @throws IOException
    */
   private Map<HRegionInfo, HServerAddress> splitTable(final HTable t)
-  throws IOException {
+  throws IOException, InterruptedException {
     // Split this table in two.
     HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
     admin.split(t.getTableName());
@@ -3376,7 +3351,7 @@ public class TestFromClientSide {
   }
 
   @Test
-  public void testListTables() throws IOException {
+  public void testListTables() throws IOException, InterruptedException {
     byte [] t1 = Bytes.toBytes("testListTables1");
     byte [] t2 = Bytes.toBytes("testListTables2");
     byte [] t3 = Bytes.toBytes("testListTables3");
@@ -3459,7 +3434,7 @@ public class TestFromClientSide {
     for (HColumnDescriptor c : desc.getFamilies())
       c.setValue(attrName, attrValue);
     // update metadata for all regions of this table
-    admin.modifyTable(tableAname, HConstants.Modify.TABLE_SET_HTD, desc);
+    admin.modifyTable(tableAname, desc);
     // enable the table
     admin.enableTable(tableAname);
 

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java Tue Aug 31 23:51:44 2010
@@ -247,12 +247,12 @@ public class TestHFileOutputFormat  {
     }
     return ret;
   }
-  
+
   @Test
   public void testMRIncrementalLoad() throws Exception {
     doIncrementalLoadTest(false);
   }
-  
+
   @Test
   public void testMRIncrementalLoadWithSplit() throws Exception {
     doIncrementalLoadTest(true);
@@ -308,13 +308,12 @@ public class TestHFileOutputFormat  {
             
       // Cause regions to reopen
       admin.disableTable(TABLE_NAME);
-      while (table.getRegionsInfo().size() != 0) {
+      while (!admin.isTableDisabled(TABLE_NAME)) {
         Thread.sleep(1000);
         LOG.info("Waiting for table to disable"); 
       }
       admin.enableTable(TABLE_NAME);
       util.waitTableAvailable(TABLE_NAME, 30000);
-      
       assertEquals("Data should remain after reopening of regions",
           tableDigestBefore, util.checksumRows(table));
     } finally {
@@ -322,9 +321,7 @@ public class TestHFileOutputFormat  {
       util.shutdownMiniCluster();
     }
   }
-  
-  
-  
+
   private void runIncrementalPELoad(
       Configuration conf, HTable table, Path outDir)
   throws Exception {

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFiles.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFiles.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFiles.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFiles.java Tue Aug 31 23:51:44 2010
@@ -112,7 +112,7 @@ public class TestLoadIncrementalHFiles {
       htd.addFamily(new HColumnDescriptor(FAMILY));
       admin.createTable(htd, SPLIT_KEYS);
 
-      HTable table = new HTable(TABLE);
+      HTable table = new HTable(util.getConfiguration(), TABLE);
       util.waitTableAvailable(TABLE, 30000);
       LoadIncrementalHFiles loader = new LoadIncrementalHFiles(
           util.getConfiguration());

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java Tue Aug 31 23:51:44 2010
@@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.HBaseConf
 import org.apache.hadoop.hbase.HMsg;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HServerInfo;
+import org.apache.zookeeper.KeeperException;
 
 /**
  * An HMaster that runs out of memory.
@@ -37,7 +38,8 @@ import org.apache.hadoop.hbase.HServerIn
 public class OOMEHMaster extends HMaster {
   private List<byte []> retainer = new ArrayList<byte[]>();
 
-  public OOMEHMaster(HBaseConfiguration conf) throws IOException {
+  public OOMEHMaster(HBaseConfiguration conf)
+  throws IOException, KeeperException, InterruptedException {
     super(conf);
   }
 
@@ -52,8 +54,9 @@ public class OOMEHMaster extends HMaster
 
   /**
    * @param args
+   * @throws IOException 
    */
-  public static void main(String[] args) {
+  public static void main(String[] args) throws IOException {
     doMain(args, OOMEHMaster.class);
   }
 }

Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java?rev=991397&view=auto
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java (added)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java Tue Aug 31 23:51:44 2010
@@ -0,0 +1,234 @@
+/**
+ * Copyright 2010 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.master;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.Semaphore;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HServerAddress;
+import org.apache.hadoop.hbase.Server;
+import org.apache.hadoop.hbase.catalog.CatalogTracker;
+import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperListener;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.zookeeper.KeeperException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the {@link ActiveMasterManager}.
+ */
+public class TestActiveMasterManager {
+  private final static Log LOG = LogFactory.getLog(TestActiveMasterManager.class);
+  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    TEST_UTIL.startMiniZKCluster();
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+    TEST_UTIL.shutdownMiniZKCluster();
+  }
+
+  /**
+   * Unit tests that uses ZooKeeper but does not use the master-side methods
+   * but rather acts directly on ZK.
+   * @throws Exception
+   */
+  @Test
+  public void testActiveMasterManagerFromZK() throws Exception {
+
+    ZooKeeperWatcher zk = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
+        "testActiveMasterManagerFromZK", null);
+    ZKUtil.createAndFailSilent(zk, zk.baseZNode);
+    try {
+      ZKUtil.deleteNode(zk, zk.masterAddressZNode);
+    } catch(KeeperException.NoNodeException nne) {}
+
+    // Create the master node with a dummy address
+    HServerAddress firstMasterAddress = new HServerAddress("firstMaster", 1234);
+    HServerAddress secondMasterAddress = new HServerAddress("secondMaster", 1234);
+
+    // Should not have a master yet
+    DummyMaster ms1 = new DummyMaster();
+    ActiveMasterManager activeMasterManager = new ActiveMasterManager(zk,
+        firstMasterAddress, ms1);
+    zk.registerListener(activeMasterManager);
+    assertFalse(activeMasterManager.clusterHasActiveMaster.get());
+
+    // First test becoming the active master uninterrupted
+    activeMasterManager.blockUntilBecomingActiveMaster();
+    assertTrue(activeMasterManager.clusterHasActiveMaster.get());
+    assertMaster(zk, firstMasterAddress);
+
+    // New manager will now try to become the active master in another thread
+    WaitToBeMasterThread t = new WaitToBeMasterThread(zk, secondMasterAddress);
+    zk.registerListener(t.manager);
+    t.start();
+    // Wait for this guy to figure out there is another active master
+    // Wait for 1 second at most
+    int sleeps = 0;
+    while(!t.manager.clusterHasActiveMaster.get() && sleeps < 100) {
+      Thread.sleep(10);
+      sleeps++;
+    }
+
+    // Both should see that there is an active master
+    assertTrue(activeMasterManager.clusterHasActiveMaster.get());
+    assertTrue(t.manager.clusterHasActiveMaster.get());
+    // But secondary one should not be the active master
+    assertFalse(t.isActiveMaster);
+
+    // Close the first server and delete it's master node
+    ms1.stop("stopping first server");
+
+    // Use a listener to capture when the node is actually deleted
+    NodeDeletionListener listener = new NodeDeletionListener(zk, zk.masterAddressZNode);
+    zk.registerListener(listener);
+
+    LOG.info("Deleting master node");
+    ZKUtil.deleteNode(zk, zk.masterAddressZNode);
+
+    // Wait for the node to be deleted
+    LOG.info("Waiting for active master manager to be notified");
+    listener.waitForDeletion();
+    LOG.info("Master node deleted");
+
+    // Now we expect the secondary manager to have and be the active master
+    // Wait for 1 second at most
+    sleeps = 0;
+    while(!t.isActiveMaster && sleeps < 100) {
+      Thread.sleep(10);
+      sleeps++;
+    }
+    LOG.debug("Slept " + sleeps + " times");
+
+    assertTrue(t.manager.clusterHasActiveMaster.get());
+    assertTrue(t.isActiveMaster);
+  }
+
+  /**
+   * Assert there is an active master and that it has the specified address.
+   * @param zk
+   * @param thisMasterAddress
+   * @throws KeeperException
+   */
+  private void assertMaster(ZooKeeperWatcher zk,
+      HServerAddress expectedAddress) throws KeeperException {
+    HServerAddress readAddress = ZKUtil.getDataAsAddress(zk, zk.masterAddressZNode);
+    assertNotNull(readAddress);
+    assertTrue(expectedAddress.equals(readAddress));
+  }
+
+  public static class WaitToBeMasterThread extends Thread {
+
+    ActiveMasterManager manager;
+    boolean isActiveMaster;
+
+    public WaitToBeMasterThread(ZooKeeperWatcher zk,
+        HServerAddress address) {
+      this.manager = new ActiveMasterManager(zk, address,
+          new DummyMaster());
+      isActiveMaster = false;
+    }
+
+    @Override
+    public void run() {
+      manager.blockUntilBecomingActiveMaster();
+      LOG.info("Second master has become the active master!");
+      isActiveMaster = true;
+    }
+  }
+
+  public static class NodeDeletionListener extends ZooKeeperListener {
+    private static final Log LOG = LogFactory.getLog(NodeDeletionListener.class);
+
+    private Semaphore lock;
+    private String node;
+
+    public NodeDeletionListener(ZooKeeperWatcher watcher, String node) {
+      super(watcher);
+      lock = new Semaphore(0);
+      this.node = node;
+    }
+
+    @Override
+    public void nodeDeleted(String path) {
+      if(path.equals(node)) {
+        LOG.debug("nodeDeleted(" + path + ")");
+        lock.release();
+      }
+    }
+
+    public void waitForDeletion() throws InterruptedException {
+      lock.acquire();
+    }
+  }
+
+  /**
+   * Dummy Master Implementation.
+   */
+  public static class DummyMaster implements Server {
+    private volatile boolean stopped;
+
+    @Override
+    public void abort(final String msg, final Throwable t) {}
+
+    @Override
+    public Configuration getConfiguration() {
+      return null;
+    }
+
+    @Override
+    public ZooKeeperWatcher getZooKeeper() {
+      return null;
+    }
+
+    @Override
+    public String getServerName() {
+      return null;
+    }
+
+    @Override
+    public boolean isStopped() {
+      return this.stopped;
+    }
+
+    @Override
+    public void stop(String why) {
+      this.stopped = true;
+    }
+
+    @Override
+    public CatalogTracker getCatalogTracker() {
+      return null;
+    }
+  }
+}

Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java?rev=991397&view=auto
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java (added)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java Tue Aug 31 23:51:44 2010
@@ -0,0 +1,41 @@
+/**
+ * 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 static org.junit.Assert.*;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Test;
+
+
+public class TestDeadServer {
+  @Test public void testIsDead() {
+    Set<String> deadServers = new HashSet<String>();
+    DeadServer ds = new DeadServer();
+    final String hostname123 = "one,123,3";
+    assertFalse(ds.isDeadServer(hostname123, false));
+    assertFalse(ds.isDeadServer(hostname123, true));
+    deadServers.add(hostname123);
+    assertTrue(ds.isDeadServer(hostname123, false));
+    assertFalse(ds.isDeadServer("one:1", true));
+    assertFalse(ds.isDeadServer("one:1234", true));
+    assertTrue(ds.isDeadServer("one:123", true));
+  }
+}
\ No newline at end of file

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestKillingServersFromMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestKillingServersFromMaster.java?rev=991397&r1=991396&r2=991397&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestKillingServersFromMaster.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestKillingServersFromMaster.java Tue Aug 31 23:51:44 2010
@@ -20,7 +20,6 @@
 package org.apache.hadoop.hbase.master;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 
@@ -28,9 +27,8 @@ import org.apache.hadoop.hbase.HBaseTest
 import org.apache.hadoop.hbase.HServerAddress;
 import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.MiniHBaseCluster;
-import org.apache.hadoop.hbase.MiniHBaseCluster.MiniHBaseClusterRegionServer;
 import org.apache.hadoop.hbase.YouAreDeadException;
-import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.MiniHBaseCluster.MiniHBaseClusterRegionServer;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;