Repository: hbase Updated Branches: refs/heads/branch-1.2 e8aa66ec0 -> 80be32720
HBASE-14502 Purge use of jmock and remove as dependency (Gabor Liptak) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/80be3272 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/80be3272 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/80be3272 Branch: refs/heads/branch-1.2 Commit: 80be32720b3965b68ea1627e4cae2e45e674318b Parents: e8aa66e Author: stack <[email protected]> Authored: Tue Oct 6 23:09:50 2015 -0700 Committer: stack <[email protected]> Committed: Tue Oct 6 23:10:34 2015 -0700 ---------------------------------------------------------------------- hbase-resource-bundle/pom.xml | 5 - .../hadoop/hbase/regionserver/TestBulkLoad.java | 127 ++++++++++--------- pom.xml | 17 --- 3 files changed, 67 insertions(+), 82 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/80be3272/hbase-resource-bundle/pom.xml ---------------------------------------------------------------------- diff --git a/hbase-resource-bundle/pom.xml b/hbase-resource-bundle/pom.xml index cc9e1bd..a835e43 100644 --- a/hbase-resource-bundle/pom.xml +++ b/hbase-resource-bundle/pom.xml @@ -58,11 +58,6 @@ <artifactId>mockito-all</artifactId> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.jmock</groupId> - <artifactId>jmock-junit4</artifactId> - <scope>provided</scope> - </dependency> </dependencies> <build> <plugins> http://git-wip-us.apache.org/repos/asf/hbase/blob/80be3272/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java index 1e10511..092f3ef 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java @@ -57,11 +57,14 @@ import org.apache.hadoop.hbase.wal.WALKey; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import org.jmock.Expectations; -import org.jmock.api.Action; -import org.jmock.api.Invocation; -import org.jmock.integration.junit4.JUnitRuleMockery; -import org.jmock.lib.concurrent.Synchroniser; + +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -78,54 +81,15 @@ public class TestBulkLoad { @ClassRule public static TemporaryFolder testFolder = new TemporaryFolder(); - @Rule - public final JUnitRuleMockery context = new JUnitRuleMockery() {{ - setThreadingPolicy(new Synchroniser()); - }}; - private final WAL log = context.mock(WAL.class); + private final WAL log = mock(WAL.class); private final Configuration conf = HBaseConfiguration.create(); private final Random random = new Random(); private final byte[] randomBytes = new byte[100]; private final byte[] family1 = Bytes.toBytes("family1"); private final byte[] family2 = Bytes.toBytes("family2"); - private final Expectations callOnce; @Rule public TestName name = new TestName(); - private static class AppendAction implements Action { - @Override - public void describeTo(Description arg0) { - // TODO Auto-generated method stub - } - - @Override - public Object invoke(Invocation invocation) throws Throwable { - WALKey walKey = (WALKey)invocation.getParameter(2); - MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); - if (mvcc != null) { - MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); - walKey.setWriteEntry(we); - } - return 01L; - } - - public static Action append(Object... args) { - return new AppendAction(); - } - } - - public TestBulkLoad() throws IOException { - callOnce = new Expectations() { - { - oneOf(log).append(with(any(HTableDescriptor.class)), with(any(HRegionInfo.class)), - with(any(WALKey.class)), with(bulkLogWalEditType(WALEdit.BULK_LOAD)), - with(any(boolean.class))); - will(AppendAction.append()); - oneOf(log).sync(with(any(long.class))); - } - }; - } - @Before public void before() throws IOException { random.nextBytes(randomBytes); @@ -141,19 +105,23 @@ public class TestBulkLoad { storeFileName = (new Path(storeFileName)).getName(); List<String> storeFileNames = new ArrayList<String>(); storeFileNames.add(storeFileName); - final Matcher<WALEdit> bulkEventMatcher = bulkLogWalEdit(WALEdit.BULK_LOAD, - tableName.toBytes(), familyName, storeFileNames); - Expectations expection = new Expectations() { - { - oneOf(log).append(with(any(HTableDescriptor.class)), with(any(HRegionInfo.class)), - with(any(WALKey.class)), with(bulkEventMatcher), with(any(boolean.class))); - will(new AppendAction()); - oneOf(log).sync(with(any(long.class))); - } - }; - context.checking(expection); + when(log.append(any(HTableDescriptor.class), any(HRegionInfo.class), any(WALKey.class), + argThat(bulkLogWalEdit(WALEdit.BULK_LOAD, tableName.toBytes(), + familyName, storeFileNames)), + any(boolean.class))).thenAnswer(new Answer() { + public Object answer(InvocationOnMock invocation) { + WALKey walKey = invocation.getArgumentAt(2, WALKey.class); + MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); + if (mvcc != null) { + MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); + walKey.setWriteEntry(we); + } + return 01L; + }; + }); testRegionWithFamiliesAndSpecifiedTableName(tableName, family1) .bulkLoadHFiles(familyPaths, false, null); + verify(log).sync(anyLong()); } @Test @@ -164,23 +132,62 @@ public class TestBulkLoad { @Test public void shouldBulkLoadSingleFamilyHLog() throws IOException { - context.checking(callOnce); + when(log.append(any(HTableDescriptor.class), any(HRegionInfo.class), + any(WALKey.class), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD)), + any(boolean.class))).thenAnswer(new Answer() { + public Object answer(InvocationOnMock invocation) { + WALKey walKey = invocation.getArgumentAt(2, WALKey.class); + MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); + if (mvcc != null) { + MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); + walKey.setWriteEntry(we); + } + return 01L; + }; + }); testRegionWithFamilies(family1).bulkLoadHFiles(withFamilyPathsFor(family1), false, null); + verify(log).sync(anyLong()); } @Test public void shouldBulkLoadManyFamilyHLog() throws IOException { - context.checking(callOnce); + when(log.append(any(HTableDescriptor.class), any(HRegionInfo.class), + any(WALKey.class), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD)), + any(boolean.class))).thenAnswer(new Answer() { + public Object answer(InvocationOnMock invocation) { + WALKey walKey = invocation.getArgumentAt(2, WALKey.class); + MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); + if (mvcc != null) { + MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); + walKey.setWriteEntry(we); + } + return 01L; + }; + }); testRegionWithFamilies(family1, family2).bulkLoadHFiles(withFamilyPathsFor(family1, family2), - false, null); + false, null); + verify(log).sync(anyLong()); } @Test public void shouldBulkLoadManyFamilyHLogEvenWhenTableNameNamespaceSpecified() throws IOException { - context.checking(callOnce); + when(log.append(any(HTableDescriptor.class), any(HRegionInfo.class), + any(WALKey.class), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD)), + any(boolean.class))).thenAnswer(new Answer() { + public Object answer(InvocationOnMock invocation) { + WALKey walKey = invocation.getArgumentAt(2, WALKey.class); + MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); + if (mvcc != null) { + MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); + walKey.setWriteEntry(we); + } + return 01L; + }; + }); TableName tableName = TableName.valueOf("test", "test"); testRegionWithFamiliesAndSpecifiedTableName(tableName, family1, family2) .bulkLoadHFiles(withFamilyPathsFor(family1, family2), false, null); + verify(log).sync(anyLong()); } @Test(expected = DoNotRetryIOException.class) http://git-wip-us.apache.org/repos/asf/hbase/blob/80be3272/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 032ac10..7f9dfcb 100644 --- a/pom.xml +++ b/pom.xml @@ -1180,7 +1180,6 @@ <jetty.version>6.1.26</jetty.version> <jetty.jspapi.version>6.1.14</jetty.jspapi.version> <jersey.version>1.9</jersey.version> - <jmock-junit4.version>2.6.0</jmock-junit4.version> <jruby.version>1.6.8</jruby.version> <junit.version>4.12</junit.version> <hamcrest.version>1.3</hamcrest.version> @@ -1730,18 +1729,6 @@ <version>${spy.version}</version> <optional>true</optional> </dependency> - <dependency> - <groupId>org.jmock</groupId> - <artifactId>jmock-junit4</artifactId> - <version>${jmock-junit4.version}</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>junit-dep</artifactId> - <groupId>junit</groupId> - </exclusion> - </exclusions> - </dependency> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk16</artifactId> @@ -1771,10 +1758,6 @@ <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> </dependency> - <dependency> - <groupId>org.jmock</groupId> - <artifactId>jmock-junit4</artifactId> - </dependency> </dependencies> <!-- To publish, use the following settings.xml file ( placed in ~/.m2/settings.xml )
