Repository: hbase Updated Branches: refs/heads/branch-1 6d40b7a0e -> 2b5da6f7a
HBASE-13372 Add unit tests for SplitTransaction and RegionMergeTransaction listeners Signed-off-by: Andrew Purtell <apurt...@apache.org> Amending-Author: Andrew Purtell <apurt...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/2b5da6f7 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/2b5da6f7 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/2b5da6f7 Branch: refs/heads/branch-1 Commit: 2b5da6f7a044165801e01356c89df706106958cd Parents: 6d40b7a Author: Gábor Lipták <glip...@gmail.com> Authored: Sat Aug 22 19:39:13 2015 -0400 Committer: Andrew Purtell <apurt...@apache.org> Committed: Mon Apr 18 16:56:59 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/2b5da6f7/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 49f3dce..3ed839b 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; @@ -210,6 +209,35 @@ public class TestRegionMergeTransaction { assertFalse(spyMT.prepare(null)); } + /** + * Test RegionMergeTransactionListener + */ + @Test public void testRegionMergeTransactionListener() throws Exception { + 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); @@ -355,9 +383,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/2b5da6f7/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 d5c9575..b548b65 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; @@ -60,7 +59,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; @@ -187,6 +185,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 {