hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject [06/50] [abbrv] hbase git commit: HBASE-13372 Add unit tests for SplitTransaction and RegionMergeTransaction listeners
Date Mon, 25 Apr 2016 21:12:50 GMT
HBASE-13372 Add unit tests for SplitTransaction and RegionMergeTransaction listeners

Signed-off-by: Andrew Purtell <apurtell@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/6d7a7fa3
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/6d7a7fa3
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/6d7a7fa3

Branch: refs/heads/HBASE-14850
Commit: 6d7a7fa3aa5a9dc720d4f1238ebf38c53e4875b9
Parents: 31b85e7
Author: Gábor Lipták <gliptak@gmail.com>
Authored: Sat Aug 22 19:39:13 2015 -0400
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Mon Apr 18 17:04:56 2016 -0700

----------------------------------------------------------------------
 .../TestRegionMergeTransaction.java             | 36 +++++++++++++++++---
 .../regionserver/TestSplitTransaction.java      | 28 ++++++++++++---
 2 files changed, 55 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/6d7a7fa3/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java
index bcb8733..4630522 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java
@@ -21,8 +21,7 @@ package org.apache.hadoop.hbase.regionserver;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -211,6 +210,35 @@ public class TestRegionMergeTransaction {
     assertFalse(spyMT.prepare(null));
   }
 
+  /**
+   * Test RegionMergeTransactionListener
+   */
+  @Test public void testRegionMergeTransactionListener() throws IOException {
+    RegionMergeTransactionImpl mt = new RegionMergeTransactionImpl(region_a, region_b,
+        false);
+    RegionMergeTransactionImpl spyMT = Mockito.spy(mt);
+    doReturn(false).when(spyMT).hasMergeQualifierInMeta(null,
+        region_a.getRegionInfo().getRegionName());
+    doReturn(false).when(spyMT).hasMergeQualifierInMeta(null,
+        region_b.getRegionInfo().getRegionName());
+    RegionMergeTransaction.TransactionListener listener =
+            Mockito.mock(RegionMergeTransaction.TransactionListener.class);
+    mt.registerTransactionListener(listener);
+    mt.prepare(null);
+    TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
+    CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
+      TEST_UTIL.getConfiguration());
+    Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
+    mt.execute(mockServer, null);
+    verify(listener).transition(mt,
+            RegionMergeTransaction.RegionMergeTransactionPhase.STARTED,
+            RegionMergeTransaction.RegionMergeTransactionPhase.PREPARED);
+    verify(listener, times(10)).transition(any(RegionMergeTransaction.class),
+            any(RegionMergeTransaction.RegionMergeTransactionPhase.class),
+            any(RegionMergeTransaction.RegionMergeTransactionPhase.class));
+    verifyNoMoreInteractions(listener);
+  }
+
   @Test
   public void testWholesomeMerge() throws IOException, InterruptedException {
     final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
@@ -356,9 +384,9 @@ public class TestRegionMergeTransaction {
   }
 
   @Test
-  public void testMeregedRegionBoundary() {
+  public void testMergedRegionBoundary() {
     TableName tableName =
-        TableName.valueOf("testMeregedRegionBoundary");
+        TableName.valueOf("testMergedRegionBoundary");
     byte[] a = Bytes.toBytes("a");
     byte[] b = Bytes.toBytes("b");
     byte[] z = Bytes.toBytes("z");

http://git-wip-us.apache.org/repos/asf/hbase/blob/6d7a7fa3/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java
index 26b3293..2ade27a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java
@@ -23,10 +23,9 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
+
+import org.mockito.Mockito;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -61,7 +60,6 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-import org.mockito.Mockito;
 
 import com.google.common.collect.ImmutableList;
 
@@ -188,6 +186,26 @@ public class TestSplitTransaction {
   }
 
   /**
+   * Test SplitTransactionListener
+   */
+  @Test public void testSplitTransactionListener() throws IOException {
+    SplitTransactionImpl st = new SplitTransactionImpl(this.parent, GOOD_SPLIT_ROW);
+    SplitTransaction.TransactionListener listener =
+            Mockito.mock(SplitTransaction.TransactionListener.class);
+    st.registerTransactionListener(listener);
+    st.prepare();
+    Server mockServer = Mockito.mock(Server.class);
+    when(mockServer.getConfiguration()).thenReturn(TEST_UTIL.getConfiguration());
+    PairOfSameType<Region> daughters = st.execute(mockServer, null);
+    verify(listener).transition(st, SplitTransaction.SplitTransactionPhase.STARTED,
+            SplitTransaction.SplitTransactionPhase.PREPARED);
+    verify(listener, times(15)).transition(any(SplitTransaction.class),
+            any(SplitTransaction.SplitTransactionPhase.class),
+            any(SplitTransaction.SplitTransactionPhase.class));
+    verifyNoMoreInteractions(listener);
+  }
+
+  /**
    * Pass an unreasonable split row.
    */
   @Test public void testPrepareWithBadSplitRow() throws IOException {


Mime
View raw message