HBASE-27598 Upgrade mockito to 4.x (#4998)

Signed-off-by: Yulin Niu <niuyulin@apache.org>
This commit is contained in:
Duo Zhang 2023-01-29 11:29:51 +08:00 committed by GitHub
parent 45fd3f628a
commit bd7a78add5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 134 additions and 143 deletions

View File

@ -42,7 +42,7 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -32,7 +32,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -35,7 +35,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -37,7 +37,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -38,7 +38,7 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -30,7 +30,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -42,7 +42,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -40,7 +40,7 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class) @Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)

View File

@ -18,7 +18,10 @@
package org.apache.hadoop.hbase.http.lib; package org.apache.hadoop.hbase.http.lib;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
@ -36,7 +39,6 @@ import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@Category({ MiscTests.class, SmallTests.class }) @Category({ MiscTests.class, SmallTests.class })
public class TestStaticUserWebFilter { public class TestStaticUserWebFilter {
@ -46,9 +48,8 @@ public class TestStaticUserWebFilter {
HBaseClassTestRule.forClass(TestStaticUserWebFilter.class); HBaseClassTestRule.forClass(TestStaticUserWebFilter.class);
private FilterConfig mockConfig(String username) { private FilterConfig mockConfig(String username) {
FilterConfig mock = Mockito.mock(FilterConfig.class); FilterConfig mock = mock(FilterConfig.class);
Mockito.doReturn(username).when(mock) doReturn(username).when(mock).getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER);
.getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER);
return mock; return mock;
} }
@ -65,7 +66,7 @@ public class TestStaticUserWebFilter {
suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class), chain); suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class), chain);
Mockito.verify(chain).doFilter(wrapperArg.capture(), Mockito.<ServletResponse> anyObject()); verify(chain).doFilter(wrapperArg.capture(), any());
HttpServletRequestWrapper wrapper = wrapperArg.getValue(); HttpServletRequestWrapper wrapper = wrapperArg.getValue();
assertEquals("myuser", wrapper.getUserPrincipal().getName()); assertEquals("myuser", wrapper.getUserPrincipal().getName());

View File

@ -19,12 +19,12 @@ package org.apache.hadoop.hbase.mapred;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.IOException; import java.io.IOException;
@ -57,7 +57,7 @@ public class TestGroupingTableMap {
HBaseClassTestRule.forClass(TestGroupingTableMap.class); HBaseClassTestRule.forClass(TestGroupingTableMap.class);
@Test @Test
@SuppressWarnings({ "deprecation", "unchecked" }) @SuppressWarnings("unchecked")
public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes() throws Exception { public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes() throws Exception {
GroupingTableMap gTableMap = null; GroupingTableMap gTableMap = null;
try { try {
@ -82,14 +82,14 @@ public class TestGroupingTableMap {
mock(OutputCollector.class); mock(OutputCollector.class);
gTableMap.map(null, result, outputCollectorMock, reporter); gTableMap.map(null, result, outputCollectorMock, reporter);
verify(result).listCells(); verify(result).listCells();
verifyZeroInteractions(outputCollectorMock); verifyNoInteractions(outputCollectorMock);
} finally { } finally {
if (gTableMap != null) gTableMap.close(); if (gTableMap != null) gTableMap.close();
} }
} }
@Test @Test
@SuppressWarnings({ "deprecation", "unchecked" }) @SuppressWarnings("unchecked")
public void shouldCreateNewKeyAlthoughExtraKey() throws Exception { public void shouldCreateNewKeyAlthoughExtraKey() throws Exception {
GroupingTableMap gTableMap = null; GroupingTableMap gTableMap = null;
try { try {
@ -122,7 +122,6 @@ public class TestGroupingTableMap {
} }
@Test @Test
@SuppressWarnings({ "deprecation" })
public void shouldCreateNewKey() throws Exception { public void shouldCreateNewKey() throws Exception {
GroupingTableMap gTableMap = null; GroupingTableMap gTableMap = null;
try { try {
@ -171,7 +170,6 @@ public class TestGroupingTableMap {
} }
@Test @Test
@SuppressWarnings({ "deprecation" })
public void shouldReturnNullFromCreateGroupKey() throws Exception { public void shouldReturnNullFromCreateGroupKey() throws Exception {
GroupingTableMap gTableMap = null; GroupingTableMap gTableMap = null;
try { try {

View File

@ -20,8 +20,8 @@ package org.apache.hadoop.hbase.mapred;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.mapred;
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.Matchers.anyObject; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
@ -207,7 +207,7 @@ public class TestTableInputFormat {
}; };
Table htable = spy(createTable(name)); Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject()); doAnswer(a).when(htable).getScanner(any(Scan.class));
return htable; return htable;
} }
@ -240,7 +240,7 @@ public class TestTableInputFormat {
}; };
Table htable = spy(createTable(name)); Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject()); doAnswer(a).when(htable).getScanner(any(Scan.class));
return htable; return htable;
} }

View File

@ -23,7 +23,7 @@ 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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -20,8 +20,7 @@ package org.apache.hadoop.hbase.mapreduce;
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.Matchers.anyObject; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -209,7 +208,7 @@ public class TestTableInputFormat {
}; };
Table htable = spy(createTable(name)); Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject()); doAnswer(a).when(htable).getScanner(any(Scan.class));
return htable; return htable;
} }
@ -242,7 +241,7 @@ public class TestTableInputFormat {
}; };
Table htable = spy(createTable(name)); Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject()); doAnswer(a).when(htable).getScanner(any(Scan.class));
return htable; return htable;
} }

View File

@ -19,8 +19,8 @@ package org.apache.hadoop.hbase.rest.client;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

View File

@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
@ -405,31 +405,31 @@ public class TestMetaTableAccessor {
HBaseTestingUtil.countRows(table); HBaseTestingUtil.countRows(table);
ClientMetaTableAccessor.Visitor visitor = mock(ClientMetaTableAccessor.Visitor.class); ClientMetaTableAccessor.Visitor visitor = mock(ClientMetaTableAccessor.Visitor.class);
doReturn(true).when(visitor).visit((Result) anyObject()); doReturn(true).when(visitor).visit(any());
// Scanning the entire table should give us three rows // Scanning the entire table should give us three rows
MetaTableAccessor.scanMetaForTableRegions(connection, visitor, tableName); MetaTableAccessor.scanMetaForTableRegions(connection, visitor, tableName);
verify(visitor, times(3)).visit((Result) anyObject()); verify(visitor, times(3)).visit(any());
// Scanning the table with a specified empty start row should also // Scanning the table with a specified empty start row should also
// give us three hbase:meta rows // give us three hbase:meta rows
reset(visitor); reset(visitor);
doReturn(true).when(visitor).visit((Result) anyObject()); doReturn(true).when(visitor).visit(any());
MetaTableAccessor.scanMeta(connection, visitor, tableName, null, 1000); MetaTableAccessor.scanMeta(connection, visitor, tableName, null, 1000);
verify(visitor, times(3)).visit((Result) anyObject()); verify(visitor, times(3)).visit(any());
// Scanning the table starting in the middle should give us two rows: // Scanning the table starting in the middle should give us two rows:
// region_a and region_b // region_a and region_b
reset(visitor); reset(visitor);
doReturn(true).when(visitor).visit((Result) anyObject()); doReturn(true).when(visitor).visit(any());
MetaTableAccessor.scanMeta(connection, visitor, tableName, Bytes.toBytes("region_ac"), 1000); MetaTableAccessor.scanMeta(connection, visitor, tableName, Bytes.toBytes("region_ac"), 1000);
verify(visitor, times(2)).visit((Result) anyObject()); verify(visitor, times(2)).visit(any());
// Scanning with a limit of 1 should only give us one row // Scanning with a limit of 1 should only give us one row
reset(visitor); reset(visitor);
doReturn(true).when(visitor).visit((Result) anyObject()); doReturn(true).when(visitor).visit(any());
MetaTableAccessor.scanMeta(connection, visitor, tableName, Bytes.toBytes("region_ac"), 1); MetaTableAccessor.scanMeta(connection, visitor, tableName, Bytes.toBytes("region_ac"), 1);
verify(visitor, times(1)).visit((Result) anyObject()); verify(visitor, times(1)).visit(any());
table.close(); table.close();
} }

View File

@ -20,9 +20,9 @@ package org.apache.hadoop.hbase.client.locking;
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.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.isA; import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

View File

@ -18,6 +18,12 @@
package org.apache.hadoop.hbase.errorhandling; package org.apache.hadoop.hbase.errorhandling;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MasterTests;
@ -25,7 +31,6 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule; import org.junit.ClassRule;
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 org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -47,11 +52,11 @@ public class TestTimeoutExceptionInjector {
@Test @Test
public void testTimerTrigger() { public void testTimerTrigger() {
final long time = 10000000; // pick a value that is very far in the future final long time = 10000000; // pick a value that is very far in the future
ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); ForeignExceptionListener listener = mock(ForeignExceptionListener.class);
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
timer.start(); timer.start();
timer.trigger(); timer.trigger();
Mockito.verify(listener, Mockito.times(1)).receive(Mockito.any()); verify(listener, times(1)).receive(any());
} }
/** /**
@ -60,11 +65,11 @@ public class TestTimeoutExceptionInjector {
@Test @Test
public void testTimerPassesOnErrorInfo() { public void testTimerPassesOnErrorInfo() {
final long time = 1000000; final long time = 1000000;
ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); ForeignExceptionListener listener = mock(ForeignExceptionListener.class);
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
timer.start(); timer.start();
timer.trigger(); timer.trigger();
Mockito.verify(listener).receive(Mockito.any()); verify(listener).receive(any());
} }
/** /**
@ -74,7 +79,7 @@ public class TestTimeoutExceptionInjector {
@Test @Test
public void testStartAfterComplete() throws InterruptedException { public void testStartAfterComplete() throws InterruptedException {
final long time = 10; final long time = 10;
ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); ForeignExceptionListener listener = mock(ForeignExceptionListener.class);
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
timer.complete(); timer.complete();
try { try {
@ -84,7 +89,7 @@ public class TestTimeoutExceptionInjector {
LOG.debug("Correctly failed timer: " + e.getMessage()); LOG.debug("Correctly failed timer: " + e.getMessage());
} }
Thread.sleep(time + 1); Thread.sleep(time + 1);
Mockito.verifyZeroInteractions(listener); verifyNoInteractions(listener);
} }
/** /**
@ -94,7 +99,7 @@ public class TestTimeoutExceptionInjector {
@Test @Test
public void testStartAfterTrigger() throws InterruptedException { public void testStartAfterTrigger() throws InterruptedException {
final long time = 10; final long time = 10;
ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class); ForeignExceptionListener listener = mock(ForeignExceptionListener.class);
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time); TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
timer.trigger(); timer.trigger();
try { try {
@ -104,7 +109,7 @@ public class TestTimeoutExceptionInjector {
LOG.debug("Correctly failed timer: " + e.getMessage()); LOG.debug("Correctly failed timer: " + e.getMessage());
} }
Thread.sleep(time * 2); Thread.sleep(time * 2);
Mockito.verify(listener, Mockito.times(1)).receive(Mockito.any()); verify(listener, times(1)).receive(any());
Mockito.verifyNoMoreInteractions(listener); verifyNoMoreInteractions(listener);
} }
} }

View File

@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.executor;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
@ -205,7 +205,7 @@ public class TestExecutorService {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
try { try {
verify(server, times(1)).abort(anyString(), (Throwable) anyObject()); verify(server, times(1)).abort(anyString(), any());
return true; return true;
} catch (Throwable t) { } catch (Throwable t) {
return false; return false;

View File

@ -17,8 +17,8 @@
*/ */
package org.apache.hadoop.hbase.procedure; package org.apache.hadoop.hbase.procedure;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;

View File

@ -19,10 +19,10 @@ package org.apache.hadoop.hbase.procedure;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyListOf; import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
@ -111,7 +111,7 @@ public class TestProcedureCoordinator {
Procedure proc2 = new Procedure(coordinator, monitor, WAKE_FREQUENCY, TIMEOUT, procName + "2", Procedure proc2 = new Procedure(coordinator, monitor, WAKE_FREQUENCY, TIMEOUT, procName + "2",
procData, expected); procData, expected);
Procedure procSpy2 = spy(proc2); Procedure procSpy2 = spy(proc2);
when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList()))
.thenReturn(procSpy, procSpy2); .thenReturn(procSpy, procSpy2);
coordinator.startProcedure(procSpy.getErrorMonitor(), procName, procData, expected); coordinator.startProcedure(procSpy.getErrorMonitor(), procName, procData, expected);
@ -132,13 +132,12 @@ public class TestProcedureCoordinator {
new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected); new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected);
final Procedure procSpy = spy(proc); final Procedure procSpy = spy(proc);
when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList()))
.thenReturn(procSpy); .thenReturn(procSpy);
// use the passed controller responses // use the passed controller responses
IOException cause = new IOException("Failed to reach comms during acquire"); IOException cause = new IOException("Failed to reach comms during acquire");
doThrow(cause).when(controller).sendGlobalBarrierAcquire(eq(procSpy), eq(procData), doThrow(cause).when(controller).sendGlobalBarrierAcquire(eq(procSpy), eq(procData), anyList());
anyListOf(String.class));
// run the operation // run the operation
proc = coordinator.startProcedure(proc.getErrorMonitor(), procName, procData, expected); proc = coordinator.startProcedure(proc.getErrorMonitor(), procName, procData, expected);
@ -148,7 +147,7 @@ public class TestProcedureCoordinator {
verify(procSpy, atLeastOnce()).receive(any()); verify(procSpy, atLeastOnce()).receive(any());
verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause)); verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause));
verify(controller, times(1)).sendGlobalBarrierAcquire(procSpy, procData, expected); verify(controller, times(1)).sendGlobalBarrierAcquire(procSpy, procData, expected);
verify(controller, never()).sendGlobalBarrierReached(any(), anyListOf(String.class)); verify(controller, never()).sendGlobalBarrierReached(any(), anyList());
} }
/** /**
@ -163,14 +162,13 @@ public class TestProcedureCoordinator {
final Procedure spy = final Procedure spy =
spy(new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected)); spy(new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected));
when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList())).thenReturn(spy);
.thenReturn(spy);
// use the passed controller responses // use the passed controller responses
IOException cause = new IOException("Failed to reach controller during prepare"); IOException cause = new IOException("Failed to reach controller during prepare");
doAnswer(new AcquireBarrierAnswer(procName, new String[] { "cohort" })).when(controller) doAnswer(new AcquireBarrierAnswer(procName, new String[] { "cohort" })).when(controller)
.sendGlobalBarrierAcquire(eq(spy), eq(procData), anyListOf(String.class)); .sendGlobalBarrierAcquire(eq(spy), eq(procData), anyList());
doThrow(cause).when(controller).sendGlobalBarrierReached(eq(spy), anyListOf(String.class)); doThrow(cause).when(controller).sendGlobalBarrierReached(eq(spy), anyList());
// run the operation // run the operation
Procedure task = Procedure task =
@ -180,9 +178,8 @@ public class TestProcedureCoordinator {
; ;
verify(spy, atLeastOnce()).receive(any()); verify(spy, atLeastOnce()).receive(any());
verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause)); verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause));
verify(controller, times(1)).sendGlobalBarrierAcquire(eq(spy), eq(procData), verify(controller, times(1)).sendGlobalBarrierAcquire(eq(spy), eq(procData), anyList());
anyListOf(String.class)); verify(controller, times(1)).sendGlobalBarrierReached(any(), anyList());
verify(controller, times(1)).sendGlobalBarrierReached(any(), anyListOf(String.class));
} }
@Test @Test
@ -273,13 +270,11 @@ public class TestProcedureCoordinator {
public void runCoordinatedOperation(Procedure spy, AcquireBarrierAnswer prepareOperation, public void runCoordinatedOperation(Procedure spy, AcquireBarrierAnswer prepareOperation,
BarrierAnswer commitOperation, String... cohort) throws Exception { BarrierAnswer commitOperation, String... cohort) throws Exception {
List<String> expected = Arrays.asList(cohort); List<String> expected = Arrays.asList(cohort);
when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyList())).thenReturn(spy);
.thenReturn(spy);
// use the passed controller responses // use the passed controller responses
doAnswer(prepareOperation).when(controller).sendGlobalBarrierAcquire(spy, procData, expected); doAnswer(prepareOperation).when(controller).sendGlobalBarrierAcquire(spy, procData, expected);
doAnswer(commitOperation).when(controller).sendGlobalBarrierReached(eq(spy), doAnswer(commitOperation).when(controller).sendGlobalBarrierReached(eq(spy), anyList());
anyListOf(String.class));
// run the operation // run the operation
Procedure task = Procedure task =
@ -294,7 +289,7 @@ public class TestProcedureCoordinator {
inorder.verify(spy).sendGlobalBarrierStart(); inorder.verify(spy).sendGlobalBarrierStart();
inorder.verify(controller).sendGlobalBarrierAcquire(task, procData, expected); inorder.verify(controller).sendGlobalBarrierAcquire(task, procData, expected);
inorder.verify(spy).sendGlobalBarrierReached(); inorder.verify(spy).sendGlobalBarrierReached();
inorder.verify(controller).sendGlobalBarrierReached(eq(task), anyListOf(String.class)); inorder.verify(controller).sendGlobalBarrierReached(eq(task), anyList());
} }
private static abstract class OperationAnswer implements Answer<Void> { private static abstract class OperationAnswer implements Answer<Void> {

View File

@ -17,9 +17,9 @@
*/ */
package org.apache.hadoop.hbase.procedure; package org.apache.hadoop.hbase.procedure;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.IOException; import java.io.IOException;
@ -420,7 +420,7 @@ public class TestProcedureMember {
} }
// no request should reach the pool // no request should reach the pool
verifyZeroInteractions(pool); verifyNoInteractions(pool);
// get two abort requests // get two abort requests
// TODO Need to do another refactor to get this to propagate to the coordinator. // TODO Need to do another refactor to get this to propagate to the coordinator.
// verify(mockMemberComms, times(2)).sendMemberAborted(any(), any()); // verify(mockMemberComms, times(2)).sendMemberAborted(any(), any());

View File

@ -19,9 +19,9 @@ package org.apache.hadoop.hbase.procedure;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyListOf; import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -291,7 +291,7 @@ public class TestZKProcedure {
Mockito.spy(new ForeignExceptionDispatcher()); Mockito.spy(new ForeignExceptionDispatcher());
Procedure coordinatorTask = Mockito.spy(new Procedure(coordinator, coordinatorTaskErrorMonitor, Procedure coordinatorTask = Mockito.spy(new Procedure(coordinator, coordinatorTaskErrorMonitor,
WAKE_FREQUENCY, TIMEOUT, opName, data, expected)); WAKE_FREQUENCY, TIMEOUT, opName, data, expected));
when(coordinator.createProcedure(any(), eq(opName), eq(data), anyListOf(String.class))) when(coordinator.createProcedure(any(), eq(opName), eq(data), anyList()))
.thenReturn(coordinatorTask); .thenReturn(coordinatorTask);
// count down the error latch when we get the remote error // count down the error latch when we get the remote error
Mockito.doAnswer(new Answer<Void>() { Mockito.doAnswer(new Answer<Void>() {

View File

@ -19,8 +19,9 @@ package org.apache.hadoop.hbase.quotas;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -43,7 +44,6 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule; import org.junit.ClassRule;
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 org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
@ -68,7 +68,7 @@ public class TestFileSystemUtilizationChore {
.reportRegionSizesForQuotas(any(RegionSizeStore.class)); .reportRegionSizesForQuotas(any(RegionSizeStore.class));
final Region region = mockRegionWithSize(regionSizes); final Region region = mockRegionWithSize(regionSizes);
Mockito.doReturn(Arrays.asList(region)).when(rs).getRegions(); doReturn(Arrays.asList(region)).when(rs).getRegions();
chore.chore(); chore.chore();
} }
@ -83,7 +83,7 @@ public class TestFileSystemUtilizationChore {
.reportRegionSizesForQuotas(any(RegionSizeStore.class)); .reportRegionSizesForQuotas(any(RegionSizeStore.class));
final Region region = mockRegionWithSize(regionSizes); final Region region = mockRegionWithSize(regionSizes);
Mockito.doReturn(Arrays.asList(region)).when(rs).getRegions(); doReturn(Arrays.asList(region)).when(rs).getRegions();
chore.chore(); chore.chore();
} }
@ -107,7 +107,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(r1Sizes); final Region r1 = mockRegionWithSize(r1Sizes);
final Region r2 = mockRegionWithSize(r2Sizes); final Region r2 = mockRegionWithSize(r2Sizes);
final Region r3 = mockRegionWithSize(r3Sizes); final Region r3 = mockRegionWithSize(r3Sizes);
Mockito.doReturn(Arrays.asList(r1, r2, r3)).when(rs).getRegions(); doReturn(Arrays.asList(r1, r2, r3)).when(rs).getRegions();
chore.chore(); chore.chore();
} }
@ -169,7 +169,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(Arrays.asList(1024L, 2048L)); final Region r1 = mockRegionWithSize(Arrays.asList(1024L, 2048L));
final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L)); final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L));
final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L)); final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L));
Mockito.doReturn(Arrays.asList(r1, r2, r3, lr1, lr2)).when(rs).getRegions(); doReturn(Arrays.asList(r1, r2, r3, lr1, lr2)).when(rs).getRegions();
chore.chore(); chore.chore();
} }
@ -200,7 +200,7 @@ public class TestFileSystemUtilizationChore {
final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L)); final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L));
final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L)); final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L));
// lr2 is no longer online, so it should be ignored // lr2 is no longer online, so it should be ignored
Mockito.doReturn(Arrays.asList(r1, r2, r3, lr1)).when(rs).getRegions(); doReturn(Arrays.asList(r1, r2, r3, lr1)).when(rs).getRegions();
chore.chore(); chore.chore();
} }
@ -221,7 +221,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(r1Sizes); final Region r1 = mockRegionWithSize(r1Sizes);
final Region r2 = mockSplitParentRegionWithSize(r2Sizes); final Region r2 = mockSplitParentRegionWithSize(r2Sizes);
Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
chore.chore(); chore.chore();
} }
@ -241,7 +241,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(r1Sizes); final Region r1 = mockRegionWithSize(r1Sizes);
final Region r2 = mockRegionReplicaWithSize(r2Sizes); final Region r2 = mockRegionReplicaWithSize(r2Sizes);
Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
chore.chore(); chore.chore();
} }
@ -267,7 +267,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithHFileLinks(r1StoreFileSizes, r1HFileSizes); final Region r1 = mockRegionWithHFileLinks(r1StoreFileSizes, r1HFileSizes);
final Region r2 = mockRegionWithHFileLinks(r2StoreFileSizes, r2HFileSizes); final Region r2 = mockRegionWithHFileLinks(r2StoreFileSizes, r2HFileSizes);
Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions(); doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
chore.chore(); chore.chore();
} }

View File

@ -22,7 +22,7 @@ import static org.apache.hadoop.hbase.quotas.MasterQuotasObserver.REMOVE_QUOTA_O
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.quotas;
import static org.apache.hbase.thirdparty.com.google.common.collect.Iterables.size; import static org.apache.hbase.thirdparty.com.google.common.collect.Iterables.size;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.quotas;
import static org.apache.hadoop.hbase.util.Bytes.toBytes; import static org.apache.hadoop.hbase.util.Bytes.toBytes;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@ -68,7 +68,6 @@ public class TestSpaceQuotaViolationPolicyRefresherChore {
private Configuration conf; private Configuration conf;
private Connection conn; private Connection conn;
@SuppressWarnings("unchecked")
@Before @Before
public void setup() throws IOException { public void setup() throws IOException {
conf = HBaseConfiguration.create(); conf = HBaseConfiguration.create();

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.quotas;
import static org.apache.hbase.thirdparty.com.google.common.collect.Iterables.size; import static org.apache.hbase.thirdparty.com.google.common.collect.Iterables.size;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -17,7 +17,7 @@
*/ */
package org.apache.hadoop.hbase.quotas; package org.apache.hadoop.hbase.quotas;
import static org.mockito.Matchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -17,8 +17,8 @@
*/ */
package org.apache.hadoop.hbase.regionserver; package org.apache.hadoop.hbase.regionserver;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -19,7 +19,11 @@ package org.apache.hadoop.hbase.regionserver;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.IOException; import java.io.IOException;
@ -53,7 +57,6 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.rules.TestName; import org.junit.rules.TestName;
import org.mockito.Mockito;
import org.mockito.exceptions.verification.WantedButNotInvoked; import org.mockito.exceptions.verification.WantedButNotInvoked;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -249,8 +252,7 @@ public class TestFailedAppendAndSync {
// to just continue. // to just continue.
// So, should be no abort at this stage. Verify. // So, should be no abort at this stage. Verify.
Mockito.verify(services, Mockito.atLeast(0)).abort(Mockito.anyString(), verify(services, atLeast(0)).abort(anyString(), any(Throwable.class));
Mockito.any(Throwable.class));
try { try {
dodgyWAL.throwAppendException = false; dodgyWAL.throwAppendException = false;
dodgyWAL.throwSyncException = true; dodgyWAL.throwSyncException = true;
@ -265,8 +267,7 @@ public class TestFailedAppendAndSync {
// happens. If it don't we'll timeout the whole test. That is fine. // happens. If it don't we'll timeout the whole test. That is fine.
while (true) { while (true) {
try { try {
Mockito.verify(services, Mockito.atLeast(1)).abort(Mockito.anyString(), verify(services, atLeast(1)).abort(anyString(), any(Throwable.class));
Mockito.any(Throwable.class));
break; break;
} catch (WantedButNotInvoked t) { } catch (WantedButNotInvoked t) {
Threads.sleep(1); Threads.sleep(1);
@ -286,8 +287,7 @@ public class TestFailedAppendAndSync {
while (true) { while (true) {
try { try {
// one more abort needs to be called // one more abort needs to be called
Mockito.verify(services, Mockito.atLeast(2)).abort(Mockito.anyString(), verify(services, atLeast(2)).abort(anyString(), any());
(Throwable) Mockito.anyObject());
break; break;
} catch (WantedButNotInvoked t) { } catch (WantedButNotInvoked t) {
Threads.sleep(1); Threads.sleep(1);
@ -295,7 +295,7 @@ public class TestFailedAppendAndSync {
} }
} finally { } finally {
// To stop logRoller, its server has to say it is stopped. // To stop logRoller, its server has to say it is stopped.
Mockito.when(services.isStopped()).thenReturn(true); when(services.isStopped()).thenReturn(true);
if (logRoller != null) logRoller.close(); if (logRoller != null) logRoller.close();
if (region != null) { if (region != null) {
try { try {

View File

@ -32,7 +32,9 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@ -182,7 +184,6 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TestName; import org.junit.rules.TestName;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher; import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -415,9 +416,8 @@ public class TestHRegion {
long onePutSize = region.getMemStoreDataSize(); long onePutSize = region.getMemStoreDataSize();
assertTrue(onePutSize > 0); assertTrue(onePutSize > 0);
RegionCoprocessorHost mockedCPHost = Mockito.mock(RegionCoprocessorHost.class); RegionCoprocessorHost mockedCPHost = mock(RegionCoprocessorHost.class);
doThrow(new IOException()).when(mockedCPHost) doThrow(new IOException()).when(mockedCPHost).postBatchMutate(any());
.postBatchMutate(Mockito.<MiniBatchOperationInProgress<Mutation>> any());
region.setCoprocessorHost(mockedCPHost); region.setCoprocessorHost(mockedCPHost);
put = new Put(value); put = new Put(value);
@ -3387,25 +3387,24 @@ public class TestHRegion {
final long initSize = region.getDataInMemoryWithoutWAL(); final long initSize = region.getDataInMemoryWithoutWAL();
// save normalCPHost and replaced by mockedCPHost // save normalCPHost and replaced by mockedCPHost
RegionCoprocessorHost normalCPHost = region.getCoprocessorHost(); RegionCoprocessorHost normalCPHost = region.getCoprocessorHost();
RegionCoprocessorHost mockedCPHost = Mockito.mock(RegionCoprocessorHost.class); RegionCoprocessorHost mockedCPHost = mock(RegionCoprocessorHost.class);
// Because the preBatchMutate returns void, we can't do usual Mockito when...then form. Must // Because the preBatchMutate returns void, we can't do usual Mockito when...then form. Must
// do below format (from Mockito doc). // do below format (from Mockito doc).
Mockito.doAnswer(new Answer<Void>() { doAnswer(new Answer<Void>() {
@Override @Override
public Void answer(InvocationOnMock invocation) throws Throwable { public Void answer(InvocationOnMock invocation) throws Throwable {
MiniBatchOperationInProgress<Mutation> mb = invocation.getArgument(0); MiniBatchOperationInProgress<Mutation> mb = invocation.getArgument(0);
mb.addOperationsFromCP(0, new Mutation[] { addPut }); mb.addOperationsFromCP(0, new Mutation[] { addPut });
return null; return null;
} }
}).when(mockedCPHost).preBatchMutate(Mockito.isA(MiniBatchOperationInProgress.class)); }).when(mockedCPHost).preBatchMutate(isA(MiniBatchOperationInProgress.class));
ColumnFamilyDescriptorBuilder builder = ColumnFamilyDescriptorBuilder builder =
ColumnFamilyDescriptorBuilder.newBuilder(COLUMN_FAMILY_BYTES); ColumnFamilyDescriptorBuilder.newBuilder(COLUMN_FAMILY_BYTES);
ScanInfo info = new ScanInfo(CONF, builder.build(), Long.MAX_VALUE, Long.MAX_VALUE, ScanInfo info = new ScanInfo(CONF, builder.build(), Long.MAX_VALUE, Long.MAX_VALUE,
region.getCellComparator()); region.getCellComparator());
Mockito.when(mockedCPHost.preFlushScannerOpen(Mockito.any(HStore.class), Mockito.any())) when(mockedCPHost.preFlushScannerOpen(any(HStore.class), any())).thenReturn(info);
.thenReturn(info);
Mockito when(mockedCPHost.preFlush(any(), any(StoreScanner.class), any()))
.when(mockedCPHost.preFlush(Mockito.any(), Mockito.any(StoreScanner.class), Mockito.any()))
.thenAnswer(i -> i.getArgument(1)); .thenAnswer(i -> i.getArgument(1));
region.setCoprocessorHost(mockedCPHost); region.setCoprocessorHost(mockedCPHost);
@ -5106,8 +5105,8 @@ public class TestHRegion {
public void testStatusSettingToAbortIfAnyExceptionDuringRegionInitilization() throws Exception { public void testStatusSettingToAbortIfAnyExceptionDuringRegionInitilization() throws Exception {
RegionInfo info; RegionInfo info;
try { try {
FileSystem fs = Mockito.mock(FileSystem.class); FileSystem fs = mock(FileSystem.class);
Mockito.when(fs.exists((Path) Mockito.anyObject())).thenThrow(new IOException()); when(fs.exists(any())).thenThrow(new IOException());
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName);
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptor columnFamilyDescriptor =
ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")).build(); ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")).build();

View File

@ -20,8 +20,8 @@ package org.apache.hadoop.hbase.regionserver;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@ -19,11 +19,11 @@ package org.apache.hadoop.hbase.regionserver;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import java.io.IOException; import java.io.IOException;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.hadoop.hbase.DroppedSnapshotException; import org.apache.hadoop.hbase.DroppedSnapshotException;
@ -40,19 +40,15 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.monitoring.MonitoredTask;
import org.apache.hadoop.hbase.regionserver.HRegion.FlushResult; import org.apache.hadoop.hbase.regionserver.HRegion.FlushResult;
import org.apache.hadoop.hbase.regionserver.HRegion.PrepareFlushResult;
import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.wal.WAL;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.mockito.Matchers;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -120,9 +116,7 @@ public class TestSplitWalDataLoss {
.abortCacheFlush(region.getRegionInfo().getEncodedNameAsBytes()); .abortCacheFlush(region.getRegionInfo().getEncodedNameAsBytes());
throw new DroppedSnapshotException("testcase"); throw new DroppedSnapshotException("testcase");
} }
}).when(spiedRegion).internalFlushCacheAndCommit(Matchers.<WAL> any(), }).when(spiedRegion).internalFlushCacheAndCommit(any(), any(), any(), any());
Matchers.<MonitoredTask> any(), Matchers.<PrepareFlushResult> any(),
Matchers.<Collection<HStore>> any());
// Find region key; don't pick up key for hbase:meta by mistake. // Find region key; don't pick up key for hbase:meta by mistake.
String key = null; String key = null;
for (Map.Entry<String, HRegion> entry : rs.getOnlineRegions().entrySet()) { for (Map.Entry<String, HRegion> entry : rs.getOnlineRegions().entrySet()) {

View File

@ -25,10 +25,10 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -21,8 +21,8 @@ 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.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;

View File

@ -824,7 +824,7 @@
<opentelemetry.version>1.15.0</opentelemetry.version> <opentelemetry.version>1.15.0</opentelemetry.version>
<opentelemetry-javaagent.version>1.15.0</opentelemetry-javaagent.version> <opentelemetry-javaagent.version>1.15.0</opentelemetry-javaagent.version>
<log4j2.version>2.17.2</log4j2.version> <log4j2.version>2.17.2</log4j2.version>
<mockito-core.version>2.28.2</mockito-core.version> <mockito.version>4.11.0</mockito.version>
<protobuf.plugin.version>0.6.1</protobuf.plugin.version> <protobuf.plugin.version>0.6.1</protobuf.plugin.version>
<thrift.path>thrift</thrift.path> <thrift.path>thrift</thrift.path>
<thrift.version>0.14.1</thrift.version> <thrift.version>0.14.1</thrift.version>
@ -1545,9 +1545,10 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-bom</artifactId>
<version>${mockito-core.version}</version> <version>${mockito.version}</version>
<scope>test</scope> <type>pom</type>
<scope>import</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.opentelemetry</groupId> <groupId>io.opentelemetry</groupId>