HBASE-13372 Add unit tests for SplitTransaction and RegionMergeTransaction listeners
Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
31b85e73da
commit
6d7a7fa3aa
|
@ -21,8 +21,7 @@ package org.apache.hadoop.hbase.regionserver;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -211,6 +210,35 @@ public class TestRegionMergeTransaction {
|
||||||
assertFalse(spyMT.prepare(null));
|
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
|
@Test
|
||||||
public void testWholesomeMerge() throws IOException, InterruptedException {
|
public void testWholesomeMerge() throws IOException, InterruptedException {
|
||||||
final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
|
final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
|
||||||
|
@ -356,9 +384,9 @@ public class TestRegionMergeTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMeregedRegionBoundary() {
|
public void testMergedRegionBoundary() {
|
||||||
TableName tableName =
|
TableName tableName =
|
||||||
TableName.valueOf("testMeregedRegionBoundary");
|
TableName.valueOf("testMergedRegionBoundary");
|
||||||
byte[] a = Bytes.toBytes("a");
|
byte[] a = Bytes.toBytes("a");
|
||||||
byte[] b = Bytes.toBytes("b");
|
byte[] b = Bytes.toBytes("b");
|
||||||
byte[] z = Bytes.toBytes("z");
|
byte[] z = Bytes.toBytes("z");
|
||||||
|
|
|
@ -23,10 +23,9 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.doThrow;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import org.mockito.Mockito;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -61,7 +60,6 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
@ -187,6 +185,26 @@ public class TestSplitTransaction {
|
||||||
st.prepare());
|
st.prepare());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Pass an unreasonable split row.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue