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.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,10 @@
package org.apache.hadoop.hbase.http.lib;
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.verify;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@ -36,7 +39,6 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@Category({ MiscTests.class, SmallTests.class })
public class TestStaticUserWebFilter {
@ -46,9 +48,8 @@ public class TestStaticUserWebFilter {
HBaseClassTestRule.forClass(TestStaticUserWebFilter.class);
private FilterConfig mockConfig(String username) {
FilterConfig mock = Mockito.mock(FilterConfig.class);
Mockito.doReturn(username).when(mock)
.getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER);
FilterConfig mock = mock(FilterConfig.class);
doReturn(username).when(mock).getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER);
return mock;
}
@ -65,7 +66,7 @@ public class TestStaticUserWebFilter {
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();
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.assertNull;
import static org.mockito.Matchers.any;
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 static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.io.IOException;
@ -57,7 +57,7 @@ public class TestGroupingTableMap {
HBaseClassTestRule.forClass(TestGroupingTableMap.class);
@Test
@SuppressWarnings({ "deprecation", "unchecked" })
@SuppressWarnings("unchecked")
public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes() throws Exception {
GroupingTableMap gTableMap = null;
try {
@ -82,14 +82,14 @@ public class TestGroupingTableMap {
mock(OutputCollector.class);
gTableMap.map(null, result, outputCollectorMock, reporter);
verify(result).listCells();
verifyZeroInteractions(outputCollectorMock);
verifyNoInteractions(outputCollectorMock);
} finally {
if (gTableMap != null) gTableMap.close();
}
}
@Test
@SuppressWarnings({ "deprecation", "unchecked" })
@SuppressWarnings("unchecked")
public void shouldCreateNewKeyAlthoughExtraKey() throws Exception {
GroupingTableMap gTableMap = null;
try {
@ -122,7 +122,6 @@ public class TestGroupingTableMap {
}
@Test
@SuppressWarnings({ "deprecation" })
public void shouldCreateNewKey() throws Exception {
GroupingTableMap gTableMap = null;
try {
@ -171,7 +170,6 @@ public class TestGroupingTableMap {
}
@Test
@SuppressWarnings({ "deprecation" })
public void shouldReturnNullFromCreateGroupKey() throws Exception {
GroupingTableMap gTableMap = null;
try {

View File

@ -20,8 +20,8 @@ package org.apache.hadoop.hbase.mapred;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
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.assertFalse;
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.doReturn;
import static org.mockito.Mockito.doThrow;
@ -207,7 +207,7 @@ public class TestTableInputFormat {
};
Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject());
doAnswer(a).when(htable).getScanner(any(Scan.class));
return htable;
}
@ -240,7 +240,7 @@ public class TestTableInputFormat {
};
Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject());
doAnswer(a).when(htable).getScanner(any(Scan.class));
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.assertTrue;
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.mock;
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.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@ -209,7 +208,7 @@ public class TestTableInputFormat {
};
Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject());
doAnswer(a).when(htable).getScanner(any(Scan.class));
return htable;
}
@ -242,7 +241,7 @@ public class TestTableInputFormat {
};
Table htable = spy(createTable(name));
doAnswer(a).when(htable).getScanner((Scan) anyObject());
doAnswer(a).when(htable).getScanner(any(Scan.class));
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.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
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.assertNull;
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.mock;
import static org.mockito.Mockito.reset;
@ -405,31 +405,31 @@ public class TestMetaTableAccessor {
HBaseTestingUtil.countRows(table);
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
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
// give us three hbase:meta rows
reset(visitor);
doReturn(true).when(visitor).visit((Result) anyObject());
doReturn(true).when(visitor).visit(any());
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:
// region_a and region_b
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);
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
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);
verify(visitor, times(1)).visit((Result) anyObject());
verify(visitor, times(1)).visit(any());
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.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

View File

@ -18,6 +18,12 @@
package org.apache.hadoop.hbase.errorhandling;
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.testclassification.MasterTests;
@ -25,7 +31,6 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,11 +52,11 @@ public class TestTimeoutExceptionInjector {
@Test
public void testTimerTrigger() {
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);
timer.start();
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
public void testTimerPassesOnErrorInfo() {
final long time = 1000000;
ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class);
ForeignExceptionListener listener = mock(ForeignExceptionListener.class);
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
timer.start();
timer.trigger();
Mockito.verify(listener).receive(Mockito.any());
verify(listener).receive(any());
}
/**
@ -74,7 +79,7 @@ public class TestTimeoutExceptionInjector {
@Test
public void testStartAfterComplete() throws InterruptedException {
final long time = 10;
ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class);
ForeignExceptionListener listener = mock(ForeignExceptionListener.class);
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
timer.complete();
try {
@ -84,7 +89,7 @@ public class TestTimeoutExceptionInjector {
LOG.debug("Correctly failed timer: " + e.getMessage());
}
Thread.sleep(time + 1);
Mockito.verifyZeroInteractions(listener);
verifyNoInteractions(listener);
}
/**
@ -94,7 +99,7 @@ public class TestTimeoutExceptionInjector {
@Test
public void testStartAfterTrigger() throws InterruptedException {
final long time = 10;
ForeignExceptionListener listener = Mockito.mock(ForeignExceptionListener.class);
ForeignExceptionListener listener = mock(ForeignExceptionListener.class);
TimeoutExceptionInjector timer = new TimeoutExceptionInjector(listener, time);
timer.trigger();
try {
@ -104,7 +109,7 @@ public class TestTimeoutExceptionInjector {
LOG.debug("Correctly failed timer: " + e.getMessage());
}
Thread.sleep(time * 2);
Mockito.verify(listener, Mockito.times(1)).receive(Mockito.any());
Mockito.verifyNoMoreInteractions(listener);
verify(listener, times(1)).receive(any());
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.assertTrue;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -205,7 +205,7 @@ public class TestExecutorService {
@Override
public boolean evaluate() throws Exception {
try {
verify(server, times(1)).abort(anyString(), (Throwable) anyObject());
verify(server, times(1)).abort(anyString(), any());
return true;
} catch (Throwable t) {
return false;

View File

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

View File

@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.procedure;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
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.reset;
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 java.io.IOException;
@ -420,7 +420,7 @@ public class TestProcedureMember {
}
// no request should reach the pool
verifyZeroInteractions(pool);
verifyNoInteractions(pool);
// get two abort requests
// TODO Need to do another refactor to get this to propagate to the coordinator.
// 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.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@ -291,7 +291,7 @@ public class TestZKProcedure {
Mockito.spy(new ForeignExceptionDispatcher());
Procedure coordinatorTask = Mockito.spy(new Procedure(coordinator, coordinatorTaskErrorMonitor,
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);
// count down the error latch when we get the remote error
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.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -43,7 +44,6 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@ -68,7 +68,7 @@ public class TestFileSystemUtilizationChore {
.reportRegionSizesForQuotas(any(RegionSizeStore.class));
final Region region = mockRegionWithSize(regionSizes);
Mockito.doReturn(Arrays.asList(region)).when(rs).getRegions();
doReturn(Arrays.asList(region)).when(rs).getRegions();
chore.chore();
}
@ -83,7 +83,7 @@ public class TestFileSystemUtilizationChore {
.reportRegionSizesForQuotas(any(RegionSizeStore.class));
final Region region = mockRegionWithSize(regionSizes);
Mockito.doReturn(Arrays.asList(region)).when(rs).getRegions();
doReturn(Arrays.asList(region)).when(rs).getRegions();
chore.chore();
}
@ -107,7 +107,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(r1Sizes);
final Region r2 = mockRegionWithSize(r2Sizes);
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();
}
@ -169,7 +169,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(Arrays.asList(1024L, 2048L));
final Region r2 = mockRegionWithSize(Arrays.asList(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();
}
@ -200,7 +200,7 @@ public class TestFileSystemUtilizationChore {
final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L));
final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L));
// 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();
}
@ -221,7 +221,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(r1Sizes);
final Region r2 = mockSplitParentRegionWithSize(r2Sizes);
Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
chore.chore();
}
@ -241,7 +241,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithSize(r1Sizes);
final Region r2 = mockRegionReplicaWithSize(r2Sizes);
Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
chore.chore();
}
@ -267,7 +267,7 @@ public class TestFileSystemUtilizationChore {
final Region r1 = mockRegionWithHFileLinks(r1StoreFileSizes, r1HFileSizes);
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();
}

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.assertNull;
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.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.junit.Assert.assertEquals;
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.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.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.mock;
import static org.mockito.Mockito.never;
@ -68,7 +68,6 @@ public class TestSpaceQuotaViolationPolicyRefresherChore {
private Configuration conf;
private Connection conn;
@SuppressWarnings("unchecked")
@Before
public void setup() throws IOException {
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.junit.Assert.assertEquals;
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.when;

View File

@ -17,7 +17,7 @@
*/
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.verify;
import static org.mockito.Mockito.when;

View File

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

View File

@ -32,7 +32,9 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@ -182,7 +184,6 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
@ -415,9 +416,8 @@ public class TestHRegion {
long onePutSize = region.getMemStoreDataSize();
assertTrue(onePutSize > 0);
RegionCoprocessorHost mockedCPHost = Mockito.mock(RegionCoprocessorHost.class);
doThrow(new IOException()).when(mockedCPHost)
.postBatchMutate(Mockito.<MiniBatchOperationInProgress<Mutation>> any());
RegionCoprocessorHost mockedCPHost = mock(RegionCoprocessorHost.class);
doThrow(new IOException()).when(mockedCPHost).postBatchMutate(any());
region.setCoprocessorHost(mockedCPHost);
put = new Put(value);
@ -3387,25 +3387,24 @@ public class TestHRegion {
final long initSize = region.getDataInMemoryWithoutWAL();
// save normalCPHost and replaced by mockedCPHost
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
// do below format (from Mockito doc).
Mockito.doAnswer(new Answer<Void>() {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
MiniBatchOperationInProgress<Mutation> mb = invocation.getArgument(0);
mb.addOperationsFromCP(0, new Mutation[] { addPut });
return null;
}
}).when(mockedCPHost).preBatchMutate(Mockito.isA(MiniBatchOperationInProgress.class));
}).when(mockedCPHost).preBatchMutate(isA(MiniBatchOperationInProgress.class));
ColumnFamilyDescriptorBuilder builder =
ColumnFamilyDescriptorBuilder.newBuilder(COLUMN_FAMILY_BYTES);
ScanInfo info = new ScanInfo(CONF, builder.build(), Long.MAX_VALUE, Long.MAX_VALUE,
region.getCellComparator());
Mockito.when(mockedCPHost.preFlushScannerOpen(Mockito.any(HStore.class), Mockito.any()))
.thenReturn(info);
Mockito
.when(mockedCPHost.preFlush(Mockito.any(), Mockito.any(StoreScanner.class), Mockito.any()))
when(mockedCPHost.preFlushScannerOpen(any(HStore.class), any())).thenReturn(info);
when(mockedCPHost.preFlush(any(), any(StoreScanner.class), any()))
.thenAnswer(i -> i.getArgument(1));
region.setCoprocessorHost(mockedCPHost);
@ -5106,8 +5105,8 @@ public class TestHRegion {
public void testStatusSettingToAbortIfAnyExceptionDuringRegionInitilization() throws Exception {
RegionInfo info;
try {
FileSystem fs = Mockito.mock(FileSystem.class);
Mockito.when(fs.exists((Path) Mockito.anyObject())).thenThrow(new IOException());
FileSystem fs = mock(FileSystem.class);
when(fs.exists(any())).thenThrow(new IOException());
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName);
ColumnFamilyDescriptor columnFamilyDescriptor =
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.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doCallRealMethod;
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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import org.apache.commons.lang3.mutable.MutableBoolean;
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.Table;
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.PrepareFlushResult;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.wal.WAL;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Matchers;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
@ -120,9 +116,7 @@ public class TestSplitWalDataLoss {
.abortCacheFlush(region.getRegionInfo().getEncodedNameAsBytes());
throw new DroppedSnapshotException("testcase");
}
}).when(spiedRegion).internalFlushCacheAndCommit(Matchers.<WAL> any(),
Matchers.<MonitoredTask> any(), Matchers.<PrepareFlushResult> any(),
Matchers.<Collection<HStore>> any());
}).when(spiedRegion).internalFlushCacheAndCommit(any(), any(), any(), any());
// Find region key; don't pick up key for hbase:meta by mistake.
String key = null;
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.assertNull;
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.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyLong;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;

View File

@ -824,7 +824,7 @@
<opentelemetry.version>1.15.0</opentelemetry.version>
<opentelemetry-javaagent.version>1.15.0</opentelemetry-javaagent.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>
<thrift.path>thrift</thrift.path>
<thrift.version>0.14.1</thrift.version>
@ -1545,9 +1545,10 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
<artifactId>mockito-bom</artifactId>
<version>${mockito.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>