HADOOP-14178. Move Mockito up to version 2.23.4. Contributed by Akira Ajisaka and Masatake Iwasaki.

This commit is contained in:
Akira Ajisaka 2019-01-29 18:29:09 -08:00
parent 02eb91856e
commit 1129288cf5
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
335 changed files with 1069 additions and 1346 deletions

View File

@ -667,7 +667,7 @@ spin.js v2.3.2
Azure Data Lake Store - Java client SDK 2.0.11 Azure Data Lake Store - Java client SDK 2.0.11
JCodings 1.0.8 JCodings 1.0.8
Joni 2.1.2 Joni 2.1.2
Mockito 1.8.5 Mockito 2.23.4
JUL to SLF4J bridge 1.7.25 JUL to SLF4J bridge 1.7.25
SLF4J API Module 1.7.25 SLF4J API Module 1.7.25
SLF4J LOG4J-12 Binding 1.7.25 SLF4J LOG4J-12 Binding 1.7.25

View File

@ -385,7 +385,7 @@
<!-- Add back in Mockito since the hadoop-hdfs test jar needs it. --> <!-- Add back in Mockito since the hadoop-hdfs test jar needs it. -->
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- Add back in the transitive dependencies excluded from hadoop-common in client TODO remove once we have a filter for "is in these artifacts" --> <!-- Add back in the transitive dependencies excluded from hadoop-common in client TODO remove once we have a filter for "is in these artifacts" -->
@ -729,7 +729,7 @@
<!-- Mockito tries to include its own unrelocated copy of hamcrest. :( --> <!-- Mockito tries to include its own unrelocated copy of hamcrest. :( -->
<filter> <filter>
<artifact>org.mockito:mockito-all</artifact> <artifact>org.mockito:mockito-core</artifact>
<excludes> <excludes>
<exclude>asm-license.txt</exclude> <exclude>asm-license.txt</exclude>
<exclude>cglib-license.txt</exclude> <exclude>cglib-license.txt</exclude>

View File

@ -48,7 +48,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -47,6 +47,7 @@
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
public class TestAuthenticationFilter { public class TestAuthenticationFilter {
@ -533,7 +534,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return null; return null;
} }
} }
).when(chain).doFilter(Mockito.<ServletRequest>anyObject(), Mockito.<ServletResponse>anyObject()); ).when(chain).doFilter(any(), any());
Mockito.when(response.containsHeader("WWW-Authenticate")).thenReturn(true); Mockito.when(response.containsHeader("WWW-Authenticate")).thenReturn(true);
filter.doFilter(request, response, chain); filter.doFilter(request, response, chain);
@ -616,8 +617,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Assert.assertNotNull("cookie missing", v); Assert.assertNotNull("cookie missing", v);
Assert.assertTrue(v.contains("u=") && v.contains("p=") && v.contains Assert.assertTrue(v.contains("u=") && v.contains("p=") && v.contains
("t=") && v.contains("e=") && v.contains("s=")); ("t=") && v.contains("e=") && v.contains("s="));
Mockito.verify(chain).doFilter(Mockito.any(ServletRequest.class), Mockito.verify(chain).doFilter(any(ServletRequest.class),
Mockito.any(ServletResponse.class)); any(ServletResponse.class));
SignerSecretProvider secretProvider = SignerSecretProvider secretProvider =
StringSignerSecretProviderCreator.newStringSignerSecretProvider(); StringSignerSecretProviderCreator.newStringSignerSecretProvider();
@ -727,7 +728,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return null; return null;
} }
} }
).when(chain).doFilter(Mockito.<ServletRequest>anyObject(), Mockito.<ServletResponse>anyObject()); ).when(chain).doFilter(any(), any());
filter.doFilter(request, response, chain); filter.doFilter(request, response, chain);
@ -780,7 +781,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return null; return null;
} }
} }
).when(chain).doFilter(Mockito.<ServletRequest>anyObject(), Mockito.<ServletResponse>anyObject()); ).when(chain).doFilter(any(), any());
filter.doFilter(request, response, chain); filter.doFilter(request, response, chain);
@ -1090,8 +1091,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Assert.assertTrue(v.contains("u=") && v.contains("p=") && v.contains Assert.assertTrue(v.contains("u=") && v.contains("p=") && v.contains
("t=") && v.contains("i=") && v.contains("e=") ("t=") && v.contains("i=") && v.contains("e=")
&& v.contains("s=")); && v.contains("s="));
Mockito.verify(chain).doFilter(Mockito.any(ServletRequest.class), Mockito.verify(chain).doFilter(any(ServletRequest.class),
Mockito.any(ServletResponse.class)); any(ServletResponse.class));
SignerSecretProvider secretProvider = SignerSecretProvider secretProvider =
StringSignerSecretProviderCreator.newStringSignerSecretProvider(); StringSignerSecretProviderCreator.newStringSignerSecretProvider();
@ -1134,8 +1135,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Mockito.verify(response).sendError(Mockito.eq(HttpServletResponse Mockito.verify(response).sendError(Mockito.eq(HttpServletResponse
.SC_UNAUTHORIZED), Mockito.anyString()); .SC_UNAUTHORIZED), Mockito.anyString());
Mockito.verify(chain, Mockito.never()).doFilter(Mockito.any Mockito.verify(chain, Mockito.never()).doFilter(
(ServletRequest.class), Mockito.any(ServletResponse.class)); any(ServletRequest.class), any(ServletResponse.class));
Assert.assertTrue("cookie is missing", Assert.assertTrue("cookie is missing",
cookieMap.containsKey(AuthenticatedURL.AUTH_COOKIE)); cookieMap.containsKey(AuthenticatedURL.AUTH_COOKIE));

View File

@ -26,8 +26,8 @@
public class TestRandomSignerSecretProvider { public class TestRandomSignerSecretProvider {
// rollover every 50 msec // rollover every 250 msec
private final int timeout = 100; private final int timeout = 500;
private final long rolloverFrequency = timeout / 2; private final long rolloverFrequency = timeout / 2;
{ {

View File

@ -193,7 +193,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -31,9 +31,9 @@
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
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.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.IOException; import java.io.IOException;

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.IOException; import java.io.IOException;

View File

@ -92,7 +92,7 @@ public void testDFSWithInvalidCommmand() throws Throwable {
public void testExceptionNullMessage() throws Exception { public void testExceptionNullMessage() throws Exception {
final String cmdName = "-cmdExNullMsg"; final String cmdName = "-cmdExNullMsg";
final Command cmd = Mockito.mock(Command.class); final Command cmd = Mockito.mock(Command.class);
Mockito.when(cmd.run(Mockito.anyVararg())).thenThrow( Mockito.when(cmd.run(Mockito.any())).thenThrow(
new IllegalArgumentException()); new IllegalArgumentException());
Mockito.when(cmd.getUsage()).thenReturn(cmdName); Mockito.when(cmd.getUsage()).thenReturn(cmdName);

View File

@ -36,7 +36,6 @@
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.shell.CopyCommands.Put; import org.apache.hadoop.fs.shell.CopyCommands.Put;
import org.apache.hadoop.util.Progressable;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -153,8 +152,7 @@ public void testInterruptedRename() throws Exception {
private OngoingStubbing<FSDataOutputStream> whenFsCreate() throws IOException { private OngoingStubbing<FSDataOutputStream> whenFsCreate() throws IOException {
return when(mockFs.create(eq(tmpPath), any(FsPermission.class), return when(mockFs.create(eq(tmpPath), any(FsPermission.class),
anyBoolean(), anyInt(), anyShort(), anyLong(), anyBoolean(), anyInt(), anyShort(), anyLong(), any()));
any(Progressable.class)));
} }
private void tryCopyStream(InputStream in, boolean shouldPass) { private void tryCopyStream(InputStream in, boolean shouldPass) {

View File

@ -20,7 +20,7 @@
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_KEY; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_KEY;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.fs.shell; package org.apache.hadoop.fs.shell;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.IOException; import java.io.IOException;

View File

@ -25,9 +25,9 @@
import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555; import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555;
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.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
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.verify; import static org.mockito.Mockito.verify;
@ -536,7 +536,7 @@ public void testFileStatusOnMountLink() throws IOException {
@Test @Test
public void testGetFileChecksum() throws AccessControlException, public void testGetFileChecksum() throws AccessControlException,
UnresolvedLinkException, IOException { UnresolvedLinkException, IOException, URISyntaxException {
AbstractFileSystem mockAFS = mock(AbstractFileSystem.class); AbstractFileSystem mockAFS = mock(AbstractFileSystem.class);
InodeTree.ResolveResult<AbstractFileSystem> res = InodeTree.ResolveResult<AbstractFileSystem> res =
new InodeTree.ResolveResult<AbstractFileSystem>(null, mockAFS , null, new InodeTree.ResolveResult<AbstractFileSystem>(null, mockAFS , null,
@ -544,13 +544,10 @@ public void testGetFileChecksum() throws AccessControlException,
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
InodeTree<AbstractFileSystem> fsState = mock(InodeTree.class); InodeTree<AbstractFileSystem> fsState = mock(InodeTree.class);
when(fsState.resolve(anyString(), anyBoolean())).thenReturn(res); when(fsState.resolve(anyString(), anyBoolean())).thenReturn(res);
ViewFs vfs = mock(ViewFs.class); ViewFs vfs = new ViewFs(conf);
vfs.fsState = fsState; vfs.fsState = fsState;
when(vfs.getFileChecksum(new Path("/tmp/someFile")))
.thenCallRealMethod();
vfs.getFileChecksum(new Path("/tmp/someFile")); vfs.getFileChecksum(new Path("/tmp/someFile"));
verify(mockAFS).getFileChecksum(new Path("someFile")); verify(mockAFS).getFileChecksum(new Path("someFile"));
} }

View File

@ -22,7 +22,6 @@
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code; import org.apache.zookeeper.KeeperException.Code;
@ -45,6 +44,8 @@
import org.apache.hadoop.util.ZKUtil.ZKAuthInfo; import org.apache.hadoop.util.ZKUtil.ZKAuthInfo;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import static org.mockito.ArgumentMatchers.any;
public class TestActiveStandbyElector { public class TestActiveStandbyElector {
private ZooKeeper mockZK; private ZooKeeper mockZK;
@ -438,8 +439,7 @@ public void testProcessCallbackEventNone() throws Exception {
Event.KeeperState.SyncConnected); Event.KeeperState.SyncConnected);
elector.processWatchEvent(mockZK, mockEvent); elector.processWatchEvent(mockZK, mockEvent);
Mockito.verify(mockZK, Mockito.times(0)).exists(Mockito.anyString(), Mockito.verify(mockZK, Mockito.times(0)).exists(Mockito.anyString(),
Mockito.anyBoolean(), Mockito.<AsyncCallback.StatCallback> anyObject(), Mockito.anyBoolean(), any(), any());
Mockito.<Object> anyObject());
// disconnection should enter safe mode // disconnection should enter safe mode
Mockito.when(mockEvent.getState()).thenReturn( Mockito.when(mockEvent.getState()).thenReturn(
@ -663,38 +663,35 @@ public void testGetActiveData() throws ActiveNotFoundException,
byte[] data = new byte[8]; byte[] data = new byte[8];
Mockito.when( Mockito.when(
mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject())).thenReturn(data); any())).thenReturn(data);
Assert.assertEquals(data, elector.getActiveData()); Assert.assertEquals(data, elector.getActiveData());
Mockito.verify(mockZK, Mockito.times(1)).getData( Mockito.verify(mockZK, Mockito.times(1)).getData(
Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), any());
Mockito.<Stat> anyObject());
// active does not exist // active does not exist
Mockito.when( Mockito.when(
mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject())).thenThrow( any())).thenThrow(
new KeeperException.NoNodeException()); new KeeperException.NoNodeException());
try { try {
elector.getActiveData(); elector.getActiveData();
Assert.fail("ActiveNotFoundException expected"); Assert.fail("ActiveNotFoundException expected");
} catch(ActiveNotFoundException e) { } catch(ActiveNotFoundException e) {
Mockito.verify(mockZK, Mockito.times(2)).getData( Mockito.verify(mockZK, Mockito.times(2)).getData(
Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), any());
Mockito.<Stat> anyObject());
} }
// error getting active data rethrows keeperexception // error getting active data rethrows keeperexception
try { try {
Mockito.when( Mockito.when(
mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject())).thenThrow( any())).thenThrow(
new KeeperException.AuthFailedException()); new KeeperException.AuthFailedException());
elector.getActiveData(); elector.getActiveData();
Assert.fail("KeeperException.AuthFailedException expected"); Assert.fail("KeeperException.AuthFailedException expected");
} catch(KeeperException.AuthFailedException ke) { } catch(KeeperException.AuthFailedException ke) {
Mockito.verify(mockZK, Mockito.times(3)).getData( Mockito.verify(mockZK, Mockito.times(3)).getData(
Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), any());
Mockito.<Stat> anyObject());
} }
} }
@ -729,7 +726,7 @@ public Code code() {
}; };
Mockito.when(mockZK.create(Mockito.anyString(), Mockito.eq(new byte[]{}), Mockito.when(mockZK.create(Mockito.anyString(), Mockito.eq(new byte[]{}),
Mockito.anyListOf(ACL.class), Mockito.anyList(),
Mockito.eq(CreateMode.PERSISTENT))).thenThrow(ke); Mockito.eq(CreateMode.PERSISTENT))).thenThrow(ke);
elector.ensureParentZNode(); elector.ensureParentZNode();

View File

@ -29,9 +29,9 @@
import java.io.PrintWriter; import java.io.PrintWriter;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
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.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.http.lib; package org.apache.hadoop.http.lib;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
@ -55,7 +56,7 @@ public void testFilter() throws Exception {
suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class), suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class),
chain); chain);
Mockito.verify(chain).doFilter(wrapperArg.capture(), Mockito.<ServletResponse>anyObject()); Mockito.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

@ -43,9 +43,9 @@
import static org.apache.hadoop.io.retry.RetryPolicies.*; import static org.apache.hadoop.io.retry.RetryPolicies.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
public class TestRetryProxy { public class TestRetryProxy {

View File

@ -22,7 +22,7 @@
import static org.apache.hadoop.test.MetricsAsserts.assertCounter; import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
import static org.apache.hadoop.test.MetricsAsserts.getMetrics; import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyObject; import static org.mockito.Mockito.any;
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.when; import static org.mockito.Mockito.when;
@ -254,7 +254,7 @@ public void testInsertion() throws Exception {
// put should offer to all but last subqueue, only put to last subqueue. // put should offer to all but last subqueue, only put to last subqueue.
Mockito.reset(fcq); Mockito.reset(fcq);
try { try {
doThrow(stopPuts).when(fcq).putQueue(anyInt(), anyObject()); doThrow(stopPuts).when(fcq).putQueue(anyInt(), any());
fcq.put(p0); fcq.put(p0);
fail("didn't fail"); fail("didn't fail");
} catch (Exception e) { } catch (Exception e) {
@ -268,7 +268,7 @@ public void testInsertion() throws Exception {
// put with lowest priority should not offer, just put. // put with lowest priority should not offer, just put.
Mockito.reset(fcq); Mockito.reset(fcq);
try { try {
doThrow(stopPuts).when(fcq).putQueue(anyInt(), anyObject()); doThrow(stopPuts).when(fcq).putQueue(anyInt(), any());
fcq.put(p2); fcq.put(p2);
fail("didn't fail"); fail("didn't fail");
} catch (Exception e) { } catch (Exception e) {

View File

@ -23,6 +23,8 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
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.mock; import static org.mockito.Mockito.mock;
@ -867,7 +869,7 @@ public void run() {
} }
// wait until reader put a call to callQueue, to make sure all readers // wait until reader put a call to callQueue, to make sure all readers
// are blocking on the queue after initialClients threads are started. // are blocking on the queue after initialClients threads are started.
verify(spy, timeout(5000).times(i + 1)).put(Mockito.<Call>anyObject()); verify(spy, timeout(5000).times(i + 1)).put(any());
} }
try { try {
@ -1604,11 +1606,11 @@ private void checkUserBinding(boolean asProxy) throws Exception {
Socket s; Socket s;
// don't attempt bind with no service host. // don't attempt bind with no service host.
s = checkConnect(null, asProxy); s = checkConnect(null, asProxy);
Mockito.verify(s, Mockito.never()).bind(Mockito.any(SocketAddress.class)); Mockito.verify(s, Mockito.never()).bind(any(SocketAddress.class));
// don't attempt bind with service host not belonging to this host. // don't attempt bind with service host not belonging to this host.
s = checkConnect("1.2.3.4", asProxy); s = checkConnect("1.2.3.4", asProxy);
Mockito.verify(s, Mockito.never()).bind(Mockito.any(SocketAddress.class)); Mockito.verify(s, Mockito.never()).bind(any(SocketAddress.class));
// do attempt bind when service host is this host. // do attempt bind when service host is this host.
InetAddress addr = InetAddress.getLocalHost(); InetAddress addr = InetAddress.getLocalHost();
@ -1643,7 +1645,7 @@ private Socket checkConnect(String addr, boolean asProxy) throws Exception {
SocketFactory mockFactory = Mockito.mock(SocketFactory.class); SocketFactory mockFactory = Mockito.mock(SocketFactory.class);
Mockito.doReturn(s).when(mockFactory).createSocket(); Mockito.doReturn(s).when(mockFactory).createSocket();
doThrow(expectedConnectEx).when(s).connect( doThrow(expectedConnectEx).when(s).connect(
Mockito.any(SocketAddress.class), Mockito.anyInt()); any(SocketAddress.class), Mockito.anyInt());
// do a dummy call and expect it to throw an exception on connect. // do a dummy call and expect it to throw an exception on connect.
// tests should verify if/how a bind occurred. // tests should verify if/how a bind occurred.

View File

@ -52,7 +52,6 @@
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.event.Level; import org.slf4j.event.Level;
@ -95,6 +94,7 @@
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
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.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -1133,7 +1133,7 @@ public Void call() throws ServiceException, InterruptedException {
return null; return null;
} }
})); }));
verify(spy, timeout(500).times(i + 1)).add(Mockito.<Call>anyObject()); verify(spy, timeout(500).times(i + 1)).add(any());
} }
try { try {
proxy.sleep(null, newSleepRequest(100)); proxy.sleep(null, newSleepRequest(100));
@ -1204,7 +1204,7 @@ public Void call() throws ServiceException, InterruptedException {
return null; return null;
} }
})); }));
verify(spy, timeout(500).times(i + 1)).add(Mockito.<Call>anyObject()); verify(spy, timeout(500).times(i + 1)).add(any());
} }
// Start another sleep RPC call and verify the call is backed off due to // Start another sleep RPC call and verify the call is backed off due to
// avg response time(3s) exceeds threshold (2s). // avg response time(3s) exceeds threshold (2s).

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.ipc; package org.apache.hadoop.ipc;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.IOException; import java.io.IOException;
@ -154,12 +153,12 @@ public Writable call(
// No stack trace should be logged for a terse exception. // No stack trace should be logged for a terse exception.
server.logException(logger, new TestException2(), dummyCall); server.logException(logger, new TestException2(), dummyCall);
verify(logger, times(1)).info(anyObject()); verify(logger, times(1)).info(any());
// Full stack trace should be logged for other exceptions. // Full stack trace should be logged for other exceptions.
final Throwable te3 = new TestException3(); final Throwable te3 = new TestException3();
server.logException(logger, te3, dummyCall); server.logException(logger, te3, dummyCall);
verify(logger, times(1)).info(anyObject(), eq(te3)); verify(logger, times(1)).info(any(), eq(te3));
} }
@Test @Test

View File

@ -34,8 +34,8 @@
import java.util.Collections; import java.util.Collections;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
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.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

@ -32,7 +32,7 @@
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Captor; import org.mockito.Captor;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -27,7 +27,7 @@
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Captor; import org.mockito.Captor;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.apache.hadoop.metrics2.MetricsVisitor; import org.apache.hadoop.metrics2.MetricsVisitor;
import org.apache.hadoop.metrics2.AbstractMetric; import org.apache.hadoop.metrics2.AbstractMetric;

View File

@ -23,8 +23,8 @@
import static org.mockito.AdditionalMatchers.eq; import static org.mockito.AdditionalMatchers.eq;
import static org.mockito.AdditionalMatchers.geq; import static org.mockito.AdditionalMatchers.geq;
import static org.mockito.AdditionalMatchers.leq; import static org.mockito.AdditionalMatchers.leq;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
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.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -31,8 +31,8 @@
import static org.apache.hadoop.metrics2.lib.Interns.info; import static org.apache.hadoop.metrics2.lib.Interns.info;
import static org.apache.hadoop.test.MetricsAsserts.*; import static org.apache.hadoop.test.MetricsAsserts.*;
import static org.mockito.Matchers.anyDouble; import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
/** /**

View File

@ -18,6 +18,8 @@
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import org.apache.hadoop.http.HttpServer2; import org.apache.hadoop.http.HttpServer2;
import org.apache.hadoop.security.authentication.server.AuthenticationFilter; import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -27,9 +29,6 @@
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Map; import java.util.Map;
public class TestAuthenticationFilter { public class TestAuthenticationFilter {
@ -69,10 +68,7 @@ public Object answer(InvocationOnMock invocationOnMock)
return null; return null;
} }
} }).when(container).addFilter(any(), any(), any());
).when(container).addFilter(Mockito.<String>anyObject(),
Mockito.<String>anyObject(),
Mockito.<Map<String, String>>anyObject());
new AuthenticationFilterInitializer().initFilter(container, conf); new AuthenticationFilterInitializer().initFilter(container, conf);
} }

View File

@ -25,8 +25,8 @@
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
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.times; import static org.mockito.Mockito.times;
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

@ -34,8 +34,8 @@
import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_NUM_ATTEMPTS_KEY; import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_NUM_ATTEMPTS_KEY;
import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_URL_KEY; import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_URL_KEY;
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.anyString; import static org.mockito.ArgumentMatchers.anyString;
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.when; import static org.mockito.Mockito.when;

View File

@ -32,9 +32,9 @@
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
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.doReturn; import static org.mockito.Mockito.doReturn;
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

@ -18,7 +18,7 @@
package org.apache.hadoop.security; package org.apache.hadoop.security;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.contains; import static org.mockito.Mockito.contains;

View File

@ -28,8 +28,8 @@
import static org.apache.hadoop.security.RuleBasedLdapGroupsMapping import static org.apache.hadoop.security.RuleBasedLdapGroupsMapping
.CONVERSION_RULE_KEY; .CONVERSION_RULE_KEY;
import static org.mockito.Matchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
/** /**
* Test cases to verify the rules supported by RuleBasedLdapGroupsMapping. * Test cases to verify the rules supported by RuleBasedLdapGroupsMapping.

View File

@ -21,8 +21,6 @@
import java.util.ArrayList; import java.util.ArrayList;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -33,6 +31,8 @@
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import static org.mockito.ArgumentMatchers.any;
/** /**
* Test the default and customized behaviors of XFrameOptionsFilter. * Test the default and customized behaviors of XFrameOptionsFilter.
* *
@ -63,8 +63,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return null; return null;
} }
} }
).when(chain).doFilter(Mockito.<ServletRequest>anyObject(), ).when(chain).doFilter(any(), any());
Mockito.<ServletResponse>anyObject());
Mockito.doAnswer( Mockito.doAnswer(
new Answer() { new Answer() {
@ -78,8 +77,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return null; return null;
} }
} }
).when(response).setHeader(Mockito.<String>anyObject(), ).when(response).setHeader(any(), any());
Mockito.<String>anyObject());
XFrameOptionsFilter filter = new XFrameOptionsFilter(); XFrameOptionsFilter filter = new XFrameOptionsFilter();
filter.init(filterConfig); filter.init(filterConfig);
@ -119,8 +117,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return null; return null;
} }
} }
).when(chain).doFilter(Mockito.<ServletRequest>anyObject(), ).when(chain).doFilter(any(), any());
Mockito.<ServletResponse>anyObject());
Mockito.doAnswer( Mockito.doAnswer(
new Answer() { new Answer() {
@ -134,8 +131,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return null; return null;
} }
} }
).when(response).setHeader(Mockito.<String>anyObject(), ).when(response).setHeader(any(), any());
Mockito.<String>anyObject());
XFrameOptionsFilter filter = new XFrameOptionsFilter(); XFrameOptionsFilter filter = new XFrameOptionsFilter();
filter.init(filterConfig); filter.init(filterConfig);

View File

@ -23,7 +23,7 @@
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -20,7 +20,6 @@
import static com.google.common.base.Preconditions.*; import static com.google.common.base.Preconditions.*;
import org.hamcrest.Description;
import org.junit.Assert; import org.junit.Assert;
import static org.mockito.AdditionalMatchers.geq; import static org.mockito.AdditionalMatchers.geq;
@ -104,19 +103,22 @@ public static MetricsRecordBuilder getMetrics(MetricsSource source) {
return getMetrics(source, true); return getMetrics(source, true);
} }
private static class InfoWithSameName extends ArgumentMatcher<MetricsInfo> { private static class InfoWithSameName
implements ArgumentMatcher<MetricsInfo>{
private final String expected; private final String expected;
InfoWithSameName(MetricsInfo info) { InfoWithSameName(MetricsInfo info) {
expected = checkNotNull(info.name(), "info name"); expected = checkNotNull(info.name(), "info name");
} }
@Override public boolean matches(Object info) { @Override
return expected.equals(((MetricsInfo)info).name()); public boolean matches(MetricsInfo info) {
return expected.equals(info.name());
} }
@Override public void describeTo(Description desc) { @Override
desc.appendText("Info with name="+ expected); public String toString() {
return "Info with name=" + expected;
} }
} }
@ -129,9 +131,10 @@ public static MetricsInfo eqName(MetricsInfo info) {
return argThat(new InfoWithSameName(info)); return argThat(new InfoWithSameName(info));
} }
private static class AnyInfo extends ArgumentMatcher<MetricsInfo> { private static class AnyInfo implements ArgumentMatcher<MetricsInfo> {
@Override public boolean matches(Object info) { @Override
return info instanceof MetricsInfo; // not null as well public boolean matches(MetricsInfo info) {
return info != null;
} }
} }

View File

@ -22,7 +22,7 @@
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.spy; import static org.mockito.Mockito.spy;
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

@ -45,7 +45,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -60,7 +60,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -35,7 +35,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -88,7 +88,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -60,7 +60,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -47,10 +47,12 @@
import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains; import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.mockito.Matchers;
import org.mockito.Mockito; 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 static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -316,15 +318,13 @@ public long[] answer(InvocationOnMock invocation) throws Throwable {
public void testFileNotFoundExceptionWithSingleProxy() throws Exception { public void testFileNotFoundExceptionWithSingleProxy() throws Exception {
ClientProtocol active = Mockito.mock(ClientProtocol.class); ClientProtocol active = Mockito.mock(ClientProtocol.class);
Mockito Mockito
.when(active.getBlockLocations(Matchers.anyString(), .when(active.getBlockLocations(anyString(), anyLong(), anyLong()))
Matchers.anyLong(), Matchers.anyLong()))
.thenThrow(new RemoteException("java.io.FileNotFoundException", .thenThrow(new RemoteException("java.io.FileNotFoundException",
"File does not exist!")); "File does not exist!"));
ClientProtocol standby = Mockito.mock(ClientProtocol.class); ClientProtocol standby = Mockito.mock(ClientProtocol.class);
Mockito Mockito
.when(standby.getBlockLocations(Matchers.anyString(), .when(standby.getBlockLocations(anyString(), anyLong(), anyLong()))
Matchers.anyLong(), Matchers.anyLong()))
.thenThrow( .thenThrow(
new RemoteException("org.apache.hadoop.ipc.StandbyException", new RemoteException("org.apache.hadoop.ipc.StandbyException",
"Standby NameNode")); "Standby NameNode"));
@ -354,18 +354,16 @@ public void testFileNotFoundExceptionWithSingleProxy() throws Exception {
} catch (RemoteException ex) { } catch (RemoteException ex) {
Exception rEx = ex.unwrapRemoteException(); Exception rEx = ex.unwrapRemoteException();
if (rEx instanceof StandbyException) { if (rEx instanceof StandbyException) {
Mockito.verify(active).getBlockLocations(Matchers.anyString(), Mockito.verify(active).getBlockLocations(anyString(), anyLong(),
Matchers.anyLong(), Matchers.anyLong()); anyLong());
Mockito.verify(standby, Mockito.times(2)) Mockito.verify(standby, Mockito.times(2))
.getBlockLocations(Matchers.anyString(), .getBlockLocations(anyString(), anyLong(), anyLong());
Matchers.anyLong(), Matchers.anyLong());
} else { } else {
Assert.assertTrue(rEx instanceof FileNotFoundException); Assert.assertTrue(rEx instanceof FileNotFoundException);
Mockito.verify(active, Mockito.times(2)) Mockito.verify(active, Mockito.times(2))
.getBlockLocations(Matchers.anyString(), .getBlockLocations(anyString(), anyLong(), anyLong());
Matchers.anyLong(), Matchers.anyLong()); Mockito.verify(standby).getBlockLocations(anyString(), anyLong(),
Mockito.verify(standby).getBlockLocations(Matchers.anyString(), anyLong());
Matchers.anyLong(), Matchers.anyLong());
} }
} }
} }
@ -384,8 +382,7 @@ public void testSingleProxyFailover() throws Exception {
RandomStringUtils.randomAlphabetic(8) + ".foo.bar:9820"); RandomStringUtils.randomAlphabetic(8) + ".foo.bar:9820");
ClientProtocol active = Mockito.mock(ClientProtocol.class); ClientProtocol active = Mockito.mock(ClientProtocol.class);
Mockito Mockito
.when(active.getBlockLocations(Matchers.anyString(), .when(active.getBlockLocations(anyString(), anyLong(), anyLong()))
Matchers.anyLong(), Matchers.anyLong()))
.thenThrow(new RemoteException("java.io.FileNotFoundException", .thenThrow(new RemoteException("java.io.FileNotFoundException",
"File does not exist!")); "File does not exist!"));
@ -539,15 +536,15 @@ public long[] answer(InvocationOnMock invocation) throws Throwable {
public void testHedgingWhenFileNotFoundException() throws Exception { public void testHedgingWhenFileNotFoundException() throws Exception {
ClientProtocol active = Mockito.mock(ClientProtocol.class); ClientProtocol active = Mockito.mock(ClientProtocol.class);
Mockito Mockito
.when(active.getBlockLocations(Matchers.anyString(), .when(active.getBlockLocations(anyString(),
Matchers.anyLong(), Matchers.anyLong())) anyLong(), anyLong()))
.thenThrow(new RemoteException("java.io.FileNotFoundException", .thenThrow(new RemoteException("java.io.FileNotFoundException",
"File does not exist!")); "File does not exist!"));
ClientProtocol standby = Mockito.mock(ClientProtocol.class); ClientProtocol standby = Mockito.mock(ClientProtocol.class);
Mockito Mockito
.when(standby.getBlockLocations(Matchers.anyString(), .when(standby.getBlockLocations(anyString(),
Matchers.anyLong(), Matchers.anyLong())) anyLong(), anyLong()))
.thenThrow( .thenThrow(
new RemoteException("org.apache.hadoop.ipc.StandbyException", new RemoteException("org.apache.hadoop.ipc.StandbyException",
"Standby NameNode")); "Standby NameNode"));
@ -568,10 +565,10 @@ public void testHedgingWhenFileNotFoundException() throws Exception {
Assert.assertTrue(rEx instanceof FileNotFoundException); Assert.assertTrue(rEx instanceof FileNotFoundException);
} }
} }
Mockito.verify(active).getBlockLocations(Matchers.anyString(), Mockito.verify(active).getBlockLocations(anyString(),
Matchers.anyLong(), Matchers.anyLong()); anyLong(), anyLong());
Mockito.verify(standby).getBlockLocations(Matchers.anyString(), Mockito.verify(standby).getBlockLocations(anyString(),
Matchers.anyLong(), Matchers.anyLong()); anyLong(), anyLong());
} }
@Test @Test

View File

@ -20,8 +20,8 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@ -25,7 +25,8 @@
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
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;
@ -174,7 +175,7 @@ public void testCachedInitialization() throws IOException, URISyntaxException {
Token<TokenIdentifier> token = new Token<TokenIdentifier>(new byte[0], Token<TokenIdentifier> token = new Token<TokenIdentifier>(new byte[0],
new byte[0], DummyFs.TOKEN_KIND, new Text("127.0.0.1:1234")); new byte[0], DummyFs.TOKEN_KIND, new Text("127.0.0.1:1234"));
doReturn(token).when(fs).getDelegationToken(anyString()); doReturn(token).when(fs).getDelegationToken(any());
doReturn(token).when(fs).getRenewToken(); doReturn(token).when(fs).getRenewToken();
fs.emulateSecurityEnabled = true; fs.emulateSecurityEnabled = true;
@ -197,7 +198,7 @@ public void testGetRemoteToken() throws IOException, URISyntaxException {
Token<TokenIdentifier> token = new Token<TokenIdentifier>(new byte[0], Token<TokenIdentifier> token = new Token<TokenIdentifier>(new byte[0],
new byte[0], DummyFs.TOKEN_KIND, new Text("127.0.0.1:1234")); new byte[0], DummyFs.TOKEN_KIND, new Text("127.0.0.1:1234"));
doReturn(token).when(fs).getDelegationToken(anyString()); doReturn(token).when(fs).getDelegationToken(any());
doReturn(token).when(fs).getRenewToken(); doReturn(token).when(fs).getRenewToken();
fs.initialize(new URI("dummyfs://127.0.0.1:1234"), conf); fs.initialize(new URI("dummyfs://127.0.0.1:1234"), conf);
@ -304,7 +305,7 @@ public void testRenewal() throws Exception {
// now that token is invalid, should get a new one // now that token is invalid, should get a new one
tokenAspect.ensureTokenInitialized(); tokenAspect.ensureTokenInitialized();
verify(fs, times(2)).getDelegationToken(anyString()); verify(fs, times(2)).getDelegationToken(any());
verify(fs).setDelegationToken(token2); verify(fs).setDelegationToken(token2);
assertNotSame(action, getActionFromTokenAspect(tokenAspect)); assertNotSame(action, getActionFromTokenAspect(tokenAspect));

View File

@ -49,7 +49,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -69,7 +69,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -155,7 +155,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -101,7 +101,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -20,7 +20,7 @@
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.assertNull; import static org.junit.Assert.assertNull;
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.spy; import static org.mockito.Mockito.spy;
@ -59,7 +59,7 @@
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.mockito.internal.util.reflection.Whitebox; import org.apache.hadoop.test.Whitebox;
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;

View File

@ -22,7 +22,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
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.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.hdfs.server.federation.resolver.order; package org.apache.hadoop.hdfs.server.federation.resolver.order;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
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.spy; import static org.mockito.Mockito.spy;

View File

@ -59,13 +59,13 @@
import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryRequest; import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryRequest;
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable; import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.Whitebox;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
/** /**
* The administrator interface of the {@link Router} implemented by * The administrator interface of the {@link Router} implemented by

View File

@ -46,13 +46,13 @@
import org.apache.hadoop.hdfs.tools.federation.RouterAdmin; import org.apache.hadoop.hdfs.tools.federation.RouterAdmin;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.Whitebox;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;

View File

@ -150,7 +150,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -55,12 +55,11 @@
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.After; import org.junit.After;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito; import org.mockito.Mockito;
import sun.net.spi.nameservice.NameService; import sun.net.spi.nameservice.NameService;
@ -169,15 +168,15 @@ public Socket createSocket() throws IOException {
return spy; return spy;
} }
private class MatchesPort extends BaseMatcher<SocketAddress> { private class MatchesPort implements ArgumentMatcher<SocketAddress> {
@Override @Override
public boolean matches(Object arg0) { public boolean matches(SocketAddress arg0) {
return ((InetSocketAddress)arg0).getPort() == portToInjectOn; return ((InetSocketAddress)arg0).getPort() == portToInjectOn;
} }
@Override @Override
public void describeTo(Description desc) { public String toString() {
desc.appendText("matches port " + portToInjectOn); return "matches port " + portToInjectOn;
} }
} }
} }

View File

@ -22,12 +22,11 @@
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.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyObject; import static org.mockito.ArgumentMatchers.anyShort;
import static org.mockito.Matchers.anyShort; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.anyString;
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.spy; import static org.mockito.Mockito.spy;
@ -53,10 +52,8 @@
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.crypto.CryptoProtocolVersion;
import org.apache.hadoop.fs.ChecksumException; import org.apache.hadoop.fs.ChecksumException;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileChecksum; import org.apache.hadoop.fs.FileChecksum;
@ -81,7 +78,6 @@
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.hdfs.web.WebHdfsConstants; import org.apache.hadoop.hdfs.web.WebHdfsConstants;
import org.apache.hadoop.hdfs.web.WebHdfsTestUtil; import org.apache.hadoop.hdfs.web.WebHdfsTestUtil;
import org.apache.hadoop.io.EnumSetWritable;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.Writable;
@ -98,7 +94,6 @@
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.internal.stubbing.answers.ThrowsException; import org.mockito.internal.stubbing.answers.ThrowsException;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
@ -252,10 +247,10 @@ public Object answer(InvocationOnMock invocation)
}; };
when(mockNN.addBlock(anyString(), when(mockNN.addBlock(anyString(),
anyString(), anyString(),
any(ExtendedBlock.class), any(),
any(DatanodeInfo[].class), any(),
anyLong(), any(String[].class), anyLong(), any(),
Matchers.<EnumSet<AddBlockFlag>>any())) any()))
.thenAnswer(answer); .thenAnswer(answer);
Mockito.doReturn(new HdfsFileStatus.Builder() Mockito.doReturn(new HdfsFileStatus.Builder()
@ -280,10 +275,8 @@ public Object answer(InvocationOnMock invocation)
.fileId(1010) .fileId(1010)
.build()) .build())
.when(mockNN) .when(mockNN)
.create(anyString(), (FsPermission) anyObject(), anyString(), .create(anyString(), any(), anyString(), any(), anyBoolean(),
(EnumSetWritable<CreateFlag>) anyObject(), anyBoolean(), anyShort(), anyLong(), any(), any());
anyShort(), anyLong(), (CryptoProtocolVersion[]) anyObject(),
anyObject());
final DFSClient client = new DFSClient(null, mockNN, conf, null); final DFSClient client = new DFSClient(null, mockNN, conf, null);
OutputStream os = client.create("testfile", true); OutputStream os = client.create("testfile", true);

View File

@ -63,8 +63,8 @@
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import org.mockito.Mockito; import org.mockito.Mockito;
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

@ -56,7 +56,7 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;

View File

@ -25,7 +25,7 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@ -52,7 +52,6 @@
import org.apache.hadoop.crypto.key.KeyProvider; import org.apache.hadoop.crypto.key.KeyProvider;
import org.apache.hadoop.crypto.key.KeyProviderFactory; import org.apache.hadoop.crypto.key.KeyProviderFactory;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FSTestWrapper; import org.apache.hadoop.fs.FSTestWrapper;
@ -89,7 +88,6 @@
import org.apache.hadoop.hdfs.web.WebHdfsConstants; import org.apache.hadoop.hdfs.web.WebHdfsConstants;
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem; import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
import org.apache.hadoop.hdfs.web.WebHdfsTestUtil; import org.apache.hadoop.hdfs.web.WebHdfsTestUtil;
import org.apache.hadoop.io.EnumSetWritable;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.AccessControlException;
@ -114,10 +112,10 @@
import org.mockito.Mockito; import org.mockito.Mockito;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyObject; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyShort; import static org.mockito.ArgumentMatchers.anyShort;
import static org.mockito.Mockito.withSettings; import static org.mockito.Mockito.withSettings;
import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.anyString;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_DEFAULT; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_DEFAULT;
@ -964,10 +962,8 @@ private static void mockCreate(ClientProtocol mcp,
"fakeKey", "fakeVersion")) "fakeKey", "fakeVersion"))
.build()) .build())
.when(mcp) .when(mcp)
.create(anyString(), (FsPermission) anyObject(), anyString(), .create(anyString(), any(), anyString(), any(), anyBoolean(),
(EnumSetWritable<CreateFlag>) anyObject(), anyBoolean(), anyShort(), anyLong(), any(), any());
anyShort(), anyLong(), (CryptoProtocolVersion[]) anyObject(),
anyObject());
} }
// This test only uses mocks. Called from the end of an existing test to // This test only uses mocks. Called from the end of an existing test to

View File

@ -21,9 +21,9 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyObject; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -40,7 +40,6 @@
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
@ -154,7 +153,7 @@ public void testRecoverFinalizedBlock() throws Throwable {
// Delay completeFile // Delay completeFile
GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG); GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG);
doAnswer(delayer).when(spyNN).complete( doAnswer(delayer).when(spyNN).complete(
anyString(), anyString(), (ExtendedBlock)anyObject(), anyLong()); anyString(), anyString(), any(), anyLong());
DFSClient client = new DFSClient(null, spyNN, conf, null); DFSClient client = new DFSClient(null, spyNN, conf, null);
file1 = new Path("/testRecoverFinalized"); file1 = new Path("/testRecoverFinalized");
@ -225,7 +224,7 @@ public void testCompleteOtherLeaseHoldersFile() throws Throwable {
GenericTestUtils.DelayAnswer delayer = GenericTestUtils.DelayAnswer delayer =
new GenericTestUtils.DelayAnswer(LOG); new GenericTestUtils.DelayAnswer(LOG);
doAnswer(delayer).when(spyNN).complete(anyString(), anyString(), doAnswer(delayer).when(spyNN).complete(anyString(), anyString(),
(ExtendedBlock) anyObject(), anyLong()); any(), anyLong());
DFSClient client = new DFSClient(null, spyNN, conf, null); DFSClient client = new DFSClient(null, spyNN, conf, null);
file1 = new Path("/testCompleteOtherLease"); file1 = new Path("/testCompleteOtherLease");

View File

@ -17,11 +17,11 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.anyShort; import static org.mockito.ArgumentMatchers.anyShort;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyObject; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -34,8 +34,6 @@
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.crypto.CryptoProtocolVersion;
import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Options; import org.apache.hadoop.fs.Options;
@ -47,7 +45,6 @@
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.io.EnumSetWritable;
import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.SecretManager.InvalidToken; import org.apache.hadoop.security.token.SecretManager.InvalidToken;
@ -374,10 +371,8 @@ public void testFactory() throws Exception {
.fileId(1010) .fileId(1010)
.build()) .build())
.when(mcp) .when(mcp)
.create(anyString(), (FsPermission) anyObject(), anyString(), .create(anyString(), any(), anyString(),
(EnumSetWritable<CreateFlag>) anyObject(), anyBoolean(), any(), anyBoolean(), anyShort(), anyLong(), any(), any());
anyShort(), anyLong(), (CryptoProtocolVersion[]) anyObject(),
anyObject());
final Configuration conf = new Configuration(); final Configuration conf = new Configuration();
final DFSClient c1 = createDFSClientAs(ugi[0], conf); final DFSClient c1 = createDFSClientAs(ugi[0], conf);

View File

@ -22,6 +22,7 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -57,8 +58,6 @@
import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils; import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset; import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
@ -576,9 +575,9 @@ public void testNoExtraReplicationWhenBlockReceivedIsLate()
InternalDataNodeTestUtils.spyOnBposToNN(dn, nn); InternalDataNodeTestUtils.spyOnBposToNN(dn, nn);
DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG); DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG);
Mockito.doAnswer(delayer).when(spy).blockReceivedAndDeleted( Mockito.doAnswer(delayer).when(spy).blockReceivedAndDeleted(
Mockito.<DatanodeRegistration>anyObject(), any(),
Mockito.anyString(), Mockito.anyString(),
Mockito.<StorageReceivedDeletedBlocks[]>anyObject()); any());
FileSystem fs = cluster.getFileSystem(); FileSystem fs = cluster.getFileSystem();
// Create and close a small file with two blocks // Create and close a small file with two blocks

View File

@ -31,8 +31,8 @@
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
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.times; import static org.mockito.Mockito.times;
/** /**

View File

@ -31,14 +31,13 @@
import org.apache.hadoop.util.FakeTimer; import org.apache.hadoop.util.FakeTimer;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
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 org.mockito.Mockito; 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 java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -81,7 +80,7 @@ public void testSlowShortCircuitReadsStatsRecorded() throws IOException,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
FileChannel dataIn = Mockito.mock(FileChannel.class); FileChannel dataIn = Mockito.mock(FileChannel.class);
Mockito.when(dataIn.read(any(ByteBuffer.class), anyLong())).thenAnswer( Mockito.when(dataIn.read(any(), anyLong())).thenAnswer(
new Answer<Object>() { new Answer<Object>() {
@Override @Override
public Object answer(InvocationOnMock invocation) throws Throwable { public Object answer(InvocationOnMock invocation) throws Throwable {
@ -93,8 +92,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
BlockReaderIoProvider blockReaderIoProvider = new BlockReaderIoProvider( BlockReaderIoProvider blockReaderIoProvider = new BlockReaderIoProvider(
clientConf.getShortCircuitConf(), metrics, TIMER); clientConf.getShortCircuitConf(), metrics, TIMER);
blockReaderIoProvider.read(dataIn, any(ByteBuffer.class), anyLong()); blockReaderIoProvider.read(dataIn, any(), anyLong());
blockReaderIoProvider.read(dataIn, any(ByteBuffer.class), anyLong()); blockReaderIoProvider.read(dataIn, any(), anyLong());
GenericTestUtils.waitFor(new Supplier<Boolean>() { GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override @Override
@ -127,7 +126,7 @@ public void testMutlipleBlockReaderIoProviderStats() throws IOException,
FileChannel dataIn1 = Mockito.mock(FileChannel.class); FileChannel dataIn1 = Mockito.mock(FileChannel.class);
FileChannel dataIn2 = Mockito.mock(FileChannel.class); FileChannel dataIn2 = Mockito.mock(FileChannel.class);
Mockito.when(dataIn1.read(any(ByteBuffer.class), anyLong())).thenAnswer( Mockito.when(dataIn1.read(any(), anyLong())).thenAnswer(
new Answer<Object>() { new Answer<Object>() {
@Override @Override
public Object answer(InvocationOnMock invocation) throws Throwable { public Object answer(InvocationOnMock invocation) throws Throwable {
@ -136,7 +135,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
} }
}); });
Mockito.when(dataIn2.read(any(ByteBuffer.class), anyLong())).thenAnswer( Mockito.when(dataIn2.read(any(), anyLong())).thenAnswer(
new Answer<Object>() { new Answer<Object>() {
@Override @Override
public Object answer(InvocationOnMock invocation) throws Throwable { public Object answer(InvocationOnMock invocation) throws Throwable {
@ -150,8 +149,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
BlockReaderIoProvider blockReaderIoProvider2 = new BlockReaderIoProvider( BlockReaderIoProvider blockReaderIoProvider2 = new BlockReaderIoProvider(
clientConf.getShortCircuitConf(), metrics, TIMER); clientConf.getShortCircuitConf(), metrics, TIMER);
blockReaderIoProvider1.read(dataIn1, any(ByteBuffer.class), anyLong()); blockReaderIoProvider1.read(dataIn1, any(), anyLong());
blockReaderIoProvider2.read(dataIn2, any(ByteBuffer.class), anyLong()); blockReaderIoProvider2.read(dataIn2, any(), anyLong());
GenericTestUtils.waitFor(new Supplier<Boolean>() { GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override @Override
@ -189,7 +188,7 @@ public void testSlowShortCircuitReadsAverageLatencyValue() throws IOException,
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
dataIns[i] = Mockito.mock(FileChannel.class); dataIns[i] = Mockito.mock(FileChannel.class);
long delay = SLOW_READ_DELAY * random.nextInt(5); long delay = SLOW_READ_DELAY * random.nextInt(5);
Mockito.when(dataIns[i].read(any(ByteBuffer.class), anyLong())) Mockito.when(dataIns[i].read(any(), anyLong()))
.thenAnswer(new Answer<Object>() { .thenAnswer(new Answer<Object>() {
@Override @Override
public Object answer(InvocationOnMock invocation) throws Throwable { public Object answer(InvocationOnMock invocation) throws Throwable {
@ -205,7 +204,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
clientConf.getShortCircuitConf(), metrics, TIMER); clientConf.getShortCircuitConf(), metrics, TIMER);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
blockReaderIoProvider.read(dataIns[i], any(ByteBuffer.class), anyLong()); blockReaderIoProvider.read(dataIns[i], any(), anyLong());
} }
GenericTestUtils.waitFor(new Supplier<Boolean>() { GenericTestUtils.waitFor(new Supplier<Boolean>() {

View File

@ -23,7 +23,7 @@
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
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.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -58,7 +58,6 @@
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException; import com.google.protobuf.ServiceException;
public class TestBlockListAsLongs { public class TestBlockListAsLongs {
@ -222,8 +221,7 @@ public BlockReportResponseProto answer(InvocationOnMock invocation) {
request.set((BlockReportRequestProto) args[1]); request.set((BlockReportRequestProto) args[1]);
return BlockReportResponseProto.newBuilder().build(); return BlockReportResponseProto.newBuilder().build();
} }
}).when(mockProxy).blockReport(any(RpcController.class), }).when(mockProxy).blockReport(any(), any(BlockReportRequestProto.class));
any(BlockReportRequestProto.class));
@SuppressWarnings("resource") @SuppressWarnings("resource")
DatanodeProtocolClientSideTranslatorPB nn = DatanodeProtocolClientSideTranslatorPB nn =

View File

@ -19,9 +19,9 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.eq;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;

View File

@ -24,7 +24,7 @@
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
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;
@ -88,7 +88,6 @@
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import com.google.protobuf.BlockingService; import com.google.protobuf.BlockingService;
import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException; import com.google.protobuf.ServiceException;
import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.fs.StorageType;
@ -303,8 +302,7 @@ private static Server createMockDatanode(BlockTokenSecretManager sm,
.getIdentifier()))); .getIdentifier())));
doAnswer(new GetLengthAnswer(sm, id)).when(mockDN) doAnswer(new GetLengthAnswer(sm, id)).when(mockDN)
.getReplicaVisibleLength(any(RpcController.class), .getReplicaVisibleLength(any(), any());
any(GetReplicaVisibleLengthRequestProto.class));
RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class, RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class,
ProtobufRpcEngine.class); ProtobufRpcEngine.class);

View File

@ -114,7 +114,7 @@
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.Matchers.any; 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;

View File

@ -42,7 +42,7 @@
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.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

@ -21,7 +21,7 @@
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.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.IOException; import java.io.IOException;

View File

@ -23,7 +23,7 @@
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.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

@ -21,6 +21,8 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
@ -61,7 +63,6 @@
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.protocol.BlockReportContext;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage; import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport; import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport;
@ -626,10 +627,10 @@ protected Object passThrough(InvocationOnMock invocation)
Mockito.doAnswer(delayer) Mockito.doAnswer(delayer)
.when(spy).blockReport( .when(spy).blockReport(
Mockito.<DatanodeRegistration>anyObject(), any(),
Mockito.anyString(), anyString(),
Mockito.<StorageBlockReport[]>anyObject(), any(),
Mockito.<BlockReportContext>anyObject()); any());
// Force a block report to be generated. The block report will have // Force a block report to be generated. The block report will have
// an RBW replica in it. Wait for the RPC to be sent, but block // an RBW replica in it. Wait for the RPC to be sent, but block

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.hdfs.server.datanode; package org.apache.hadoop.hdfs.server.datanode;
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -42,9 +41,6 @@
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse; import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat; import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat;
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports;
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary;
import org.junit.Assert; import org.junit.Assert;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
@ -52,7 +48,7 @@
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
/** /**
@ -161,13 +157,13 @@ public DatanodeRegistration answer(InvocationOnMock invocation)
1L)); 1L));
when( when(
namenode.sendHeartbeat(Mockito.any(DatanodeRegistration.class), namenode.sendHeartbeat(Mockito.any(),
Mockito.any(StorageReport[].class), Mockito.anyLong(), Mockito.any(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyInt(), Mockito.any(VolumeFailureSummary.class), Mockito.anyInt(), Mockito.any(),
Mockito.anyBoolean(), Mockito.anyBoolean(),
Mockito.any(SlowPeerReports.class), Mockito.any(),
Mockito.any(SlowDiskReports.class))).thenReturn( Mockito.any())).thenReturn(
new HeartbeatResponse(new DatanodeCommand[0], new NNHAStatusHeartbeat( new HeartbeatResponse(new DatanodeCommand[0], new NNHAStatusHeartbeat(
HAServiceState.ACTIVE, 1), null, ThreadLocalRandom.current() HAServiceState.ACTIVE, 1), null, ThreadLocalRandom.current()
.nextLong() | 1L)); .nextLong() | 1L));

View File

@ -48,7 +48,6 @@
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi;
import org.apache.hadoop.hdfs.server.datanode.metrics.DataNodeMetrics; import org.apache.hadoop.hdfs.server.datanode.metrics.DataNodeMetrics;
import org.apache.hadoop.hdfs.server.protocol.BlockCommand; import org.apache.hadoop.hdfs.server.protocol.BlockCommand;
import org.apache.hadoop.hdfs.server.protocol.BlockReportContext;
import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand; import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
import org.apache.hadoop.hdfs.server.protocol.DatanodeProtocol; import org.apache.hadoop.hdfs.server.protocol.DatanodeProtocol;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
@ -59,7 +58,6 @@
import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo; import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo;
import org.apache.hadoop.hdfs.server.protocol.RegisterCommand; import org.apache.hadoop.hdfs.server.protocol.RegisterCommand;
import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports; import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports;
import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport;
import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks; import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks;
import org.apache.hadoop.hdfs.server.protocol.StorageReport; import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary; import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary;
@ -143,7 +141,7 @@ private DatanodeProtocolClientSideTranslatorPB setupNNMock(int nnIdx)
.when(mock).versionRequest(); .when(mock).versionRequest();
Mockito.doReturn(DFSTestUtil.getLocalDatanodeRegistration()) Mockito.doReturn(DFSTestUtil.getLocalDatanodeRegistration())
.when(mock).registerDatanode(Mockito.any(DatanodeRegistration.class)); .when(mock).registerDatanode(Mockito.any());
Mockito.doAnswer(new HeartbeatAnswer(nnIdx)) Mockito.doAnswer(new HeartbeatAnswer(nnIdx))
.when(mock).sendHeartbeat( .when(mock).sendHeartbeat(
@ -200,10 +198,8 @@ public void testBasicFunctionality() throws Exception {
waitForBothActors(bpos); waitForBothActors(bpos);
// The DN should have register to both NNs. // The DN should have register to both NNs.
Mockito.verify(mockNN1).registerDatanode( Mockito.verify(mockNN1).registerDatanode(Mockito.any());
Mockito.any(DatanodeRegistration.class)); Mockito.verify(mockNN2).registerDatanode(Mockito.any());
Mockito.verify(mockNN2).registerDatanode(
Mockito.any(DatanodeRegistration.class));
// Should get block reports from both NNs // Should get block reports from both NNs
waitForBlockReport(mockNN1); waitForBlockReport(mockNN1);
@ -267,10 +263,10 @@ public void testIgnoreDeletionsFromNonActive() throws Exception {
Mockito.doReturn(new BlockCommand(DatanodeProtocol.DNA_INVALIDATE, Mockito.doReturn(new BlockCommand(DatanodeProtocol.DNA_INVALIDATE,
FAKE_BPID, new Block[] { FAKE_BLOCK.getLocalBlock() })) FAKE_BPID, new Block[] { FAKE_BLOCK.getLocalBlock() }))
.when(mockNN2).blockReport( .when(mockNN2).blockReport(
Mockito.<DatanodeRegistration>anyObject(), Mockito.any(),
Mockito.eq(FAKE_BPID), Mockito.eq(FAKE_BPID),
Mockito.<StorageBlockReport[]>anyObject(), Mockito.any(),
Mockito.<BlockReportContext>anyObject()); Mockito.any());
bpos.start(); bpos.start();
try { try {
@ -287,8 +283,7 @@ public void testIgnoreDeletionsFromNonActive() throws Exception {
// Should ignore the delete command from the standby // Should ignore the delete command from the standby
Mockito.verify(mockFSDataset, Mockito.never()) Mockito.verify(mockFSDataset, Mockito.never())
.invalidate(Mockito.eq(FAKE_BPID), .invalidate(Mockito.eq(FAKE_BPID), Mockito.any());
(Block[]) Mockito.anyObject());
} }
/** /**
@ -487,10 +482,10 @@ private void waitForBlockReport(final DatanodeProtocolClientSideTranslatorPB moc
public Boolean get() { public Boolean get() {
try { try {
Mockito.verify(mockNN).blockReport( Mockito.verify(mockNN).blockReport(
Mockito.<DatanodeRegistration>anyObject(), Mockito.any(),
Mockito.eq(FAKE_BPID), Mockito.eq(FAKE_BPID),
Mockito.<StorageBlockReport[]>anyObject(), Mockito.any(),
Mockito.<BlockReportContext>anyObject()); Mockito.any());
return true; return true;
} catch (Throwable t) { } catch (Throwable t) {
LOG.info("waiting on block report: " + t.getMessage()); LOG.info("waiting on block report: " + t.getMessage());
@ -513,10 +508,10 @@ public Boolean get() {
private Boolean get(DatanodeProtocolClientSideTranslatorPB mockNN) { private Boolean get(DatanodeProtocolClientSideTranslatorPB mockNN) {
try { try {
Mockito.verify(mockNN).blockReport( Mockito.verify(mockNN).blockReport(
Mockito.<DatanodeRegistration>anyObject(), Mockito.any(),
Mockito.eq(FAKE_BPID), Mockito.eq(FAKE_BPID),
Mockito.<StorageBlockReport[]>anyObject(), Mockito.any(),
Mockito.<BlockReportContext>anyObject()); Mockito.any());
return true; return true;
} catch (Throwable t) { } catch (Throwable t) {
LOG.info("waiting on block report: " + t.getMessage()); LOG.info("waiting on block report: " + t.getMessage());
@ -538,7 +533,7 @@ private ReceivedDeletedBlockInfo[] waitForBlockReceived(
public Boolean get() { public Boolean get() {
try { try {
Mockito.verify(mockNN).blockReceivedAndDeleted( Mockito.verify(mockNN).blockReceivedAndDeleted(
Mockito.<DatanodeRegistration>anyObject(), Mockito.any(),
Mockito.eq(fakeBlockPoolId), Mockito.eq(fakeBlockPoolId),
captor.capture()); captor.capture());
return true; return true;
@ -600,9 +595,9 @@ public void testReportBadBlockWhenStandbyNNTimesOut() throws Exception {
// Now mockNN1 is acting like active namenode and mockNN2 as Standby // Now mockNN1 is acting like active namenode and mockNN2 as Standby
assertSame(mockNN1, bpos.getActiveNN()); assertSame(mockNN1, bpos.getActiveNN());
Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(0)) Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(0))
.when(mockNN1).reportBadBlocks(Mockito.any(LocatedBlock[].class)); .when(mockNN1).reportBadBlocks(Mockito.any());
Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(1)) Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(1))
.when(mockNN2).reportBadBlocks(Mockito.any(LocatedBlock[].class)); .when(mockNN2).reportBadBlocks(Mockito.any());
bpos.reportBadBlocks(FAKE_BLOCK, mockFSDataset.getVolume(FAKE_BLOCK) bpos.reportBadBlocks(FAKE_BLOCK, mockFSDataset.getVolume(FAKE_BLOCK)
.getStorageID(), mockFSDataset.getVolume(FAKE_BLOCK) .getStorageID(), mockFSDataset.getVolume(FAKE_BLOCK)
.getStorageType()); .getStorageType());
@ -641,10 +636,10 @@ public void testTrySendErrorReportWhenStandbyNNTimesOut() throws Exception {
// Now mockNN1 is acting like active namenode and mockNN2 as Standby // Now mockNN1 is acting like active namenode and mockNN2 as Standby
assertSame(mockNN1, bpos.getActiveNN()); assertSame(mockNN1, bpos.getActiveNN());
Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(0)) Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(0))
.when(mockNN1).errorReport(Mockito.any(DatanodeRegistration.class), .when(mockNN1).errorReport(Mockito.any(),
Mockito.anyInt(), Mockito.anyString()); Mockito.anyInt(), Mockito.anyString());
Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(1)) Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(1))
.when(mockNN2).errorReport(Mockito.any(DatanodeRegistration.class), .when(mockNN2).errorReport(Mockito.any(),
Mockito.anyInt(), Mockito.anyString()); Mockito.anyInt(), Mockito.anyString());
String errorString = "Can't send invalid block " + FAKE_BLOCK; String errorString = "Can't send invalid block " + FAKE_BLOCK;
bpos.trySendErrorReport(DatanodeProtocol.INVALID_BLOCK, errorString); bpos.trySendErrorReport(DatanodeProtocol.INVALID_BLOCK, errorString);
@ -679,20 +674,13 @@ public void testTrySendErrorReportWhenNNThrowsIOException()
bpos.triggerHeartbeatForTests(); bpos.triggerHeartbeatForTests();
// Now mockNN1 is acting like active namenode and mockNN2 as Standby // Now mockNN1 is acting like active namenode and mockNN2 as Standby
assertSame(mockNN1, bpos.getActiveNN()); assertSame(mockNN1, bpos.getActiveNN());
Mockito.doAnswer(new Answer<Void>() {
// Throw an IOException when this function is first called which will // Throw an IOException when this function is first called which will
// in turn add that errorReport back to the bpThreadQueue and let it // in turn add that errorReport back to the bpThreadQueue and let it
// process the next time. // process the next time.
@Override Mockito.doThrow(new IOException("Throw IOException in the first call."))
public Void answer(InvocationOnMock invocation) throws Throwable { .doAnswer((Answer<Void>) invocation -> {
if (firstCallTime == 0) {
firstCallTime = Time.now();
throw new IOException();
} else {
secondCallTime = Time.now(); secondCallTime = Time.now();
return null; return null;
}
}
}).when(mockNN1).errorReport(Mockito.any(DatanodeRegistration.class), }).when(mockNN1).errorReport(Mockito.any(DatanodeRegistration.class),
Mockito.anyInt(), Mockito.anyString()); Mockito.anyInt(), Mockito.anyString());
String errorString = "Can't send invalid block " + FAKE_BLOCK; String errorString = "Can't send invalid block " + FAKE_BLOCK;
@ -880,9 +868,9 @@ public void testRefreshNameNodes() throws Exception {
// The DN should have register to both NNs. // The DN should have register to both NNs.
Mockito.verify(mockNN1) Mockito.verify(mockNN1)
.registerDatanode(Mockito.any(DatanodeRegistration.class)); .registerDatanode(Mockito.any());
Mockito.verify(mockNN2) Mockito.verify(mockNN2)
.registerDatanode(Mockito.any(DatanodeRegistration.class)); .registerDatanode(Mockito.any());
// Should get block reports from both NNs // Should get block reports from both NNs
waitForBlockReport(mockNN1); waitForBlockReport(mockNN1);
@ -927,8 +915,7 @@ public void testRefreshNameNodes() throws Exception {
Thread.sleep(1000); Thread.sleep(1000);
// verify new NN registered // verify new NN registered
Mockito.verify(mockNN3) Mockito.verify(mockNN3).registerDatanode(Mockito.any());
.registerDatanode(Mockito.any(DatanodeRegistration.class));
// When we receive a block, it should report it to both NNs // When we receive a block, it should report it to both NNs
bpos.notifyNamenodeReceivedBlock(FAKE_BLOCK, null, "", false); bpos.notifyNamenodeReceivedBlock(FAKE_BLOCK, null, "", false);

View File

@ -17,8 +17,8 @@
*/ */
package org.apache.hadoop.hdfs.server.datanode; package org.apache.hadoop.hdfs.server.datanode;
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.timeout; import static org.mockito.Mockito.timeout;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;

View File

@ -21,7 +21,6 @@
import org.apache.hadoop.hdfs.AppendTestUtil; import org.apache.hadoop.hdfs.AppendTestUtil;
import org.apache.hadoop.hdfs.DFSClient; import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_SIZE_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_SIZE_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY;
@ -29,11 +28,10 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyListOf; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Matchers.anyObject;
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;
@ -77,7 +75,6 @@
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.StripedFileTestUtil; import org.apache.hadoop.hdfs.StripedFileTestUtil;
import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports;
import org.apache.hadoop.util.AutoCloseableLock; import org.apache.hadoop.util.AutoCloseableLock;
import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.DatanodeID;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
@ -101,8 +98,6 @@
import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat; import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat;
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.hdfs.server.protocol.ReplicaRecoveryInfo; import org.apache.hadoop.hdfs.server.protocol.ReplicaRecoveryInfo;
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.GenericTestUtils.SleepAnswer; import org.apache.hadoop.test.GenericTestUtils.SleepAnswer;
import org.apache.hadoop.util.DataChecksum; import org.apache.hadoop.util.DataChecksum;
@ -223,17 +218,17 @@ public DatanodeRegistration answer(InvocationOnMock invocation)
(1, CLUSTER_ID, POOL_ID, 1L)); (1, CLUSTER_ID, POOL_ID, 1L));
when(namenode.sendHeartbeat( when(namenode.sendHeartbeat(
Mockito.any(DatanodeRegistration.class), Mockito.any(),
Mockito.any(StorageReport[].class), Mockito.any(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyInt(), Mockito.anyInt(),
Mockito.any(VolumeFailureSummary.class), Mockito.any(),
Mockito.anyBoolean(), Mockito.anyBoolean(),
Mockito.any(SlowPeerReports.class), Mockito.any(),
Mockito.any(SlowDiskReports.class))) Mockito.any()))
.thenReturn(new HeartbeatResponse( .thenReturn(new HeartbeatResponse(
new DatanodeCommand[0], new DatanodeCommand[0],
new NNHAStatusHeartbeat(HAServiceState.ACTIVE, 1), new NNHAStatusHeartbeat(HAServiceState.ACTIVE, 1),
@ -317,9 +312,9 @@ private void testSyncReplicas(ReplicaRecoveryInfo replica1,
syncList.add(record1); syncList.add(record1);
syncList.add(record2); syncList.add(record2);
when(dn1.updateReplicaUnderRecovery((ExtendedBlock)anyObject(), anyLong(), when(dn1.updateReplicaUnderRecovery(any(ExtendedBlock.class), anyLong(),
anyLong(), anyLong())).thenReturn("storage1"); anyLong(), anyLong())).thenReturn("storage1");
when(dn2.updateReplicaUnderRecovery((ExtendedBlock)anyObject(), anyLong(), when(dn2.updateReplicaUnderRecovery(any(ExtendedBlock.class), anyLong(),
anyLong(), anyLong())).thenReturn("storage2"); anyLong(), anyLong())).thenReturn("storage2");
BlockRecoveryWorker.RecoveryTaskContiguous RecoveryTaskContiguous = BlockRecoveryWorker.RecoveryTaskContiguous RecoveryTaskContiguous =
@ -555,7 +550,7 @@ public void testRecoveryInProgressException()
BlockRecoveryWorker.RecoveryTaskContiguous spyTask BlockRecoveryWorker.RecoveryTaskContiguous spyTask
= spy(RecoveryTaskContiguous); = spy(RecoveryTaskContiguous);
spyTask.recover(); spyTask.recover();
verify(spyTask, never()).syncBlock(anyListOf(BlockRecord.class)); verify(spyTask, never()).syncBlock(anyList());
} }
} }
@ -583,7 +578,7 @@ public void testErrorReplicas() throws IOException, InterruptedException {
} catch(IOException e){ } catch(IOException e){
GenericTestUtils.assertExceptionContains("All datanodes failed", e); GenericTestUtils.assertExceptionContains("All datanodes failed", e);
} }
verify(spyTask, never()).syncBlock(anyListOf(BlockRecord.class)); verify(spyTask, never()).syncBlock(anyList());
} }
} }

View File

@ -92,8 +92,8 @@
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
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.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout;

View File

@ -55,7 +55,6 @@
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse; import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports; import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports;
import org.apache.hadoop.hdfs.server.protocol.StorageReport; import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.log4j.Level; import org.apache.log4j.Level;
@ -170,7 +169,7 @@ public void testSendLifelineIfHeartbeatBlocked() throws Exception {
anyInt(), anyInt(),
anyInt(), anyInt(),
anyInt(), anyInt(),
any(VolumeFailureSummary.class), any(),
anyBoolean(), anyBoolean(),
any(SlowPeerReports.class), any(SlowPeerReports.class),
any(SlowDiskReports.class)); any(SlowDiskReports.class));
@ -185,7 +184,7 @@ public void testSendLifelineIfHeartbeatBlocked() throws Exception {
anyInt(), anyInt(),
anyInt(), anyInt(),
anyInt(), anyInt(),
any(VolumeFailureSummary.class)); any());
// While waiting on the latch for the expected number of lifeline messages, // While waiting on the latch for the expected number of lifeline messages,
// poll DataNode tracking information. Thanks to the lifeline, we expect // poll DataNode tracking information. Thanks to the lifeline, we expect
@ -212,7 +211,7 @@ public void testSendLifelineIfHeartbeatBlocked() throws Exception {
anyInt(), anyInt(),
anyInt(), anyInt(),
anyInt(), anyInt(),
any(VolumeFailureSummary.class)); any());
// Also verify lifeline call through metrics. We expect at least // Also verify lifeline call through metrics. We expect at least
// numLifelines, guaranteed by waiting on the latch. There is a small // numLifelines, guaranteed by waiting on the latch. There is a small
@ -239,7 +238,7 @@ public void testNoLifelineSentIfHeartbeatsOnTime() throws Exception {
anyInt(), anyInt(),
anyInt(), anyInt(),
anyInt(), anyInt(),
any(VolumeFailureSummary.class), any(),
anyBoolean(), anyBoolean(),
any(SlowPeerReports.class), any(SlowPeerReports.class),
any(SlowDiskReports.class)); any(SlowDiskReports.class));
@ -265,7 +264,7 @@ public void testNoLifelineSentIfHeartbeatsOnTime() throws Exception {
anyInt(), anyInt(),
anyInt(), anyInt(),
anyInt(), anyInt(),
any(VolumeFailureSummary.class)); any());
// Also verify no lifeline calls through metrics. // Also verify no lifeline calls through metrics.
assertEquals("Expect metrics to count no lifeline calls.", 0, assertEquals("Expect metrics to count no lifeline calls.", 0,

View File

@ -41,7 +41,6 @@
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -51,7 +50,13 @@
import java.util.UUID; import java.util.UUID;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Mockito.*; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
/** /**
* Mock-based unit test to verify that DataXceiver does not fail when no * Mock-based unit test to verify that DataXceiver does not fail when no
@ -86,7 +91,7 @@ public NullDataNode(Configuration conf, OutputStream out, int port) throws
doReturn(pair).when(saslClient).socketSend( doReturn(pair).when(saslClient).socketSend(
any(Socket.class), any(OutputStream.class), any(InputStream.class), any(Socket.class), any(OutputStream.class), any(InputStream.class),
any(DataEncryptionKeyFactory.class), any(Token.class), any(DataEncryptionKeyFactory.class), any(),
any(DatanodeID.class)); any(DatanodeID.class));
doReturn(mock(ReplicaHandler.class)).when(data).createTemporary( doReturn(mock(ReplicaHandler.class)).when(data).createTemporary(
any(StorageType.class), any(String.class), any(ExtendedBlock.class), any(StorageType.class), any(String.class), any(ExtendedBlock.class),
@ -154,12 +159,12 @@ public void testBackwardsCompat() throws Exception {
doReturn(mockBlockReceiver).when(xceiver).getBlockReceiver( doReturn(mockBlockReceiver).when(xceiver).getBlockReceiver(
any(ExtendedBlock.class), any(StorageType.class), any(ExtendedBlock.class), any(StorageType.class),
any(DataInputStream.class), anyString(), anyString(), any(), anyString(), any(),
any(BlockConstructionStage.class), anyLong(), anyLong(), anyLong(), any(BlockConstructionStage.class), anyLong(), anyLong(), anyLong(),
anyString(), any(DatanodeInfo.class), any(DataNode.class), anyString(), any(DatanodeInfo.class), any(DataNode.class),
any(DataChecksum.class), any(CachingStrategy.class), any(DataChecksum.class), any(CachingStrategy.class),
ArgumentCaptor.forClass(Boolean.class).capture(), ArgumentCaptor.forClass(Boolean.class).capture(),
anyBoolean(), any(String.class)); anyBoolean(), any());
Token<BlockTokenIdentifier> token = (Token<BlockTokenIdentifier>)mock( Token<BlockTokenIdentifier> token = (Token<BlockTokenIdentifier>)mock(
Token.class); Token.class);

View File

@ -34,14 +34,20 @@
import org.junit.rules.Timeout; import org.junit.rules.Timeout;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.*; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
/** /**
@ -146,12 +152,10 @@ private static DataXceiver makeStubDataXceiver(
getMockDn(nonLocalLazyPersist), getMockDn(nonLocalLazyPersist),
mock(DataXceiverServer.class))); mock(DataXceiverServer.class)));
doReturn(mockBlockReceiver).when(xceiverSpy).getBlockReceiver( doReturn(mockBlockReceiver).when(xceiverSpy).getBlockReceiver(
any(ExtendedBlock.class), any(StorageType.class), any(), any(), any(), anyString(), anyString(),
any(DataInputStream.class), anyString(), anyString(), any(), anyLong(), anyLong(), anyLong(),
any(BlockConstructionStage.class), anyLong(), anyLong(), anyLong(), anyString(), any(), any(), any(), any(),
anyString(), any(DatanodeInfo.class), any(DataNode.class), captor.capture(), anyBoolean(), any());
any(DataChecksum.class), any(CachingStrategy.class),
captor.capture(), anyBoolean(), any(String.class));
doReturn(mock(DataOutputStream.class)).when(xceiverSpy) doReturn(mock(DataOutputStream.class)).when(xceiverSpy)
.getBufferedOutputStream(); .getBufferedOutputStream();
return xceiverSpy; return xceiverSpy;

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.hdfs.server.datanode; package org.apache.hadoop.hdfs.server.datanode;
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
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,17 +42,12 @@
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB;
import org.apache.hadoop.hdfs.server.protocol.BlockReportContext;
import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand; import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse; import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat; import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat;
import org.apache.hadoop.hdfs.server.protocol.RegisterCommand; import org.apache.hadoop.hdfs.server.protocol.RegisterCommand;
import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports;
import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport;
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.slf4j.event.Level; import org.slf4j.event.Level;
import org.junit.After; import org.junit.After;
@ -139,8 +133,8 @@ public Boolean get() {
Mockito.verify(mockNN).blockReport( Mockito.verify(mockNN).blockReport(
Mockito.eq(datanodeRegistration), Mockito.eq(datanodeRegistration),
Mockito.eq(POOL_ID), Mockito.eq(POOL_ID),
Mockito.<StorageBlockReport[]>anyObject(), Mockito.any(),
Mockito.<BlockReportContext>anyObject()); Mockito.any());
return true; return true;
} catch (Throwable t) { } catch (Throwable t) {
LOG.info("waiting on block report: " + t.getMessage()); LOG.info("waiting on block report: " + t.getMessage());
@ -212,17 +206,17 @@ public HeartbeatResponse answer(InvocationOnMock invocation)
return heartbeatResponse; return heartbeatResponse;
} }
}).when(namenode).sendHeartbeat( }).when(namenode).sendHeartbeat(
Mockito.any(DatanodeRegistration.class), Mockito.any(),
Mockito.any(StorageReport[].class), Mockito.any(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyInt(), Mockito.anyInt(),
Mockito.any(VolumeFailureSummary.class), Mockito.any(),
Mockito.anyBoolean(), Mockito.anyBoolean(),
Mockito.any(SlowPeerReports.class), Mockito.any(),
Mockito.any(SlowDiskReports.class)); Mockito.any());
dn = new DataNode(conf, locations, null, null) { dn = new DataNode(conf, locations, null, null) {
@Override @Override

View File

@ -29,7 +29,6 @@
import org.apache.hadoop.hdfs.protocol.BlockListAsLongs; import org.apache.hadoop.hdfs.protocol.BlockListAsLongs;
import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.protocol.BlockReportContext;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport; import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_SPLIT_THRESHOLD_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_SPLIT_THRESHOLD_KEY;
@ -42,7 +41,8 @@
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.*; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
/** /**
@ -135,7 +135,7 @@ public void testAlwaysSplit() throws IOException, InterruptedException {
Mockito.verify(nnSpy, times(cluster.getStoragesPerDatanode())).blockReport( Mockito.verify(nnSpy, times(cluster.getStoragesPerDatanode())).blockReport(
any(DatanodeRegistration.class), any(DatanodeRegistration.class),
anyString(), anyString(),
captor.capture(), Mockito.<BlockReportContext>anyObject()); captor.capture(), any());
verifyCapturedArguments(captor, 1, BLOCKS_IN_FILE); verifyCapturedArguments(captor, 1, BLOCKS_IN_FILE);
} }
@ -167,7 +167,7 @@ public void testCornerCaseUnderThreshold() throws IOException, InterruptedExcept
Mockito.verify(nnSpy, times(1)).blockReport( Mockito.verify(nnSpy, times(1)).blockReport(
any(DatanodeRegistration.class), any(DatanodeRegistration.class),
anyString(), anyString(),
captor.capture(), Mockito.<BlockReportContext>anyObject()); captor.capture(), any());
verifyCapturedArguments(captor, cluster.getStoragesPerDatanode(), BLOCKS_IN_FILE); verifyCapturedArguments(captor, cluster.getStoragesPerDatanode(), BLOCKS_IN_FILE);
} }
@ -199,7 +199,7 @@ public void testCornerCaseAtThreshold() throws IOException, InterruptedException
Mockito.verify(nnSpy, times(cluster.getStoragesPerDatanode())).blockReport( Mockito.verify(nnSpy, times(cluster.getStoragesPerDatanode())).blockReport(
any(DatanodeRegistration.class), any(DatanodeRegistration.class),
anyString(), anyString(),
captor.capture(), Mockito.<BlockReportContext>anyObject()); captor.capture(), any());
verifyCapturedArguments(captor, 1, BLOCKS_IN_FILE); verifyCapturedArguments(captor, 1, BLOCKS_IN_FILE);
} }

View File

@ -22,10 +22,10 @@
import static org.apache.hadoop.test.MetricsAsserts.getMetrics; import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
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.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import java.io.FileInputStream; import java.io.FileInputStream;

View File

@ -18,8 +18,8 @@
package org.apache.hadoop.hdfs.server.datanode; package org.apache.hadoop.hdfs.server.datanode;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
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.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;

View File

@ -34,7 +34,6 @@
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports; import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports; import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports;
import org.apache.hadoop.hdfs.server.protocol.StorageReport; import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -44,9 +43,9 @@
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
public class TestStorageReport { public class TestStorageReport {
public static final Logger LOG = public static final Logger LOG =
@ -109,7 +108,7 @@ public void testStorageReportHasStorageTypeAndState() throws IOException {
any(DatanodeRegistration.class), any(DatanodeRegistration.class),
captor.capture(), captor.capture(),
anyLong(), anyLong(), anyInt(), anyInt(), anyInt(), anyLong(), anyLong(), anyInt(), anyInt(), anyInt(),
Mockito.any(VolumeFailureSummary.class), Mockito.anyBoolean(), any(), Mockito.anyBoolean(),
Mockito.any(SlowPeerReports.class), Mockito.any(SlowPeerReports.class),
Mockito.any(SlowDiskReports.class)); Mockito.any(SlowDiskReports.class));

View File

@ -17,9 +17,8 @@
*/ */
package org.apache.hadoop.hdfs.server.datanode; package org.apache.hadoop.hdfs.server.datanode;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout;
@ -33,7 +32,6 @@
import org.apache.hadoop.hdfs.client.BlockReportOptions; import org.apache.hadoop.hdfs.client.BlockReportOptions;
import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB;
import org.apache.hadoop.hdfs.server.protocol.BlockReportContext;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage; import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
@ -81,7 +79,7 @@ private void testTriggerBlockReport(boolean incremental) throws Exception {
any(DatanodeRegistration.class), any(DatanodeRegistration.class),
anyString(), anyString(),
any(StorageBlockReport[].class), any(StorageBlockReport[].class),
Mockito.<BlockReportContext>anyObject()); any());
Mockito.verify(spy, times(1)).blockReceivedAndDeleted( Mockito.verify(spy, times(1)).blockReceivedAndDeleted(
any(DatanodeRegistration.class), any(DatanodeRegistration.class),
anyString(), anyString(),
@ -124,7 +122,7 @@ private void testTriggerBlockReport(boolean incremental) throws Exception {
any(DatanodeRegistration.class), any(DatanodeRegistration.class),
anyString(), anyString(),
any(StorageBlockReport[].class), any(StorageBlockReport[].class),
Mockito.<BlockReportContext>anyObject()); any());
} }
cluster.shutdown(); cluster.shutdown();

View File

@ -126,7 +126,7 @@ public void call(Set<FsVolumeSpi> healthyVolumes,
GenericTestUtils.waitFor(() -> numCallbackInvocations.get() > 0, 5, 10000); GenericTestUtils.waitFor(() -> numCallbackInvocations.get() > 0, 5, 10000);
// Ensure that the check was invoked at least once. // Ensure that the check was invoked at least once.
verify(volume, times(1)).check(anyObject()); verify(volume, times(1)).check(any());
if (result) { if (result) {
assertThat(numCallbackInvocations.get(), is(1L)); assertThat(numCallbackInvocations.get(), is(1L));
} }
@ -160,7 +160,7 @@ public void testCheckAllVolumes() throws Exception {
// Ensure each volume's check() method was called exactly once. // Ensure each volume's check() method was called exactly once.
for (FsVolumeSpi volume : volumes) { for (FsVolumeSpi volume : volumes) {
verify(volume, times(1)).check(anyObject()); verify(volume, times(1)).check(any());
} }
} }
@ -217,10 +217,10 @@ static List<FsVolumeSpi> makeVolumes(
when(volume.getStorageLocation()).thenReturn(location); when(volume.getStorageLocation()).thenReturn(location);
if (health != null) { if (health != null) {
when(volume.check(anyObject())).thenReturn(health); when(volume.check(any())).thenReturn(health);
} else { } else {
final DiskErrorException de = new DiskErrorException("Fake Exception"); final DiskErrorException de = new DiskErrorException("Fake Exception");
when(volume.check(anyObject())).thenThrow(de); when(volume.check(any())).thenThrow(de);
} }
volumes.add(volume); volumes.add(volume);
} }

View File

@ -26,7 +26,6 @@
import org.apache.hadoop.util.FakeTimer; import org.apache.hadoop.util.FakeTimer;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -37,8 +36,11 @@
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyObject; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
@ -106,7 +108,7 @@ public void testCheckingClosedVolume() throws Exception {
// The closed volume should not have been checked as it cannot // The closed volume should not have been checked as it cannot
// be referenced. // be referenced.
verify(volumes.get(0), times(0)).check(anyObject()); verify(volumes.get(0), times(0)).check(any());
} }
@Test(timeout=60000) @Test(timeout=60000)
@ -147,14 +149,10 @@ private static FsVolumeSpi makeHungVolume() throws Exception {
when(reference.getVolume()).thenReturn(volume); when(reference.getVolume()).thenReturn(volume);
when(volume.obtainReference()).thenReturn(reference); when(volume.obtainReference()).thenReturn(reference);
when(volume.getStorageLocation()).thenReturn(location); when(volume.getStorageLocation()).thenReturn(location);
when(volume.check(anyObject())).thenAnswer( when(volume.check(any())).thenAnswer(
new Answer<VolumeCheckResult>() { (Answer<VolumeCheckResult>) invocation -> {
@Override
public VolumeCheckResult answer(InvocationOnMock invocation)
throws Throwable {
Thread.sleep(Long.MAX_VALUE); // Sleep forever. Thread.sleep(Long.MAX_VALUE); // Sleep forever.
return VolumeCheckResult.HEALTHY; // unreachable. return VolumeCheckResult.HEALTHY; // unreachable.
}
}); });
return volume; return volume;
} }

View File

@ -20,32 +20,22 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.LogVerificationAppender;
import org.apache.hadoop.hdfs.server.datanode.StorageLocation; import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi;
import org.apache.hadoop.util.FakeTimer; import org.apache.hadoop.util.FakeTimer;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName; import org.junit.rules.TestName;
import static org.mockito.Matchers.anyObject; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -80,15 +70,12 @@ static FsVolumeSpi makeSlowVolume() throws Exception {
when(volume.obtainReference()).thenReturn(reference); when(volume.obtainReference()).thenReturn(reference);
when(volume.getStorageLocation()).thenReturn(location); when(volume.getStorageLocation()).thenReturn(location);
when(volume.check(anyObject())).thenAnswer(new Answer<VolumeCheckResult>() { when(volume.check(any())).thenAnswer(
@Override (Answer<VolumeCheckResult>) invocationOnMock -> {
public VolumeCheckResult answer(
InvocationOnMock invocationOnMock) throws Throwable {
// Wait for the disk check to timeout and then release lock. // Wait for the disk check to timeout and then release lock.
lock.lock(); lock.lock();
lock.unlock(); lock.unlock();
return VolumeCheckResult.HEALTHY; return VolumeCheckResult.HEALTHY;
}
}); });
return volume; return volume;
@ -128,7 +115,7 @@ public void call(Set<FsVolumeSpi> healthyVolumes,
lock.unlock(); lock.unlock();
// Ensure that the check was invoked only once. // Ensure that the check was invoked only once.
verify(volume, times(1)).check(anyObject()); verify(volume, times(1)).check(any());
assertThat(numCallbackInvocations.get(), is(1L)); assertThat(numCallbackInvocations.get(), is(1L));
} }
} }

View File

@ -39,7 +39,7 @@
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
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.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

View File

@ -69,7 +69,6 @@
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito; import org.mockito.Mockito;
import java.io.File; import java.io.File;
@ -97,10 +96,10 @@
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Matchers.anyListOf; 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.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;
@ -213,7 +212,7 @@ public void testAddVolumes() throws IOException {
DataStorage.VolumeBuilder builder = DataStorage.VolumeBuilder builder =
new DataStorage.VolumeBuilder(storage, sd); new DataStorage.VolumeBuilder(storage, sd);
when(storage.prepareVolume(eq(datanode), eq(loc), when(storage.prepareVolume(eq(datanode), eq(loc),
anyListOf(NamespaceInfo.class))) anyList()))
.thenReturn(builder); .thenReturn(builder);
dataset.addVolume(loc, nsInfos); dataset.addVolume(loc, nsInfos);
@ -332,7 +331,7 @@ public void testRemoveNewlyAddedVolume() throws IOException {
DataStorage.VolumeBuilder builder = DataStorage.VolumeBuilder builder =
new DataStorage.VolumeBuilder(storage, sd); new DataStorage.VolumeBuilder(storage, sd);
when(storage.prepareVolume(eq(datanode), eq(loc), when(storage.prepareVolume(eq(datanode), eq(loc),
anyListOf(NamespaceInfo.class))) anyList()))
.thenReturn(builder); .thenReturn(builder);
dataset.addVolume(loc, nsInfos); dataset.addVolume(loc, nsInfos);
@ -366,7 +365,7 @@ public void testAddVolumeFailureReleasesInUseLock() throws IOException {
DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd);
when(storage.prepareVolume(eq(datanode), when(storage.prepareVolume(eq(datanode),
eq(StorageLocation.parse(badDir.toURI().toString())), eq(StorageLocation.parse(badDir.toURI().toString())),
Matchers.<List<NamespaceInfo>>any())) anyList()))
.thenReturn(builder); .thenReturn(builder);
StorageLocation location = StorageLocation.parse(badDir.toString()); StorageLocation location = StorageLocation.parse(badDir.toString());
@ -510,7 +509,7 @@ private long getDfsUsedValueOfNewVolume(long cacheDfsUsed,
new DataStorage.VolumeBuilder(storage, sd); new DataStorage.VolumeBuilder(storage, sd);
when( when(
storage.prepareVolume(eq(datanode), eq(loc), storage.prepareVolume(eq(datanode), eq(loc),
anyListOf(NamespaceInfo.class))).thenReturn(builder); anyList())).thenReturn(builder);
String cacheFilePath = String cacheFilePath =
String.format("%s/%s/%s/%s/%s", path, CURRENT_DIR, BLOCK_POOL_IDS[0], String.format("%s/%s/%s/%s/%s", path, CURRENT_DIR, BLOCK_POOL_IDS[0],

View File

@ -70,7 +70,7 @@
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
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.doAnswer; import static org.mockito.Mockito.doAnswer;
/** /**

View File

@ -20,6 +20,7 @@
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.junit.Assert.fail; import static org.junit.Assert.fail;
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;
@ -59,7 +60,6 @@
import org.apache.hadoop.hdfs.util.Holder; import org.apache.hadoop.hdfs.util.Holder;
import org.apache.hadoop.hdfs.util.MD5FileUtils; import org.apache.hadoop.hdfs.util.MD5FileUtils;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.mockito.Matchers;
import org.mockito.Mockito; import org.mockito.Mockito;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -200,7 +200,7 @@ public static FSEditLog createStandaloneEditLog(File logDir)
List<StorageDirectory> sds = Lists.newArrayList(sd); List<StorageDirectory> sds = Lists.newArrayList(sd);
Mockito.doReturn(sds).when(storage).dirIterable(NameNodeDirType.EDITS); Mockito.doReturn(sds).when(storage).dirIterable(NameNodeDirType.EDITS);
Mockito.doReturn(sd).when(storage) Mockito.doReturn(sd).when(storage)
.getStorageDirectory(Matchers.<URI>anyObject()); .getStorageDirectory(any());
FSEditLog editLog = new FSEditLog(new Configuration(), FSEditLog editLog = new FSEditLog(new Configuration(),
storage, storage,

View File

@ -37,7 +37,7 @@
import java.util.Optional; import java.util.Optional;
import static org.mockito.Matchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
/** /**

View File

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

View File

@ -54,7 +54,7 @@
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.mockito.Mockito; import org.mockito.Mockito;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@ -89,7 +89,6 @@
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
@ -621,14 +620,7 @@ private void doSecondaryFailsToReturnImage() throws IOException {
} }
private File filePathContaining(final String substring) { private File filePathContaining(final String substring) {
return Mockito.argThat( return Mockito.argThat(arg -> arg.getAbsolutePath().contains(substring));
new ArgumentMatcher<File>() {
@Override
public boolean matches(Object argument) {
String path = ((File) argument).getAbsolutePath();
return path.contains(substring);
}
});
} }
private void checkTempImages(NNStorage storage) throws IOException { private void checkTempImages(NNStorage storage) throws IOException {
@ -1993,7 +1985,7 @@ public void testNamespaceVerifiedOnFileTransfer() throws IOException {
NNStorage dstImage = Mockito.mock(NNStorage.class); NNStorage dstImage = Mockito.mock(NNStorage.class);
Mockito.doReturn(Lists.newArrayList(new File("/wont-be-written"))) Mockito.doReturn(Lists.newArrayList(new File("/wont-be-written")))
.when(dstImage).getFiles( .when(dstImage).getFiles(
Mockito.<NameNodeDirType>anyObject(), Mockito.anyString()); Mockito.<NameNodeDirType>any(), Mockito.anyString());
File mockImageFile = File.createTempFile("image", ""); File mockImageFile = File.createTempFile("image", "");
FileOutputStream imageFile = new FileOutputStream(mockImageFile); FileOutputStream imageFile = new FileOutputStream(mockImageFile);

View File

@ -32,7 +32,7 @@
import java.io.IOException; import java.io.IOException;
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.*; import static org.mockito.Mockito.*;
/** /**
@ -77,7 +77,7 @@ private FSNamesystem makeNameSystemSpy(Block block, INodeFile file)
doReturn(blockInfo).when(namesystemSpy).getStoredBlock(any(Block.class)); doReturn(blockInfo).when(namesystemSpy).getStoredBlock(any(Block.class));
doReturn(blockInfo).when(file).getLastBlock(); doReturn(blockInfo).when(file).getLastBlock();
doNothing().when(namesystemSpy).closeFileCommitBlocks( doNothing().when(namesystemSpy).closeFileCommitBlocks(
any(String.class), any(INodeFile.class), any(BlockInfo.class)); any(), any(INodeFile.class), any(BlockInfo.class));
doReturn(mock(FSEditLog.class)).when(namesystemSpy).getEditLog(); doReturn(mock(FSEditLog.class)).when(namesystemSpy).getEditLog();
return namesystemSpy; return namesystemSpy;

Some files were not shown because too many files have changed in this diff Show More