hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jxi...@apache.org
Subject svn commit: r1504515 - in /hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase: ./ test/ util/
Date Thu, 18 Jul 2013 16:38:48 GMT
Author: jxiang
Date: Thu Jul 18 16:38:47 2013
New Revision: 1504515

URL: http://svn.apache.org/r1504515
Log:
HBASE-8845 Add integration test for split, online merge, and compaction

Modified:
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IngestIntegrationTestBase.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestSlowDeterministic.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestWithChaosMonkey.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedList.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedListWithChaosMonkey.java
    hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/util/ChaosMonkey.java

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IngestIntegrationTestBase.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IngestIntegrationTestBase.java?rev=1504515&r1=1504514&r2=1504515&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IngestIntegrationTestBase.java
(original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IngestIntegrationTestBase.java
Thu Jul 18 16:38:47 2013
@@ -20,20 +20,19 @@ package org.apache.hadoop.hbase;
 
 import java.io.IOException;
 
-import junit.framework.Assert;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.LoadTestTool;
+import org.junit.Assert;
 
 /**
  * A base class for tests that do something with the cluster while running
  * {@link LoadTestTool} to write and verify some data.
  */
 public abstract class IngestIntegrationTestBase {
-  private static String tableName = null;
+  protected static String tableName = null;
 
   /** A soft limit on how long we should run */
   private static final String RUN_TIME_KEY = "hbase.%s.runtime";

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestSlowDeterministic.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestSlowDeterministic.java?rev=1504515&r1=1504514&r2=1504515&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestSlowDeterministic.java
(original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestSlowDeterministic.java
Thu Jul 18 16:38:47 2013
@@ -18,11 +18,25 @@
 package org.apache.hadoop.hbase;
 
 import org.apache.hadoop.hbase.util.ChaosMonkey;
+import org.apache.hadoop.hbase.util.ChaosMonkey.Action;
 import org.apache.hadoop.hbase.util.ChaosMonkey.BatchRestartRs;
+import org.apache.hadoop.hbase.util.ChaosMonkey.CompactRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.CompactTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.CompositeSequentialPolicy;
+import org.apache.hadoop.hbase.util.ChaosMonkey.DoActionsOncePolicy;
+import org.apache.hadoop.hbase.util.ChaosMonkey.FlushRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.FlushTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MergeRandomAdjacentRegionsOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MoveRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MoveRegionsOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.PeriodicRandomActionPolicy;
 import org.apache.hadoop.hbase.util.ChaosMonkey.RestartActiveMaster;
 import org.apache.hadoop.hbase.util.ChaosMonkey.RestartRandomRs;
 import org.apache.hadoop.hbase.util.ChaosMonkey.RestartRsHoldingMeta;
 import org.apache.hadoop.hbase.util.ChaosMonkey.RollingBatchRestartRs;
+import org.apache.hadoop.hbase.util.ChaosMonkey.SnapshotTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.SplitRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.LoadTestTool;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -37,24 +51,50 @@ import org.junit.experimental.categories
 @Category(IntegrationTests.class)
 public class IntegrationTestDataIngestSlowDeterministic extends IngestIntegrationTestBase
{
   private static final int SERVER_COUNT = 4; // number of slaves for the smallest cluster
-  private static final long DEFAULT_RUN_TIME = 10 * 60 * 1000;
-  private static final long CHAOS_EVERY_MS = 150 * 1000; // Chaos every 2.5 minutes.
+  private static final long DEFAULT_RUN_TIME = 20 * 60 * 1000;
 
   private ChaosMonkey monkey;
 
   @Before
   public void setUp() throws Exception {
     super.setUp(SERVER_COUNT);
-    ChaosMonkey.Action[] actions = new ChaosMonkey.Action[] {
-        new RestartRandomRs(60000),
-        new BatchRestartRs(5000, 0.5f),
-        new RestartActiveMaster(5000),
-        new RollingBatchRestartRs(5000, 1.0f),
-        new RestartRsHoldingMeta(35000)
+
+    // Actions such as compact/flush a table/region,
+    // move one region around. They are not so destructive,
+    // can be executed more frequently.
+    Action[] actions1 = new Action[] {
+      new CompactTable(tableName, 0.5f),
+      new CompactRandomRegionOfTable(tableName, 0.6f),
+      new FlushTable(tableName),
+      new FlushRandomRegionOfTable(tableName),
+      new MoveRandomRegionOfTable(tableName)
+    };
+
+    // Actions such as split/merge/snapshot.
+    // They should not cause data loss, or unreliability
+    // such as region stuck in transition.
+    Action[] actions2 = new Action[] {
+      new SplitRandomRegionOfTable(tableName),
+      new MergeRandomAdjacentRegionsOfTable(tableName),
+      new SnapshotTable(tableName)
     };
-    monkey = new ChaosMonkey(util, new ChaosMonkey.CompositeSequentialPolicy(
-            new ChaosMonkey.DoActionsOncePolicy(CHAOS_EVERY_MS, actions),
-            new ChaosMonkey.PeriodicRandomActionPolicy(CHAOS_EVERY_MS, actions)));
+
+    // Destructive actions to mess things around.
+    Action[] actions3 = new Action[] {
+      new MoveRegionsOfTable(tableName),
+      new RestartRandomRs(60000),
+      new BatchRestartRs(5000, 0.5f),
+      new RestartActiveMaster(5000),
+      new RollingBatchRestartRs(5000, 1.0f),
+      new RestartRsHoldingMeta(35000)
+    };
+
+    monkey = new ChaosMonkey(util,
+      new PeriodicRandomActionPolicy(60 * 1000, actions1),
+      new PeriodicRandomActionPolicy(90 * 1000, actions2),
+      new CompositeSequentialPolicy(
+        new DoActionsOncePolicy(150 * 1000, actions3),
+        new PeriodicRandomActionPolicy(150 * 1000, actions3)));
     monkey.start();
   }
 

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestWithChaosMonkey.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestWithChaosMonkey.java?rev=1504515&r1=1504514&r2=1504515&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestWithChaosMonkey.java
(original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDataIngestWithChaosMonkey.java
Thu Jul 18 16:38:47 2013
@@ -20,6 +20,18 @@ package org.apache.hadoop.hbase;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.util.ChaosMonkey;
+import org.apache.hadoop.hbase.util.ChaosMonkey.Action;
+import org.apache.hadoop.hbase.util.ChaosMonkey.CompactRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.CompactTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.FlushRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.FlushTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MergeRandomAdjacentRegionsOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MoveRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MoveRegionsOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.PeriodicRandomActionPolicy;
+import org.apache.hadoop.hbase.util.ChaosMonkey.SnapshotTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.SplitRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.LoadTestTool;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -36,8 +48,8 @@ public class IntegrationTestDataIngestWi
 
   private static int NUM_SLAVES_BASE = 4; //number of slaves for the smallest cluster
 
-  // run for 5 min by default
-  private static final long DEFAULT_RUN_TIME = 5 * 60 * 1000;
+  // run for 10 min by default
+  private static final long DEFAULT_RUN_TIME = 10 * 60 * 1000;
 
   private ChaosMonkey monkey;
 
@@ -57,7 +69,32 @@ public class IntegrationTestDataIngestWi
       NUM_SLAVES_BASE = 5;
     }
     super.setUp(NUM_SLAVES_BASE);
-    monkey = new ChaosMonkey(util, ChaosMonkey.EVERY_MINUTE_RANDOM_ACTION_POLICY);
+
+    // Actions such as compact/flush a table/region,
+    // move one region around. They are not so destructive,
+    // can be executed more frequently.
+    Action[] actions1 = new Action[] {
+      new CompactTable(tableName, 0.5f),
+      new CompactRandomRegionOfTable(tableName, 0.6f),
+      new FlushTable(tableName),
+      new FlushRandomRegionOfTable(tableName),
+      new MoveRandomRegionOfTable(tableName)
+    };
+
+    // Actions such as split/merge/snapshot.
+    // They should not cause data loss, or unreliability
+    // such as region stuck in transition.
+    Action[] actions2 = new Action[] {
+      new SplitRandomRegionOfTable(tableName),
+      new MergeRandomAdjacentRegionsOfTable(tableName),
+      new SnapshotTable(tableName),
+      new MoveRegionsOfTable(tableName)
+    };
+
+    monkey = new ChaosMonkey(util,
+      new PeriodicRandomActionPolicy(30 * 1000, actions1),
+      new PeriodicRandomActionPolicy(60 * 1000, actions2),
+      ChaosMonkey.getPolicyByName(ChaosMonkey.EVERY_MINUTE_RANDOM_ACTION_POLICY));
     monkey.start();
   }
 

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedList.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedList.java?rev=1504515&r1=1504514&r2=1504515&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedList.java
(original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedList.java
Thu Jul 18 16:38:47 2013
@@ -21,8 +21,6 @@ package org.apache.hadoop.hbase.test;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
-import java.io.StringWriter;
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -574,7 +572,6 @@ public class IntegrationTestBigLinkedLis
             comma = ",";
             refsSb.append(Bytes.toStringBinary(ref));
           }
-          byte[] bytes = new byte[key.getLength()];
           keyString = Bytes.toStringBinary(key.getBytes(), 0, key.getLength());
         }
 
@@ -945,7 +942,7 @@ public class IntegrationTestBigLinkedLis
     }
   }
 
-  private static byte[] getTableName(Configuration conf) {
+  static byte[] getTableName(Configuration conf) {
     return Bytes.toBytes(conf.get(TABLE_NAME_KEY, DEFAULT_TABLE_NAME));
   }
 

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedListWithChaosMonkey.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedListWithChaosMonkey.java?rev=1504515&r1=1504514&r2=1504515&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedListWithChaosMonkey.java
(original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestBigLinkedListWithChaosMonkey.java
Thu Jul 18 16:38:47 2013
@@ -25,6 +25,17 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.hbase.IntegrationTestingUtility;
 import org.apache.hadoop.hbase.IntegrationTests;
 import org.apache.hadoop.hbase.util.ChaosMonkey;
+import org.apache.hadoop.hbase.util.ChaosMonkey.Action;
+import org.apache.hadoop.hbase.util.ChaosMonkey.CompactRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.CompactTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.FlushRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.FlushTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MergeRandomAdjacentRegionsOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MoveRandomRegionOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.MoveRegionsOfTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.PeriodicRandomActionPolicy;
+import org.apache.hadoop.hbase.util.ChaosMonkey.SnapshotTable;
+import org.apache.hadoop.hbase.util.ChaosMonkey.SplitRandomRegionOfTable;
 import org.apache.hadoop.util.ToolRunner;
 import org.junit.After;
 import org.junit.Before;
@@ -51,6 +62,7 @@ public class IntegrationTestBigLinkedLis
     } else {
       this.getTestingUtil().getConfiguration()
           .set(TABLE_NAME_KEY, "IntegrationTestBigLinkedListWithChaosMonkey");
+      setConf(conf);
     }
   }
 
@@ -60,7 +72,34 @@ public class IntegrationTestBigLinkedLis
       this.NUM_SLAVES_BASE = 5; // only used in MiniCluster mode
     }
     super.setUp();
-    monkey = new ChaosMonkey(util, ChaosMonkey.EVERY_MINUTE_RANDOM_ACTION_POLICY);
+
+    String tableName = getConf().get(TABLE_NAME_KEY, DEFAULT_TABLE_NAME);
+
+    // Actions such as compact/flush a table/region,
+    // move one region around. They are not so destructive,
+    // can be executed more frequently.
+    Action[] actions1 = new Action[] {
+      new CompactTable(tableName, 0.5f),
+      new CompactRandomRegionOfTable(tableName, 0.6f),
+      new FlushTable(tableName),
+      new FlushRandomRegionOfTable(tableName),
+      new MoveRandomRegionOfTable(tableName)
+    };
+
+    // Actions such as split/merge/snapshot.
+    // They should not cause data loss, or unreliability
+    // such as region stuck in transition.
+    Action[] actions2 = new Action[] {
+      new SplitRandomRegionOfTable(tableName),
+      new MergeRandomAdjacentRegionsOfTable(tableName),
+      new SnapshotTable(tableName),
+      new MoveRegionsOfTable(tableName)
+    };
+
+    monkey = new ChaosMonkey(util,
+      new PeriodicRandomActionPolicy(30 * 1000, actions1),
+      new PeriodicRandomActionPolicy(60 * 1000, actions2),
+      ChaosMonkey.getPolicyByName(ChaosMonkey.EVERY_MINUTE_RANDOM_ACTION_POLICY));
     LOG.info("Chaos Monkey Starting");
     monkey.start();
   }

Modified: hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/util/ChaosMonkey.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/util/ChaosMonkey.java?rev=1504515&r1=1504514&r2=1504515&view=diff
==============================================================================
--- hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/util/ChaosMonkey.java (original)
+++ hbase/trunk/hbase-it/src/test/java/org/apache/hadoop/hbase/util/ChaosMonkey.java Thu Jul
18 16:38:47 2013
@@ -36,6 +36,7 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.hbase.ClusterStatus;
 import org.apache.hadoop.hbase.HBaseCluster;
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.IntegrationTestDataIngestWithChaosMonkey;
 import org.apache.hadoop.hbase.IntegrationTestingUtility;
@@ -105,10 +106,14 @@ public class ChaosMonkey extends Abstrac
   private void setPoliciesByName(String... policies) {
     this.policies = new Policy[policies.length];
     for (int i=0; i < policies.length; i++) {
-      this.policies[i] = NAMED_POLICIES.get(policies[i]);
+      this.policies[i] = getPolicyByName(policies[i]);
     }
   }
 
+  public static Policy getPolicyByName(String policy) {
+    return NAMED_POLICIES.get(policy);
+  }
+
   /**
    * Context for Action's
    */
@@ -327,6 +332,10 @@ public class ChaosMonkey extends Abstrac
     private final long sleepTime;
     private final byte[] tableNameBytes;
 
+    public MoveRegionsOfTable(String tableName) {
+      this(-1, tableName);
+    }
+
     public MoveRegionsOfTable(long sleepTime, String tableName) {
       this.sleepTime = sleepTime;
       this.tableNameBytes = Bytes.toBytes(tableName);
@@ -349,9 +358,248 @@ public class ChaosMonkey extends Abstrac
           LOG.debug("Error moving region", e);
         }
       }
-      Thread.sleep(sleepTime);
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+  public static class MoveRandomRegionOfTable extends Action {
+    private final long sleepTime;
+    private final byte[] tableNameBytes;
+
+    public MoveRandomRegionOfTable(String tableName) {
+      this(-1, tableName);
+    }
+
+    public MoveRandomRegionOfTable(long sleepTime, String tableName) {
+      this.sleepTime = sleepTime;
+      this.tableNameBytes = Bytes.toBytes(tableName);
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      HBaseAdmin admin = util.getHBaseAdmin();
+
+      List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+      HRegionInfo region = selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+      admin.unassign(region.getRegionName(), false);
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
     }
   }
+
+  public static class SplitRandomRegionOfTable extends Action {
+    private final byte[] tableNameBytes;
+    private final long sleepTime;
+
+    public SplitRandomRegionOfTable(String tableName) {
+      this(-1, tableName);
+    }
+
+    public SplitRandomRegionOfTable(int sleepTime, String tableName) {
+      this.tableNameBytes = Bytes.toBytes(tableName);
+      this.sleepTime = sleepTime;
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      HBaseAdmin admin = util.getHBaseAdmin();
+
+      List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+      HRegionInfo region = selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+      admin.split(region.getRegionName());
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+  public static class MergeRandomAdjacentRegionsOfTable extends Action {
+    private final byte[] tableNameBytes;
+    private final String tableName;
+    private final long sleepTime;
+
+    public MergeRandomAdjacentRegionsOfTable(String tableName) {
+      this(-1, tableName);
+    }
+
+    public MergeRandomAdjacentRegionsOfTable(int sleepTime, String tableName) {
+      this.tableNameBytes = Bytes.toBytes(tableName);
+      this.tableName = tableName;
+      this.sleepTime = sleepTime;
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      HBaseAdmin admin = util.getHBaseAdmin();
+  
+      List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+      if (regions.size() < 2) {
+        LOG.info("Table " + tableName + " doesn't have enough region to merge");
+        return;
+      }
+
+      int i = RandomUtils.nextInt(regions.size() - 1);
+      HRegionInfo a = regions.get(i++);
+      HRegionInfo b = regions.get(i);
+      admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+  public static class CompactTable extends Action {
+    private final byte[] tableNameBytes;
+    private final int majorRatio;
+    private final long sleepTime;
+
+    public CompactTable(
+        String tableName, float majorRatio) {
+      this(-1, tableName, majorRatio);
+    }
+
+    public CompactTable(
+        int sleepTime, String tableName, float majorRatio) {
+      this.tableNameBytes = Bytes.toBytes(tableName);
+      this.majorRatio = (int) (100 * majorRatio);
+      this.sleepTime = sleepTime;
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      HBaseAdmin admin = util.getHBaseAdmin();
+      if (RandomUtils.nextInt(100) < majorRatio) {
+        admin.majorCompact(tableNameBytes);
+      } else {
+        admin.compact(tableNameBytes);
+      }
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+  public static class CompactRandomRegionOfTable extends Action {
+    private final byte[] tableNameBytes;
+    private final int majorRatio;
+    private final long sleepTime;
+
+    public CompactRandomRegionOfTable(
+        String tableName, float majorRatio) {
+      this(-1, tableName, majorRatio);
+    }
+
+    public CompactRandomRegionOfTable(
+        int sleepTime, String tableName, float majorRatio) {
+      this.tableNameBytes = Bytes.toBytes(tableName);
+      this.majorRatio = (int) (100 * majorRatio);
+      this.sleepTime = sleepTime;
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      HBaseAdmin admin = util.getHBaseAdmin();
+      List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+      HRegionInfo region = selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+      if (RandomUtils.nextInt(100) < majorRatio) {
+        admin.majorCompact(region.getRegionName());
+      } else {
+        admin.compact(region.getRegionName());
+      }
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+  public static class FlushTable extends Action {
+    private final byte[] tableNameBytes;
+    private final long sleepTime;
+
+    public FlushTable(String tableName) {
+      this(-1, tableName);
+    }
+
+    public FlushTable(int sleepTime, String tableName) {
+      this.tableNameBytes = Bytes.toBytes(tableName);
+      this.sleepTime = sleepTime;
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      HBaseAdmin admin = util.getHBaseAdmin();
+      admin.flush(tableNameBytes);
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+  public static class FlushRandomRegionOfTable extends Action {
+    private final byte[] tableNameBytes;
+    private final long sleepTime;
+
+    public FlushRandomRegionOfTable(String tableName) {
+     this (-1, tableName);
+    }
+
+    public FlushRandomRegionOfTable(int sleepTime, String tableName) {
+      this.tableNameBytes = Bytes.toBytes(tableName);
+      this.sleepTime = sleepTime;
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      HBaseAdmin admin = util.getHBaseAdmin();
+      List<HRegionInfo> regions = admin.getTableRegions(tableNameBytes);
+      HRegionInfo region = selectRandomItem(
+        regions.toArray(new HRegionInfo[regions.size()]));
+      admin.flush(region.getRegionName());
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+  public static class SnapshotTable extends Action {
+    private final String tableName;
+    private final long sleepTime;
+
+    public SnapshotTable(String tableName) {
+      this(-1, tableName);
+    }
+
+    public SnapshotTable(int sleepTime, String tableName) {
+      this.tableName = tableName;
+      this.sleepTime = sleepTime;
+    }
+
+    @Override
+    public void perform() throws Exception {
+      HBaseTestingUtility util = context.getHaseIntegrationTestingUtility();
+      String snapshotName = tableName + "-it-" + System.currentTimeMillis();
+      HBaseAdmin admin = util.getHBaseAdmin();
+      admin.snapshot(snapshotName, tableName);
+      if (sleepTime > 0) {
+        Thread.sleep(sleepTime);
+      }
+    }
+  }
+
+
   /**
    * Restarts a ratio of the running regionservers at the same time
    */



Mime
View raw message