From 1129288cf5045e17b0e761a0d75f40bf2fe6de03 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Tue, 29 Jan 2019 18:29:09 -0800 Subject: [PATCH] HADOOP-14178. Move Mockito up to version 2.23.4. Contributed by Akira Ajisaka and Masatake Iwasaki. --- LICENSE.txt | 2 +- .../hadoop-client-minicluster/pom.xml | 4 +- hadoop-common-project/hadoop-auth/pom.xml | 2 +- .../server/TestAuthenticationFilter.java | 19 ++--- .../util/TestRandomSignerSecretProvider.java | 4 +- hadoop-common-project/hadoop-common/pom.xml | 2 +- .../hadoop/conf/TestReconfiguration.java | 6 +- .../hadoop/fs/TestFileSystemTokens.java | 1 - .../hadoop/fs/TestFilterFileSystem.java | 1 - .../org/apache/hadoop/fs/TestFsShell.java | 2 +- .../org/apache/hadoop/fs/shell/TestCopy.java | 4 +- .../org/apache/hadoop/fs/shell/TestLs.java | 2 +- .../org/apache/hadoop/fs/shell/TestMove.java | 2 +- .../hadoop/fs/viewfs/ViewFsBaseTest.java | 13 ++-- .../hadoop/ha/TestActiveStandbyElector.java | 23 +++--- .../hadoop/http/TestIsActiveServlet.java | 6 +- .../http/lib/TestStaticUserWebFilter.java | 3 +- .../hadoop/io/retry/TestRetryProxy.java | 6 +- .../apache/hadoop/ipc/TestFairCallQueue.java | 6 +- .../java/org/apache/hadoop/ipc/TestIPC.java | 10 ++- .../java/org/apache/hadoop/ipc/TestRPC.java | 6 +- .../org/apache/hadoop/ipc/TestServer.java | 5 +- .../metrics2/impl/TestGraphiteMetrics.java | 4 +- .../metrics2/impl/TestMetricsSystemImpl.java | 2 +- .../metrics2/impl/TestMetricsVisitor.java | 2 +- .../metrics2/lib/TestMutableMetrics.java | 4 +- .../lib/TestMutableRollingAverages.java | 4 +- .../security/TestAuthenticationFilter.java | 10 +-- .../security/TestLdapGroupsMapping.java | 4 +- .../TestLdapGroupsMappingWithFailover.java | 4 +- .../TestLdapGroupsMappingWithOneQuery.java | 6 +- .../TestLdapGroupsMappingWithPosixGroup.java | 2 +- .../TestRuleBasedLdapGroupsMapping.java | 4 +- .../http/TestXFrameOptionsFilter.java | 16 ++-- .../hadoop/service/TestServiceOperations.java | 2 +- .../apache/hadoop/test/MetricsAsserts.java | 21 +++--- .../org/apache/hadoop/util/TestRunJar.java | 2 +- hadoop-common-project/hadoop-kms/pom.xml | 2 +- hadoop-common-project/hadoop-nfs/pom.xml | 2 +- hadoop-hdds/framework/pom.xml | 2 +- hadoop-hdds/server-scm/pom.xml | 2 +- .../hadoop-hdfs-client/pom.xml | 2 +- .../ha/TestRequestHedgingProxyProvider.java | 43 +++++------ .../hdfs/web/TestByteRangeInputStream.java | 4 +- .../hadoop/hdfs/web/TestTokenAspect.java | 9 ++- .../hadoop-hdfs-httpfs/pom.xml | 2 +- .../hadoop-hdfs-native-client/pom.xml | 2 +- hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml | 2 +- hadoop-hdfs-project/hadoop-hdfs-rbf/pom.xml | 2 +- .../federation/FederationTestUtils.java | 4 +- .../order/TestAvailableSpaceResolver.java | 2 +- .../resolver/order/TestLocalResolver.java | 2 +- .../federation/router/TestRouterAdmin.java | 2 +- .../federation/router/TestRouterAdminCLI.java | 2 +- hadoop-hdfs-project/hadoop-hdfs/pom.xml | 2 +- .../hadoop/hdfs/TestDFSClientFailover.java | 11 ++- .../hadoop/hdfs/TestDFSClientRetries.java | 29 +++---- .../hadoop/hdfs/TestDFSOutputStream.java | 4 +- .../hdfs/TestDFSStripedInputStream.java | 2 +- .../hdfs/TestDistributedFileSystem.java | 2 +- .../hadoop/hdfs/TestEncryptionZones.java | 16 ++-- .../apache/hadoop/hdfs/TestFileAppend4.java | 11 ++- .../org/apache/hadoop/hdfs/TestLease.java | 19 ++--- .../apache/hadoop/hdfs/TestReplication.java | 7 +- .../impl/TestBlockReaderIoProvider.java | 4 +- .../impl/TestBlockReaderLocalMetrics.java | 23 +++--- .../hdfs/protocol/TestBlockListAsLongs.java | 8 +- .../client/TestQuorumJournalManagerUnit.java | 6 +- .../security/token/block/TestBlockToken.java | 6 +- .../blockmanagement/TestBlockManager.java | 2 +- .../TestBlockManagerSafeMode.java | 2 +- .../TestCorruptReplicaInfo.java | 2 +- .../TestReplicationPolicy.java | 2 +- .../server/datanode/BlockReportTestBase.java | 11 +-- .../datanode/InternalDataNodeTestUtils.java | 16 ++-- .../server/datanode/TestBPOfferService.java | 73 ++++++++---------- .../TestBlockCountersInPendingIBR.java | 4 +- .../server/datanode/TestBlockRecovery.java | 31 ++++---- .../datanode/TestDataNodeHotSwapVolumes.java | 4 +- .../server/datanode/TestDataNodeLifeline.java | 11 ++- .../TestDataXceiverBackwardsCompat.java | 15 ++-- .../TestDataXceiverLazyPersistHint.java | 20 +++-- .../TestDatanodeProtocolRetryPolicy.java | 20 ++--- ...stDnRespectsBlockReportSplitThreshold.java | 10 +-- .../server/datanode/TestFsDatasetCache.java | 8 +- .../datanode/TestIncrementalBlockReports.java | 4 +- .../server/datanode/TestStorageReport.java | 9 +-- .../datanode/TestTriggerBlockReport.java | 10 +-- .../checker/TestDatasetVolumeChecker.java | 8 +- .../TestDatasetVolumeCheckerFailures.java | 20 +++-- .../TestDatasetVolumeCheckerTimeout.java | 23 ++---- .../TestThrottledAsyncCheckerTimeout.java | 2 +- .../fsdataset/impl/TestFsDatasetImpl.java | 17 ++--- .../server/diskbalancer/TestDiskBalancer.java | 2 +- .../hdfs/server/namenode/FSImageTestUtil.java | 4 +- .../server/namenode/TestAuditLogAtDebug.java | 2 +- .../hdfs/server/namenode/TestAuditLogger.java | 2 +- .../namenode/TestAuditLoggerWithCommands.java | 2 +- .../hdfs/server/namenode/TestCheckpoint.java | 12 +-- .../TestCommitBlockSynchronization.java | 4 +- .../hdfs/server/namenode/TestDeleteRace.java | 7 +- .../namenode/TestDiskspaceQuotaUpdate.java | 10 +-- .../namenode/TestEditLogFileInputStream.java | 2 +- .../namenode/TestEditLogJournalFailures.java | 6 +- .../server/namenode/TestFSDirWriteFileOp.java | 14 ++-- .../namenode/TestFSPermissionChecker.java | 2 +- .../hadoop/hdfs/server/namenode/TestFsck.java | 7 +- .../server/namenode/TestGetImageServlet.java | 9 +-- .../TestNNStorageRetentionManager.java | 4 +- .../server/namenode/TestSaveNamespace.java | 20 ++--- .../server/namenode/TestStorageRestore.java | 4 +- .../server/namenode/ha/TestDNFencing.java | 13 ++-- .../namenode/ha/TestFailureToReadEdits.java | 10 +-- .../server/namenode/ha/TestObserverNode.java | 6 +- .../namenode/ha/TestPipelinesFailover.java | 7 +- .../namenode/ha/TestStandbyCheckpoints.java | 16 ++-- .../snapshot/TestRenameWithSnapshots.java | 38 +++++----- .../snapshot/TestSnapshotManager.java | 4 +- .../hadoop/hdfs/tools/TestDFSAdmin.java | 2 +- .../tools/TestDelegationTokenFetcher.java | 7 +- .../apache/hadoop/hdfs/web/TestWebHDFS.java | 4 +- .../hadoop/hdfs/web/TestWebHdfsTokens.java | 3 +- .../mapred/TestLocalContainerLauncher.java | 2 +- .../mapred/TestTaskAttemptListenerImpl.java | 14 +--- .../apache/hadoop/mapred/TestYarnChild.java | 2 +- .../TestJobHistoryEventHandler.java | 2 +- .../v2/app/TestKillAMPreemptionPolicy.java | 14 ++-- .../mapreduce/v2/app/TestMRAppMaster.java | 2 +- .../mapreduce/v2/app/TestStagingCleanup.java | 4 +- .../v2/app/TestTaskHeartbeatHandler.java | 2 +- .../app/commit/TestCommitterEventHandler.java | 10 +-- .../v2/app/job/impl/TestJobImpl.java | 2 +- .../launcher/TestContainerLauncherImpl.java | 2 +- .../local/TestLocalContainerAllocator.java | 2 +- .../v2/app/rm/TestRMCommunicator.java | 15 ++-- .../v2/app/rm/TestRMContainerAllocator.java | 8 +- .../TestLocalDistributedCacheManager.java | 4 +- .../org/apache/hadoop/mapred/TestMapTask.java | 2 +- .../org/apache/hadoop/mapred/TestTask.java | 4 +- .../mapreduce/TestJobMonitorAndPrint.java | 6 +- .../mapreduce/TestJobResourceUploader.java | 4 +- ...estJobResourceUploaderWithSharedCache.java | 6 +- .../mapreduce/lib/db/DriverForTest.java | 2 +- .../mapreduce/security/TestTokenCache.java | 2 +- .../mapreduce/task/reduce/TestFetcher.java | 1 - .../mapreduce/task/reduce/TestMerger.java | 2 +- .../hadoop/mapreduce/tools/TestCLI.java | 2 +- ...toryServerFileSystemStateStoreService.java | 11 +-- .../mapreduce/v2/hs/TestJobHistory.java | 4 +- .../mapreduce/v2/hs/webapp/TestBlocks.java | 2 +- .../v2/hs/webapp/TestHsJobBlock.java | 2 +- .../hadoop/mapred/JobClientUnitTest.java | 2 +- .../mapred/TestClientServiceDelegate.java | 2 +- .../mapred/TestMRCJCFileInputFormat.java | 2 +- .../apache/hadoop/mapred/TestYARNRunner.java | 2 +- .../TestYarnClientProtocolProvider.java | 2 +- .../TestUmbilicalProtocolWithJobToken.java | 7 +- .../pom.xml | 2 +- .../handlers/TestCombineHandler.java | 11 ++- .../TestNativeCollectorOnlyHandler.java | 8 +- .../nativetask/serde/TestKVSerializer.java | 28 +++---- .../hadoop/mapred/TestShuffleHandler.java | 2 +- .../hadoop-mapreduce-client/pom.xml | 2 +- hadoop-mapreduce-project/pom.xml | 2 +- hadoop-project/pom.xml | 4 +- hadoop-tools/hadoop-archive-logs/pom.xml | 2 +- hadoop-tools/hadoop-archives/pom.xml | 2 +- hadoop-tools/hadoop-aws/pom.xml | 2 +- .../hadoop/fs/s3a/MockS3ClientFactory.java | 2 +- .../hadoop/fs/s3a/TestS3AGetFileStatus.java | 33 +++----- .../s3a/commit/staging/StagingTestBase.java | 2 +- .../org/apache/hadoop/mapreduce/MockJob.java | 5 +- hadoop-tools/hadoop-azure/pom.xml | 2 +- .../fs/azure/ITestWasbRemoteCallHelper.java | 69 +++++++---------- .../ITestAzureFileSystemInstrumentation.java | 57 +++----------- hadoop-tools/hadoop-datajoin/pom.xml | 2 +- hadoop-tools/hadoop-distcp/pom.xml | 2 +- hadoop-tools/hadoop-extras/pom.xml | 2 +- hadoop-tools/hadoop-fs2img/pom.xml | 2 +- hadoop-tools/hadoop-gridmix/pom.xml | 2 +- .../mapred/gridmix/TestGridMixClasses.java | 8 +- hadoop-tools/hadoop-kafka/pom.xml | 2 +- .../metrics2/impl/TestKafkaMetrics.java | 4 +- hadoop-tools/hadoop-streaming/pom.xml | 2 +- .../pom.xml | 2 +- .../distributedshell/TestDSAppMaster.java | 5 +- .../hadoop-yarn-services-api/pom.xml | 2 +- .../hadoop-yarn-services-core/pom.xml | 2 +- .../service/MockRunningServiceContext.java | 12 +-- .../hadoop/yarn/service/MockServiceAM.java | 6 +- .../hadoop/yarn/service/ServiceTestUtils.java | 6 +- .../service/client/TestServiceClient.java | 12 +-- .../instance/TestComponentInstance.java | 6 +- .../service/provider/TestProviderUtils.java | 2 +- .../providers/TestAbstractClientProvider.java | 4 +- .../providers/TestDefaultClientProvider.java | 4 +- .../hadoop-yarn-submarine/pom.xml | 2 +- .../client/cli/TestRunJobCliParsing.java | 2 +- .../yarnservice/TestYarnServiceRunJobCli.java | 4 +- .../hadoop-yarn/hadoop-yarn-client/pom.xml | 2 +- .../api/async/impl/TestAMRMClientAsync.java | 8 +- .../api/async/impl/TestNMClientAsync.java | 4 +- .../yarn/client/api/impl/TestAHSClient.java | 2 +- .../yarn/client/api/impl/TestAMRMClient.java | 2 +- .../api/impl/TestSharedCacheClientImpl.java | 2 +- .../yarn/client/api/impl/TestYarnClient.java | 2 +- .../client/api/impl/TestYarnClientImpl.java | 7 +- .../hadoop/yarn/client/cli/TestLogsCLI.java | 10 +-- .../client/cli/TestNodeAttributesCLI.java | 2 +- .../yarn/client/cli/TestRMAdminCLI.java | 17 ++--- .../hadoop/yarn/client/cli/TestYarnCLI.java | 6 +- .../hadoop-yarn/hadoop-yarn-common/pom.xml | 6 +- .../client/api/impl/TestTimelineClient.java | 8 +- .../api/impl/TestTimelineClientForATS1_5.java | 2 +- .../impl/pb/TestRpcClientFactoryPBImpl.java | 2 +- .../impl/pb/TestRpcServerFactoryPBImpl.java | 2 +- .../pom.xml | 2 +- .../webapp/TestTimelineWebServices.java | 2 +- .../hadoop-yarn-server-common/pom.xml | 2 +- .../utils/FederationPoliciesTestUtil.java | 2 +- .../hadoop-yarn-server-nodemanager/pom.xml | 6 +- .../TestDefaultContainerExecutor.java | 9 +-- .../TestLinuxContainerExecutor.java | 4 +- .../TestLinuxContainerExecutorWithMocks.java | 17 ++--- .../nodemanager/TestNodeManagerReboot.java | 2 +- .../BaseContainerManagerTest.java | 8 +- .../containermanager/TestAuxServices.java | 4 +- .../TestContainerManagerRecovery.java | 2 +- .../application/TestApplication.java | 11 +-- .../container/TestContainer.java | 50 ++++--------- .../task/DockerContainerDeletionMatcher.java | 5 +- .../deletion/task/FileDeletionMatcher.java | 5 +- .../launcher/TestContainerLaunch.java | 2 +- .../launcher/TestContainerRelaunch.java | 4 +- .../launcher/TestContainersLauncher.java | 8 +- .../MockPrivilegedOperationCaptor.java | 10 +-- .../TestCGroupElasticMemoryController.java | 2 +- .../resources/TestCGroupsHandlerImpl.java | 2 +- .../resources/TestDefaultOOMHandler.java | 2 +- .../TestNetworkPacketTaggingHandlerImpl.java | 4 +- ...estTrafficControlBandwidthHandlerImpl.java | 2 +- .../resources/TestTrafficController.java | 4 +- .../fpga/TestFpgaResourceHandler.java | 5 +- .../resources/gpu/TestGpuResourceHandler.java | 8 +- .../numa/TestNumaResourceAllocator.java | 6 +- .../numa/TestNumaResourceHandlerImpl.java | 6 +- .../runtime/TestDockerContainerRuntime.java | 66 +++++++--------- .../docker/TestDockerCommandExecutor.java | 6 +- .../localizer/TestContainerLocalizer.java | 27 +++---- .../TestLocalResourcesTrackerImpl.java | 6 +- .../localizer/TestLocalizedResource.java | 22 +++--- .../TestResourceLocalizationService.java | 75 ++++++------------- .../sharedcache/TestSharedCacheUploader.java | 4 +- .../TestAppLogAggregatorImpl.java | 2 +- .../TestLogAggregationService.java | 9 ++- .../TestNonAggregatingLogHandler.java | 16 ++-- .../TestResourcePluginManager.java | 2 +- .../TestDevicePluginAdapter.java | 8 +- .../fpga/TestFpgaDiscoverer.java | 4 +- .../TestContainerSchedulerQueuing.java | 2 +- .../TestContainerSchedulerRecovery.java | 4 +- .../TestNMLeveldbStateStoreService.java | 2 +- .../pom.xml | 6 +- .../resourcemanager/TestAppManager.java | 8 +- .../TestAppManagerWithFairScheduler.java | 4 +- .../resourcemanager/TestApplicationACLs.java | 2 +- .../TestApplicationMasterLauncher.java | 2 +- .../resourcemanager/TestClientRMService.java | 35 ++++----- .../resourcemanager/TestClientRMTokens.java | 6 +- .../yarn/server/resourcemanager/TestRM.java | 14 ++-- .../TestRMEmbeddedElector.java | 2 +- .../TestRMNodeTransitions.java | 17 +++-- .../server/resourcemanager/TestRMRestart.java | 6 +- .../TestResourceTrackerService.java | 2 +- .../TestWorkPreservingRMRestart.java | 2 +- .../TestRMAppLogAggregationStatus.java | 2 +- ...CapacityPreemptionPolicyMockFramework.java | 14 ++-- .../TestPreemptionForQueueWithPriorities.java | 2 +- ...tProportionalCapacityPreemptionPolicy.java | 19 +++-- ...cityPreemptionPolicyForNodePartitions.java | 2 +- ...PreemptionPolicyForReservedContainers.java | 2 +- ...cityPreemptionPolicyInterQueueWithDRF.java | 2 +- ...nalCapacityPreemptionPolicyIntraQueue.java | 2 +- ...reemptionPolicyIntraQueueFairOrdering.java | 2 +- ...tyPreemptionPolicyIntraQueueUserLimit.java | 2 +- ...cityPreemptionPolicyIntraQueueWithDRF.java | 2 +- ...acityPreemptionPolicyPreemptToBalance.java | 2 +- .../TestFileSystemNodeAttributeStore.java | 2 +- .../ReservationSystemTestUtil.java | 8 +- .../TestCapacitySchedulerPlanFollower.java | 12 +-- .../TestFairSchedulerPlanFollower.java | 10 +-- .../TestReservationInputValidator.java | 2 +- .../planning/TestSimpleCapacityReplanner.java | 2 +- .../rmapp/TestNodesListManager.java | 11 ++- .../rmapp/TestRMAppTransitions.java | 9 +-- .../attempt/TestRMAppAttemptTransitions.java | 26 +++---- .../rmcontainer/TestRMContainerImpl.java | 16 ++-- .../TestConfigurationMutationACLPolicies.java | 4 +- .../scheduler/TestSchedulerUtils.java | 4 +- .../capacity/TestApplicationLimits.java | 14 ++-- .../TestApplicationLimitsByPartition.java | 13 ++-- .../capacity/TestChildQueueOrder.java | 9 +-- .../scheduler/capacity/TestLeafQueue.java | 11 +-- .../scheduler/capacity/TestParentQueue.java | 4 +- .../scheduler/capacity/TestQueueState.java | 3 +- .../capacity/TestQueueStateManager.java | 2 +- .../scheduler/capacity/TestReservations.java | 2 +- .../scheduler/capacity/TestUtils.java | 4 +- .../fair/TestContinuousScheduling.java | 2 +- .../scheduler/fair/TestFSSchedulerNode.java | 2 +- ...SingleConstraintAppPlacementAllocator.java | 4 +- .../security/TestClientToAMTokens.java | 2 +- .../security/TestDelegationTokenRenewer.java | 2 +- .../security/TestProxyCAManager.java | 2 +- .../security/TestRMAuthenticationFilter.java | 3 +- .../volume/csi/TestVolumeProcessor.java | 2 +- .../TestApplicationsRequestBuilder.java | 4 +- .../resourcemanager/webapp/TestRMWebApp.java | 2 +- .../webapp/TestRMWebServices.java | 2 +- .../hadoop-yarn-server-router/pom.xml | 2 +- .../pom.xml | 2 +- .../sharedcachemanager/TestCleanerTask.java | 7 +- .../TestSCMAdminProtocolService.java | 4 +- .../store/TestInMemorySCMStore.java | 3 +- .../hadoop-yarn-server-tests/pom.xml | 2 +- .../TestTimelineServiceClientIntegration.java | 2 +- .../security/TestTimelineAuthFilterForV2.java | 4 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../TestNMTimelineCollectorManager.java | 2 +- ...stPerNodeTimelineCollectorsAuxService.java | 2 +- .../collector/TestTimelineCollector.java | 2 +- ...ineReaderWhitelistAuthorizationFilter.java | 2 +- .../hadoop-yarn-server-web-proxy/pom.xml | 2 +- .../webproxy/amfilter/TestAmFilter.java | 3 +- 335 files changed, 1069 insertions(+), 1346 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index a01cff4482..1d97b95c10 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -667,7 +667,7 @@ spin.js v2.3.2 Azure Data Lake Store - Java client SDK 2.0.11 JCodings 1.0.8 Joni 2.1.2 -Mockito 1.8.5 +Mockito 2.23.4 JUL to SLF4J bridge 1.7.25 SLF4J API Module 1.7.25 SLF4J LOG4J-12 Binding 1.7.25 diff --git a/hadoop-client-modules/hadoop-client-minicluster/pom.xml b/hadoop-client-modules/hadoop-client-minicluster/pom.xml index 5ceb2c0809..9007462771 100644 --- a/hadoop-client-modules/hadoop-client-minicluster/pom.xml +++ b/hadoop-client-modules/hadoop-client-minicluster/pom.xml @@ -385,7 +385,7 @@ org.mockito - mockito-all + mockito-core true @@ -729,7 +729,7 @@ - org.mockito:mockito-all + org.mockito:mockito-core asm-license.txt cglib-license.txt diff --git a/hadoop-common-project/hadoop-auth/pom.xml b/hadoop-common-project/hadoop-auth/pom.xml index 45d727f751..d9ea33dfb2 100644 --- a/hadoop-common-project/hadoop-auth/pom.xml +++ b/hadoop-common-project/hadoop-auth/pom.xml @@ -48,7 +48,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java b/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java index 87223d157d..20c0343f95 100644 --- a/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java +++ b/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/server/TestAuthenticationFilter.java @@ -47,6 +47,7 @@ import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; public class TestAuthenticationFilter { @@ -533,7 +534,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } } - ).when(chain).doFilter(Mockito.anyObject(), Mockito.anyObject()); + ).when(chain).doFilter(any(), any()); Mockito.when(response.containsHeader("WWW-Authenticate")).thenReturn(true); filter.doFilter(request, response, chain); @@ -616,8 +617,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { Assert.assertNotNull("cookie missing", v); Assert.assertTrue(v.contains("u=") && v.contains("p=") && v.contains ("t=") && v.contains("e=") && v.contains("s=")); - Mockito.verify(chain).doFilter(Mockito.any(ServletRequest.class), - Mockito.any(ServletResponse.class)); + Mockito.verify(chain).doFilter(any(ServletRequest.class), + any(ServletResponse.class)); SignerSecretProvider secretProvider = StringSignerSecretProviderCreator.newStringSignerSecretProvider(); @@ -727,7 +728,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } } - ).when(chain).doFilter(Mockito.anyObject(), Mockito.anyObject()); + ).when(chain).doFilter(any(), any()); filter.doFilter(request, response, chain); @@ -780,7 +781,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } } - ).when(chain).doFilter(Mockito.anyObject(), Mockito.anyObject()); + ).when(chain).doFilter(any(), any()); 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 ("t=") && v.contains("i=") && v.contains("e=") && v.contains("s=")); - Mockito.verify(chain).doFilter(Mockito.any(ServletRequest.class), - Mockito.any(ServletResponse.class)); + Mockito.verify(chain).doFilter(any(ServletRequest.class), + any(ServletResponse.class)); SignerSecretProvider secretProvider = StringSignerSecretProviderCreator.newStringSignerSecretProvider(); @@ -1134,8 +1135,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { Mockito.verify(response).sendError(Mockito.eq(HttpServletResponse .SC_UNAUTHORIZED), Mockito.anyString()); - Mockito.verify(chain, Mockito.never()).doFilter(Mockito.any - (ServletRequest.class), Mockito.any(ServletResponse.class)); + Mockito.verify(chain, Mockito.never()).doFilter( + any(ServletRequest.class), any(ServletResponse.class)); Assert.assertTrue("cookie is missing", cookieMap.containsKey(AuthenticatedURL.AUTH_COOKIE)); diff --git a/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestRandomSignerSecretProvider.java b/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestRandomSignerSecretProvider.java index 45398c286b..f9c922caac 100644 --- a/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestRandomSignerSecretProvider.java +++ b/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestRandomSignerSecretProvider.java @@ -26,8 +26,8 @@ public class TestRandomSignerSecretProvider { - // rollover every 50 msec - private final int timeout = 100; + // rollover every 250 msec + private final int timeout = 500; private final long rolloverFrequency = timeout / 2; { diff --git a/hadoop-common-project/hadoop-common/pom.xml b/hadoop-common-project/hadoop-common/pom.xml index 3036b64397..a62f7ae0a3 100644 --- a/hadoop-common-project/hadoop-common/pom.xml +++ b/hadoop-common-project/hadoop-common/pom.xml @@ -193,7 +193,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestReconfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestReconfiguration.java index b4dcd54e27..39d3bae655 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestReconfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestReconfiguration.java @@ -31,9 +31,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemTokens.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemTokens.java index 6d2bd6595c..0372537cb3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemTokens.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemTokens.java @@ -19,7 +19,6 @@ package org.apache.hadoop.fs; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java index 9e01aefaca..e7f42ff2b5 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java @@ -19,7 +19,6 @@ package org.apache.hadoop.fs; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShell.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShell.java index da93196574..e83e30e41e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShell.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShell.java @@ -92,7 +92,7 @@ public void testDFSWithInvalidCommmand() throws Throwable { public void testExceptionNullMessage() throws Exception { final String cmdName = "-cmdExNullMsg"; final Command cmd = Mockito.mock(Command.class); - Mockito.when(cmd.run(Mockito.anyVararg())).thenThrow( + Mockito.when(cmd.run(Mockito.any())).thenThrow( new IllegalArgumentException()); Mockito.when(cmd.getUsage()).thenReturn(cmdName); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopy.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopy.java index 01336288b4..74fb34d9fd 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopy.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopy.java @@ -36,7 +36,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.shell.CopyCommands.Put; -import org.apache.hadoop.util.Progressable; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -153,8 +152,7 @@ public void testInterruptedRename() throws Exception { private OngoingStubbing whenFsCreate() throws IOException { return when(mockFs.create(eq(tmpPath), any(FsPermission.class), - anyBoolean(), anyInt(), anyShort(), anyLong(), - any(Progressable.class))); + anyBoolean(), anyInt(), anyShort(), anyLong(), any())); } private void tryCopyStream(InputStream in, boolean shouldPass) { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestLs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestLs.java index 2e5c3e3bca..4a4f453d5e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestLs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestLs.java @@ -20,7 +20,7 @@ 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.junit.Assert.*; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; import java.io.ByteArrayOutputStream; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestMove.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestMove.java index 94930e5d4f..1f379448ee 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestMove.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestMove.java @@ -19,7 +19,7 @@ package org.apache.hadoop.fs.shell; import static org.junit.Assert.*; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java index d72ab74921..e080cd6715 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java @@ -25,9 +25,9 @@ import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -536,7 +536,7 @@ public void testFileStatusOnMountLink() throws IOException { @Test public void testGetFileChecksum() throws AccessControlException, - UnresolvedLinkException, IOException { + UnresolvedLinkException, IOException, URISyntaxException { AbstractFileSystem mockAFS = mock(AbstractFileSystem.class); InodeTree.ResolveResult res = new InodeTree.ResolveResult(null, mockAFS , null, @@ -544,13 +544,10 @@ public void testGetFileChecksum() throws AccessControlException, @SuppressWarnings("unchecked") InodeTree fsState = mock(InodeTree.class); when(fsState.resolve(anyString(), anyBoolean())).thenReturn(res); - ViewFs vfs = mock(ViewFs.class); + ViewFs vfs = new ViewFs(conf); vfs.fsState = fsState; - when(vfs.getFileChecksum(new Path("/tmp/someFile"))) - .thenCallRealMethod(); vfs.getFileChecksum(new Path("/tmp/someFile")); - verify(mockAFS).getFileChecksum(new Path("someFile")); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElector.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElector.java index ca3389f7b1..a68dad6509 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElector.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElector.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; -import org.apache.zookeeper.AsyncCallback; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.Code; @@ -45,6 +44,8 @@ import org.apache.hadoop.util.ZKUtil.ZKAuthInfo; import org.apache.hadoop.test.GenericTestUtils; +import static org.mockito.ArgumentMatchers.any; + public class TestActiveStandbyElector { private ZooKeeper mockZK; @@ -438,8 +439,7 @@ public void testProcessCallbackEventNone() throws Exception { Event.KeeperState.SyncConnected); elector.processWatchEvent(mockZK, mockEvent); Mockito.verify(mockZK, Mockito.times(0)).exists(Mockito.anyString(), - Mockito.anyBoolean(), Mockito. anyObject(), - Mockito. anyObject()); + Mockito.anyBoolean(), any(), any()); // disconnection should enter safe mode Mockito.when(mockEvent.getState()).thenReturn( @@ -663,38 +663,35 @@ public void testGetActiveData() throws ActiveNotFoundException, byte[] data = new byte[8]; Mockito.when( mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), - Mockito. anyObject())).thenReturn(data); + any())).thenReturn(data); Assert.assertEquals(data, elector.getActiveData()); Mockito.verify(mockZK, Mockito.times(1)).getData( - Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), - Mockito. anyObject()); + Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), any()); // active does not exist Mockito.when( mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), - Mockito. anyObject())).thenThrow( + any())).thenThrow( new KeeperException.NoNodeException()); try { elector.getActiveData(); Assert.fail("ActiveNotFoundException expected"); } catch(ActiveNotFoundException e) { Mockito.verify(mockZK, Mockito.times(2)).getData( - Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), - Mockito. anyObject()); + Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), any()); } // error getting active data rethrows keeperexception try { Mockito.when( mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), - Mockito. anyObject())).thenThrow( + any())).thenThrow( new KeeperException.AuthFailedException()); elector.getActiveData(); Assert.fail("KeeperException.AuthFailedException expected"); } catch(KeeperException.AuthFailedException ke) { Mockito.verify(mockZK, Mockito.times(3)).getData( - Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), - Mockito. anyObject()); + Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false), any()); } } @@ -729,7 +726,7 @@ public Code code() { }; Mockito.when(mockZK.create(Mockito.anyString(), Mockito.eq(new byte[]{}), - Mockito.anyListOf(ACL.class), + Mockito.anyList(), Mockito.eq(CreateMode.PERSISTENT))).thenThrow(ke); elector.ensureParentZNode(); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestIsActiveServlet.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestIsActiveServlet.java index 5f5d51e1d7..cfc7e359e9 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestIsActiveServlet.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestIsActiveServlet.java @@ -29,9 +29,9 @@ import java.io.PrintWriter; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/lib/TestStaticUserWebFilter.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/lib/TestStaticUserWebFilter.java index 9b161df25f..03b37e3046 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/lib/TestStaticUserWebFilter.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/lib/TestStaticUserWebFilter.java @@ -18,6 +18,7 @@ package org.apache.hadoop.http.lib; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import javax.servlet.FilterChain; @@ -55,7 +56,7 @@ public void testFilter() throws Exception { suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class), chain); - Mockito.verify(chain).doFilter(wrapperArg.capture(), Mockito.anyObject()); + Mockito.verify(chain).doFilter(wrapperArg.capture(), any()); HttpServletRequestWrapper wrapper = wrapperArg.getValue(); assertEquals("myuser", wrapper.getUserPrincipal().getName()); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java index 1accb0a0b2..241e21046d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestRetryProxy.java @@ -43,9 +43,9 @@ import static org.apache.hadoop.io.retry.RetryPolicies.*; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; public class TestRetryProxy { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java index 776db5e002..21e2018854 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java @@ -22,7 +22,7 @@ import static org.apache.hadoop.test.MetricsAsserts.assertCounter; import static org.apache.hadoop.test.MetricsAsserts.getMetrics; 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.mock; 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. Mockito.reset(fcq); try { - doThrow(stopPuts).when(fcq).putQueue(anyInt(), anyObject()); + doThrow(stopPuts).when(fcq).putQueue(anyInt(), any()); fcq.put(p0); fail("didn't fail"); } catch (Exception e) { @@ -268,7 +268,7 @@ public void testInsertion() throws Exception { // put with lowest priority should not offer, just put. Mockito.reset(fcq); try { - doThrow(stopPuts).when(fcq).putQueue(anyInt(), anyObject()); + doThrow(stopPuts).when(fcq).putQueue(anyInt(), any()); fcq.put(p2); fail("didn't fail"); } catch (Exception e) { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java index 6d2f9c769b..1c1ad00451 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java @@ -23,6 +23,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; 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.doThrow; 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 // are blocking on the queue after initialClients threads are started. - verify(spy, timeout(5000).times(i + 1)).put(Mockito.anyObject()); + verify(spy, timeout(5000).times(i + 1)).put(any()); } try { @@ -1604,11 +1606,11 @@ private void checkUserBinding(boolean asProxy) throws Exception { Socket s; // don't attempt bind with no service host. 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. 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. InetAddress addr = InetAddress.getLocalHost(); @@ -1643,7 +1645,7 @@ private Socket checkConnect(String addr, boolean asProxy) throws Exception { SocketFactory mockFactory = Mockito.mock(SocketFactory.class); Mockito.doReturn(s).when(mockFactory).createSocket(); 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. // tests should verify if/how a bind occurred. diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java index d4fa60dd53..4d52e5fb96 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java @@ -52,7 +52,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.event.Level; @@ -95,6 +94,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; @@ -1133,7 +1133,7 @@ public Void call() throws ServiceException, InterruptedException { return null; } })); - verify(spy, timeout(500).times(i + 1)).add(Mockito.anyObject()); + verify(spy, timeout(500).times(i + 1)).add(any()); } try { proxy.sleep(null, newSleepRequest(100)); @@ -1204,7 +1204,7 @@ public Void call() throws ServiceException, InterruptedException { return null; } })); - verify(spy, timeout(500).times(i + 1)).add(Mockito.anyObject()); + verify(spy, timeout(500).times(i + 1)).add(any()); } // Start another sleep RPC call and verify the call is backed off due to // avg response time(3s) exceeds threshold (2s). diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java index 420d6b9408..fbaa75bd43 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java @@ -19,7 +19,6 @@ package org.apache.hadoop.ipc; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import java.io.IOException; @@ -154,12 +153,12 @@ public Writable call( // No stack trace should be logged for a terse exception. 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. final Throwable te3 = new TestException3(); server.logException(logger, te3, dummyCall); - verify(logger, times(1)).info(anyObject(), eq(te3)); + verify(logger, times(1)).info(any(), eq(te3)); } @Test diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java index 2f3ee4f0a7..743080acd7 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java @@ -34,8 +34,8 @@ import java.util.Collections; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java index f3a2553511..47a3b4cdc0 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java @@ -32,7 +32,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import static org.junit.Assert.*; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsVisitor.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsVisitor.java index 2f1b397c85..d7614d2d0b 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsVisitor.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsVisitor.java @@ -27,7 +27,7 @@ import static org.mockito.Mockito.*; import org.mockito.ArgumentCaptor; 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.AbstractMetric; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java index b0d7debe44..29d47cfab0 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java @@ -23,8 +23,8 @@ import static org.mockito.AdditionalMatchers.eq; import static org.mockito.AdditionalMatchers.geq; import static org.mockito.AdditionalMatchers.leq; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.junit.Assert.*; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableRollingAverages.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableRollingAverages.java index 04c1d8da93..9bfdd73bee 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableRollingAverages.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMutableRollingAverages.java @@ -31,8 +31,8 @@ import static org.apache.hadoop.metrics2.lib.Interns.info; import static org.apache.hadoop.test.MetricsAsserts.*; -import static org.mockito.Matchers.anyDouble; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyDouble; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; /** diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java index ead3758593..e0b3e515a0 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestAuthenticationFilter.java @@ -18,6 +18,8 @@ import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; + import org.apache.hadoop.http.HttpServer2; import org.apache.hadoop.security.authentication.server.AuthenticationFilter; import org.apache.hadoop.conf.Configuration; @@ -27,9 +29,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import java.io.File; -import java.io.FileWriter; -import java.io.Writer; import java.util.Map; public class TestAuthenticationFilter { @@ -69,10 +68,7 @@ public Object answer(InvocationOnMock invocationOnMock) return null; } - } - ).when(container).addFilter(Mockito.anyObject(), - Mockito.anyObject(), - Mockito.>anyObject()); + }).when(container).addFilter(any(), any(), any()); new AuthenticationFilterInitializer().initFilter(container, conf); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java index 174333859b..dba2b086f8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java @@ -25,8 +25,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithFailover.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithFailover.java index 4f6ea1f3ba..2f14c735ab 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithFailover.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithFailover.java @@ -34,8 +34,8 @@ import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_NUM_ATTEMPTS_KEY; import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_URL_KEY; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithOneQuery.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithOneQuery.java index f51a944bc6..7ae802e26d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithOneQuery.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithOneQuery.java @@ -32,9 +32,9 @@ import org.junit.Before; import org.junit.Test; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithPosixGroup.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithPosixGroup.java index 4a213454a6..7ecc636984 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithPosixGroup.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingWithPosixGroup.java @@ -18,7 +18,7 @@ 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.contains; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestRuleBasedLdapGroupsMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestRuleBasedLdapGroupsMapping.java index 6592c79e3f..cd04ae09e3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestRuleBasedLdapGroupsMapping.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestRuleBasedLdapGroupsMapping.java @@ -28,8 +28,8 @@ import static org.apache.hadoop.security.RuleBasedLdapGroupsMapping .CONVERSION_RULE_KEY; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; /** * Test cases to verify the rules supported by RuleBasedLdapGroupsMapping. diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/http/TestXFrameOptionsFilter.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/http/TestXFrameOptionsFilter.java index d9e36c42e4..1c1d97d7ca 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/http/TestXFrameOptionsFilter.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/http/TestXFrameOptionsFilter.java @@ -21,8 +21,6 @@ import java.util.ArrayList; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,6 +31,8 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import static org.mockito.ArgumentMatchers.any; + /** * Test the default and customized behaviors of XFrameOptionsFilter. * @@ -63,8 +63,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } } - ).when(chain).doFilter(Mockito.anyObject(), - Mockito.anyObject()); + ).when(chain).doFilter(any(), any()); Mockito.doAnswer( new Answer() { @@ -78,8 +77,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } } - ).when(response).setHeader(Mockito.anyObject(), - Mockito.anyObject()); + ).when(response).setHeader(any(), any()); XFrameOptionsFilter filter = new XFrameOptionsFilter(); filter.init(filterConfig); @@ -119,8 +117,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } } - ).when(chain).doFilter(Mockito.anyObject(), - Mockito.anyObject()); + ).when(chain).doFilter(any(), any()); Mockito.doAnswer( new Answer() { @@ -134,8 +131,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } } - ).when(response).setHeader(Mockito.anyObject(), - Mockito.anyObject()); + ).when(response).setHeader(any(), any()); XFrameOptionsFilter filter = new XFrameOptionsFilter(); filter.init(filterConfig); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestServiceOperations.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestServiceOperations.java index cc1cfbf5a9..9794c54998 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestServiceOperations.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestServiceOperations.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java index d3848345e0..0cb5288e88 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java @@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.*; -import org.hamcrest.Description; import org.junit.Assert; import static org.mockito.AdditionalMatchers.geq; @@ -104,19 +103,22 @@ public static MetricsRecordBuilder getMetrics(MetricsSource source) { return getMetrics(source, true); } - private static class InfoWithSameName extends ArgumentMatcher { + private static class InfoWithSameName + implements ArgumentMatcher{ private final String expected; InfoWithSameName(MetricsInfo info) { expected = checkNotNull(info.name(), "info name"); } - @Override public boolean matches(Object info) { - return expected.equals(((MetricsInfo)info).name()); + @Override + public boolean matches(MetricsInfo info) { + return expected.equals(info.name()); } - @Override public void describeTo(Description desc) { - desc.appendText("Info with name="+ expected); + @Override + public String toString() { + return "Info with name=" + expected; } } @@ -129,9 +131,10 @@ public static MetricsInfo eqName(MetricsInfo info) { return argThat(new InfoWithSameName(info)); } - private static class AnyInfo extends ArgumentMatcher { - @Override public boolean matches(Object info) { - return info instanceof MetricsInfo; // not null as well + private static class AnyInfo implements ArgumentMatcher { + @Override + public boolean matches(MetricsInfo info) { + return info != null; } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java index a8c27d4757..1f7c71222f 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-common-project/hadoop-kms/pom.xml b/hadoop-common-project/hadoop-kms/pom.xml index 3a6ed54dbb..0eed09a256 100644 --- a/hadoop-common-project/hadoop-kms/pom.xml +++ b/hadoop-common-project/hadoop-kms/pom.xml @@ -45,7 +45,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-common-project/hadoop-nfs/pom.xml b/hadoop-common-project/hadoop-nfs/pom.xml index 68c3339cfc..fb3fe68ba9 100644 --- a/hadoop-common-project/hadoop-nfs/pom.xml +++ b/hadoop-common-project/hadoop-nfs/pom.xml @@ -60,7 +60,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdds/framework/pom.xml b/hadoop-hdds/framework/pom.xml index 650442db29..40d039a0bc 100644 --- a/hadoop-hdds/framework/pom.xml +++ b/hadoop-hdds/framework/pom.xml @@ -35,7 +35,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdds/server-scm/pom.xml b/hadoop-hdds/server-scm/pom.xml index aff0d29b09..298dfc309e 100644 --- a/hadoop-hdds/server-scm/pom.xml +++ b/hadoop-hdds/server-scm/pom.xml @@ -88,7 +88,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml b/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml index 1a1854d8b9..2b18885fc4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-client/pom.xml @@ -60,7 +60,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRequestHedgingProxyProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRequestHedgingProxyProvider.java index fc81a09f42..5704ef0bd4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRequestHedgingProxyProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRequestHedgingProxyProvider.java @@ -47,10 +47,12 @@ import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains; import static org.junit.Assert.assertEquals; -import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; 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.mock; @@ -316,15 +318,13 @@ public long[] answer(InvocationOnMock invocation) throws Throwable { public void testFileNotFoundExceptionWithSingleProxy() throws Exception { ClientProtocol active = Mockito.mock(ClientProtocol.class); Mockito - .when(active.getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong())) + .when(active.getBlockLocations(anyString(), anyLong(), anyLong())) .thenThrow(new RemoteException("java.io.FileNotFoundException", "File does not exist!")); ClientProtocol standby = Mockito.mock(ClientProtocol.class); Mockito - .when(standby.getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong())) + .when(standby.getBlockLocations(anyString(), anyLong(), anyLong())) .thenThrow( new RemoteException("org.apache.hadoop.ipc.StandbyException", "Standby NameNode")); @@ -354,18 +354,16 @@ public void testFileNotFoundExceptionWithSingleProxy() throws Exception { } catch (RemoteException ex) { Exception rEx = ex.unwrapRemoteException(); if (rEx instanceof StandbyException) { - Mockito.verify(active).getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong()); + Mockito.verify(active).getBlockLocations(anyString(), anyLong(), + anyLong()); Mockito.verify(standby, Mockito.times(2)) - .getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong()); + .getBlockLocations(anyString(), anyLong(), anyLong()); } else { Assert.assertTrue(rEx instanceof FileNotFoundException); Mockito.verify(active, Mockito.times(2)) - .getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong()); - Mockito.verify(standby).getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong()); + .getBlockLocations(anyString(), anyLong(), anyLong()); + Mockito.verify(standby).getBlockLocations(anyString(), anyLong(), + anyLong()); } } } @@ -384,8 +382,7 @@ public void testSingleProxyFailover() throws Exception { RandomStringUtils.randomAlphabetic(8) + ".foo.bar:9820"); ClientProtocol active = Mockito.mock(ClientProtocol.class); Mockito - .when(active.getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong())) + .when(active.getBlockLocations(anyString(), anyLong(), anyLong())) .thenThrow(new RemoteException("java.io.FileNotFoundException", "File does not exist!")); @@ -539,15 +536,15 @@ public long[] answer(InvocationOnMock invocation) throws Throwable { public void testHedgingWhenFileNotFoundException() throws Exception { ClientProtocol active = Mockito.mock(ClientProtocol.class); Mockito - .when(active.getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong())) + .when(active.getBlockLocations(anyString(), + anyLong(), anyLong())) .thenThrow(new RemoteException("java.io.FileNotFoundException", "File does not exist!")); ClientProtocol standby = Mockito.mock(ClientProtocol.class); Mockito - .when(standby.getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong())) + .when(standby.getBlockLocations(anyString(), + anyLong(), anyLong())) .thenThrow( new RemoteException("org.apache.hadoop.ipc.StandbyException", "Standby NameNode")); @@ -568,10 +565,10 @@ public void testHedgingWhenFileNotFoundException() throws Exception { Assert.assertTrue(rEx instanceof FileNotFoundException); } } - Mockito.verify(active).getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong()); - Mockito.verify(standby).getBlockLocations(Matchers.anyString(), - Matchers.anyLong(), Matchers.anyLong()); + Mockito.verify(active).getBlockLocations(anyString(), + anyLong(), anyLong()); + Mockito.verify(standby).getBlockLocations(anyString(), + anyLong(), anyLong()); } @Test diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestByteRangeInputStream.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestByteRangeInputStream.java index 35c620cb85..6c426f575b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestByteRangeInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestByteRangeInputStream.java @@ -20,8 +20,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestTokenAspect.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestTokenAspect.java index c022d4f891..4662f4747a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestTokenAspect.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/web/TestTokenAspect.java @@ -25,7 +25,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; 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.doThrow; import static org.mockito.Mockito.mock; @@ -174,7 +175,7 @@ public void testCachedInitialization() throws IOException, URISyntaxException { Token token = new Token(new byte[0], 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(); fs.emulateSecurityEnabled = true; @@ -197,7 +198,7 @@ public void testGetRemoteToken() throws IOException, URISyntaxException { Token token = new Token(new byte[0], 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(); 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 tokenAspect.ensureTokenInitialized(); - verify(fs, times(2)).getDelegationToken(anyString()); + verify(fs, times(2)).getDelegationToken(any()); verify(fs).setDelegationToken(token2); assertNotSame(action, getActionFromTokenAspect(tokenAspect)); diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/pom.xml b/hadoop-hdfs-project/hadoop-hdfs-httpfs/pom.xml index c3d112ed99..76e9fb01b1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/pom.xml @@ -49,7 +49,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/pom.xml b/hadoop-hdfs-project/hadoop-hdfs-native-client/pom.xml index 7464b3b553..d54341b171 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/pom.xml @@ -69,7 +69,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml b/hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml index d99e4954ce..bffa54986d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml @@ -155,7 +155,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/pom.xml b/hadoop-hdfs-project/hadoop-hdfs-rbf/pom.xml index 386eb4166c..6886f00705 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/pom.xml @@ -101,7 +101,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/FederationTestUtils.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/FederationTestUtils.java index ce320f462b..c48e6e26b9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/FederationTestUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/FederationTestUtils.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; 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.spy; @@ -59,7 +59,7 @@ import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.security.AccessControlException; 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.stubbing.Answer; import org.slf4j.Logger; diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestAvailableSpaceResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestAvailableSpaceResolver.java index dfbdf514b7..3d6b61aca0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestAvailableSpaceResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestAvailableSpaceResolver.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; 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.when; diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestLocalResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestLocalResolver.java index 42ede62936..795e3ff64b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestLocalResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestLocalResolver.java @@ -18,7 +18,7 @@ package org.apache.hadoop.hdfs.server.federation.resolver.order; 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.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java index c834dcfd7f..96ae4e9815 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java @@ -59,13 +59,13 @@ import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryRequest; import org.apache.hadoop.hdfs.server.federation.store.records.MountTable; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.test.Whitebox; import org.apache.hadoop.util.Time; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; -import org.mockito.internal.util.reflection.Whitebox; /** * The administrator interface of the {@link Router} implemented by diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java index d968c602fb..80aca55d83 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java @@ -46,13 +46,13 @@ import org.apache.hadoop.hdfs.tools.federation.RouterAdmin; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.test.GenericTestUtils; +import org.apache.hadoop.test.Whitebox; import org.apache.hadoop.util.ToolRunner; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; -import org.mockito.internal.util.reflection.Whitebox; import com.google.common.base.Supplier; diff --git a/hadoop-hdfs-project/hadoop-hdfs/pom.xml b/hadoop-hdfs-project/hadoop-hdfs/pom.xml index f97ca1731f..c35475fec8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/pom.xml @@ -150,7 +150,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.mockito - mockito-all + mockito-core test diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java index 64103b4529..f65bc3a92d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java @@ -55,12 +55,11 @@ import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.util.StringUtils; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.After; import org.junit.Assume; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import sun.net.spi.nameservice.NameService; @@ -169,15 +168,15 @@ public Socket createSocket() throws IOException { return spy; } - private class MatchesPort extends BaseMatcher { + private class MatchesPort implements ArgumentMatcher { @Override - public boolean matches(Object arg0) { + public boolean matches(SocketAddress arg0) { return ((InetSocketAddress)arg0).getPort() == portToInjectOn; } @Override - public void describeTo(Description desc) { - desc.appendText("matches port " + portToInjectOn); + public String toString() { + return "matches port " + portToInjectOn; } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java index 49de91d3e7..6dfd86c68b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java @@ -22,12 +22,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyShort; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyShort; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -53,10 +52,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.crypto.CryptoProtocolVersion; import org.apache.hadoop.fs.ChecksumException; import org.apache.hadoop.fs.CommonConfigurationKeys; -import org.apache.hadoop.fs.CreateFlag; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileChecksum; @@ -81,7 +78,6 @@ import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.hdfs.web.WebHdfsConstants; import org.apache.hadoop.hdfs.web.WebHdfsTestUtil; -import org.apache.hadoop.io.EnumSetWritable; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Writable; @@ -98,7 +94,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.internal.stubbing.answers.ThrowsException; import org.mockito.invocation.InvocationOnMock; @@ -252,10 +247,10 @@ public Object answer(InvocationOnMock invocation) }; when(mockNN.addBlock(anyString(), anyString(), - any(ExtendedBlock.class), - any(DatanodeInfo[].class), - anyLong(), any(String[].class), - Matchers.>any())) + any(), + any(), + anyLong(), any(), + any())) .thenAnswer(answer); Mockito.doReturn(new HdfsFileStatus.Builder() @@ -280,10 +275,8 @@ public Object answer(InvocationOnMock invocation) .fileId(1010) .build()) .when(mockNN) - .create(anyString(), (FsPermission) anyObject(), anyString(), - (EnumSetWritable) anyObject(), anyBoolean(), - anyShort(), anyLong(), (CryptoProtocolVersion[]) anyObject(), - anyObject()); + .create(anyString(), any(), anyString(), any(), anyBoolean(), + anyShort(), anyLong(), any(), any()); final DFSClient client = new DFSClient(null, mockNN, conf, null); OutputStream os = client.create("testfile", true); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java index 581f954885..1891956dc0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java @@ -63,8 +63,8 @@ import org.junit.Test; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; import org.mockito.Mockito; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java index 57341714f0..604a8c6b0e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java @@ -56,7 +56,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; 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.spy; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystem.java index 135cb4f358..629abd7d9d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystem.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; 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.mock; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java index 465e925dbe..7ad25b7d0c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java @@ -52,7 +52,6 @@ import org.apache.hadoop.crypto.key.KeyProvider; import org.apache.hadoop.crypto.key.KeyProviderFactory; import org.apache.hadoop.fs.CommonConfigurationKeysPublic; -import org.apache.hadoop.fs.CreateFlag; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSTestWrapper; @@ -89,7 +88,6 @@ import org.apache.hadoop.hdfs.web.WebHdfsConstants; import org.apache.hadoop.hdfs.web.WebHdfsFileSystem; import org.apache.hadoop.hdfs.web.WebHdfsTestUtil; -import org.apache.hadoop.io.EnumSetWritable; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.security.AccessControlException; @@ -114,10 +112,10 @@ import org.mockito.Mockito; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyShort; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyShort; import static org.mockito.Mockito.withSettings; import static org.mockito.Mockito.anyString; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_DEFAULT; @@ -964,10 +962,8 @@ private static void mockCreate(ClientProtocol mcp, "fakeKey", "fakeVersion")) .build()) .when(mcp) - .create(anyString(), (FsPermission) anyObject(), anyString(), - (EnumSetWritable) anyObject(), anyBoolean(), - anyShort(), anyLong(), (CryptoProtocolVersion[]) anyObject(), - anyObject()); + .create(anyString(), any(), anyString(), any(), anyBoolean(), + anyShort(), anyLong(), any(), any()); } // This test only uses mocks. Called from the end of an existing test to diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileAppend4.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileAppend4.java index ff0fd1964b..5df7c7f64b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileAppend4.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileAppend4.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.spy; @@ -40,7 +40,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; 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.LocatedBlocks; import org.apache.hadoop.hdfs.server.datanode.DataNode; @@ -154,7 +153,7 @@ public void testRecoverFinalizedBlock() throws Throwable { // Delay completeFile GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG); doAnswer(delayer).when(spyNN).complete( - anyString(), anyString(), (ExtendedBlock)anyObject(), anyLong()); + anyString(), anyString(), any(), anyLong()); DFSClient client = new DFSClient(null, spyNN, conf, null); file1 = new Path("/testRecoverFinalized"); @@ -225,7 +224,7 @@ public void testCompleteOtherLeaseHoldersFile() throws Throwable { GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG); doAnswer(delayer).when(spyNN).complete(anyString(), anyString(), - (ExtendedBlock) anyObject(), anyLong()); + any(), anyLong()); DFSClient client = new DFSClient(null, spyNN, conf, null); file1 = new Path("/testCompleteOtherLease"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLease.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLease.java index 381fe7148b..19a4bb6d59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLease.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLease.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hdfs; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.anyShort; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.anyShort; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -34,8 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.FileSystem; import org.apache.hadoop.fs.Options; @@ -47,7 +45,6 @@ import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; -import org.apache.hadoop.io.EnumSetWritable; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.token.SecretManager.InvalidToken; @@ -374,10 +371,8 @@ public void testFactory() throws Exception { .fileId(1010) .build()) .when(mcp) - .create(anyString(), (FsPermission) anyObject(), anyString(), - (EnumSetWritable) anyObject(), anyBoolean(), - anyShort(), anyLong(), (CryptoProtocolVersion[]) anyObject(), - anyObject()); + .create(anyString(), any(), anyString(), + any(), anyBoolean(), anyShort(), anyLong(), any(), any()); final Configuration conf = new Configuration(); final DFSClient c1 = createDFSClientAs(ugi[0], conf); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java index 7c5a0ced3b..7e51ed958c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReplication.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; 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.SimulatedFSDataset; 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.metrics2.MetricsRecordBuilder; import org.apache.hadoop.test.GenericTestUtils; @@ -576,9 +575,9 @@ public void testNoExtraReplicationWhenBlockReceivedIsLate() InternalDataNodeTestUtils.spyOnBposToNN(dn, nn); DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG); Mockito.doAnswer(delayer).when(spy).blockReceivedAndDeleted( - Mockito.anyObject(), + any(), Mockito.anyString(), - Mockito.anyObject()); + any()); FileSystem fs = cluster.getFileSystem(); // Create and close a small file with two blocks diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderIoProvider.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderIoProvider.java index 3eae51634d..ae79f4d17d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderIoProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderIoProvider.java @@ -31,8 +31,8 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.times; /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderLocalMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderLocalMetrics.java index b461f2e468..6ee2898c03 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderLocalMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/client/impl/TestBlockReaderLocalMetrics.java @@ -31,14 +31,13 @@ import org.apache.hadoop.util.FakeTimer; import static org.junit.Assert.assertTrue; import org.junit.Test; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.io.IOException; -import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Random; import java.util.concurrent.TimeUnit; @@ -81,7 +80,7 @@ public void testSlowShortCircuitReadsStatsRecorded() throws IOException, TimeUnit.MILLISECONDS); FileChannel dataIn = Mockito.mock(FileChannel.class); - Mockito.when(dataIn.read(any(ByteBuffer.class), anyLong())).thenAnswer( + Mockito.when(dataIn.read(any(), anyLong())).thenAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { @@ -93,8 +92,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { BlockReaderIoProvider blockReaderIoProvider = new BlockReaderIoProvider( clientConf.getShortCircuitConf(), metrics, TIMER); - blockReaderIoProvider.read(dataIn, any(ByteBuffer.class), anyLong()); - blockReaderIoProvider.read(dataIn, any(ByteBuffer.class), anyLong()); + blockReaderIoProvider.read(dataIn, any(), anyLong()); + blockReaderIoProvider.read(dataIn, any(), anyLong()); GenericTestUtils.waitFor(new Supplier() { @Override @@ -127,7 +126,7 @@ public void testMutlipleBlockReaderIoProviderStats() throws IOException, FileChannel dataIn1 = 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() { @Override 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() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { @@ -150,8 +149,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable { BlockReaderIoProvider blockReaderIoProvider2 = new BlockReaderIoProvider( clientConf.getShortCircuitConf(), metrics, TIMER); - blockReaderIoProvider1.read(dataIn1, any(ByteBuffer.class), anyLong()); - blockReaderIoProvider2.read(dataIn2, any(ByteBuffer.class), anyLong()); + blockReaderIoProvider1.read(dataIn1, any(), anyLong()); + blockReaderIoProvider2.read(dataIn2, any(), anyLong()); GenericTestUtils.waitFor(new Supplier() { @Override @@ -189,7 +188,7 @@ public void testSlowShortCircuitReadsAverageLatencyValue() throws IOException, for (int i = 0; i < 5; i++) { dataIns[i] = Mockito.mock(FileChannel.class); 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() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { @@ -205,7 +204,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { clientConf.getShortCircuitConf(), metrics, TIMER); 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() { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestBlockListAsLongs.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestBlockListAsLongs.java index cd2b5e86e3..05a8bc5a5e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestBlockListAsLongs.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestBlockListAsLongs.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; 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.mock; @@ -58,7 +58,6 @@ import org.mockito.stubbing.Answer; import com.google.protobuf.ByteString; -import com.google.protobuf.RpcController; import com.google.protobuf.ServiceException; public class TestBlockListAsLongs { @@ -222,9 +221,8 @@ public BlockReportResponseProto answer(InvocationOnMock invocation) { request.set((BlockReportRequestProto) args[1]); return BlockReportResponseProto.newBuilder().build(); } - }).when(mockProxy).blockReport(any(RpcController.class), - any(BlockReportRequestProto.class)); - + }).when(mockProxy).blockReport(any(), any(BlockReportRequestProto.class)); + @SuppressWarnings("resource") DatanodeProtocolClientSideTranslatorPB nn = new DatanodeProtocolClientSideTranslatorPB(mockProxy); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/client/TestQuorumJournalManagerUnit.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/client/TestQuorumJournalManagerUnit.java index 837c7d9e7b..0e226de7df 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/client/TestQuorumJournalManagerUnit.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/client/TestQuorumJournalManagerUnit.java @@ -19,9 +19,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.eq; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java index 9c537a432f..20e0d4629f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; @@ -88,7 +88,6 @@ import org.mockito.stubbing.Answer; import com.google.protobuf.BlockingService; -import com.google.protobuf.RpcController; import com.google.protobuf.ServiceException; import org.apache.hadoop.fs.StorageType; @@ -303,8 +302,7 @@ private static Server createMockDatanode(BlockTokenSecretManager sm, .getIdentifier()))); doAnswer(new GetLengthAnswer(sm, id)).when(mockDN) - .getReplicaVisibleLength(any(RpcController.class), - any(GetReplicaVisibleLengthRequestProto.class)); + .getReplicaVisibleLength(any(), any()); RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class, ProtobufRpcEngine.class); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java index 0097da80c4..af840d691a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java @@ -114,7 +114,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java index 6ad530d7c4..fd224ea3df 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java @@ -42,7 +42,7 @@ import static org.junit.Assert.assertFalse; 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.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestCorruptReplicaInfo.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestCorruptReplicaInfo.java index 9716d4061c..c107c73ff5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestCorruptReplicaInfo.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestCorruptReplicaInfo.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.io.IOException; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java index f08fa131bf..02d5a3a711 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/BlockReportTestBase.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/BlockReportTestBase.java index 535b629a67..e06be41773 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/BlockReportTestBase.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/BlockReportTestBase.java @@ -21,6 +21,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; 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.FilenameFilter; @@ -61,7 +63,6 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants; 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.DatanodeStorage; import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport; @@ -626,10 +627,10 @@ protected Object passThrough(InvocationOnMock invocation) Mockito.doAnswer(delayer) .when(spy).blockReport( - Mockito.anyObject(), - Mockito.anyString(), - Mockito.anyObject(), - Mockito.anyObject()); + any(), + anyString(), + any(), + any()); // 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 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/InternalDataNodeTestUtils.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/InternalDataNodeTestUtils.java index b453991e91..97302b55a2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/InternalDataNodeTestUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/InternalDataNodeTestUtils.java @@ -18,7 +18,6 @@ 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.when; @@ -42,9 +41,6 @@ import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse; import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat; 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.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -52,7 +48,7 @@ import com.google.common.base.Preconditions; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; /** @@ -161,13 +157,13 @@ public DatanodeRegistration answer(InvocationOnMock invocation) 1L)); when( - namenode.sendHeartbeat(Mockito.any(DatanodeRegistration.class), - Mockito.any(StorageReport[].class), Mockito.anyLong(), + namenode.sendHeartbeat(Mockito.any(), + Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt(), - Mockito.anyInt(), Mockito.any(VolumeFailureSummary.class), + Mockito.anyInt(), Mockito.any(), Mockito.anyBoolean(), - Mockito.any(SlowPeerReports.class), - Mockito.any(SlowDiskReports.class))).thenReturn( + Mockito.any(), + Mockito.any())).thenReturn( new HeartbeatResponse(new DatanodeCommand[0], new NNHAStatusHeartbeat( HAServiceState.ACTIVE, 1), null, ThreadLocalRandom.current() .nextLong() | 1L)); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java index 1dc9aa9fe8..87bbd738dd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java @@ -48,7 +48,6 @@ import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi; import org.apache.hadoop.hdfs.server.datanode.metrics.DataNodeMetrics; 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.DatanodeProtocol; 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.RegisterCommand; 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.StorageReport; import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary; @@ -143,7 +141,7 @@ private DatanodeProtocolClientSideTranslatorPB setupNNMock(int nnIdx) .when(mock).versionRequest(); Mockito.doReturn(DFSTestUtil.getLocalDatanodeRegistration()) - .when(mock).registerDatanode(Mockito.any(DatanodeRegistration.class)); + .when(mock).registerDatanode(Mockito.any()); Mockito.doAnswer(new HeartbeatAnswer(nnIdx)) .when(mock).sendHeartbeat( @@ -200,11 +198,9 @@ public void testBasicFunctionality() throws Exception { waitForBothActors(bpos); // The DN should have register to both NNs. - Mockito.verify(mockNN1).registerDatanode( - Mockito.any(DatanodeRegistration.class)); - Mockito.verify(mockNN2).registerDatanode( - Mockito.any(DatanodeRegistration.class)); - + Mockito.verify(mockNN1).registerDatanode(Mockito.any()); + Mockito.verify(mockNN2).registerDatanode(Mockito.any()); + // Should get block reports from both NNs waitForBlockReport(mockNN1); waitForBlockReport(mockNN2); @@ -267,10 +263,10 @@ public void testIgnoreDeletionsFromNonActive() throws Exception { Mockito.doReturn(new BlockCommand(DatanodeProtocol.DNA_INVALIDATE, FAKE_BPID, new Block[] { FAKE_BLOCK.getLocalBlock() })) .when(mockNN2).blockReport( - Mockito.anyObject(), + Mockito.any(), Mockito.eq(FAKE_BPID), - Mockito.anyObject(), - Mockito.anyObject()); + Mockito.any(), + Mockito.any()); bpos.start(); try { @@ -287,8 +283,7 @@ public void testIgnoreDeletionsFromNonActive() throws Exception { // Should ignore the delete command from the standby Mockito.verify(mockFSDataset, Mockito.never()) - .invalidate(Mockito.eq(FAKE_BPID), - (Block[]) Mockito.anyObject()); + .invalidate(Mockito.eq(FAKE_BPID), Mockito.any()); } /** @@ -487,10 +482,10 @@ private void waitForBlockReport(final DatanodeProtocolClientSideTranslatorPB moc public Boolean get() { try { Mockito.verify(mockNN).blockReport( - Mockito.anyObject(), + Mockito.any(), Mockito.eq(FAKE_BPID), - Mockito.anyObject(), - Mockito.anyObject()); + Mockito.any(), + Mockito.any()); return true; } catch (Throwable t) { LOG.info("waiting on block report: " + t.getMessage()); @@ -513,10 +508,10 @@ public Boolean get() { private Boolean get(DatanodeProtocolClientSideTranslatorPB mockNN) { try { Mockito.verify(mockNN).blockReport( - Mockito.anyObject(), + Mockito.any(), Mockito.eq(FAKE_BPID), - Mockito.anyObject(), - Mockito.anyObject()); + Mockito.any(), + Mockito.any()); return true; } catch (Throwable t) { LOG.info("waiting on block report: " + t.getMessage()); @@ -538,9 +533,9 @@ private ReceivedDeletedBlockInfo[] waitForBlockReceived( public Boolean get() { try { Mockito.verify(mockNN).blockReceivedAndDeleted( - Mockito.anyObject(), - Mockito.eq(fakeBlockPoolId), - captor.capture()); + Mockito.any(), + Mockito.eq(fakeBlockPoolId), + captor.capture()); return true; } catch (Throwable t) { return false; @@ -600,9 +595,9 @@ public void testReportBadBlockWhenStandbyNNTimesOut() throws Exception { // Now mockNN1 is acting like active namenode and mockNN2 as Standby assertSame(mockNN1, bpos.getActiveNN()); Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(0)) - .when(mockNN1).reportBadBlocks(Mockito.any(LocatedBlock[].class)); + .when(mockNN1).reportBadBlocks(Mockito.any()); 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) .getStorageID(), mockFSDataset.getVolume(FAKE_BLOCK) .getStorageType()); @@ -641,10 +636,10 @@ public void testTrySendErrorReportWhenStandbyNNTimesOut() throws Exception { // Now mockNN1 is acting like active namenode and mockNN2 as Standby assertSame(mockNN1, bpos.getActiveNN()); Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(0)) - .when(mockNN1).errorReport(Mockito.any(DatanodeRegistration.class), + .when(mockNN1).errorReport(Mockito.any(), Mockito.anyInt(), Mockito.anyString()); Mockito.doAnswer(new BPOfferServiceSynchronousCallAnswer(1)) - .when(mockNN2).errorReport(Mockito.any(DatanodeRegistration.class), + .when(mockNN2).errorReport(Mockito.any(), Mockito.anyInt(), Mockito.anyString()); String errorString = "Can't send invalid block " + FAKE_BLOCK; bpos.trySendErrorReport(DatanodeProtocol.INVALID_BLOCK, errorString); @@ -679,21 +674,14 @@ public void testTrySendErrorReportWhenNNThrowsIOException() bpos.triggerHeartbeatForTests(); // Now mockNN1 is acting like active namenode and mockNN2 as Standby assertSame(mockNN1, bpos.getActiveNN()); - Mockito.doAnswer(new Answer() { - // Throw an IOException when this function is first called which will - // in turn add that errorReport back to the bpThreadQueue and let it - // process the next time. - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - if (firstCallTime == 0) { - firstCallTime = Time.now(); - throw new IOException(); - } else { + // Throw an IOException when this function is first called which will + // in turn add that errorReport back to the bpThreadQueue and let it + // process the next time. + Mockito.doThrow(new IOException("Throw IOException in the first call.")) + .doAnswer((Answer) invocation -> { secondCallTime = Time.now(); return null; - } - } - }).when(mockNN1).errorReport(Mockito.any(DatanodeRegistration.class), + }).when(mockNN1).errorReport(Mockito.any(DatanodeRegistration.class), Mockito.anyInt(), Mockito.anyString()); String errorString = "Can't send invalid block " + FAKE_BLOCK; bpos.trySendErrorReport(DatanodeProtocol.INVALID_BLOCK, errorString); @@ -880,9 +868,9 @@ public void testRefreshNameNodes() throws Exception { // The DN should have register to both NNs. Mockito.verify(mockNN1) - .registerDatanode(Mockito.any(DatanodeRegistration.class)); + .registerDatanode(Mockito.any()); Mockito.verify(mockNN2) - .registerDatanode(Mockito.any(DatanodeRegistration.class)); + .registerDatanode(Mockito.any()); // Should get block reports from both NNs waitForBlockReport(mockNN1); @@ -927,8 +915,7 @@ public void testRefreshNameNodes() throws Exception { Thread.sleep(1000); // verify new NN registered - Mockito.verify(mockNN3) - .registerDatanode(Mockito.any(DatanodeRegistration.class)); + Mockito.verify(mockNN3).registerDatanode(Mockito.any()); // When we receive a block, it should report it to both NNs bpos.notifyNamenodeReceivedBlock(FAKE_BLOCK, null, "", false); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockCountersInPendingIBR.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockCountersInPendingIBR.java index 43d39a6924..6f5e6208c4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockCountersInPendingIBR.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockCountersInPendingIBR.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hdfs.server.datanode; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.timeout; import org.apache.hadoop.conf.Configuration; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockRecovery.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockRecovery.java index 80f9fb6b00..f12285cb9b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockRecovery.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBlockRecovery.java @@ -21,7 +21,6 @@ import org.apache.hadoop.hdfs.AppendTestUtil; import org.apache.hadoop.hdfs.DFSClient; 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_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY; @@ -29,11 +28,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -77,7 +75,6 @@ import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.StripedFileTestUtil; -import org.apache.hadoop.hdfs.server.protocol.SlowPeerReports; import org.apache.hadoop.util.AutoCloseableLock; import org.apache.hadoop.hdfs.protocol.DatanodeID; 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.NamespaceInfo; 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.SleepAnswer; import org.apache.hadoop.util.DataChecksum; @@ -223,17 +218,17 @@ public DatanodeRegistration answer(InvocationOnMock invocation) (1, CLUSTER_ID, POOL_ID, 1L)); when(namenode.sendHeartbeat( - Mockito.any(DatanodeRegistration.class), - Mockito.any(StorageReport[].class), + Mockito.any(), + Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), - Mockito.any(VolumeFailureSummary.class), + Mockito.any(), Mockito.anyBoolean(), - Mockito.any(SlowPeerReports.class), - Mockito.any(SlowDiskReports.class))) + Mockito.any(), + Mockito.any())) .thenReturn(new HeartbeatResponse( new DatanodeCommand[0], new NNHAStatusHeartbeat(HAServiceState.ACTIVE, 1), @@ -317,9 +312,9 @@ private void testSyncReplicas(ReplicaRecoveryInfo replica1, syncList.add(record1); syncList.add(record2); - when(dn1.updateReplicaUnderRecovery((ExtendedBlock)anyObject(), anyLong(), + when(dn1.updateReplicaUnderRecovery(any(ExtendedBlock.class), anyLong(), anyLong(), anyLong())).thenReturn("storage1"); - when(dn2.updateReplicaUnderRecovery((ExtendedBlock)anyObject(), anyLong(), + when(dn2.updateReplicaUnderRecovery(any(ExtendedBlock.class), anyLong(), anyLong(), anyLong())).thenReturn("storage2"); BlockRecoveryWorker.RecoveryTaskContiguous RecoveryTaskContiguous = @@ -555,7 +550,7 @@ public void testRecoveryInProgressException() BlockRecoveryWorker.RecoveryTaskContiguous spyTask = spy(RecoveryTaskContiguous); 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){ GenericTestUtils.assertExceptionContains("All datanodes failed", e); } - verify(spyTask, never()).syncBlock(anyListOf(BlockRecord.class)); + verify(spyTask, never()).syncBlock(anyList()); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeHotSwapVolumes.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeHotSwapVolumes.java index c19c849319..f34ac51ce6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeHotSwapVolumes.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeHotSwapVolumes.java @@ -92,8 +92,8 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.timeout; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeLifeline.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeLifeline.java index 14134e697d..dcfbf02737 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeLifeline.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeLifeline.java @@ -55,7 +55,6 @@ import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse; 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.apache.hadoop.test.GenericTestUtils; import org.apache.log4j.Level; @@ -170,7 +169,7 @@ public void testSendLifelineIfHeartbeatBlocked() throws Exception { anyInt(), anyInt(), anyInt(), - any(VolumeFailureSummary.class), + any(), anyBoolean(), any(SlowPeerReports.class), any(SlowDiskReports.class)); @@ -185,7 +184,7 @@ public void testSendLifelineIfHeartbeatBlocked() throws Exception { anyInt(), anyInt(), anyInt(), - any(VolumeFailureSummary.class)); + any()); // While waiting on the latch for the expected number of lifeline messages, // poll DataNode tracking information. Thanks to the lifeline, we expect @@ -212,7 +211,7 @@ public void testSendLifelineIfHeartbeatBlocked() throws Exception { anyInt(), anyInt(), anyInt(), - any(VolumeFailureSummary.class)); + any()); // Also verify lifeline call through metrics. We expect at least // numLifelines, guaranteed by waiting on the latch. There is a small @@ -239,7 +238,7 @@ public void testNoLifelineSentIfHeartbeatsOnTime() throws Exception { anyInt(), anyInt(), anyInt(), - any(VolumeFailureSummary.class), + any(), anyBoolean(), any(SlowPeerReports.class), any(SlowDiskReports.class)); @@ -265,7 +264,7 @@ public void testNoLifelineSentIfHeartbeatsOnTime() throws Exception { anyInt(), anyInt(), anyInt(), - any(VolumeFailureSummary.class)); + any()); // Also verify no lifeline calls through metrics. assertEquals("Expect metrics to count no lifeline calls.", 0, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverBackwardsCompat.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverBackwardsCompat.java index 0f65269462..71c18bca52 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverBackwardsCompat.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverBackwardsCompat.java @@ -41,7 +41,6 @@ import org.mockito.ArgumentCaptor; import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -51,7 +50,13 @@ import java.util.UUID; 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 @@ -86,7 +91,7 @@ public NullDataNode(Configuration conf, OutputStream out, int port) throws doReturn(pair).when(saslClient).socketSend( any(Socket.class), any(OutputStream.class), any(InputStream.class), - any(DataEncryptionKeyFactory.class), any(Token.class), + any(DataEncryptionKeyFactory.class), any(), any(DatanodeID.class)); doReturn(mock(ReplicaHandler.class)).when(data).createTemporary( any(StorageType.class), any(String.class), any(ExtendedBlock.class), @@ -154,12 +159,12 @@ public void testBackwardsCompat() throws Exception { doReturn(mockBlockReceiver).when(xceiver).getBlockReceiver( any(ExtendedBlock.class), any(StorageType.class), - any(DataInputStream.class), anyString(), anyString(), + any(), anyString(), any(), any(BlockConstructionStage.class), anyLong(), anyLong(), anyLong(), anyString(), any(DatanodeInfo.class), any(DataNode.class), any(DataChecksum.class), any(CachingStrategy.class), ArgumentCaptor.forClass(Boolean.class).capture(), - anyBoolean(), any(String.class)); + anyBoolean(), any()); Token token = (Token)mock( Token.class); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverLazyPersistHint.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverLazyPersistHint.java index 8fda664897..dab33b2c03 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverLazyPersistHint.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataXceiverLazyPersistHint.java @@ -34,14 +34,20 @@ import org.junit.rules.Timeout; import org.mockito.ArgumentCaptor; -import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Arrays; import static org.hamcrest.MatcherAssert.assertThat; 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), mock(DataXceiverServer.class))); doReturn(mockBlockReceiver).when(xceiverSpy).getBlockReceiver( - any(ExtendedBlock.class), any(StorageType.class), - any(DataInputStream.class), anyString(), anyString(), - any(BlockConstructionStage.class), anyLong(), anyLong(), anyLong(), - anyString(), any(DatanodeInfo.class), any(DataNode.class), - any(DataChecksum.class), any(CachingStrategy.class), - captor.capture(), anyBoolean(), any(String.class)); + any(), any(), any(), anyString(), anyString(), + any(), anyLong(), anyLong(), anyLong(), + anyString(), any(), any(), any(), any(), + captor.capture(), anyBoolean(), any()); doReturn(mock(DataOutputStream.class)).when(xceiverSpy) .getBufferedOutputStream(); return xceiverSpy; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDatanodeProtocolRetryPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDatanodeProtocolRetryPolicy.java index 634968b505..93f9f44b04 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDatanodeProtocolRetryPolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDatanodeProtocolRetryPolicy.java @@ -18,7 +18,6 @@ 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.when; @@ -43,17 +42,12 @@ import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; 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.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse; import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat; 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.slf4j.event.Level; import org.junit.After; @@ -139,8 +133,8 @@ public Boolean get() { Mockito.verify(mockNN).blockReport( Mockito.eq(datanodeRegistration), Mockito.eq(POOL_ID), - Mockito.anyObject(), - Mockito.anyObject()); + Mockito.any(), + Mockito.any()); return true; } catch (Throwable t) { LOG.info("waiting on block report: " + t.getMessage()); @@ -212,17 +206,17 @@ public HeartbeatResponse answer(InvocationOnMock invocation) return heartbeatResponse; } }).when(namenode).sendHeartbeat( - Mockito.any(DatanodeRegistration.class), - Mockito.any(StorageReport[].class), + Mockito.any(), + Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), - Mockito.any(VolumeFailureSummary.class), + Mockito.any(), Mockito.anyBoolean(), - Mockito.any(SlowPeerReports.class), - Mockito.any(SlowDiskReports.class)); + Mockito.any(), + Mockito.any()); dn = new DataNode(conf, locations, null, null) { @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDnRespectsBlockReportSplitThreshold.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDnRespectsBlockReportSplitThreshold.java index d168c2e9c5..9d24ccb0c4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDnRespectsBlockReportSplitThreshold.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDnRespectsBlockReportSplitThreshold.java @@ -29,7 +29,6 @@ import org.apache.hadoop.hdfs.protocol.BlockListAsLongs; import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; 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.StorageBlockReport; 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.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; /** @@ -135,7 +135,7 @@ public void testAlwaysSplit() throws IOException, InterruptedException { Mockito.verify(nnSpy, times(cluster.getStoragesPerDatanode())).blockReport( any(DatanodeRegistration.class), anyString(), - captor.capture(), Mockito.anyObject()); + captor.capture(), any()); verifyCapturedArguments(captor, 1, BLOCKS_IN_FILE); } @@ -167,7 +167,7 @@ public void testCornerCaseUnderThreshold() throws IOException, InterruptedExcept Mockito.verify(nnSpy, times(1)).blockReport( any(DatanodeRegistration.class), anyString(), - captor.capture(), Mockito.anyObject()); + captor.capture(), any()); verifyCapturedArguments(captor, cluster.getStoragesPerDatanode(), BLOCKS_IN_FILE); } @@ -199,7 +199,7 @@ public void testCornerCaseAtThreshold() throws IOException, InterruptedException Mockito.verify(nnSpy, times(cluster.getStoragesPerDatanode())).blockReport( any(DatanodeRegistration.class), anyString(), - captor.capture(), Mockito.anyObject()); + captor.capture(), any()); verifyCapturedArguments(captor, 1, BLOCKS_IN_FILE); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestFsDatasetCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestFsDatasetCache.java index a0c6498331..eccc23728a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestFsDatasetCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestFsDatasetCache.java @@ -22,10 +22,10 @@ import static org.apache.hadoop.test.MetricsAsserts.getMetrics; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doReturn; import java.io.FileInputStream; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestIncrementalBlockReports.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestIncrementalBlockReports.java index 3a6276c7d7..4221ecaf2a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestIncrementalBlockReports.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestIncrementalBlockReports.java @@ -18,8 +18,8 @@ package org.apache.hadoop.hdfs.server.datanode; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.times; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestStorageReport.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestStorageReport.java index e2bae62030..9df6209e21 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestStorageReport.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestStorageReport.java @@ -34,7 +34,6 @@ import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports; 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.After; import org.junit.Before; import org.junit.Test; @@ -44,9 +43,9 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; public class TestStorageReport { public static final Logger LOG = @@ -109,7 +108,7 @@ public void testStorageReportHasStorageTypeAndState() throws IOException { any(DatanodeRegistration.class), captor.capture(), anyLong(), anyLong(), anyInt(), anyInt(), anyInt(), - Mockito.any(VolumeFailureSummary.class), Mockito.anyBoolean(), + any(), Mockito.anyBoolean(), Mockito.any(SlowPeerReports.class), Mockito.any(SlowDiskReports.class)); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestTriggerBlockReport.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestTriggerBlockReport.java index f7c9911218..db08bab658 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestTriggerBlockReport.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestTriggerBlockReport.java @@ -17,9 +17,8 @@ */ package org.apache.hadoop.hdfs.server.datanode; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.timeout; @@ -33,7 +32,6 @@ import org.apache.hadoop.hdfs.client.BlockReportOptions; import org.apache.hadoop.hdfs.protocol.Block; 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.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage; @@ -81,7 +79,7 @@ private void testTriggerBlockReport(boolean incremental) throws Exception { any(DatanodeRegistration.class), anyString(), any(StorageBlockReport[].class), - Mockito.anyObject()); + any()); Mockito.verify(spy, times(1)).blockReceivedAndDeleted( any(DatanodeRegistration.class), anyString(), @@ -124,7 +122,7 @@ private void testTriggerBlockReport(boolean incremental) throws Exception { any(DatanodeRegistration.class), anyString(), any(StorageBlockReport[].class), - Mockito.anyObject()); + any()); } cluster.shutdown(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeChecker.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeChecker.java index 737458f007..9a45e62274 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeChecker.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeChecker.java @@ -126,7 +126,7 @@ public void call(Set healthyVolumes, GenericTestUtils.waitFor(() -> numCallbackInvocations.get() > 0, 5, 10000); // Ensure that the check was invoked at least once. - verify(volume, times(1)).check(anyObject()); + verify(volume, times(1)).check(any()); if (result) { assertThat(numCallbackInvocations.get(), is(1L)); } @@ -160,7 +160,7 @@ public void testCheckAllVolumes() throws Exception { // Ensure each volume's check() method was called exactly once. for (FsVolumeSpi volume : volumes) { - verify(volume, times(1)).check(anyObject()); + verify(volume, times(1)).check(any()); } } @@ -217,10 +217,10 @@ static List makeVolumes( when(volume.getStorageLocation()).thenReturn(location); if (health != null) { - when(volume.check(anyObject())).thenReturn(health); + when(volume.check(any())).thenReturn(health); } else { final DiskErrorException de = new DiskErrorException("Fake Exception"); - when(volume.check(anyObject())).thenThrow(de); + when(volume.check(any())).thenThrow(de); } volumes.add(volume); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerFailures.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerFailures.java index 0fe892d966..7eb79b70ae 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerFailures.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerFailures.java @@ -26,7 +26,6 @@ import org.apache.hadoop.util.FakeTimer; import org.junit.Before; import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,8 +36,11 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** @@ -106,7 +108,7 @@ public void testCheckingClosedVolume() throws Exception { // The closed volume should not have been checked as it cannot // be referenced. - verify(volumes.get(0), times(0)).check(anyObject()); + verify(volumes.get(0), times(0)).check(any()); } @Test(timeout=60000) @@ -147,15 +149,11 @@ private static FsVolumeSpi makeHungVolume() throws Exception { when(reference.getVolume()).thenReturn(volume); when(volume.obtainReference()).thenReturn(reference); when(volume.getStorageLocation()).thenReturn(location); - when(volume.check(anyObject())).thenAnswer( - new Answer() { - @Override - public VolumeCheckResult answer(InvocationOnMock invocation) - throws Throwable { + when(volume.check(any())).thenAnswer( + (Answer) invocation -> { Thread.sleep(Long.MAX_VALUE); // Sleep forever. return VolumeCheckResult.HEALTHY; // unreachable. - } - }); + }); return volume; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerTimeout.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerTimeout.java index 953de4f7a3..fa044740be 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerTimeout.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestDatasetVolumeCheckerTimeout.java @@ -20,32 +20,22 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.DFSConfigKeys; 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.fsdataset.FsVolumeReference; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi; 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.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.slf4j.LoggerFactory; -import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; @@ -80,16 +70,13 @@ static FsVolumeSpi makeSlowVolume() throws Exception { when(volume.obtainReference()).thenReturn(reference); when(volume.getStorageLocation()).thenReturn(location); - when(volume.check(anyObject())).thenAnswer(new Answer() { - @Override - public VolumeCheckResult answer( - InvocationOnMock invocationOnMock) throws Throwable { + when(volume.check(any())).thenAnswer( + (Answer) invocationOnMock -> { // Wait for the disk check to timeout and then release lock. lock.lock(); lock.unlock(); return VolumeCheckResult.HEALTHY; - } - }); + }); return volume; } @@ -128,7 +115,7 @@ public void call(Set healthyVolumes, lock.unlock(); // 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)); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestThrottledAsyncCheckerTimeout.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestThrottledAsyncCheckerTimeout.java index 5336b7b3b4..91a793b7d2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestThrottledAsyncCheckerTimeout.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/checker/TestThrottledAsyncCheckerTimeout.java @@ -39,7 +39,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; 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.timeout; import static org.mockito.Mockito.verify; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java index 9270be8c90..efac368d67 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestFsDatasetImpl.java @@ -69,7 +69,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.Mockito; import java.io.File; @@ -97,10 +96,10 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -213,7 +212,7 @@ public void testAddVolumes() throws IOException { DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); when(storage.prepareVolume(eq(datanode), eq(loc), - anyListOf(NamespaceInfo.class))) + anyList())) .thenReturn(builder); dataset.addVolume(loc, nsInfos); @@ -332,7 +331,7 @@ public void testRemoveNewlyAddedVolume() throws IOException { DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); when(storage.prepareVolume(eq(datanode), eq(loc), - anyListOf(NamespaceInfo.class))) + anyList())) .thenReturn(builder); dataset.addVolume(loc, nsInfos); @@ -366,7 +365,7 @@ public void testAddVolumeFailureReleasesInUseLock() throws IOException { DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); when(storage.prepareVolume(eq(datanode), eq(StorageLocation.parse(badDir.toURI().toString())), - Matchers.>any())) + anyList())) .thenReturn(builder); StorageLocation location = StorageLocation.parse(badDir.toString()); @@ -510,7 +509,7 @@ private long getDfsUsedValueOfNewVolume(long cacheDfsUsed, new DataStorage.VolumeBuilder(storage, sd); when( storage.prepareVolume(eq(datanode), eq(loc), - anyListOf(NamespaceInfo.class))).thenReturn(builder); + anyList())).thenReturn(builder); String cacheFilePath = String.format("%s/%s/%s/%s/%s", path, CURRENT_DIR, BLOCK_POOL_IDS[0], diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancer.java index e7896944f6..95984fca74 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancer.java @@ -70,7 +70,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java index 883e43ca90..985ab35ba1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -59,7 +60,6 @@ import org.apache.hadoop.hdfs.util.Holder; import org.apache.hadoop.hdfs.util.MD5FileUtils; import org.apache.hadoop.io.IOUtils; -import org.mockito.Matchers; import org.mockito.Mockito; import com.google.common.base.Joiner; @@ -200,7 +200,7 @@ public static FSEditLog createStandaloneEditLog(File logDir) List sds = Lists.newArrayList(sd); Mockito.doReturn(sds).when(storage).dirIterable(NameNodeDirType.EDITS); Mockito.doReturn(sd).when(storage) - .getStorageDirectory(Matchers.anyObject()); + .getStorageDirectory(any()); FSEditLog editLog = new FSEditLog(new Configuration(), storage, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogAtDebug.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogAtDebug.java index 08e1315186..62da809b8e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogAtDebug.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogAtDebug.java @@ -37,7 +37,7 @@ import java.util.Optional; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogger.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogger.java index 76cc9063da..e8b948f3b0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogger.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLogger.java @@ -75,7 +75,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java index 222a1de5ae..0814d4aab8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java @@ -54,7 +54,7 @@ import static org.junit.Assert.fail; 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.spy; import static org.mockito.Mockito.when; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java index 353b3b381b..8aa5347f4d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java @@ -89,7 +89,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -621,14 +620,7 @@ private void doSecondaryFailsToReturnImage() throws IOException { } private File filePathContaining(final String substring) { - return Mockito.argThat( - new ArgumentMatcher() { - @Override - public boolean matches(Object argument) { - String path = ((File) argument).getAbsolutePath(); - return path.contains(substring); - } - }); + return Mockito.argThat(arg -> arg.getAbsolutePath().contains(substring)); } private void checkTempImages(NNStorage storage) throws IOException { @@ -1993,7 +1985,7 @@ public void testNamespaceVerifiedOnFileTransfer() throws IOException { NNStorage dstImage = Mockito.mock(NNStorage.class); Mockito.doReturn(Lists.newArrayList(new File("/wont-be-written"))) .when(dstImage).getFiles( - Mockito.anyObject(), Mockito.anyString()); + Mockito.any(), Mockito.anyString()); File mockImageFile = File.createTempFile("image", ""); FileOutputStream imageFile = new FileOutputStream(mockImageFile); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCommitBlockSynchronization.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCommitBlockSynchronization.java index 844dab5a1b..fd9fee5710 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCommitBlockSynchronization.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCommitBlockSynchronization.java @@ -32,7 +32,7 @@ import java.io.IOException; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; 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(file).getLastBlock(); 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(); return namesystemSpy; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java index d42f43c708..61b70925c1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java @@ -42,7 +42,6 @@ import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; import org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy; @@ -317,12 +316,12 @@ private void testDeleteAndCommitBlockSynchronizationRace(boolean hasSnapshot) DelayAnswer delayer = new DelayAnswer(LOG); Mockito.doAnswer(delayer).when(nnSpy).commitBlockSynchronization( Mockito.eq(blk), - Mockito.anyInt(), // new genstamp + Mockito.anyLong(), // new genstamp Mockito.anyLong(), // new length Mockito.eq(true), // close file Mockito.eq(false), // delete block - (DatanodeID[]) Mockito.anyObject(), // new targets - (String[]) Mockito.anyObject()); // new target storages + Mockito.any(), // new targets + Mockito.any()); // new target storages fs.recoverLease(fPath); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java index bb793fe67c..815f4acd2c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java @@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import java.io.IOException; import java.util.ArrayList; @@ -46,8 +48,6 @@ import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; -import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; -import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils.LogCapturer; import org.junit.AfterClass; @@ -470,11 +470,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { invocation.callRealMethod(); return null; } - }).when(nnSpy).blockReceivedAndDeleted( - Mockito.anyObject(), - Mockito.anyString(), - Mockito.anyObject() - ); + }).when(nnSpy).blockReceivedAndDeleted(any(), anyString(), any()); getDFS().mkdirs(dir); getDFS().setQuota(dir, Long.MAX_VALUE - 1, Long.MAX_VALUE - 1); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java index 3824b833e7..2545e0e9e0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java @@ -20,7 +20,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogJournalFailures.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogJournalFailures.java index 07791daad7..dff2ec614c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogJournalFailures.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogJournalFailures.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirWriteFileOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirWriteFileOp.java index 762fa61dd6..e3cfc01395 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirWriteFileOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirWriteFileOp.java @@ -18,13 +18,13 @@ package org.apache.hadoop.hdfs.server.namenode; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyByte; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyList; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anySet; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyByte; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anySet; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSPermissionChecker.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSPermissionChecker.java index 53fb97d573..6312e92fd0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSPermissionChecker.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSPermissionChecker.java @@ -34,7 +34,7 @@ import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.aclEntry; import static org.junit.Assert.fail; 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.mock; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java index 88dd788cf4..a37ed2da41 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java @@ -25,9 +25,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -1354,7 +1353,7 @@ public void testFsckFileNotFound() throws Exception { when(fsName.getBlockManager()).thenReturn(blockManager); when(fsName.getFSDirectory()).thenReturn(fsd); when(fsd.getFSNamesystem()).thenReturn(fsName); - when(fsd.resolvePath(anyObject(), anyString(), any(DirOp.class))).thenReturn(iip); + when(fsd.resolvePath(any(), anyString(), any(DirOp.class))).thenReturn(iip); when(blockManager.getDatanodeManager()).thenReturn(dnManager); NamenodeFsck fsck = new NamenodeFsck(conf, namenode, nettop, pmap, out, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetImageServlet.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetImageServlet.java index f79f879e45..c78f4e0fbe 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetImageServlet.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetImageServlet.java @@ -33,7 +33,6 @@ import org.apache.hadoop.security.authentication.util.KerberosName; import org.apache.hadoop.security.authorize.AccessControlList; import org.junit.Test; -import org.mockito.ArgumentMatcher; import org.mockito.Mockito; public class TestGetImageServlet { @@ -73,12 +72,8 @@ public void testIsValidRequestor() throws IOException { "hdfs/host2@TEST-REALM.COM", conf)); // Mark atm as an admin. - Mockito.when(acls.isUserAllowed(Mockito.argThat(new ArgumentMatcher() { - @Override - public boolean matches(Object argument) { - return ((UserGroupInformation) argument).getShortUserName().equals("atm"); - } - }))).thenReturn(true); + Mockito.when(acls.isUserAllowed(Mockito.argThat( + ugi -> ugi.getShortUserName().equals("atm")))).thenReturn(true); // Make sure that NN2 is still considered a valid requestor. assertTrue(ImageServlet.isValidRequestor(context, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNNStorageRetentionManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNNStorageRetentionManager.java index b94e5a321b..546f730a11 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNNStorageRetentionManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNNStorageRetentionManager.java @@ -20,6 +20,7 @@ import static org.apache.hadoop.hdfs.server.namenode.NNStorage.getFinalizedEditsFileName; import static org.apache.hadoop.hdfs.server.namenode.NNStorage.getImageFileName; import static org.apache.hadoop.hdfs.server.namenode.NNStorage.getInProgressEditsFileName; +import static org.mockito.ArgumentMatchers.any; import java.io.File; import java.io.IOException; @@ -414,8 +415,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable { } return null; } - }).when(mockStorage).inspectStorageDirs( - Mockito.anyObject()); + }).when(mockStorage).inspectStorageDirs(any()); return mockStorage; } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java index 6688ef2831..ee919944bc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -172,36 +172,36 @@ private void saveNamespaceWithInjectedFault(Fault fault) throws Exception { // The spy throws a RuntimeException when writing to the second directory doAnswer(new FaultySaveImage(true)). when(spyImage).saveFSImage( - anyObject(), - anyObject(), anyObject()); + any(), + any(), any()); shouldFail = false; break; case SAVE_SECOND_FSIMAGE_IOE: // The spy throws an IOException when writing to the second directory doAnswer(new FaultySaveImage(false)). when(spyImage).saveFSImage( - anyObject(), - anyObject(), anyObject()); + any(), + any(), any()); shouldFail = false; break; case SAVE_ALL_FSIMAGES: // The spy throws IOException in all directories doThrow(new RuntimeException("Injected")). when(spyImage).saveFSImage( - anyObject(), - anyObject(), anyObject()); + any(), + any(), any()); shouldFail = true; break; case WRITE_STORAGE_ALL: // The spy throws an exception before writing any VERSION files doAnswer(new FaultyWriteProperties(Fault.WRITE_STORAGE_ALL)) - .when(spyStorage).writeProperties(anyObject()); + .when(spyStorage).writeProperties(any()); shouldFail = true; break; case WRITE_STORAGE_ONE: // The spy throws on exception on one particular storage directory doAnswer(new FaultyWriteProperties(Fault.WRITE_STORAGE_ONE)) - .when(spyStorage).writeProperties(anyObject()); + .when(spyStorage).writeProperties(any()); shouldFail = false; break; default: fail("Unknown fail type"); @@ -414,7 +414,7 @@ public void doTestFailedSaveNamespace(boolean restoreStorageAfterFailure) FSNamesystem.getNamespaceEditsDirs(conf)); doThrow(new IOException("Injected fault: saveFSImage")). - when(spyImage).saveFSImage(anyObject(), anyObject(), anyObject()); + when(spyImage).saveFSImage(any(), any(), any()); try { doAnEdit(fsn, 1); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java index aa10291ef0..4995208a0e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -50,7 +51,6 @@ import org.apache.hadoop.util.Shell; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import com.google.common.collect.ImmutableSet; /** @@ -128,7 +128,7 @@ public void invalidateStorage(FSImage fi, Set filesToInvalidate) throws IO EditLogOutputStream mockStream = spy(j.getCurrentStream()); j.setCurrentStreamForTests(mockStream); doThrow(new IOException("Injected fault: write")). - when(mockStream).write(Mockito.anyObject()); + when(mockStream).write(any()); } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java index 1166dae42c..625563a914 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java @@ -18,6 +18,8 @@ package org.apache.hadoop.hdfs.server.namenode.ha; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import java.io.IOException; import java.io.PrintWriter; @@ -53,9 +55,6 @@ import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; -import org.apache.hadoop.hdfs.server.protocol.BlockReportContext; -import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; -import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils.DelayAnswer; @@ -545,10 +544,10 @@ protected Object passThrough(InvocationOnMock invocation) Mockito.doAnswer(delayer) .when(spy).blockReport( - Mockito.anyObject(), - Mockito.anyString(), - Mockito.anyObject(), - Mockito.anyObject()); + any(), + anyString(), + any(), + any()); dn.scheduleAllBlockReport(0); delayer.waitForCall(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java index 8785993840..e233b63128 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java @@ -20,9 +20,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.spy; @@ -48,7 +48,6 @@ import org.apache.hadoop.hdfs.server.namenode.EditLogInputStream; import org.apache.hadoop.hdfs.server.namenode.FSEditLog; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp; -import org.apache.hadoop.hdfs.server.namenode.MetaRecoveryContext; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.test.GenericTestUtils; @@ -340,8 +339,7 @@ private LimitedEditLogAnswer causeFailureOnEditLogRead() throws IOException { FSEditLog spyEditLog = NameNodeAdapter.spyOnEditLog(nn1); LimitedEditLogAnswer answer = new LimitedEditLogAnswer(); doAnswer(answer).when(spyEditLog).selectInputStreams( - anyLong(), anyLong(), (MetaRecoveryContext)anyObject(), anyBoolean(), - anyBoolean()); + anyLong(), anyLong(), any(), anyBoolean(), anyBoolean()); return answer; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java index 061f6ed92f..38feec4752 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doAnswer; import java.io.File; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestPipelinesFailover.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestPipelinesFailover.java index e1f00f17a1..bf93a37981 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestPipelinesFailover.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestPipelinesFailover.java @@ -41,7 +41,6 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSNNTopology; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; -import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil; @@ -367,12 +366,12 @@ public void testFailoverRightBeforeCommitSynchronization() throws Exception { DelayAnswer delayer = new DelayAnswer(LOG); Mockito.doAnswer(delayer).when(nnSpy).commitBlockSynchronization( Mockito.eq(blk), - Mockito.anyInt(), // new genstamp + Mockito.anyLong(), // new genstamp Mockito.anyLong(), // new length Mockito.eq(true), // close file Mockito.eq(false), // delete block - (DatanodeID[]) Mockito.anyObject(), // new targets - (String[]) Mockito.anyObject()); // new target storages + Mockito.any(), // new targets + Mockito.any()); // new target storages DistributedFileSystem fsOtherUser = createFsAsOtherUser(cluster, conf); assertFalse(fsOtherUser.recoverLease(TEST_PATH)); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java index b9880f0396..6804bb92fd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java @@ -62,6 +62,7 @@ import java.util.Random; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; public class TestStandbyCheckpoints { private static final int NUM_DIRS_IN_LOG = 200000; @@ -274,7 +275,7 @@ public void testCheckpointWhenNoNewTransactionsHappened() // We shouldn't save any checkpoints at txid=0 Thread.sleep(1000); Mockito.verify(spyImage1, Mockito.never()) - .saveNamespace((FSNamesystem) Mockito.anyObject()); + .saveNamespace(any()); // Roll the primary and wait for the standby to catch up HATestUtil.waitForStandbyToCatchUp(nns[0], nns[1]); @@ -282,8 +283,7 @@ public void testCheckpointWhenNoNewTransactionsHappened() // We should make exactly one checkpoint at this new txid. Mockito.verify(spyImage1, Mockito.times(1)).saveNamespace( - (FSNamesystem) Mockito.anyObject(), Mockito.eq(NameNodeFile.IMAGE), - (Canceler) Mockito.anyObject()); + any(), Mockito.eq(NameNodeFile.IMAGE), any()); } /** @@ -409,8 +409,8 @@ public void testStandbyExceptionThrownDuringCheckpoint() throws Exception { FSImage spyImage1 = NameNodeAdapter.spyOnFsImage(nns[1]); DelayAnswer answerer = new DelayAnswer(LOG); Mockito.doAnswer(answerer).when(spyImage1) - .saveNamespace(Mockito.any(FSNamesystem.class), - Mockito.eq(NameNodeFile.IMAGE), Mockito.any(Canceler.class)); + .saveNamespace(any(FSNamesystem.class), + Mockito.eq(NameNodeFile.IMAGE), any(Canceler.class)); // Perform some edits and wait for a checkpoint to start on the SBN. doEdits(0, 1000); @@ -454,9 +454,9 @@ public void testReadsAllowedDuringCheckpoint() throws Exception { FSImage spyImage1 = NameNodeAdapter.spyOnFsImage(nns[1]); DelayAnswer answerer = new DelayAnswer(LOG); Mockito.doAnswer(answerer).when(spyImage1) - .saveNamespace(Mockito.any(FSNamesystem.class), - Mockito.any(NameNodeFile.class), - Mockito.any(Canceler.class)); + .saveNamespace(any(FSNamesystem.class), + any(NameNodeFile.class), + any(Canceler.class)); // Perform some edits and wait for a checkpoint to start on the SBN. doEdits(0, 1000); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java index 987fd505af..db3d93fd53 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java @@ -53,9 +53,14 @@ import java.util.List; import java.util.Random; -import static org.junit.Assert.*; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyObject; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; @@ -1265,8 +1270,8 @@ public void testRenameUndo_1() throws Exception { INodeDirectory dir2 = fsdir.getINode4Write(sdir2.toString()).asDirectory(); INodeDirectory mockDir2 = spy(dir2); - doReturn(false).when(mockDir2).addChild((INode) anyObject(), anyBoolean(), - Mockito.anyInt()); + doReturn(false).when(mockDir2).addChild(any(), anyBoolean(), + anyInt()); INodeDirectory root = fsdir.getINode4Write("/").asDirectory(); root.replaceChild(dir2, mockDir2, fsdir.getINodeMap()); @@ -1335,8 +1340,8 @@ public void testRenameUndo_2() throws Exception { INodeDirectory dir2 = fsdir.getINode4Write(sdir2.toString()).asDirectory(); INodeDirectory mockDir2 = spy(dir2); - doReturn(false).when(mockDir2).addChild((INode) anyObject(), anyBoolean(), - Mockito.anyInt()); + doReturn(false).when(mockDir2).addChild(any(), anyBoolean(), + anyInt()); INodeDirectory root = fsdir.getINode4Write("/").asDirectory(); root.replaceChild(dir2, mockDir2, fsdir.getINodeMap()); @@ -1399,8 +1404,8 @@ public void testRenameUndo_3() throws Exception { INodeDirectory dir3 = fsdir.getINode4Write(sdir3.toString()).asDirectory(); INodeDirectory mockDir3 = spy(dir3); - doReturn(false).when(mockDir3).addChild((INode) anyObject(), anyBoolean(), - Mockito.anyInt()); + doReturn(false).when(mockDir3).addChild(any(), anyBoolean(), + anyInt()); INodeDirectory root = fsdir.getINode4Write("/").asDirectory(); root.replaceChild(dir3, mockDir3, fsdir.getINodeMap()); @@ -1502,10 +1507,10 @@ public void testRenameUndo_4() throws Exception { INodeDirectory dir3 = fsdir.getINode4Write(sdir3.toString()).asDirectory(); INodeDirectory mockDir3 = spy(dir3); // fail the rename but succeed in undo - doReturn(false).when(mockDir3).addChild((INode) Mockito.isNull(), - anyBoolean(), Mockito.anyInt()); - Mockito.when(mockDir3.addChild((INode) Mockito.isNotNull(), anyBoolean(), - Mockito.anyInt())).thenReturn(false).thenCallRealMethod(); + doReturn(false).when(mockDir3).addChild(Mockito.isNull(), + anyBoolean(), anyInt()); + Mockito.when(mockDir3.addChild(Mockito.isNotNull(), anyBoolean(), + anyInt())).thenReturn(false).thenCallRealMethod(); INodeDirectory root = fsdir.getINode4Write("/").asDirectory(); root.replaceChild(dir3, mockDir3, fsdir.getINodeMap()); foo3Node.setParent(mockDir3); @@ -1554,10 +1559,7 @@ public void testRenameUndo_5() throws Exception { final Path foo2 = new Path(subdir2, foo.getName()); FSDirectory fsdir2 = Mockito.spy(fsdir); Mockito.doThrow(new NSQuotaExceededException("fake exception")).when(fsdir2) - .addLastINode((INodesInPath) Mockito.anyObject(), - (INode) Mockito.anyObject(), - (FsPermission) Mockito.anyObject(), - Mockito.anyBoolean()); + .addLastINode(any(), any(), any(), anyBoolean()); Whitebox.setInternalState(fsn, "dir", fsdir2); // rename /test/dir1/foo to /test/dir2/subdir2/foo. // FSDirectory#verifyQuota4Rename will pass since the remaining quota is 2. @@ -1627,7 +1629,7 @@ public void testRenameUndo_6() throws Exception { hdfs.setQuota(dir2, 4, Long.MAX_VALUE - 1); FSDirectory fsdir2 = Mockito.spy(fsdir); Mockito.doThrow(new RuntimeException("fake exception")).when(fsdir2) - .removeLastINode((INodesInPath) Mockito.anyObject()); + .removeLastINode(any()); Whitebox.setInternalState(fsn, "dir", fsdir2); // rename /test/dir1/foo to /test/dir2/sub_dir2/subsub_dir2. // FSDirectory#verifyQuota4Rename will pass since foo only be counted diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotManager.java index fd353885f7..8bb8c95bff 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotManager.java @@ -18,7 +18,7 @@ package org.apache.hadoop.hdfs.server.namenode.snapshot; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -54,7 +54,7 @@ public void testSnapshotLimits() throws Exception { INodesInPath iip = mock(INodesInPath.class); SnapshotManager sm = spy(new SnapshotManager(new Configuration(), fsdir)); - doReturn(ids).when(sm).getSnapshottableRoot((INodesInPath) anyObject()); + doReturn(ids).when(sm).getSnapshottableRoot(any()); doReturn(testMaxSnapshotLimit).when(sm).getMaxSnapshotID(); // Create testMaxSnapshotLimit snapshots. These should all succeed. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java index 015c9a45c9..063217bf92 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java @@ -91,7 +91,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.hamcrest.CoreMatchers.containsString; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDelegationTokenFetcher.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDelegationTokenFetcher.java index 3f9fdf1b98..5c1ec4a74d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDelegationTokenFetcher.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDelegationTokenFetcher.java @@ -22,7 +22,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -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.doThrow; import static org.mockito.Mockito.mock; @@ -67,7 +68,7 @@ public class TestDelegationTokenFetcher { @Test(expected = IOException.class) public void testTokenFetchFail() throws Exception { WebHdfsFileSystem fs = mock(WebHdfsFileSystem.class); - doThrow(new IOException()).when(fs).getDelegationToken(anyString()); + doThrow(new IOException()).when(fs).getDelegationToken(any()); Path p = new Path(f.getRoot().getAbsolutePath(), tokenFile); DelegationTokenFetcher.saveDelegationToken(conf, fs, null, p); } @@ -83,7 +84,7 @@ public void expectedTokenIsRetrievedFromHttp() throws Exception { WebHdfsFileSystem fs = mock(WebHdfsFileSystem.class); - doReturn(testToken).when(fs).getDelegationToken(anyString()); + doReturn(testToken).when(fs).getDelegationToken(any()); Path p = new Path(f.getRoot().getAbsolutePath(), tokenFile); DelegationTokenFetcher.saveDelegationToken(conf, fs, null, p); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java index 83f64c8828..0f4d441900 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java @@ -129,8 +129,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.MapType; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java index b925e70061..0b1dfa5b9a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java @@ -22,7 +22,6 @@ import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.SIMPLE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import java.io.File; @@ -323,7 +322,7 @@ public WebHdfsFileSystem run() throws IOException { fs.create(p, (short)1).close(); verify(fs, times(1)).getDelegationToken(); verify(fs, never()).replaceExpiredDelegationToken(); - verify(fs, times(1)).getDelegationToken(anyString()); + verify(fs, times(1)).getDelegationToken(any()); verify(fs, times(1)).setDelegationToken(any()); token = fs.getRenewToken(); Assert.assertNotNull(token); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestLocalContainerLauncher.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestLocalContainerLauncher.java index 16686abcae..94cd5182a5 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestLocalContainerLauncher.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestLocalContainerLauncher.java @@ -19,7 +19,7 @@ package org.apache.hadoop.mapred; import static org.apache.hadoop.fs.CreateFlag.CREATE; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestTaskAttemptListenerImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestTaskAttemptListenerImpl.java index 068ebfa253..29d0952a08 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestTaskAttemptListenerImpl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestTaskAttemptListenerImpl.java @@ -66,7 +66,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -342,18 +342,7 @@ protected void registerHeartbeatHandler(Configuration conf) { @Test public void testCheckpointIDTracking() throws IOException, InterruptedException{ - SystemClock clock = SystemClock.getInstance(); - configureMocks(); - - org.apache.hadoop.mapreduce.v2.app.job.Task mockTask = - mock(org.apache.hadoop.mapreduce.v2.app.job.Task.class); - when(mockTask.canCommit(any(TaskAttemptId.class))).thenReturn(true); - Job mockJob = mock(Job.class); - when(mockJob.getTask(any(TaskId.class))).thenReturn(mockTask); - when(appCtx.getJob(any(JobId.class))).thenReturn(mockJob); - when(appCtx.getClock()).thenReturn(clock); - listener = new MockTaskAttemptListenerImpl( appCtx, secret, rmHeartbeatHandler, policy) { @Override @@ -559,7 +548,6 @@ private void configureMocks() { TaskStatus.State.RUNNING, "", "RUNNING", "", TaskStatus.Phase.REDUCE, new Counters()); - when(dispatcher.getEventHandler()).thenReturn(ea); when(appCtx.getEventHandler()).thenReturn(ea); policy = new CheckpointAMPreemptionPolicy(); policy.init(appCtx); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestYarnChild.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestYarnChild.java index 404b1cba9e..8ad62065fa 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestYarnChild.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestYarnChild.java @@ -112,7 +112,7 @@ public void testReportErrorWhenCapacityExceptionHappenInThirdOfExceptionChain() private void verifyReportError(Exception exception, boolean fastFail) throws IOException { YarnChild.reportError(exception, task, umbilical); - verify(umbilical).fatalError(any(TaskAttemptID.class), anyString(), + verify(umbilical).fatalError(any(), anyString(), eq(fastFail)); } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/jobhistory/TestJobHistoryEventHandler.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/jobhistory/TestJobHistoryEventHandler.java index 096d13ec82..b9cb8046f9 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/jobhistory/TestJobHistoryEventHandler.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/jobhistory/TestJobHistoryEventHandler.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestKillAMPreemptionPolicy.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestKillAMPreemptionPolicy.java index 09c7f02c9f..3c3c4c9062 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestKillAMPreemptionPolicy.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestKillAMPreemptionPolicy.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.mapreduce.v2.app; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -85,9 +85,9 @@ public void testKillAMPreemptPolicy() { policy.init(mActxt); pM = getPreemptionMessage(true, false, container); policy.preempt(mPctxt, pM); - verify(mActxt.getEventHandler(), times(2)).handle( + verify(mActxt.getEventHandler(), times(1)).handle( any(TaskAttemptEvent.class)); - verify(mActxt.getEventHandler(), times(2)).handle( + verify(mActxt.getEventHandler(), times(1)).handle( any(JobCounterUpdateEvent.class)); // strictContract is null & contract is not null @@ -95,9 +95,9 @@ public void testKillAMPreemptPolicy() { policy.init(mActxt); pM = getPreemptionMessage(false, true, container); policy.preempt(mPctxt, pM); - verify(mActxt.getEventHandler(), times(2)).handle( + verify(mActxt.getEventHandler(), times(1)).handle( any(TaskAttemptEvent.class)); - verify(mActxt.getEventHandler(), times(2)).handle( + verify(mActxt.getEventHandler(), times(1)).handle( any(JobCounterUpdateEvent.class)); // strictContract is not null & contract is not null @@ -105,9 +105,9 @@ public void testKillAMPreemptPolicy() { policy.init(mActxt); pM = getPreemptionMessage(true, true, container); policy.preempt(mPctxt, pM); - verify(mActxt.getEventHandler(), times(4)).handle( + verify(mActxt.getEventHandler(), times(2)).handle( any(TaskAttemptEvent.class)); - verify(mActxt.getEventHandler(), times(4)).handle( + verify(mActxt.getEventHandler(), times(2)).handle( any(JobCounterUpdateEvent.class)); } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestMRAppMaster.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestMRAppMaster.java index fbce003010..cb1963cdfa 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestMRAppMaster.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestMRAppMaster.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestStagingCleanup.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestStagingCleanup.java index 5d5b4fabc4..2efa9103f1 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestStagingCleanup.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestStagingCleanup.java @@ -19,8 +19,8 @@ package org.apache.hadoop.mapreduce.v2.app; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestTaskHeartbeatHandler.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestTaskHeartbeatHandler.java index 0fbde2c776..f0368ebe87 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestTaskHeartbeatHandler.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestTaskHeartbeatHandler.java @@ -19,7 +19,7 @@ package org.apache.hadoop.mapreduce.v2.app; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/commit/TestCommitterEventHandler.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/commit/TestCommitterEventHandler.java index a620763e0e..a3e85aad84 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/commit/TestCommitterEventHandler.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/commit/TestCommitterEventHandler.java @@ -48,12 +48,9 @@ import org.apache.commons.io.FileUtils; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.mapreduce.JobContext; import org.apache.hadoop.mapreduce.MRJobConfig; -import org.apache.hadoop.mapreduce.OutputCommitter; import org.apache.hadoop.mapreduce.TypeConverter; import org.apache.hadoop.mapreduce.v2.api.records.JobId; -import org.apache.hadoop.mapreduce.v2.app.AppContext; import org.apache.hadoop.mapreduce.v2.app.job.event.JobCommitCompletedEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.JobCommitFailedEvent; import org.apache.hadoop.mapreduce.v2.util.MRApps; @@ -62,12 +59,9 @@ import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.event.Event; -import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.util.Clock; -import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.util.SystemClock; -import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -167,7 +161,7 @@ public void testCommitWindow() throws Exception { } Assert.assertEquals("committer did not complete commit after RM hearbeat", 1, jeh.numCommitCompletedEvents); - verify(committer, times(1)).commitJob(any(JobContext.class)); + verify(committer, times(1)).commitJob(any()); //Clean up so we can try to commit again (Don't do this at home) cleanup(); @@ -182,7 +176,7 @@ public void testCommitWindow() throws Exception { } Assert.assertEquals("committer did not commit", 2, jeh.numCommitCompletedEvents); - verify(committer, times(2)).commitJob(any(JobContext.class)); + verify(committer, times(2)).commitJob(any()); ceh.stop(); dispatcher.stop(); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java index 8592b20dad..861dbfad52 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java @@ -18,7 +18,7 @@ package org.apache.hadoop.mapreduce.v2.app.job.impl; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/launcher/TestContainerLauncherImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/launcher/TestContainerLauncherImpl.java index 7788300cf4..2057cc80ff 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/launcher/TestContainerLauncherImpl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/launcher/TestContainerLauncherImpl.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.mapreduce.v2.app.launcher; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java index fc1969bd7a..a286994161 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/local/TestLocalContainerAllocator.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.mapreduce.v2.app.local; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMCommunicator.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMCommunicator.java index a7c63c27c0..52db7b5f77 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMCommunicator.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMCommunicator.java @@ -24,7 +24,6 @@ import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.util.Clock; import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import static org.mockito.Mockito.doThrow; @@ -81,15 +80,13 @@ public void testRMContainerAllocatorYarnRuntimeExceptionIsHandled() doThrow(new YarnRuntimeException("Test")).doNothing() .when(communicator).heartbeat(); - when(mockClock.getTime()).thenReturn(1L).thenAnswer(new Answer() { - @Override - public Integer answer(InvocationOnMock invocation) throws Throwable { + when(mockClock.getTime()).thenReturn(1L).thenAnswer( + (Answer) invocation -> { communicator.stop(); - return 2; - } - }).thenThrow(new AssertionError( - "GetClock called second time, when it should not have since the thread " + - "should have quit")); + return 2L; + }).thenThrow(new AssertionError( + "GetClock called second time, when it should not " + + "have since the thread should have quit")); AllocatorRunnable testRunnable = communicator.new AllocatorRunnable(); testRunnable.run(); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java index c79daf7029..f3ac950e9e 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java @@ -20,10 +20,10 @@ import static org.apache.hadoop.mapreduce.v2.app.rm.ContainerRequestCreator.createRequest; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.inOrder; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestLocalDistributedCacheManager.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestLocalDistributedCacheManager.java index fa60e2df21..b565d23029 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestLocalDistributedCacheManager.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestLocalDistributedCacheManager.java @@ -20,8 +20,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestMapTask.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestMapTask.java index 56baead7d2..d5164de46d 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestMapTask.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestMapTask.java @@ -36,7 +36,7 @@ import java.io.File; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestTask.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestTask.java index 500229c341..1419244034 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestTask.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestTask.java @@ -18,7 +18,7 @@ package org.apache.hadoop.mapred; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.io.IOException; @@ -30,7 +30,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class TestTask { diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java index fabe5f272c..779a031c66 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobMonitorAndPrint.java @@ -19,9 +19,9 @@ package org.apache.hadoop.mapreduce; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploader.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploader.java index d347da55e8..80338970d2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploader.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploader.java @@ -23,8 +23,8 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.times; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import java.io.IOException; import java.net.URI; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploaderWithSharedCache.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploaderWithSharedCache.java index 53219af42c..5555043bcd 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploaderWithSharedCache.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJobResourceUploaderWithSharedCache.java @@ -19,9 +19,9 @@ package org.apache.hadoop.mapreduce; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/db/DriverForTest.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/db/DriverForTest.java index ea40c8ed17..1090bbc688 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/db/DriverForTest.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/lib/db/DriverForTest.java @@ -29,7 +29,7 @@ import java.util.Properties; import java.util.logging.Logger; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; /** diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java index a44e5331f4..9dc4f3e4c3 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/security/TestTokenCache.java @@ -19,7 +19,7 @@ package org.apache.hadoop.mapreduce.security; import static org.junit.Assert.*; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; import java.io.IOException; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestFetcher.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestFetcher.java index 204c2bdc11..94e7b9a92a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestFetcher.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestFetcher.java @@ -33,7 +33,6 @@ import org.junit.rules.TestName; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import java.io.ByteArrayInputStream; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMerger.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMerger.java index a6b19646cf..c29d785ccf 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMerger.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMerger.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.mapreduce.task.reduce; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java index 985eea3f65..40089db899 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java @@ -34,7 +34,7 @@ import org.junit.Assert; import org.junit.Test; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.times; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryServerFileSystemStateStoreService.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryServerFileSystemStateStoreService.java index 0a790028a1..a6601518d0 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryServerFileSystemStateStoreService.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryServerFileSystemStateStoreService.java @@ -193,15 +193,8 @@ public void testUpdatedTokenRecovery() throws IOException { final FileSystem spyfs = spy(fs); // make the update token process fail halfway through where we're left // with just the temporary update file and no token file - ArgumentMatcher updateTmpMatcher = new ArgumentMatcher() { - @Override - public boolean matches(Object argument) { - if (argument instanceof Path) { - return ((Path) argument).getName().startsWith("update"); - } - return false; - } - }; + ArgumentMatcher updateTmpMatcher = + arg -> arg.getName().startsWith("update"); doThrow(intentionalErr) .when(spyfs).rename(argThat(updateTmpMatcher), isA(Path.class)); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistory.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistory.java index 9f36477bd3..1595e8b1f4 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistory.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistory.java @@ -46,8 +46,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestBlocks.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestBlocks.java index 27c412b8a8..18687ff4fe 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestBlocks.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestBlocks.java @@ -71,7 +71,7 @@ import org.junit.Test; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; /** diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestHsJobBlock.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestHsJobBlock.java index 7fa238e1ce..f503c5cc9b 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestHsJobBlock.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/TestHsJobBlock.java @@ -49,7 +49,7 @@ import java.util.HashMap; import java.util.Map; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/JobClientUnitTest.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/JobClientUnitTest.java index b5edf2d0b9..04488cd1d2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/JobClientUnitTest.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/JobClientUnitTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestClientServiceDelegate.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestClientServiceDelegate.java index 275456df83..ef460e8d74 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestClientServiceDelegate.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestClientServiceDelegate.java @@ -18,7 +18,7 @@ package org.apache.hadoop.mapred; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestMRCJCFileInputFormat.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestMRCJCFileInputFormat.java index 20d0173cc8..190f728346 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestMRCJCFileInputFormat.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestMRCJCFileInputFormat.java @@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals; 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.when; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestYARNRunner.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestYARNRunner.java index 5e6cec1b0d..332a0e1a2a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestYARNRunner.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestYARNRunner.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestYarnClientProtocolProvider.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestYarnClientProtocolProvider.java index 308b7775a6..53115e80ce 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestYarnClientProtocolProvider.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestYarnClientProtocolProvider.java @@ -19,7 +19,7 @@ package org.apache.hadoop.mapreduce; 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.when; import static org.mockito.Mockito.spy; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/security/TestUmbilicalProtocolWithJobToken.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/security/TestUmbilicalProtocolWithJobToken.java index 5d536639fe..bb1784de56 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/security/TestUmbilicalProtocolWithJobToken.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/security/TestUmbilicalProtocolWithJobToken.java @@ -19,10 +19,9 @@ package org.apache.hadoop.mapreduce.security; import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.doReturn; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/pom.xml b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/pom.xml index ca08b1f799..4689e198f1 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/pom.xml +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/pom.xml @@ -52,7 +52,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestCombineHandler.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestCombineHandler.java index 68499a79bd..dd865db887 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestCombineHandler.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestCombineHandler.java @@ -27,9 +27,10 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.Mockito; +import static org.mockito.ArgumentMatchers.eq; + @SuppressWarnings({ "rawtypes", "unchecked", "deprecation" }) public class TestCombineHandler { @@ -53,8 +54,10 @@ public void setUp() throws IOException { @Test public void testCommandDispatcherSetting() throws IOException { this.handler = new CombinerHandler(nativeHandler, combinerRunner, puller, pusher); - Mockito.verify(nativeHandler, Mockito.times(1)).setCommandDispatcher(Matchers.eq(handler)); - Mockito.verify(nativeHandler, Mockito.times(1)).setDataReceiver(Matchers.eq(puller)); + Mockito.verify(nativeHandler, + Mockito.times(1)).setCommandDispatcher(eq(handler)); + Mockito.verify(nativeHandler, + Mockito.times(1)).setDataReceiver(eq(puller)); } @Test @@ -65,7 +68,7 @@ public void testCombine() throws IOException, InterruptedException, ClassNotFoun handler.close(); Mockito.verify(combinerRunner, Mockito.times(1)) - .combine(Matchers.eq(puller), Matchers.eq(pusher)); + .combine(eq(puller), eq(pusher)); Mockito.verify(pusher, Mockito.times(1)).close(); Mockito.verify(puller, Mockito.times(1)).close(); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestNativeCollectorOnlyHandler.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestNativeCollectorOnlyHandler.java index 314963b1fd..e66984b9b2 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestNativeCollectorOnlyHandler.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/handlers/TestNativeCollectorOnlyHandler.java @@ -39,9 +39,11 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.Mockito; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; + @SuppressWarnings({ "rawtypes", "unchecked", "deprecation" }) public class TestNativeCollectorOnlyHandler { @@ -84,8 +86,8 @@ public void testCollect() throws IOException { handler.close(); handler.close(); - Mockito.verify(pusher, Mockito.times(1)).collect(Matchers.any(BytesWritable.class), - Matchers.any(BytesWritable.class), Matchers.anyInt()); + Mockito.verify(pusher, Mockito.times(1)).collect(any(BytesWritable.class), + any(BytesWritable.class), anyInt()); Mockito.verify(pusher, Mockito.times(1)).close(); Mockito.verify(combiner, Mockito.times(1)).close(); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java index 1a7dace598..c4a1a9ae58 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/test/java/org/apache/hadoop/mapred/nativetask/serde/TestKVSerializer.java @@ -31,9 +31,11 @@ import org.apache.hadoop.mapred.nativetask.testutil.TestInput.KV; import org.apache.hadoop.mapred.nativetask.util.SizedWritable; import org.junit.Assert; -import org.mockito.Matchers; import org.mockito.Mockito; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; + @SuppressWarnings({ "rawtypes", "unchecked" }) public class TestKVSerializer { @@ -86,9 +88,9 @@ public void testSerializeKV() throws IOException { // flush once, write 4 int, and 2 byte array Mockito.verify(dataOut, Mockito.times(1)).flush(); - Mockito.verify(dataOut, Mockito.times(4)).writeInt(Matchers.anyInt()); - Mockito.verify(dataOut, Mockito.times(2)).write(Matchers.any(byte[].class), - Matchers.anyInt(), Matchers.anyInt()); + Mockito.verify(dataOut, Mockito.times(4)).writeInt(anyInt()); + Mockito.verify(dataOut, Mockito.times(2)).write(any(byte[].class), + anyInt(), anyInt()); Assert.assertEquals(written, key.length + value.length + Constants.SIZEOF_KV_LENGTH); } @@ -99,14 +101,14 @@ public void testSerializeNoFlush() throws IOException { // suppose there are enough space Mockito.when(dataOut.hasUnFlushedData()).thenReturn(true); - Mockito.when(dataOut.shortOfSpace(Matchers.anyInt())).thenReturn(false); + Mockito.when(dataOut.shortOfSpace(anyInt())).thenReturn(false); final int written = serializer.serializeKV(dataOut, key, value); // flush 0, write 4 int, and 2 byte array Mockito.verify(dataOut, Mockito.times(0)).flush(); - Mockito.verify(dataOut, Mockito.times(4)).writeInt(Matchers.anyInt()); - Mockito.verify(dataOut, Mockito.times(2)).write(Matchers.any(byte[].class), - Matchers.anyInt(), Matchers.anyInt()); + Mockito.verify(dataOut, Mockito.times(4)).writeInt(anyInt()); + Mockito.verify(dataOut, Mockito.times(2)).write(any(byte[].class), + anyInt(), anyInt()); Assert.assertEquals(written, key.length + value.length + Constants.SIZEOF_KV_LENGTH); } @@ -125,9 +127,9 @@ public void testSerializePartitionKV() throws IOException { // flush once, write 4 int, and 2 byte array Mockito.verify(dataOut, Mockito.times(1)).flush(); - Mockito.verify(dataOut, Mockito.times(5)).writeInt(Matchers.anyInt()); - Mockito.verify(dataOut, Mockito.times(2)).write(Matchers.any(byte[].class), - Matchers.anyInt(), Matchers.anyInt()); + Mockito.verify(dataOut, Mockito.times(5)).writeInt(anyInt()); + Mockito.verify(dataOut, Mockito.times(2)).write(any(byte[].class), + anyInt(), anyInt()); Assert.assertEquals(written, key.length + value.length + Constants.SIZEOF_KV_LENGTH + Constants.SIZEOF_PARTITION_LENGTH); @@ -147,7 +149,7 @@ public void testDeserializer() throws IOException { Assert.assertTrue(serializer.deserializeKV(in, key, value) > 0); Mockito.verify(in, Mockito.times(4)).readInt(); - Mockito.verify(in, Mockito.times(2)).readFully(Matchers.any(byte[].class), - Matchers.anyInt(), Matchers.anyInt()); + Mockito.verify(in, Mockito.times(2)).readFully(any(byte[].class), + anyInt(), anyInt()); } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-shuffle/src/test/java/org/apache/hadoop/mapred/TestShuffleHandler.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-shuffle/src/test/java/org/apache/hadoop/mapred/TestShuffleHandler.java index 801724851d..cd9dab0ee4 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-shuffle/src/test/java/org/apache/hadoop/mapred/TestShuffleHandler.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-shuffle/src/test/java/org/apache/hadoop/mapred/TestShuffleHandler.java @@ -27,7 +27,7 @@ import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1; import static org.junit.Assert.assertEquals; import static org.junit.Assume.assumeTrue; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml b/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml index e22cf77e32..08b945728f 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml @@ -90,7 +90,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-mapreduce-project/pom.xml b/hadoop-mapreduce-project/pom.xml index a848fc0e8d..130c027ec8 100644 --- a/hadoop-mapreduce-project/pom.xml +++ b/hadoop-mapreduce-project/pom.xml @@ -96,7 +96,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-project/pom.xml b/hadoop-project/pom.xml index 83fd7df4d2..a07c01d685 100644 --- a/hadoop-project/pom.xml +++ b/hadoop-project/pom.xml @@ -1064,8 +1064,8 @@ org.mockito - mockito-all - 1.8.5 + mockito-core + 2.23.4 org.objenesis diff --git a/hadoop-tools/hadoop-archive-logs/pom.xml b/hadoop-tools/hadoop-archive-logs/pom.xml index 4f17d29b7e..54de9d396a 100644 --- a/hadoop-tools/hadoop-archive-logs/pom.xml +++ b/hadoop-tools/hadoop-archive-logs/pom.xml @@ -124,7 +124,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-archives/pom.xml b/hadoop-tools/hadoop-archives/pom.xml index bf0fb5e33e..5a0c285e81 100644 --- a/hadoop-tools/hadoop-archives/pom.xml +++ b/hadoop-tools/hadoop-archives/pom.xml @@ -41,7 +41,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-aws/pom.xml b/hadoop-tools/hadoop-aws/pom.xml index 017f00fd36..f89bc8dc01 100644 --- a/hadoop-tools/hadoop-aws/pom.xml +++ b/hadoop-tools/hadoop-aws/pom.xml @@ -420,7 +420,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/MockS3ClientFactory.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/MockS3ClientFactory.java index 0403d36c69..2397f6cbaf 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/MockS3ClientFactory.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/MockS3ClientFactory.java @@ -45,7 +45,7 @@ public AmazonS3 createS3Client(URI name, // return a stub value MultipartUploadListing noUploads = new MultipartUploadListing(); noUploads.setMultipartUploads(new ArrayList<>(0)); - when(s3.listMultipartUploads(anyObject())) + when(s3.listMultipartUploads(any())) .thenReturn(noUploads); when(s3.getBucketLocation(anyString())) .thenReturn(Region.US_West.toString()); diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AGetFileStatus.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AGetFileStatus.java index 586264d1e7..e90518a9cb 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AGetFileStatus.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AGetFileStatus.java @@ -19,8 +19,10 @@ package org.apache.hadoop.fs.s3a; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.util.Collections; @@ -39,10 +41,8 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.contract.ContractTestUtils; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; import org.junit.Test; +import org.mockito.ArgumentMatcher; /** * S3A tests for getFileStatus using mock S3 client. @@ -155,25 +155,10 @@ private void setupListMocks(List prefixes, .thenReturn(v2Result); } - private Matcher correctGetMetadataRequest( + private ArgumentMatcher correctGetMetadataRequest( String bucket, String key) { - return new BaseMatcher() { - - @Override - public void describeTo(Description description) { - description.appendText("bucket and key match"); - } - - @Override - public boolean matches(Object o) { - if(o instanceof GetObjectMetadataRequest) { - GetObjectMetadataRequest getObjectMetadataRequest = - (GetObjectMetadataRequest)o; - return getObjectMetadataRequest.getBucketName().equals(bucket) - && getObjectMetadataRequest.getKey().equals(key); - } - return false; - } - }; + return request -> request != null + && request.getBucketName().equals(bucket) + && request.getKey().equals(key); } } diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java index 2bee08c5f6..17ad7f6654 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/staging/StagingTestBase.java @@ -79,7 +79,7 @@ import org.apache.hadoop.service.ServiceOperations; import org.apache.hadoop.test.HadoopTestBase; -import static org.mockito.Matchers.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; /** diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/mapreduce/MockJob.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/mapreduce/MockJob.java index 7886c92467..d1f307e95b 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/mapreduce/MockJob.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/mapreduce/MockJob.java @@ -30,8 +30,9 @@ import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.authorize.AccessControlList; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * This is a mock job which doesn't talk to YARN. diff --git a/hadoop-tools/hadoop-azure/pom.xml b/hadoop-tools/hadoop-azure/pom.xml index c396858d27..2597f58b3a 100644 --- a/hadoop-tools/hadoop-azure/pom.xml +++ b/hadoop-tools/hadoop-azure/pom.xml @@ -259,7 +259,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestWasbRemoteCallHelper.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestWasbRemoteCallHelper.java index 6f7e699c13..a6700d4b55 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestWasbRemoteCallHelper.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestWasbRemoteCallHelper.java @@ -47,7 +47,7 @@ import java.nio.charset.StandardCharsets; import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_USE_SECURE_MODE; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.times; @@ -317,27 +317,6 @@ public void testWhenOneInstanceIsDown() throws Throwable { Mockito.when(mockHttpResponseServiceLocal.getEntity()) .thenReturn(mockHttpEntity); - - - class HttpGetForService1 extends ArgumentMatcher{ - @Override public boolean matches(Object o) { - return checkHttpGetMatchHost((HttpGet) o, "localhost1"); - } - } - class HttpGetForService2 extends ArgumentMatcher{ - @Override public boolean matches(Object o) { - return checkHttpGetMatchHost((HttpGet) o, "localhost2"); - } - } - class HttpGetForServiceLocal extends ArgumentMatcher{ - @Override public boolean matches(Object o) { - try { - return checkHttpGetMatchHost((HttpGet) o, InetAddress.getLocalHost().getCanonicalHostName()); - } catch (UnknownHostException e) { - return checkHttpGetMatchHost((HttpGet) o, "localhost"); - } - } - } Mockito.when(mockHttpClient.execute(argThat(new HttpGetForService1()))) .thenReturn(mockHttpResponseService1); Mockito.when(mockHttpClient.execute(argThat(new HttpGetForService2()))) @@ -401,30 +380,11 @@ public void testWhenServiceInstancesAreDown() throws Throwable { Mockito.when(mockHttpResponseService3.getEntity()) .thenReturn(mockHttpEntity); - class HttpGetForService1 extends ArgumentMatcher{ - @Override public boolean matches(Object o) { - return checkHttpGetMatchHost((HttpGet) o, "localhost1"); - } - } - class HttpGetForService2 extends ArgumentMatcher{ - @Override public boolean matches(Object o) { - return checkHttpGetMatchHost((HttpGet) o, "localhost2"); - } - } - class HttpGetForService3 extends ArgumentMatcher { - @Override public boolean matches(Object o){ - try { - return checkHttpGetMatchHost((HttpGet) o, InetAddress.getLocalHost().getCanonicalHostName()); - } catch (UnknownHostException e) { - return checkHttpGetMatchHost((HttpGet) o, "localhost"); - } - } - } Mockito.when(mockHttpClient.execute(argThat(new HttpGetForService1()))) .thenReturn(mockHttpResponseService1); Mockito.when(mockHttpClient.execute(argThat(new HttpGetForService2()))) .thenReturn(mockHttpResponseService2); - Mockito.when(mockHttpClient.execute(argThat(new HttpGetForService3()))) + Mockito.when(mockHttpClient.execute(argThat(new HttpGetForServiceLocal()))) .thenReturn(mockHttpResponseService3); //Need 3 times because performop() does 3 fs operations. @@ -445,7 +405,7 @@ class HttpGetForService3 extends ArgumentMatcher { Mockito.verify(mockHttpClient, atLeast(2)) .execute(argThat(new HttpGetForService2())); Mockito.verify(mockHttpClient, atLeast(3)) - .execute(argThat(new HttpGetForService3())); + .execute(argThat(new HttpGetForServiceLocal())); Mockito.verify(mockHttpClient, times(7)).execute(Mockito.any()); } } @@ -565,4 +525,27 @@ private static boolean checkHttpGetMatchHost(HttpGet g, String h) { return g != null && g.getURI().getHost().equals(h); } + private class HttpGetForService1 implements ArgumentMatcher{ + @Override + public boolean matches(HttpGet httpGet) { + return checkHttpGetMatchHost(httpGet, "localhost1"); + } + } + private class HttpGetForService2 implements ArgumentMatcher{ + @Override + public boolean matches(HttpGet httpGet) { + return checkHttpGetMatchHost(httpGet, "localhost2"); + } + } + private class HttpGetForServiceLocal implements ArgumentMatcher{ + @Override + public boolean matches(HttpGet httpGet) { + try { + return checkHttpGetMatchHost(httpGet, + InetAddress.getLocalHost().getCanonicalHostName()); + } catch (UnknownHostException e) { + return checkHttpGetMatchHost(httpGet, "localhost"); + } + } + } } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/ITestAzureFileSystemInstrumentation.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/ITestAzureFileSystemInstrumentation.java index 5f08d80d14..bf2118524b 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/ITestAzureFileSystemInstrumentation.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/ITestAzureFileSystemInstrumentation.java @@ -30,10 +30,7 @@ import static org.apache.hadoop.fs.azure.metrics.AzureFileSystemInstrumentation.WASB_WEB_RESPONSES; import static org.apache.hadoop.test.MetricsAsserts.assertCounter; import static org.apache.hadoop.test.MetricsAsserts.getMetrics; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.verify; import java.io.InputStream; @@ -51,9 +48,8 @@ import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.MetricsTag; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -524,16 +520,16 @@ public boolean matches(MetricsTag toMatch) { } @Override - public void describeTo(Description desc) { - super.describeTo(desc); - desc.appendText(" with value " + tagValue); + public String toString() { + return super.toString() + " with value " + tagValue; } } /** * A matcher class for asserting that we got a tag with any value. */ - private static class TagExistsMatcher extends BaseMatcher { + private static class TagExistsMatcher + implements ArgumentMatcher { private final String tagName; public TagExistsMatcher(String tagName) { @@ -541,46 +537,13 @@ public TagExistsMatcher(String tagName) { } @Override - public boolean matches(Object toMatch) { - MetricsTag asTag = (MetricsTag)toMatch; - return asTag.name().equals(tagName) && matches(asTag); - } - - protected boolean matches(MetricsTag toMatch) { - return true; + public boolean matches(MetricsTag asTag) { + return asTag.name().equals(tagName); } @Override - public void describeTo(Description desc) { - desc.appendText("Has tag " + tagName); - } - } - - /** - * A matcher class for asserting that a long value is in a - * given range. - */ - private static class InRange extends BaseMatcher { - private final long inclusiveLowerLimit; - private final long inclusiveUpperLimit; - private long obtained; - - public InRange(long inclusiveLowerLimit, long inclusiveUpperLimit) { - this.inclusiveLowerLimit = inclusiveLowerLimit; - this.inclusiveUpperLimit = inclusiveUpperLimit; - } - - @Override - public boolean matches(Object number) { - obtained = (Long)number; - return obtained >= inclusiveLowerLimit && - obtained <= inclusiveUpperLimit; - } - - @Override - public void describeTo(Description description) { - description.appendText("Between " + inclusiveLowerLimit + - " and " + inclusiveUpperLimit + " inclusively"); + public String toString() { + return "Has tag " + tagName; } } } diff --git a/hadoop-tools/hadoop-datajoin/pom.xml b/hadoop-tools/hadoop-datajoin/pom.xml index ba23b439df..19c6786d3d 100644 --- a/hadoop-tools/hadoop-datajoin/pom.xml +++ b/hadoop-tools/hadoop-datajoin/pom.xml @@ -41,7 +41,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-distcp/pom.xml b/hadoop-tools/hadoop-distcp/pom.xml index eccdaac97b..5b73bf0a6e 100644 --- a/hadoop-tools/hadoop-distcp/pom.xml +++ b/hadoop-tools/hadoop-distcp/pom.xml @@ -100,7 +100,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-extras/pom.xml b/hadoop-tools/hadoop-extras/pom.xml index 0a1862518f..fe9f41cb46 100644 --- a/hadoop-tools/hadoop-extras/pom.xml +++ b/hadoop-tools/hadoop-extras/pom.xml @@ -41,7 +41,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-fs2img/pom.xml b/hadoop-tools/hadoop-fs2img/pom.xml index 8588eee3d0..935305a335 100644 --- a/hadoop-tools/hadoop-fs2img/pom.xml +++ b/hadoop-tools/hadoop-fs2img/pom.xml @@ -63,7 +63,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-gridmix/pom.xml b/hadoop-tools/hadoop-gridmix/pom.xml index 2af0a3c836..de6736861e 100644 --- a/hadoop-tools/hadoop-gridmix/pom.xml +++ b/hadoop-tools/hadoop-gridmix/pom.xml @@ -105,7 +105,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridMixClasses.java b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridMixClasses.java index 362b35e5de..372b2cab38 100644 --- a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridMixClasses.java +++ b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridMixClasses.java @@ -595,16 +595,16 @@ public void testLoadJobLoadRecordReader() throws Exception { Configuration conf = new Configuration(); FileSystem fs1 = mock(FileSystem.class); - when(fs1.open((Path) anyObject())).thenReturn( + when(fs1.open(any(Path.class))).thenReturn( new FakeFSDataInputStream(new FakeInputStream())); Path p1 = mock(Path.class); - when(p1.getFileSystem((JobConf) anyObject())).thenReturn(fs1); + when(p1.getFileSystem(any())).thenReturn(fs1); FileSystem fs2 = mock(FileSystem.class); - when(fs2.open((Path) anyObject())).thenReturn( + when(fs2.open(any(Path.class))).thenReturn( new FakeFSDataInputStream(new FakeInputStream())); Path p2 = mock(Path.class); - when(p2.getFileSystem((JobConf) anyObject())).thenReturn(fs2); + when(p2.getFileSystem(any())).thenReturn(fs2); Path[] paths = {p1, p2}; diff --git a/hadoop-tools/hadoop-kafka/pom.xml b/hadoop-tools/hadoop-kafka/pom.xml index 9d79c2c09b..a707aab0cb 100644 --- a/hadoop-tools/hadoop-kafka/pom.xml +++ b/hadoop-tools/hadoop-kafka/pom.xml @@ -108,7 +108,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java b/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java index cd40ac80d2..bfaef7b74f 100644 --- a/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java +++ b/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java @@ -43,7 +43,7 @@ import java.util.concurrent.Future; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -133,7 +133,7 @@ public void visit(MetricsVisitor visitor) { // Send the record and store the result in a mock Future. Future f = mock(Future.class); - when(mockProducer.send((ProducerRecord) anyObject())).thenReturn(f); + when(mockProducer.send(any())).thenReturn(f); kafkaSink.putMetrics(record); // Get the argument and verity it. diff --git a/hadoop-tools/hadoop-streaming/pom.xml b/hadoop-tools/hadoop-streaming/pom.xml index 9c7865b5f7..303ada6f4d 100644 --- a/hadoop-tools/hadoop-streaming/pom.xml +++ b/hadoop-tools/hadoop-streaming/pom.xml @@ -42,7 +42,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/pom.xml index bc160c9e84..a12c78e3a6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/pom.xml @@ -123,7 +123,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSAppMaster.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSAppMaster.java index 9474eaec49..af095bc918 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSAppMaster.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSAppMaster.java @@ -40,7 +40,7 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.junit.Assert; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import java.io.IOException; @@ -92,7 +92,8 @@ public void testDSAppMasterAllocateHandler() throws Exception { master.setAmRMClient(mockClient); master.setNumTotalContainers(targetContainers); Mockito.doNothing().when(mockClient) - .addContainerRequest(Matchers.any(AMRMClient.ContainerRequest.class)); + .addContainerRequest(ArgumentMatchers.any( + AMRMClient.ContainerRequest.class)); ApplicationMaster.RMCallbackHandler handler = master.getRMCallbackHandler(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml index 227e03663f..82c41efb7e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml @@ -173,7 +173,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml index 9386ac2b58..695d93bc1b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/pom.xml @@ -234,7 +234,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockRunningServiceContext.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockRunningServiceContext.java index 0245cd6fa4..c67c28909b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockRunningServiceContext.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockRunningServiceContext.java @@ -51,7 +51,7 @@ import java.util.Map; import java.util.concurrent.Future; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -82,7 +82,7 @@ public NMClientAsync createNMClient() { NMClientAsync nmClientAsync = super.createNMClient(); NMClient nmClient = mock(NMClient.class); try { - when(nmClient.getContainerStatus(anyObject(), anyObject())) + when(nmClient.getContainerStatus(any(), any())) .thenAnswer( (Answer) invocation -> ContainerStatus .newInstance((ContainerId) invocation.getArguments()[0], @@ -119,13 +119,13 @@ protected ServiceManager createServiceManager() { this.scheduler.init(fsWatcher.getConf()); - when(mockLaunchService.launchCompInstance(anyObject(), anyObject(), - anyObject(), anyObject())).thenAnswer( + when(mockLaunchService.launchCompInstance(any(), any(), + any(), any())).thenAnswer( (Answer>) this::launchAndReinitHelper); - when(mockLaunchService.reInitCompInstance(anyObject(), anyObject(), - anyObject(), anyObject())).thenAnswer(( + when(mockLaunchService.reInitCompInstance(any(), any(), + any(), any())).thenAnswer(( Answer>) this::launchAndReinitHelper); stabilizeComponents(this); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockServiceAM.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockServiceAM.java index ae59c90be4..ce4f9dd2b9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockServiceAM.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/MockServiceAM.java @@ -72,8 +72,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeoutException; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -253,7 +253,7 @@ public NMClientAsync createNMClient() { NMClientAsync nmClientAsync = super.createNMClient(); NMClient nmClient = mock(NMClient.class); try { - when(nmClient.getContainerStatus(anyObject(), anyObject())) + when(nmClient.getContainerStatus(any(), any())) .thenAnswer(invocation -> containerStatuses.get(invocation.getArguments()[0])); } catch (YarnException | IOException e) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java index 02cf6012eb..b3ba58d084 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java @@ -78,7 +78,7 @@ import static org.apache.hadoop.yarn.service.conf.YarnServiceConstants .CONTAINER_STATE_REPORT_AS_SERVICE_STATE; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -186,10 +186,10 @@ public static SliderFileSystem initMockFs(Service ext) throws IOException { FileSystem mockFs = mock(FileSystem.class); JsonSerDeser jsonSerDeser = mock(JsonSerDeser.class); when(sfs.getFileSystem()).thenReturn(mockFs); - when(sfs.buildClusterDirPath(anyObject())).thenReturn( + when(sfs.buildClusterDirPath(any())).thenReturn( new Path("cluster_dir_path")); if (ext != null) { - when(jsonSerDeser.load(anyObject(), anyObject())).thenReturn(ext); + when(jsonSerDeser.load(any(), any())).thenReturn(ext); } ServiceApiUtil.setJsonSerDeser(jsonSerDeser); return sfs; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java index 92afae2733..4527da433c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java @@ -52,7 +52,6 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +60,7 @@ import java.util.ArrayList; import java.util.List; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -220,18 +220,18 @@ static MockServiceClient create(ServiceTestUtils.ServiceFSWatcher rule, ApplicationAttemptReport.newInstance(client.attemptId, "localhost", 0, null, null, null, YarnApplicationAttemptState.RUNNING, null); - when(yarnClient.getApplicationAttemptReport(Matchers.any())) + when(yarnClient.getApplicationAttemptReport(any())) .thenReturn(attemptReport); when(yarnClient.getApplicationReport(client.appId)).thenReturn(appReport); when(client.amProxy.upgrade( - Matchers.any(UpgradeServiceRequestProto.class))).thenAnswer( + any(UpgradeServiceRequestProto.class))).thenAnswer( (Answer) invocation -> { UpgradeServiceResponseProto response = UpgradeServiceResponseProto.newBuilder().build(); client.proxyResponse = response; return response; }); - when(client.amProxy.upgrade(Matchers.any( + when(client.amProxy.upgrade(any( CompInstancesUpgradeRequestProto.class))).thenAnswer( (Answer) invocation -> { CompInstancesUpgradeResponseProto response = @@ -240,7 +240,7 @@ static MockServiceClient create(ServiceTestUtils.ServiceFSWatcher rule, return response; }); - when(client.amProxy.getCompInstances(Matchers.any( + when(client.amProxy.getCompInstances(any( GetCompInstancesRequestProto.class))).thenAnswer( (Answer) invocation -> { @@ -304,7 +304,7 @@ private T getLastProxyResponse(Class clazz) { private static YarnClient createMockYarnClient() throws IOException, YarnException { YarnClient yarnClient = mock(YarnClient.class); - when(yarnClient.getApplications(Matchers.any( + when(yarnClient.getApplications(any( GetApplicationsRequest.class))).thenReturn(new ArrayList<>()); return yarnClient; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java index f6ead01c59..3b9ce4359a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java @@ -56,9 +56,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java index ff1fb7f7a3..0f7f37594c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java @@ -38,7 +38,7 @@ import java.util.ArrayList; import java.util.List; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java index ae626086f9..8908a1d415 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.List; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -60,7 +60,7 @@ public void testConfigFiles() throws IOException { ClientProvider clientProvider = new ClientProvider(); FileSystem mockFs = mock(FileSystem.class); FileStatus mockFileStatus = mock(FileStatus.class); - when(mockFs.exists(anyObject())).thenReturn(true); + when(mockFs.exists(any())).thenReturn(true); String compName = "sleeper"; ConfigFile configFile = new ConfigFile(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java index 366515c8b4..6d6720bb7e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.yarn.service.providers; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,7 +40,7 @@ public class TestDefaultClientProvider { public void testConfigFile() throws IOException { DefaultClientProvider defaultClientProvider = new DefaultClientProvider(); FileSystem mockFs = mock(FileSystem.class); - when(mockFs.exists(anyObject())).thenReturn(true); + when(mockFs.exists(any())).thenReturn(true); String compName = "sleeper"; ConfigFile configFile = new ConfigFile(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/pom.xml index a0282ed205..00f4306678 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/pom.xml @@ -123,7 +123,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java index 2a8f1da631..3c785a04ef 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java @@ -36,7 +36,7 @@ import java.io.IOException; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/yarnservice/TestYarnServiceRunJobCli.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/yarnservice/TestYarnServiceRunJobCli.java index f3d140975f..ee6b5c1078 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/yarnservice/TestYarnServiceRunJobCli.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/yarnservice/TestYarnServiceRunJobCli.java @@ -52,8 +52,8 @@ import java.util.Map; import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.EXIT_SUCCESS; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml index dd672c2ee7..b680b2f8b7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml @@ -66,7 +66,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java index 7306b3ac3c..f56747e346 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestAMRMClientAsync.java @@ -18,10 +18,10 @@ package org.apache.hadoop.yarn.client.api.async.impl; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestNMClientAsync.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestNMClientAsync.java index 6c7270457a..40038b1cab 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestNMClientAsync.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/async/impl/TestNMClientAsync.java @@ -18,8 +18,8 @@ package org.apache.hadoop.yarn.client.api.async.impl; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java index e05e57e093..3dbd1dd4f2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.client.api.impl; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java index cf837794f0..da4f6ee5c8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestSharedCacheClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestSharedCacheClientImpl.java index ed026fe616..b297d926c0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestSharedCacheClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestSharedCacheClientImpl.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java index 7ad7e3a8a4..3848b10682 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java @@ -93,7 +93,7 @@ import java.util.Map; import java.util.Set; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientImpl.java index dd0aa5c1a0..a6259a7be0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientImpl.java @@ -51,7 +51,7 @@ import java.nio.ByteBuffer; import java.util.Collection; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -123,7 +123,7 @@ public void testBestEffortTimelineDelegationToken() @Override TimelineClient createTimelineClient() throws IOException, YarnException { timelineClient = mock(TimelineClient.class); - when(timelineClient.getDelegationToken(any(String.class))) + when(timelineClient.getDelegationToken(any())) .thenThrow(new RuntimeException("Best effort test exception")); return timelineClient; } @@ -162,8 +162,7 @@ public void testAutomaticTimelineDelegationTokenLoading() @Override TimelineClient createTimelineClient() throws IOException, YarnException { timelineClient = mock(TimelineClient.class); - when(timelineClient.getDelegationToken(any(String.class))) - .thenReturn(dToken); + when(timelineClient.getDelegationToken(any())).thenReturn(dToken); return timelineClient; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java index 1e9fface3f..f9061eb6e7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java @@ -21,16 +21,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Matchers.*; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; @@ -875,7 +875,7 @@ public void testFetchRunningApplicationLogs() throws Exception { matchedLogTypes.put(containerId1.toString(), mockContainer1); matchedLogTypes.put(containerId2.toString(), mockContainer2); doReturn(matchedLogTypes).when(cli).getMatchedLogTypesForRunningApp( - anyListOf(ContainerLogsRequest.class), anyBoolean(), + anyList(), anyBoolean(), anyBoolean()); cli.setConf(new YarnConfiguration()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestNodeAttributesCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestNodeAttributesCLI.java index 7f48493d09..fb2e3cdaa3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestNodeAttributesCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestNodeAttributesCLI.java @@ -34,7 +34,7 @@ import org.apache.hadoop.yarn.api.records.NodeToAttributeValue; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java index 4d0aea2b07..637f121d56 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java @@ -22,10 +22,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -580,12 +580,9 @@ public void testGetGroups() throws Exception { String[] args = { "-getGroups", "admin" }; assertEquals(0, rmAdminCLI.run(args)); verify(admin).getGroupsForUser(eq("admin")); - verify(out).println(argThat(new ArgumentMatcher() { - @Override - public boolean matches(Object argument) { - return ("" + argument).equals("admin : group1 group2"); - } - })); + verify(out).println(argThat( + (ArgumentMatcher) arg -> + ("" + arg).equals("admin : group1 group2"))); } finally { System.setOut(origOut); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java index e02e089d15..17d570f30c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java @@ -20,9 +20,9 @@ import org.apache.hadoop.yarn.api.records.NodeAttribute; import org.apache.hadoop.yarn.api.records.NodeAttributeType; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml index eeabf72c6c..7b5a4b75e7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml @@ -108,10 +108,6 @@ org.apache.hadoop hadoop-annotations - junit junit @@ -119,7 +115,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClient.java index 715f7e5ff2..6c2efb3526 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClient.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.client.api.impl; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -332,12 +332,12 @@ public static ClientResponse mockEntityClientResponse( ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when( - spyTimelineWriter).doPostingObject( - any(TimelineEntities.class), any(String.class)); + spyTimelineWriter).doPostingObject( + any(TimelineEntities.class), any()); return response; } doReturn(response).when(spyTimelineWriter) - .doPostingObject(any(TimelineEntities.class), any(String.class)); + .doPostingObject(any(TimelineEntities.class), any()); when(response.getStatusInfo()).thenReturn(status); TimelinePutResponse.TimelinePutError error = new TimelinePutResponse.TimelinePutError(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientForATS1_5.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientForATS1_5.java index 8573033980..76e5714f52 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientForATS1_5.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientForATS1_5.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.client.api.impl; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcClientFactoryPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcClientFactoryPBImpl.java index 41febd3de7..7967c41765 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcClientFactoryPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcClientFactoryPBImpl.java @@ -23,7 +23,7 @@ import java.net.InetSocketAddress; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcServerFactoryPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcServerFactoryPBImpl.java index 6a5ce840be..c8650e169a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcServerFactoryPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/factories/impl/pb/TestRpcServerFactoryPBImpl.java @@ -23,7 +23,7 @@ import java.net.InetSocketAddress; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml index bfac67398b..22f28e2d9c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml @@ -53,7 +53,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java index b6d2967d2a..d8161bbcdb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java @@ -20,7 +20,7 @@ import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml index 45cc5eabf9..e3f7a6b24b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml @@ -96,7 +96,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/utils/FederationPoliciesTestUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/utils/FederationPoliciesTestUtil.java index 9cc6d06a84..a9b9029b25 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/utils/FederationPoliciesTestUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/utils/FederationPoliciesTestUtil.java @@ -37,7 +37,7 @@ import java.util.List; import java.util.Map; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml index 5a70f61729..55f67d343f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml @@ -125,10 +125,6 @@ io.dropwizard.metrics metrics-core - junit junit @@ -136,7 +132,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java index f08b93f629..dba79b33a5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java @@ -22,9 +22,9 @@ import static org.apache.hadoop.fs.CreateFlag.OVERWRITE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -38,7 +38,6 @@ import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; -import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; @@ -587,7 +586,7 @@ public ContainerLocalizer createContainerLocalizer(String user, } catch (YarnException e) { throw new IOException(e); } - when(spyLocalizer.getProxy(any(InetSocketAddress.class))) + when(spyLocalizer.getProxy(any())) .thenReturn(nmProxy); return spyLocalizer; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java index 20c68046c2..ae1f574c07 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -679,7 +679,7 @@ public void testReapContainer() throws Exception { ContainerReapContext ctx = builder.build(); lce.reapContainer(ctx); verify(lce, times(1)).reapContainer(ctx); - verify(lce, times(1)).postComplete(anyObject()); + verify(lce, times(1)).postComplete(any()); } @Test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java index 26e268dccd..51c7d963d7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java @@ -22,8 +22,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -46,7 +46,6 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileUtil; @@ -80,8 +79,7 @@ import org.mockito.stubbing.Answer; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -596,8 +594,8 @@ public void testNoExitCodeFromPrivilegedOperation() throws Exception { spy(PrivilegedOperationExecutor.getInstance(conf)); doThrow(new PrivilegedOperationException("interrupted")) .when(spyPrivilegedExecutor).executePrivilegedOperation( - any(List.class), any(PrivilegedOperation.class), - any(File.class), any(Map.class), anyBoolean(), anyBoolean()); + any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean()); LinuxContainerRuntime runtime = new DefaultLinuxContainerRuntime( spyPrivilegedExecutor); runtime.initialize(conf, null); @@ -720,8 +718,7 @@ public void testContainerLaunchEnvironment() PrivilegedOperation.class); // Verify that verify(mockPrivilegedExec, times(1)) - .executePrivilegedOperation(anyListOf( - String.class), opCaptor.capture(), any( - File.class), eq(null), eq(false), eq(false)); + .executePrivilegedOperation(any(), opCaptor.capture(), any(), + eq(null), eq(false), eq(false)); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerReboot.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerReboot.java index f661cf5b73..fbd3646940 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerReboot.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerReboot.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java index 0dca7de025..15c1cac9cb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/BaseContainerManagerTest.java @@ -18,13 +18,13 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager; +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.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.doNothing; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestAuxServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestAuxServices.java index aef40911f2..925289a1a4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestAuxServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestAuxServices.java @@ -27,8 +27,8 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java index ec4254d1aa..e129caab1a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManagerRecovery.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/application/TestApplication.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/application/TestApplication.java index cbe19ffa7d..e3907f8d25 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/application/TestApplication.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/application/TestApplication.java @@ -18,7 +18,6 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.application; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import java.io.IOException; @@ -490,7 +489,8 @@ public void testNMTokenSecretManagerCleanup() { } } - private class ContainerKillMatcher extends ArgumentMatcher { + private class ContainerKillMatcher implements + ArgumentMatcher { private ContainerId cId; public ContainerKillMatcher(ContainerId cId) { @@ -498,7 +498,7 @@ public ContainerKillMatcher(ContainerId cId) { } @Override - public boolean matches(Object argument) { + public boolean matches(ContainerEvent argument) { if (argument instanceof ContainerKillEvent) { ContainerKillEvent event = (ContainerKillEvent) argument; return event.getContainerID().equals(cId); @@ -507,7 +507,8 @@ public boolean matches(Object argument) { } } - private class ContainerInitMatcher extends ArgumentMatcher { + private class ContainerInitMatcher implements + ArgumentMatcher { private ContainerId cId; public ContainerInitMatcher(ContainerId cId) { @@ -515,7 +516,7 @@ public ContainerInitMatcher(ContainerId cId) { } @Override - public boolean matches(Object argument) { + public boolean matches(ContainerEvent argument) { if (argument instanceof ContainerInitEvent) { ContainerInitEvent event = (ContainerInitEvent) argument; return event.getContainerID().equals(cId); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java index 95ff9684ce..4d7559ec23 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.refEq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.refEq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; @@ -167,13 +167,7 @@ public void testLocalizationLaunch() throws Exception { final WrappedContainer wcf = wc; // verify container launch ArgumentMatcher matchesContainerLaunch = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - ContainersLauncherEvent launchEvent = (ContainersLauncherEvent) o; - return wcf.c == launchEvent.getContainer(); - } - }; + event -> wcf.c == event.getContainer(); verify(wc.launcherBus).handle(argThat(matchesContainerLaunch)); } finally { if (wc != null) { @@ -949,28 +943,16 @@ public void testServiceData() throws Exception { for (final Map.Entry e : wc.serviceData.entrySet()) { ArgumentMatcher matchesServiceReq = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - AuxServicesEvent evt = (AuxServicesEvent) o; - return e.getKey().equals(evt.getServiceID()) + evt -> e.getKey().equals(evt.getServiceID()) && 0 == e.getValue().compareTo(evt.getServiceData()); - } - }; verify(wc.auxBus).handle(argThat(matchesServiceReq)); } final WrappedContainer wcf = wc; // verify launch on empty resource request ArgumentMatcher matchesLaunchReq = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - ContainersLauncherEvent evt = (ContainersLauncherEvent) o; - return evt.getType() == ContainersLauncherEventType.LAUNCH_CONTAINER + evt -> evt.getType() == ContainersLauncherEventType.LAUNCH_CONTAINER && wcf.cId.equals(evt.getContainer().getContainerId()); - } - }; verify(wc.launcherBus).handle(argThat(matchesLaunchReq)); } finally { if (wc != null) { @@ -1174,7 +1156,7 @@ private void verifyDockerContainerCleanupCall(WrappedContainer wc) } // Argument matcher for matching container localization cleanup event. - private static class LocalizationCleanupMatcher extends + private static class LocalizationCleanupMatcher implements ArgumentMatcher { Container c; @@ -1183,12 +1165,12 @@ private static class LocalizationCleanupMatcher extends } @Override - public boolean matches(Object o) { - if (!(o instanceof ContainerLocalizationCleanupEvent)) { + public boolean matches(LocalizationEvent e) { + if (!(e instanceof ContainerLocalizationCleanupEvent)) { return false; } ContainerLocalizationCleanupEvent evt = - (ContainerLocalizationCleanupEvent) o; + (ContainerLocalizationCleanupEvent) e; return (evt.getContainer() == c); } @@ -1210,15 +1192,15 @@ private static class ResourcesReleasedMatcher extends } @Override - public boolean matches(Object o) { + public boolean matches(LocalizationEvent e) { // match event type and container. - if(!super.matches(o)){ + if(!super.matches(e)){ return false; } // match resources. ContainerLocalizationCleanupEvent evt = - (ContainerLocalizationCleanupEvent) o; + (ContainerLocalizationCleanupEvent) e; final HashSet expected = new HashSet(resources); for (Collection rc : evt.getResources().values()) { @@ -1233,7 +1215,7 @@ public boolean matches(Object o) { } // Accept iff the resource payload matches. - private static class ResourcesRequestedMatcher extends + private static class ResourcesRequestedMatcher implements ArgumentMatcher { final HashSet resources = new HashSet(); @@ -1248,9 +1230,9 @@ private static class ResourcesRequestedMatcher extends } @Override - public boolean matches(Object o) { + public boolean matches(LocalizationEvent e) { ContainerLocalizationRequestEvent evt = - (ContainerLocalizationRequestEvent) o; + (ContainerLocalizationRequestEvent) e; final HashSet expected = new HashSet(resources); for (Collection rc : evt.getRequestedResources() diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/DockerContainerDeletionMatcher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/DockerContainerDeletionMatcher.java index 8fa56fcf37..1ff7f54661 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/DockerContainerDeletionMatcher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/DockerContainerDeletionMatcher.java @@ -24,7 +24,7 @@ * {@link DockerContainerDeletionTask}. */ public class DockerContainerDeletionMatcher - extends ArgumentMatcher { + implements ArgumentMatcher { private final DeletionService delService; private final String containerId; @@ -36,8 +36,7 @@ public DockerContainerDeletionMatcher(DeletionService delService, } @Override - public boolean matches(Object o) { - DockerContainerDeletionTask task = (DockerContainerDeletionTask)o; + public boolean matches(DockerContainerDeletionTask task) { if (task.getContainerId() == null && containerId == null) { return true; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/FileDeletionMatcher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/FileDeletionMatcher.java index faad456429..10d2c08584 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/FileDeletionMatcher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/deletion/task/FileDeletionMatcher.java @@ -25,7 +25,7 @@ /** * ArgumentMatcher to check the arguments of the {@link FileDeletionTask}. */ -public class FileDeletionMatcher extends ArgumentMatcher { +public class FileDeletionMatcher implements ArgumentMatcher { private final DeletionService delService; private final String user; @@ -41,8 +41,7 @@ public FileDeletionMatcher(DeletionService delService, String user, } @Override - public boolean matches(Object o) { - FileDeletionTask fd = (FileDeletionTask) o; + public boolean matches(FileDeletionTask fd) { if (fd.getUser() == null && user != null) { return false; } else if (fd.getUser() != null && user == null) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java index 93accf24db..c1f426862a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java @@ -21,7 +21,7 @@ import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows; import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.BufferedReader; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerRelaunch.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerRelaunch.java index 3b57938ebd..9ff926c2cf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerRelaunch.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerRelaunch.java @@ -40,8 +40,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainersLauncher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainersLauncher.java index c6c87889f2..f48d785569 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainersLauncher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainersLauncher.java @@ -34,7 +34,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -100,19 +99,18 @@ public class TestContainersLauncher { @Mock private ContainerLaunch containerLaunch; - @InjectMocks - private ContainersLauncher tempContainersLauncher = new ContainersLauncher( - context, dispatcher, exec, dirsHandler, containerManager); - private ContainersLauncher spy; @Before public void setup() throws IllegalArgumentException, IllegalAccessException { MockitoAnnotations.initMocks(this); + ContainersLauncher tempContainersLauncher = new ContainersLauncher( + context, dispatcher, exec, dirsHandler, containerManager); ConcurrentMap applications = new ConcurrentHashMap<>(); applications.put(appId, app1); spy = spy(tempContainersLauncher); + spy.containerLauncher = containerLauncher; conf = doReturn(conf).when(spy).getConfig(); when(event.getContainer()).thenReturn(container); when(container.getContainerId()).thenReturn(containerId); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/MockPrivilegedOperationCaptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/MockPrivilegedOperationCaptor.java index 187da6b4d4..315de5ccb3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/MockPrivilegedOperationCaptor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/MockPrivilegedOperationCaptor.java @@ -19,13 +19,11 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import java.io.File; import java.util.List; import java.util.Map; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyList; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -56,8 +54,8 @@ public static List capturePrivilegedOperations( //due to type erasure + mocking, this verification requires a suppress // warning annotation on the entire method verify(mockExecutor, times(invocationCount)) - .executePrivilegedOperation(anyList(), opCaptor.capture(), - any(File.class), any(Map.class), eq(grabOutput), eq(false)); + .executePrivilegedOperation(any(), opCaptor.capture(), + any(), any(Map.class), eq(grabOutput), eq(false)); //verification completed. we need to isolate specific invications. // hence, reset mock here diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java index e93bc5da1a..40a296cf22 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupElasticMemoryController.java @@ -31,7 +31,7 @@ import java.util.concurrent.Executors; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java index 70badaf4ef..b1e8989213 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java @@ -48,7 +48,7 @@ import java.util.UUID; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestDefaultOOMHandler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestDefaultOOMHandler.java index 8a6ca74609..9773d90ed0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestDefaultOOMHandler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestDefaultOOMHandler.java @@ -37,7 +37,7 @@ import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsHandler.CGROUP_PARAM_MEMORY_MEMSW_USAGE_BYTES; import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsHandler.CGROUP_PARAM_MEMORY_OOM_CONTROL; import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsHandler.CGROUP_PARAM_MEMORY_USAGE_BYTES; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestNetworkPacketTaggingHandlerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestNetworkPacketTaggingHandlerImpl.java index 541be21f59..74f6bff6af 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestNetworkPacketTaggingHandlerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestNetworkPacketTaggingHandlerImpl.java @@ -20,7 +20,7 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; @@ -31,7 +31,7 @@ import java.util.List; import static org.mockito.Mockito.doNothing; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.yarn.api.records.ContainerId; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficControlBandwidthHandlerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficControlBandwidthHandlerImpl.java index 09f4f1d1a8..ee6b41e758 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficControlBandwidthHandlerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficControlBandwidthHandlerImpl.java @@ -39,7 +39,7 @@ import java.io.File; import java.util.List; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficController.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficController.java index c5236635fd..63c654463f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficController.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestTrafficController.java @@ -41,8 +41,8 @@ import java.util.Arrays; import java.util.List; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java index 06eff85cce..499c1e14ef 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java @@ -407,10 +407,11 @@ private void verifyDeniedDevices(ContainerId containerId, private static IntelFpgaOpenclPlugin mockPlugin(String type, List list) { IntelFpgaOpenclPlugin plugin = mock(IntelFpgaOpenclPlugin.class); - when(plugin.initPlugin(Mockito.anyObject())).thenReturn(true); + when(plugin.initPlugin(Mockito.any())).thenReturn(true); when(plugin.getFpgaType()).thenReturn(type); when(plugin.downloadIP(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap())).thenReturn("/tmp"); - when(plugin.configureIP(Mockito.anyString(), Mockito.anyObject())).thenReturn(true); + when(plugin.configureIP(Mockito.anyString(), Mockito.any())) + .thenReturn(true); when(plugin.discover(Mockito.anyInt())).thenReturn(list); return plugin; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/gpu/TestGpuResourceHandler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/gpu/TestGpuResourceHandler.java index 3b1f2a9fb4..fff9068442 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/gpu/TestGpuResourceHandler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/gpu/TestGpuResourceHandler.java @@ -54,10 +54,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyList; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceAllocator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceAllocator.java index e1ba19c5b8..c8072c327a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceAllocator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceAllocator.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -42,7 +43,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; /** * Test class for NumaResourceAllocator. @@ -62,7 +62,7 @@ public void setUp() throws IOException, YarnException { Container mockContainer = mock(Container.class); when(mockContainer.getResourceMappings()) .thenReturn(new ResourceMappings()); - when(mockContainers.get(Matchers.any())).thenReturn(mockContainer); + when(mockContainers.get(any())).thenReturn(mockContainer); when(mockContext.getContainers()).thenReturn(mockContainers); NMStateStoreService mock = mock(NMStateStoreService.class); when(mockContext.getNMStateStore()).thenReturn(mock); @@ -232,7 +232,7 @@ public void testRecoverNumaResource() throws Exception { Arrays.asList(new NumaResourceAllocation("0", 70000, "0", 4))); value.addAssignedResources("numa", assignedResources); when(mockContainer.getResourceMappings()).thenReturn(value); - when(mockContainers.get(Matchers.any())).thenReturn(mockContainer); + when(mockContainers.get(any())).thenReturn(mockContainer); when(mockContext.getContainers()).thenReturn(mockContainers); NMStateStoreService mock = mock(NMStateStoreService.class); when(mockContext.getNMStateStore()).thenReturn(mock); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceHandlerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceHandlerImpl.java index 341cbf0a81..fcef088ce6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceHandlerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/numa/TestNumaResourceHandlerImpl.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -39,7 +40,6 @@ import org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; /** * Test class for NumaResourceHandlerImpl. @@ -127,7 +127,7 @@ public void testReacquireContainer() throws Exception { assignedRscs.updateAssignedResources(Arrays.asList(numaResourceAllocation)); resourceMappings.addAssignedResources("numa", assignedRscs); when(mockContainer.getResourceMappings()).thenReturn(resourceMappings); - when(mockContainers.get(Matchers.any())).thenReturn(mockContainer); + when(mockContainers.get(any())).thenReturn(mockContainer); when(mockContext.getContainers()).thenReturn(mockContainers); numaResourceHandler = new NumaResourceHandlerImpl(conf, mockContext); numaResourceHandler.bootstrap(conf); @@ -162,7 +162,7 @@ private Context createAndGetMockContext() { mockContainer = mock(Container.class); when(mockContainer.getResourceMappings()) .thenReturn(new ResourceMappings()); - when(mockContainers.get(Matchers.any())).thenReturn(mockContainer); + when(mockContainers.get(any())).thenReturn(mockContainer); when(mockContext.getContainers()).thenReturn(mockContainers); return mockContext; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java index 0b5ce3ac37..ef0f2e00b1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java @@ -113,10 +113,9 @@ import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntimeConstants.SIGNAL; import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntimeConstants.USER; import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntimeConstants.USER_FILECACHE_DIRS; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; -import static org.mockito.Mockito.anyList; import static org.mockito.Mockito.anyMap; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -388,17 +387,14 @@ private PrivilegedOperation capturePrivilegedOperation() return capturePrivilegedOperation(1); } - @SuppressWarnings("unchecked") private PrivilegedOperation capturePrivilegedOperation(int invocations) throws PrivilegedOperationException { ArgumentCaptor opCaptor = ArgumentCaptor.forClass( PrivilegedOperation.class); - //due to type erasure + mocking, this verification requires a suppress - // warning annotation on the entire method verify(mockExecutor, times(invocations)) - .executePrivilegedOperation(anyList(), opCaptor.capture(), any( - File.class), anyMap(), anyBoolean(), anyBoolean()); + .executePrivilegedOperation(any(), opCaptor.capture(), any(), + any(), anyBoolean(), anyBoolean()); //verification completed. we need to isolate specific invocations. // hence, reset mock here @@ -1675,8 +1671,8 @@ public void testDockerStopOnTermSignalWhenRunning() throws ContainerExecutionException, PrivilegedOperationException, IOException { when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( DockerCommandExecutor.DockerContainerStatus.RUNNING.getName()); List dockerCommands = getDockerCommandsForDockerStop( ContainerExecutor.Signal.TERM); @@ -1689,8 +1685,8 @@ public void testDockerStopWithQuitSignalWhenRunning() throws ContainerExecutionException, PrivilegedOperationException, IOException { when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( DockerCommandExecutor.DockerContainerStatus.RUNNING.getName() + ",SIGQUIT"); @@ -1744,8 +1740,8 @@ public void testDockerStopOnTermSignalWhenRunningPrivileged() submittingUser); env.put(ENV_DOCKER_CONTAINER_RUN_PRIVILEGED_CONTAINER, "true"); when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( DockerCommandExecutor.DockerContainerStatus.RUNNING.getName()); List dockerCommands = getDockerCommandsForDockerStop( ContainerExecutor.Signal.TERM); @@ -1761,8 +1757,8 @@ public void testDockerStopOnKillSignalWhenRunningPrivileged() submittingUser); env.put(ENV_DOCKER_CONTAINER_RUN_PRIVILEGED_CONTAINER, "true"); when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( DockerCommandExecutor.DockerContainerStatus.RUNNING.getName()); List dockerCommands = getDockerCommandsForDockerStop( ContainerExecutor.Signal.KILL); @@ -1783,8 +1779,8 @@ public void testDockerKillOnQuitSignalWhenRunningPrivileged() submittingUser); env.put(ENV_DOCKER_CONTAINER_RUN_PRIVILEGED_CONTAINER, "true"); when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( DockerCommandExecutor.DockerContainerStatus.RUNNING.getName()); List dockerCommands = getDockerCommandsForDockerStop( ContainerExecutor.Signal.QUIT); @@ -1810,8 +1806,8 @@ public void testDockerRmOnWhenExited() throws Exception { runtime.initialize(enableMockContainerExecutor(conf), null); runtime.reapContainer(builder.build()); verify(mockExecutor, times(1)) - .executePrivilegedOperation(anyList(), any(), any( - File.class), anyMap(), anyBoolean(), anyBoolean()); + .executePrivilegedOperation(any(), any(), any(), + any(), anyBoolean(), anyBoolean()); } @Test @@ -1827,8 +1823,8 @@ public void testNoDockerRmWhenDelayedDeletionEnabled() runtime.initialize(enableMockContainerExecutor(conf), null); runtime.reapContainer(builder.build()); verify(mockExecutor, never()) - .executePrivilegedOperation(anyList(), any(), any( - File.class), anyMap(), anyBoolean(), anyBoolean()); + .executePrivilegedOperation(any(), any(), any(), + anyMap(), anyBoolean(), anyBoolean()); } private List getDockerCommandsForDockerStop( @@ -1962,8 +1958,8 @@ private void checkVolumeCreateCommand() //due to type erasure + mocking, this verification requires a suppress // warning annotation on the entire method verify(mockExecutor, times(3)) - .executePrivilegedOperation(anyList(), opCaptor.capture(), any( - File.class), anyMap(), anyBoolean(), anyBoolean()); + .executePrivilegedOperation(any(), opCaptor.capture(), any(), + any(), anyBoolean(), anyBoolean()); //verification completed. we need to isolate specific invications. // hence, reset mock here @@ -2037,13 +2033,9 @@ private void testDockerCommandPluginWithVolumesOutput( DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime( mockExecutor, mockCGroupsHandler); when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( - null); - when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( - dockerVolumeListOutput); + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( + null, dockerVolumeListOutput); Context mockNMContext = createMockNMContext(); ResourcePluginManager rpm = mock(ResourcePluginManager.class); @@ -2132,13 +2124,9 @@ public void testDockerCommandPlugin() throws Exception { DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(mockExecutor, mockCGroupsHandler); when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( - null); - when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( - "volume1,local"); + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( + null, "volume1,local"); Context mockNMContext = createMockNMContext(); ResourcePluginManager rpm = mock(ResourcePluginManager.class); @@ -2359,8 +2347,8 @@ public void testDockerContainerRelaunch() DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(mockExecutor, mockCGroupsHandler); when(mockExecutor - .executePrivilegedOperation(anyList(), any(PrivilegedOperation.class), - any(File.class), anyMap(), anyBoolean(), anyBoolean())).thenReturn( + .executePrivilegedOperation(any(), any(PrivilegedOperation.class), + any(), any(), anyBoolean(), anyBoolean())).thenReturn( DockerCommandExecutor.DockerContainerStatus.STOPPED.getName()); runtime.initialize(conf, nmContext); runtime.relaunchContainer(builder.build()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/TestDockerCommandExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/TestDockerCommandExecutor.java index 143e9b1d03..dcba179a28 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/TestDockerCommandExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/docker/TestDockerCommandExecutor.java @@ -51,9 +51,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestContainerLocalizer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestContainerLocalizer.java index 12592b23e6..3777867e0f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestContainerLocalizer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestContainerLocalizer.java @@ -20,13 +20,13 @@ import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Matchers.same; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -212,13 +212,7 @@ public void testMain() throws Exception { // verify all HB use localizerID provided verify(nmProxy, never()).heartbeat(argThat( - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - LocalizerStatus status = (LocalizerStatus) o; - return !containerId.equals(status.getLocalizerId()); - } - })); + status -> !containerId.equals(status.getLocalizerId()))); } @Test(timeout = 15000) @@ -402,14 +396,13 @@ public Future answer(InvocationOnMock invoc) doReturn(cs).when(localizer).createCompletionService(syncExec); } - static class HBMatches extends ArgumentMatcher { + static class HBMatches implements ArgumentMatcher { final LocalResource rsrc; HBMatches(LocalResource rsrc) { this.rsrc = rsrc; } @Override - public boolean matches(Object o) { - LocalizerStatus status = (LocalizerStatus) o; + public boolean matches(LocalizerStatus status) { for (LocalResourceStatus localized : status.getResources()) { switch (localized.getStatus()) { case FETCH_SUCCESS: diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalResourcesTrackerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalResourcesTrackerImpl.java index 6cab5934e8..15d9e2cdb7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalResourcesTrackerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalResourcesTrackerImpl.java @@ -18,10 +18,10 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalizedResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalizedResource.java index cd85d92700..a04b73473d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalizedResource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestLocalizedResource.java @@ -18,8 +18,8 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -192,7 +192,8 @@ static LocalResource createMockResource() { } - static class LocalizerEventMatcher extends ArgumentMatcher { + static class LocalizerEventMatcher implements + ArgumentMatcher { Credentials creds; LocalResourceVisibility vis; private final ContainerId idRef; @@ -206,9 +207,11 @@ public LocalizerEventMatcher(ContainerId idRef, Credentials creds, this.idRef = idRef; } @Override - public boolean matches(Object o) { - if (!(o instanceof LocalizerResourceRequestEvent)) return false; - LocalizerResourceRequestEvent evt = (LocalizerResourceRequestEvent) o; + public boolean matches(LocalizerEvent le) { + if (!(le instanceof LocalizerResourceRequestEvent)) { + return false; + } + LocalizerResourceRequestEvent evt = (LocalizerResourceRequestEvent) le; return idRef == evt.getContext().getContainerId() && type == evt.getType() && vis == evt.getVisibility() @@ -216,7 +219,8 @@ public boolean matches(Object o) { } } - static class ContainerEventMatcher extends ArgumentMatcher { + static class ContainerEventMatcher implements + ArgumentMatcher { private final ContainerId idRef; private final ContainerEventType type; public ContainerEventMatcher(ContainerId idRef, ContainerEventType type) { @@ -224,9 +228,7 @@ public ContainerEventMatcher(ContainerId idRef, ContainerEventType type) { this.type = type; } @Override - public boolean matches(Object o) { - if (!(o instanceof ContainerEvent)) return false; - ContainerEvent evt = (ContainerEvent) o; + public boolean matches(ContainerEvent evt) { return idRef == evt.getContainerID() && type == evt.getType(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java index 21896ca4c0..9f5f608fed 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java @@ -23,14 +23,14 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyShort; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyShort; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -65,7 +65,6 @@ import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.hadoop.fs.Options; import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState; import org.apache.hadoop.yarn.server.nodemanager.containermanager.deletion.task.FileDeletionMatcher; import org.apache.hadoop.yarn.server.nodemanager.executor.LocalizerStartContext; @@ -304,19 +303,19 @@ public void testDirectoryCleanupOnNewlyCreatedStateStore() p = new Path((new URI(p.toString())).getPath()); Path usercache = new Path(p, ContainerLocalizer.USERCACHE); verify(spylfs) - .rename(eq(usercache), any(Path.class), any(Options.Rename.class)); + .rename(eq(usercache), any(Path.class), any()); verify(spylfs) .mkdir(eq(usercache), eq(defaultPerm), eq(true)); Path publicCache = new Path(p, ContainerLocalizer.FILECACHE); verify(spylfs) - .rename(eq(usercache), any(Path.class), any(Options.Rename.class)); + .rename(eq(usercache), any(Path.class), any()); verify(spylfs) .mkdir(eq(publicCache), eq(defaultPerm), eq(true)); Path nmPriv = new Path(p, ResourceLocalizationService.NM_PRIVATE_DIR); verify(spylfs) - .rename(eq(usercache), any(Path.class), any(Options.Rename.class)); + .rename(eq(usercache), any(Path.class), any()); verify(spylfs).mkdir(eq(nmPriv), eq(ResourceLocalizationService.NM_PRIVATE_PERM), eq(true)); } @@ -899,14 +898,8 @@ public FileStatus answer(InvocationOnMock invocation) throws Throwable { spyService.handle(new ApplicationLocalizationEvent( LocalizationEventType.INIT_APPLICATION_RESOURCES, app)); ArgumentMatcher matchesAppInit = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - ApplicationEvent evt = (ApplicationEvent) o; - return evt.getType() == ApplicationEventType.APPLICATION_INITED + evt -> evt.getType() == ApplicationEventType.APPLICATION_INITED && appId == evt.getApplicationID(); - } - }; dispatcher.await(); verify(applicationBus).handle(argThat(matchesAppInit)); @@ -1055,14 +1048,8 @@ public boolean matches(Object o) { dispatcher.await(); // verify container notification ArgumentMatcher matchesContainerLoc = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - ContainerEvent evt = (ContainerEvent) o; - return evt.getType() == ContainerEventType.RESOURCE_LOCALIZED + evt -> evt.getType() == ContainerEventType.RESOURCE_LOCALIZED && c.getContainerId() == evt.getContainerID(); - } - }; // total 3 resource localzation calls. one for each resource. verify(containerBus, times(3)).handle(argThat(matchesContainerLoc)); @@ -1076,8 +1063,8 @@ public boolean matches(Object o) { } } - private static class DownloadingPathsMatcher extends ArgumentMatcher - implements VarargMatcher { + private static class DownloadingPathsMatcher implements + ArgumentMatcher, VarargMatcher { static final long serialVersionUID = 0; private transient Set matchPaths; @@ -1087,8 +1074,7 @@ private static class DownloadingPathsMatcher extends ArgumentMatcher } @Override - public boolean matches(Object varargs) { - Path[] downloadingPaths = (Path[]) varargs; + public boolean matches(Path[] downloadingPaths) { if (matchPaths.size() != downloadingPaths.length) { return false; } @@ -1226,14 +1212,8 @@ private void initApp(ResourceLocalizationService spyService, spyService.handle(new ApplicationLocalizationEvent( LocalizationEventType.INIT_APPLICATION_RESOURCES, app)); ArgumentMatcher matchesAppInit = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - ApplicationEvent evt = (ApplicationEvent) o; - return evt.getType() == ApplicationEventType.APPLICATION_INITED + evt -> evt.getType() == ApplicationEventType.APPLICATION_INITED && appId == evt.getApplicationID(); - } - }; dispatcher.await(); verify(applicationBus).handle(argThat(matchesAppInit)); } @@ -1323,14 +1303,8 @@ private void doLocalization(ResourceLocalizationService spyService, dispatcher.await(); // verify container notification ArgumentMatcher successContainerLoc = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - ContainerEvent evt = (ContainerEvent) o; - return evt.getType() == ContainerEventType.RESOURCE_LOCALIZED - && c1.getContainerId() == evt.getContainerID(); - } - }; + evt -> evt.getType() == ContainerEventType.RESOURCE_LOCALIZED + && c1.getContainerId() == evt.getContainerID(); // Only one resource gets localized for container c1. verify(containerBus).handle(argThat(successContainerLoc)); @@ -2909,14 +2883,9 @@ public void testFailedDirsResourceRelease() throws Exception { } ArgumentMatcher matchesAppDestroy = - new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - ApplicationEvent evt = (ApplicationEvent) o; - return (evt.getType() == ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP) - && appId == evt.getApplicationID(); - } - }; + evt -> evt.getType() == + ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP + && appId == evt.getApplicationID(); dispatcher.await(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/sharedcache/TestSharedCacheUploader.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/sharedcache/TestSharedCacheUploader.java index 9234c62fd5..35d2b0dfbc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/sharedcache/TestSharedCacheUploader.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/sharedcache/TestSharedCacheUploader.java @@ -21,8 +21,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestAppLogAggregatorImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestAppLogAggregatorImpl.java index b74eabc0d9..ab9d0f1c09 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestAppLogAggregatorImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestAppLogAggregatorImpl.java @@ -70,7 +70,7 @@ import java.util.Set; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java index 8b2e3cc98c..1130c0cf7f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java @@ -20,7 +20,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -778,7 +783,7 @@ public void testLogAggregationInitAppFailsWithoutKillingNM() throws Exception { (int) (Math.random() * 1000)); doThrow(new YarnRuntimeException("KABOOM!")) .when(logAggregationService).initAppAggregator( - eq(appId), eq(user), any(Credentials.class), + eq(appId), eq(user), any(), anyMap(), any(LogAggregationContext.class), anyLong()); LogAggregationContext contextWithAMAndFailed = Records.newRecord(LogAggregationContext.class); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/loghandler/TestNonAggregatingLogHandler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/loghandler/TestNonAggregatingLogHandler.java index dead603120..8d5adf6432 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/loghandler/TestNonAggregatingLogHandler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/loghandler/TestNonAggregatingLogHandler.java @@ -20,11 +20,11 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -493,8 +493,8 @@ public static void runMockedFailedDirs(LogHandler logHandler, return; } - static class DeletePathsMatcher extends ArgumentMatcher implements - VarargMatcher { + static class DeletePathsMatcher implements + ArgumentMatcher, VarargMatcher { // to get rid of serialization warning static final long serialVersionUID = 0; @@ -506,7 +506,7 @@ static class DeletePathsMatcher extends ArgumentMatcher implements } @Override - public boolean matches(Object varargs) { + public boolean matches(Path[] varargs) { return new EqualsBuilder().append(matchPaths, varargs).isEquals(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/TestResourcePluginManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/TestResourcePluginManager.java index cbb7e58315..87ce575f0e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/TestResourcePluginManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/TestResourcePluginManager.java @@ -58,7 +58,7 @@ import java.util.Map; import java.io.File; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/TestDevicePluginAdapter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/TestDevicePluginAdapter.java index 083850b1b9..b9a0763572 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/TestDevicePluginAdapter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/TestDevicePluginAdapter.java @@ -65,9 +65,9 @@ import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -484,7 +484,7 @@ public void testPreferPluginScheduler() throws IOException, YarnException { adapter.getDeviceResourceHandler().preStart(c1); // Use customized scheduler verify(spyPlugin, times(1)).allocateDevices( - any(TreeSet.class), anyInt()); + any(Set.class), anyInt()); Assert.assertEquals(2, dmm.getAvailableDevices(resourceName)); Assert.assertEquals(1, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/fpga/TestFpgaDiscoverer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/fpga/TestFpgaDiscoverer.java index d5bcdb306c..dd99845895 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/fpga/TestFpgaDiscoverer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/fpga/TestFpgaDiscoverer.java @@ -35,8 +35,8 @@ import java.lang.reflect.Field; import java.util.*; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java index 235b131739..3e7a735a41 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerQueuing.java @@ -73,7 +73,7 @@ import org.junit.Test; import org.slf4j.LoggerFactory; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerRecovery.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerRecovery.java index fd038d851c..b09a1f260e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerRecovery.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/scheduler/TestContainerSchedulerRecovery.java @@ -71,8 +71,7 @@ public class TestContainerSchedulerRecovery { @Mock private ContainerId containerId; - @InjectMocks private ContainerScheduler spy = - new ContainerScheduler(context, dispatcher, metrics, 0); + private ContainerScheduler spy; private RecoveredContainerState createRecoveredContainerState( @@ -97,6 +96,7 @@ private void setupContainerMonitor() { ContainerManager cm = mock(ContainerManager.class); when(cm.getContainersMonitor()).thenReturn(containersMonitor); when(context.getContainerManager()).thenReturn(cm); + spy = new ContainerScheduler(context, dispatcher, metrics, 0); } @Before public void setUp() throws Exception { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java index 87208f7649..157e5d39be 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/recovery/TestNMLeveldbStateStoreService.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml index 399aed8405..787fe8f406 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml @@ -52,10 +52,6 @@ org.apache.hadoop hadoop-annotations - junit junit @@ -63,7 +59,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java index 3c39f6494c..a0fbebf4e4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java @@ -98,10 +98,10 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.isA; -import static org.mockito.Matchers.matches; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java index feb7ed246c..e30c2a62d8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java @@ -19,8 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager; import static org.apache.hadoop.yarn.exceptions.InvalidResourceRequestException.InvalidResourceType.GREATER_THEN_MAX_ALLOCATION; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.matches; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java index c7ed02c9c2..53ea10dbfc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java @@ -20,7 +20,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import java.io.File; import java.io.FileWriter; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java index 8fb1aa855d..aa5c402fed 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java @@ -97,7 +97,7 @@ import com.google.common.base.Supplier; 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.spy; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java index d95a4b18cf..03436dc762 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java @@ -20,11 +20,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -558,7 +558,7 @@ public void handle(Event event) { QueueACLsManager mockQueueACLsManager = mock(QueueACLsManager.class); when( mockQueueACLsManager.checkAccess(any(UserGroupInformation.class), - any(QueueACL.class), any(RMApp.class), any(String.class), + any(QueueACL.class), any(RMApp.class), any(), any())).thenReturn(true); return new ClientRMService(rmContext, scheduler, appManager, mockAclsManager, mockQueueACLsManager, null); @@ -806,11 +806,12 @@ public void testNonExistingQueue() throws Exception { */ private ClientRMService createClientRMServiceForMoveApplicationRequest( ApplicationId applicationId, String appOwner, - ApplicationACLsManager appAclsManager, QueueACLsManager queueAclsManager) - throws IOException { + ApplicationACLsManager appAclsManager, + QueueACLsManager queueAclsManager) { RMApp app = mock(RMApp.class); when(app.getUser()).thenReturn(appOwner); when(app.getState()).thenReturn(RMAppState.RUNNING); + when(app.getApplicationId()).thenReturn(applicationId); ConcurrentHashMap apps = new ConcurrentHashMap<>(); apps.put(applicationId, app); @@ -851,8 +852,8 @@ private QueueACLsManager getQueueAclManager(String allowedQueue, any(UserGroupInformation.class), any(QueueACL.class), any(RMApp.class), - any(String.class), - anyListOf(String.class))).thenAnswer(new Answer() { + any(), + any())).thenAnswer(new Answer() { @Override public Boolean answer(InvocationOnMock invocationOnMock) { final UserGroupInformation user = @@ -868,8 +869,8 @@ public Boolean answer(InvocationOnMock invocationOnMock) { any(UserGroupInformation.class), any(QueueACL.class), any(RMApp.class), - any(String.class), - anyListOf(String.class), + any(), + any(), any(String.class))).thenAnswer(new Answer() { @Override public Boolean answer(InvocationOnMock invocationOnMock) { @@ -896,14 +897,14 @@ private QueueACLsManager getQueueAclManager() { any(QueueACL.class), any(RMApp.class), any(String.class), - anyListOf(String.class), + anyList(), any(String.class))).thenReturn(false); when(queueACLsManager.checkAccess( any(UserGroupInformation.class), any(QueueACL.class), any(RMApp.class), any(String.class), - anyListOf(String.class))).thenReturn(true); + anyList())).thenReturn(true); return queueACLsManager; } @@ -920,7 +921,7 @@ public void testGetQueueInfo() throws Exception { any())) .thenReturn(true); when(mockAclsManager.checkAccess(any(UserGroupInformation.class), - any(ApplicationAccessType.class), anyString(), + any(ApplicationAccessType.class), any(), any(ApplicationId.class))).thenReturn(true); ClientRMService rmService = new ClientRMService(rmContext, scheduler, @@ -1105,7 +1106,7 @@ public void handle(Event event) {} ApplicationACLsManager mockAclsManager = mock(ApplicationACLsManager.class); QueueACLsManager mockQueueACLsManager = mock(QueueACLsManager.class); when(mockQueueACLsManager.checkAccess(any(UserGroupInformation.class), - any(QueueACL.class), any(RMApp.class), any(String.class), + any(QueueACL.class), any(RMApp.class), any(), any())) .thenReturn(true); ClientRMService rmService = @@ -2450,7 +2451,7 @@ public void handle(Event event) { QueueACLsManager queueAclsManager = mock(QueueACLsManager.class); when(queueAclsManager.checkAccess(any(UserGroupInformation.class), any(QueueACL.class), any(RMApp.class), any(String.class), - anyListOf(String.class))).thenReturn(false); + anyList())).thenReturn(false); // Simulate app ACL manager which returns false always ApplicationACLsManager appAclsManager = mock(ApplicationACLsManager.class); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java index 0f085d6cb1..f381a86556 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java @@ -20,9 +20,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java index 3679319031..9e4512180b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java @@ -23,7 +23,7 @@ import org.apache.hadoop.yarn.event.DrainDispatcher; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler; import org.junit.Before; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; @@ -571,9 +571,9 @@ public void testApplicationKillAtAcceptedState() throws Exception { @Override public EventHandler getEventHandler() { - class EventArgMatcher extends ArgumentMatcher { + class EventArgMatcher implements ArgumentMatcher { @Override - public boolean matches(Object argument) { + public boolean matches(AbstractEvent argument) { if (argument instanceof RMAppAttemptEvent) { if (((RMAppAttemptEvent) argument).getType().equals( RMAppAttemptEventType.KILL)) { @@ -658,9 +658,9 @@ public void testKillFinishingApp() throws Exception{ @Override public EventHandler getEventHandler() { - class EventArgMatcher extends ArgumentMatcher { + class EventArgMatcher implements ArgumentMatcher { @Override - public boolean matches(Object argument) { + public boolean matches(AbstractEvent argument) { if (argument instanceof RMAppAttemptEvent) { if (((RMAppAttemptEvent) argument).getType().equals( RMAppAttemptEventType.KILL)) { @@ -712,9 +712,9 @@ public void testKillFailingApp() throws Exception{ @Override public EventHandler getEventHandler() { - class EventArgMatcher extends ArgumentMatcher { + class EventArgMatcher implements ArgumentMatcher { @Override - public boolean matches(Object argument) { + public boolean matches(AbstractEvent argument) { if (argument instanceof RMAppAttemptEvent) { if (((RMAppAttemptEvent) argument).getType().equals( RMAppAttemptEventType.KILL)) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java index 8c038618c1..b91d32a9f7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java @@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java index 487d226072..fb2dd2019c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; 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.doReturn; import static org.mockito.Mockito.mock; @@ -232,7 +232,8 @@ public void testExpiredContainer() { * 1. RMNode status from new to Running, handle the add_node event * 2. handle the node update event */ - verify(scheduler,times(2)).handle(any(NodeUpdateSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeUpdateSchedulerEvent.class)); } @Test @@ -359,10 +360,10 @@ public void testStatusChange(){ doReturn(Collections.singletonList(containerStatus2)) .when(statusEvent2).getContainers(); - verify(scheduler,times(1)).handle(any(NodeUpdateSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); node.handle(statusEvent1); node.handle(statusEvent2); - verify(scheduler,times(1)).handle(any(NodeUpdateSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); Assert.assertEquals(2, node.getQueueSize()); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.EXPIRE)); Assert.assertEquals(0, node.getQueueSize()); @@ -454,9 +455,9 @@ public void testUnhealthyExpire() { @Test public void testUnhealthyExpireForSchedulerRemove() { RMNodeImpl node = getUnhealthyNode(); - verify(scheduler,times(2)).handle(any(NodeRemovedSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeRemovedSchedulerEvent.class)); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.EXPIRE)); - verify(scheduler,times(2)).handle(any(NodeRemovedSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeRemovedSchedulerEvent.class)); Assert.assertEquals(NodeState.LOST, node.getState()); } @@ -1083,9 +1084,9 @@ public void testForHandlingDuplicatedCompltedContainers() { doReturn(Collections.singletonList(containerStatus1)).when(statusEvent1) .getContainers(); - verify(scheduler, times(1)).handle(any(NodeUpdateSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); node.handle(statusEvent1); - verify(scheduler, times(1)).handle(any(NodeUpdateSchedulerEvent.class)); + verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); Assert.assertEquals(1, node.getQueueSize()); Assert.assertEquals(1, node.getCompletedContainers().size()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java index d5880ca9e4..be7275667a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java index 78828f2b82..5b4d36f808 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java @@ -32,7 +32,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.NodeEventDispatcher; import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.FileSystemNodeAttributeStore; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java index a821b0ad0a..f747c4b8f1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java @@ -109,7 +109,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.webapp .RMWebServices.DEFAULT_QUEUE; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/logaggregationstatus/TestRMAppLogAggregationStatus.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/logaggregationstatus/TestRMAppLogAggregationStatus.java index c2bc611780..8d31fe1a8b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/logaggregationstatus/TestRMAppLogAggregationStatus.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/logaggregationstatus/TestRMAppLogAggregationStatus.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.logaggregationstatus; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicyMockFramework.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicyMockFramework.java index fa66cbc163..ad2432121c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicyMockFramework.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicyMockFramework.java @@ -81,10 +81,10 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.hadoop.yarn.event.Event; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -949,7 +949,7 @@ public void checkReservedResource(CSQueue queue, String partition, int reserved) } static class IsPreemptionRequestForQueueAndNode - extends ArgumentMatcher { + implements ArgumentMatcher { private final ApplicationAttemptId appAttId; private final String queueName; private final NodeId nodeId; @@ -961,9 +961,7 @@ static class IsPreemptionRequestForQueueAndNode this.nodeId = nodeId; } @Override - public boolean matches(Object o) { - ContainerPreemptEvent cpe = (ContainerPreemptEvent)o; - + public boolean matches(ContainerPreemptEvent cpe) { return appAttId.equals(cpe.getAppId()) && queueName.equals(cpe.getContainer().getQueueName()) && nodeId.equals(cpe.getContainer().getAllocatedNode()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestPreemptionForQueueWithPriorities.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestPreemptionForQueueWithPriorities.java index 38c2a2a284..f9fda99d80 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestPreemptionForQueueWithPriorities.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestPreemptionForQueueWithPriorities.java @@ -29,7 +29,7 @@ import java.io.IOException; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java index 22a241f6fe..d02950dc95 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java @@ -84,11 +84,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -1069,7 +1069,7 @@ public void testRefreshPreemptionProperties() throws Exception { } static class IsPreemptionRequestFor - extends ArgumentMatcher { + implements ArgumentMatcher { private final ApplicationAttemptId appAttId; private final SchedulerEventType type; IsPreemptionRequestFor(ApplicationAttemptId appAttId) { @@ -1081,9 +1081,8 @@ static class IsPreemptionRequestFor this.type = type; } @Override - public boolean matches(Object o) { - return appAttId.equals(((ContainerPreemptEvent)o).getAppId()) - && type.equals(((ContainerPreemptEvent)o).getType()); + public boolean matches(ContainerPreemptEvent evt) { + return appAttId.equals(evt.getAppId()) && type.equals(evt.getType()); } @Override public String toString() { @@ -1127,7 +1126,7 @@ private void setResourceAndNodeDetails() { FiCaSchedulerNode mNode = mock(FiCaSchedulerNode.class); when(mNode.getPartition()).thenReturn(RMNodeLabelsManager.NO_LABEL); - when(mCS.getSchedulerNode(any(NodeId.class))).thenReturn(mNode); + when(mCS.getSchedulerNode(any())).thenReturn(mNode); } ParentQueue buildMockRootQueue(Random r, int[]... queueData) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForNodePartitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForNodePartitions.java index 67c09cd7e5..0300e19934 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForNodePartitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForNodePartitions.java @@ -30,7 +30,7 @@ import java.util.HashMap; import java.util.Map; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForReservedContainers.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForReservedContainers.java index 38b2e78966..6b78c3944e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForReservedContainers.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForReservedContainers.java @@ -25,7 +25,7 @@ import java.io.IOException; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyInterQueueWithDRF.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyInterQueueWithDRF.java index 14a3a9ad7d..7e3d6866ff 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyInterQueueWithDRF.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyInterQueueWithDRF.java @@ -28,7 +28,7 @@ import java.io.IOException; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueue.java index 750054c3cc..584cb1fcca 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueue.java @@ -25,7 +25,7 @@ import java.io.IOException; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueFairOrdering.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueFairOrdering.java index 1678651169..6e56cb5a24 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueFairOrdering.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueFairOrdering.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueUserLimit.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueUserLimit.java index 0440db321b..ba5f4d1573 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueUserLimit.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueUserLimit.java @@ -24,7 +24,7 @@ import java.io.IOException; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueWithDRF.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueWithDRF.java index a1d89d74da..1f744877eb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueWithDRF.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueWithDRF.java @@ -25,7 +25,7 @@ import java.io.IOException; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java index 22e8f63951..6f67e4b13c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java @@ -28,7 +28,7 @@ import java.util.Map; import java.util.Set; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java index 4a7a59fc38..a53b88e962 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.nodelabels; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java index 09d3327263..9c138d1279 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java @@ -17,8 +17,8 @@ *****************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anySetOf; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -277,7 +277,7 @@ null, null, null, new RMContainerTokenSecretManager(conf), new ClientToAMTokenSecretManagerInRM(), null)); RMNodeLabelsManager nlm = mock(RMNodeLabelsManager.class); - when(nlm.getQueueResource(any(String.class), anySetOf(String.class), + when(nlm.getQueueResource(any(String.class), anySet(), any(Resource.class))).thenAnswer(new Answer() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { @@ -286,7 +286,7 @@ public Resource answer(InvocationOnMock invocation) throws Throwable { } }); - when(nlm.getResourceByLabel(any(String.class), any(Resource.class))) + when(nlm.getResourceByLabel(any(), any(Resource.class))) .thenAnswer(new Answer() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java index 4320d3dc68..b4ad8be858 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -30,7 +31,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.AccessControlException; -import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.server.resourcemanager.RMContext; @@ -55,7 +55,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; public class TestCapacitySchedulerPlanFollower extends @@ -82,11 +82,13 @@ public void setUp() throws Exception { spy(new ConcurrentHashMap()); RMApp rmApp = mock(RMApp.class); RMAppAttempt rmAppAttempt = mock(RMAppAttempt.class); - when(rmApp.getRMAppAttempt((ApplicationAttemptId) Matchers.any())) + when(rmApp.getRMAppAttempt(any())) .thenReturn(rmAppAttempt); when(rmApp.getCurrentAppAttempt()).thenReturn(rmAppAttempt); - Mockito.doReturn(rmApp).when(spyApps).get((ApplicationId) Matchers.any()); - Mockito.doReturn(true).when(spyApps).containsKey((ApplicationId) Matchers.any()); + Mockito.doReturn(rmApp) + .when(spyApps).get(ArgumentMatchers.any()); + Mockito.doReturn(true) + .when(spyApps).containsKey(ArgumentMatchers.any()); when(spyRMContext.getRMApps()).thenReturn(spyApps); when(spyRMContext.getScheduler()).thenReturn(scheduler); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java index f0f2b35f3d..77bea57469 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -31,7 +32,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.AccessControlException; -import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.conf.YarnConfiguration; @@ -56,7 +56,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; public class TestFairSchedulerPlanFollower extends @@ -95,9 +95,9 @@ public void setUp() throws Exception { ConcurrentMap spyApps = spy(new ConcurrentHashMap()); RMApp rmApp = mock(RMApp.class); - when(rmApp.getRMAppAttempt((ApplicationAttemptId) Matchers.any())) - .thenReturn(null); - Mockito.doReturn(rmApp).when(spyApps).get((ApplicationId) Matchers.any()); + when(rmApp.getRMAppAttempt(any())).thenReturn(null); + Mockito.doReturn(rmApp) + .when(spyApps).get(ArgumentMatchers.any()); when(spyRMContext.getRMApps()).thenReturn(spyApps); ReservationSystemTestUtil.setupFSAllocationFile(ALLOC_FILE); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java index a22e3ef20f..027b807466 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java @@ -17,7 +17,7 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java index ddd290dffe..b8521969b3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java index e41bbc8007..43674e869b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmapp; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; @@ -236,14 +236,14 @@ public void testCachedResolverWithEvent() throws Exception { * Create dispatcher object */ private Dispatcher getDispatcher() { - Dispatcher dispatcher = new DrainDispatcher() { - @SuppressWarnings({ "rawtypes", "unchecked" }) + return new DrainDispatcher() { + @SuppressWarnings("unchecked") @Override public EventHandler getEventHandler() { - class EventArgMatcher extends ArgumentMatcher { + class EventArgMatcher implements ArgumentMatcher { @Override - public boolean matches(Object argument) { + public boolean matches(AbstractEvent argument) { if (argument instanceof RMAppNodeUpdateEvent) { ApplicationId appid = ((RMAppNodeUpdateEvent) argument).getApplicationId(); @@ -258,7 +258,6 @@ public boolean matches(Object argument) { return handler; } }; - return dispatcher; } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index 33ef610804..32dcd3bebf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -93,7 +93,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.mockito.ArgumentCaptor; -import org.mockito.Matchers; import java.io.File; import java.io.IOException; @@ -108,9 +107,9 @@ import java.util.Map; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -255,7 +254,7 @@ renewer, new AMRMTokenSecretManager(conf, this.rmContext), ResourceScheduler resourceScheduler = mock(ResourceScheduler.class); doReturn(null).when(resourceScheduler) - .getAppResourceUsageReport(Matchers.any()); + .getAppResourceUsageReport(any()); doReturn(resourceScheduler).when(rmContext).getScheduler(); doReturn(mock(RMTimelineCollectorManager.class)).when(rmContext) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java index faecdb4660..a970fcbd40 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java @@ -24,10 +24,10 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -121,7 +121,6 @@ import org.junit.runners.Parameterized; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; -import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -302,7 +301,7 @@ public void setUp() throws Exception { when(appResUsgRpt.getMemorySeconds()).thenReturn(0L); when(appResUsgRpt.getVcoreSeconds()).thenReturn(0L); when(resourceScheduler - .getAppResourceUsageReport((ApplicationAttemptId)Matchers.any())) + .getAppResourceUsageReport(any())) .thenReturn(appResUsgRpt); spyRMContext = spy(rmContext); Mockito.doReturn(resourceScheduler).when(spyRMContext).getScheduler(); @@ -417,13 +416,8 @@ private void testAppAttemptSubmittedToFailedState(String diagnostics) { unregisterAttempt(applicationAttempt.getAppAttemptId()); // ATTEMPT_FAILED should be notified to app if app attempt is submitted to // failed state. - ArgumentMatcher matcher = new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - RMAppEvent event = (RMAppEvent) o; - return event.getType() == RMAppEventType.ATTEMPT_FAILED; - } - }; + ArgumentMatcher matcher = + event -> event.getType() == RMAppEventType.ATTEMPT_FAILED; verify(application).handle(argThat(matcher)); verifyTokenCount(applicationAttempt.getAppAttemptId(), 1); verifyApplicationAttemptFinished(RMAppAttemptState.FAILED); @@ -495,7 +489,7 @@ private void testAppAttemptAllocatedState(Container amContainer) { // Check events verify(applicationMasterLauncher).handle(any(AMLauncherEvent.class)); verify(scheduler, times(2)).allocate(any(ApplicationAttemptId.class), - any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), + any(List.class), any(), any(List.class), any(), any(), any(ContainerUpdates.class)); verify(nmTokenManager).clearNodeSetForAttempt( applicationAttempt.getAppAttemptId()); @@ -643,7 +637,7 @@ private Container allocateApplicationAttempt() { when(allocation.getContainers()). thenReturn(Collections.singletonList(container)); when(scheduler.allocate(any(ApplicationAttemptId.class), any(List.class), - any(List.class), any(List.class), any(List.class), any(List.class), + any(), any(List.class), any(), any(), any(ContainerUpdates.class))). thenReturn(allocation); RMContainer rmContainer = mock(RMContainerImpl.class); @@ -1211,7 +1205,7 @@ public void testLaunchedFailWhileAHSEnabled() { when(allocation.getContainers()). thenReturn(Collections.singletonList(amContainer)); when(scheduler.allocate(any(ApplicationAttemptId.class), any(List.class), - any(List.class), any(List.class), any(List.class), any(List.class), + any(), any(List.class), any(), any(), any(ContainerUpdates.class))) .thenReturn(allocation); RMContainer rmContainer = mock(RMContainerImpl.class); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java index bb6591b370..54c45d1445 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java @@ -19,8 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmcontainer; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; @@ -75,7 +75,7 @@ import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -107,8 +107,9 @@ public void testReleaseWhileRunning() { ConcurrentMap rmApps = spy(new ConcurrentHashMap()); RMApp rmApp = mock(RMApp.class); - when(rmApp.getRMAppAttempt((ApplicationAttemptId)Matchers.any())).thenReturn(null); - Mockito.doReturn(rmApp).when(rmApps).get((ApplicationId)Matchers.any()); + when(rmApp.getRMAppAttempt(any())).thenReturn(null); + Mockito.doReturn(rmApp) + .when(rmApps).get(ArgumentMatchers.any()); RMApplicationHistoryWriter writer = mock(RMApplicationHistoryWriter.class); SystemMetricsPublisher publisher = mock(SystemMetricsPublisher.class); @@ -414,8 +415,9 @@ public void testContainerTransitionNotifyAllocationTagsManager() ConcurrentMap rmApps = spy(new ConcurrentHashMap()); RMApp rmApp = mock(RMApp.class); - when(rmApp.getRMAppAttempt(Matchers.any())).thenReturn(null); - Mockito.doReturn(rmApp).when(rmApps).get(Matchers.any()); + when(rmApp.getRMAppAttempt(any())).thenReturn(null); + Mockito.doReturn(rmApp).when(rmApps).get( + ArgumentMatchers.any()); RMApplicationHistoryWriter writer = mock(RMApplicationHistoryWriter.class); SystemMetricsPublisher publisher = mock(SystemMetricsPublisher.class); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestConfigurationMutationACLPolicies.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestConfigurationMutationACLPolicies.java index 9a23c1d180..8741432cc0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestConfigurationMutationACLPolicies.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestConfigurationMutationACLPolicies.java @@ -36,8 +36,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerUtils.java index 75d65b93cb..0c0dcb70ac 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerUtils.java @@ -27,8 +27,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java index 24ae244a96..36d8e7e785 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java @@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -74,7 +74,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import com.google.common.collect.ImmutableMap; @@ -634,15 +634,17 @@ public void testHeadroom() throws Exception { when(amResourceRequest.getCapability()).thenReturn(amResource); when(rmApp.getAMResourceRequests()).thenReturn( Collections.singletonList(amResourceRequest)); - Mockito.doReturn(rmApp).when(spyApps).get((ApplicationId)Matchers.any()); + Mockito.doReturn(rmApp) + .when(spyApps).get(ArgumentMatchers.any()); when(spyRMContext.getRMApps()).thenReturn(spyApps); RMAppAttempt rmAppAttempt = mock(RMAppAttempt.class); - when(rmApp.getRMAppAttempt((ApplicationAttemptId) Matchers.any())) + when(rmApp.getRMAppAttempt(any())) .thenReturn(rmAppAttempt); when(rmApp.getCurrentAppAttempt()).thenReturn(rmAppAttempt); - Mockito.doReturn(rmApp).when(spyApps).get((ApplicationId) Matchers.any()); + Mockito.doReturn(rmApp) + .when(spyApps).get(ArgumentMatchers.any()); Mockito.doReturn(true).when(spyApps) - .containsKey((ApplicationId) Matchers.any()); + .containsKey(ArgumentMatchers.any()); Priority priority_1 = TestUtils.createMockPriority(1); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java index d73f1c8437..1eea046e21 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -63,7 +64,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import com.google.common.collect.ImmutableMap; @@ -646,15 +647,17 @@ public void testHeadroom() throws Exception { when(amResourceRequest.getCapability()).thenReturn(amResource); when(rmApp.getAMResourceRequests()).thenReturn( Collections.singletonList(amResourceRequest)); - Mockito.doReturn(rmApp).when(spyApps).get((ApplicationId) Matchers.any()); + Mockito.doReturn(rmApp) + .when(spyApps).get(ArgumentMatchers.any()); when(spyRMContext.getRMApps()).thenReturn(spyApps); RMAppAttempt rmAppAttempt = mock(RMAppAttempt.class); - when(rmApp.getRMAppAttempt((ApplicationAttemptId) Matchers.any())) + when(rmApp.getRMAppAttempt(any())) .thenReturn(rmAppAttempt); when(rmApp.getCurrentAppAttempt()).thenReturn(rmAppAttempt); - Mockito.doReturn(rmApp).when(spyApps).get((ApplicationId) Matchers.any()); + Mockito.doReturn(rmApp) + .when(spyApps).get(ArgumentMatchers.any()); Mockito.doReturn(true).when(spyApps) - .containsKey((ApplicationId) Matchers.any()); + .containsKey(ArgumentMatchers.any()); Priority priority_1 = TestUtils.createMockPriority(1); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestChildQueueOrder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestChildQueueOrder.java index fcfa0dd179..93aebace8a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestChildQueueOrder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestChildQueueOrder.java @@ -19,9 +19,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -37,7 +37,6 @@ import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.Container; import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.Priority; import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.conf.YarnConfiguration; @@ -264,7 +263,7 @@ public void testSortedQueues() throws Exception { // Stub an App and its containerCompleted FiCaSchedulerApp app_0 = getMockApplication(0,user_0); doReturn(true).when(app_0).containerCompleted(any(RMContainer.class), - any(ContainerStatus.class), any(RMContainerEventType.class), + any(), any(RMContainerEventType.class), any(String.class)); Priority priority = TestUtils.createMockPriority(1); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java index 04bb7912d1..28f02e4340 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java @@ -29,8 +29,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -109,7 +109,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestUtils.toSchedulerKey; @@ -157,13 +157,14 @@ private void setUpInternal(ResourceCalculator rC) throws Exception { ConcurrentMap spyApps = spy(new ConcurrentHashMap()); RMApp rmApp = mock(RMApp.class); - when(rmApp.getRMAppAttempt((ApplicationAttemptId)Matchers.any())).thenReturn(null); + when(rmApp.getRMAppAttempt(any())).thenReturn(null); amResourceRequest = mock(ResourceRequest.class); when(amResourceRequest.getCapability()).thenReturn( Resources.createResource(0, 0)); when(rmApp.getAMResourceRequests()).thenReturn( Collections.singletonList(amResourceRequest)); - Mockito.doReturn(rmApp).when(spyApps).get((ApplicationId)Matchers.any()); + Mockito.doReturn(rmApp) + .when(spyApps).get(ArgumentMatchers.any()); when(spyRMContext.getRMApps()).thenReturn(spyApps); csConf = diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestParentQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestParentQueue.java index fe66aba05e..a960d896c0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestParentQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestParentQueue.java @@ -22,8 +22,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.inOrder; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java index 0a39e99b38..e671ed617f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java @@ -18,13 +18,12 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.IOException; -import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.Priority; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java index 7763dac79a..a4c1300df3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java index 870588715d..a1b536ab46 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUtils.java index c692bae3e6..23f6fc4a75 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUtils.java @@ -55,7 +55,7 @@ import java.util.Map; import java.util.Set; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -111,7 +111,7 @@ public Resource answer(InvocationOnMock invocation) throws Throwable { } }); - when(nlm.getResourceByLabel(any(String.class), any(Resource.class))) + when(nlm.getResourceByLabel(any(), any(Resource.class))) .thenAnswer(new Answer() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java index e6a841a9c2..b6ffaa5d6d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestContinuousScheduling.java @@ -46,7 +46,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSSchedulerNode.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSSchedulerNode.java index 0e3d3445b2..913ad94fd8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSSchedulerNode.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFSSchedulerNode.java @@ -31,7 +31,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; 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.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/TestSingleConstraintAppPlacementAllocator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/TestSingleConstraintAppPlacementAllocator.java index a665b8d181..d9b6c20844 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/TestSingleConstraintAppPlacementAllocator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/TestSingleConstraintAppPlacementAllocator.java @@ -42,8 +42,8 @@ import java.util.Set; import java.util.function.LongBinaryOperator; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java index a0f4007cf8..7c77de4d88 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java @@ -79,7 +79,7 @@ import java.util.TimerTask; 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.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestDelegationTokenRenewer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestDelegationTokenRenewer.java index 1a35563e5f..dca3686c50 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestDelegationTokenRenewer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestDelegationTokenRenewer.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; 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.doReturn; import static org.mockito.Mockito.doThrow; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestProxyCAManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestProxyCAManager.java index 109ced91e0..c1b2c63e30 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestProxyCAManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestProxyCAManager.java @@ -29,7 +29,7 @@ import java.security.PrivateKey; import java.security.cert.X509Certificate; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestRMAuthenticationFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestRMAuthenticationFilter.java index 4190cc68b3..e1ba29bd83 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestRMAuthenticationFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestRMAuthenticationFilter.java @@ -72,8 +72,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { return null; } - }).when(container).addFilter(Mockito.anyObject(), - Mockito.anyObject(), Mockito.>anyObject()); + }).when(container).addFilter(Mockito.any(), Mockito.any(), Mockito.any()); new RMAuthenticationFilterInitializer().initFilter(container, conf); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java index c4f1e2e60a..5113ba532d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/volume/csi/TestVolumeProcessor.java @@ -64,7 +64,7 @@ import java.util.Arrays; import java.util.List; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestApplicationsRequestBuilder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestApplicationsRequestBuilder.java index 7c9b7110d6..30e1c62b3e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestApplicationsRequestBuilder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestApplicationsRequestBuilder.java @@ -29,8 +29,8 @@ import static org.apache.hadoop.yarn.server.webapp.WebServices.parseQueries; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java index 93377be1ea..e17100eeb0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java @@ -21,7 +21,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.MockNodes.newResource; import static org.apache.hadoop.yarn.webapp.Params.TITLE; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java index 2f67c44fc2..cb8056624a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml index 5cd2744ab9..a16b20af27 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml @@ -93,7 +93,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/pom.xml index fa819db01f..7788fac509 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/pom.xml @@ -56,7 +56,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestCleanerTask.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestCleanerTask.java index 421b5bb2b2..23c80d9655 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestCleanerTask.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestCleanerTask.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.sharedcachemanager; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -33,7 +33,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.sharedcachemanager.metrics.CleanerMetrics; import org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestSCMAdminProtocolService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestSCMAdminProtocolService.java index e6cf15fc3e..e183ffa5cf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestSCMAdminProtocolService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/TestSCMAdminProtocolService.java @@ -19,8 +19,8 @@ package org.apache.hadoop.yarn.server.sharedcachemanager; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/store/TestInMemorySCMStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/store/TestInMemorySCMStore.java index 6d67ad32fb..35adbdd34e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/store/TestInMemorySCMStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-sharedcachemanager/src/test/java/org/apache/hadoop/yarn/server/sharedcachemanager/store/TestInMemorySCMStore.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -39,7 +39,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.Future; import org.apache.hadoop.conf.Configuration; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/pom.xml index a05cdc4b46..982f8eac27 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/pom.xml @@ -57,7 +57,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/TestTimelineServiceClientIntegration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/TestTimelineServiceClientIntegration.java index 7cf7428db2..21a77d89e2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/TestTimelineServiceClientIntegration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/TestTimelineServiceClientIntegration.java @@ -20,7 +20,7 @@ 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.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/security/TestTimelineAuthFilterForV2.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/security/TestTimelineAuthFilterForV2.java index 356bfc79dd..c353cf0408 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/security/TestTimelineAuthFilterForV2.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/security/TestTimelineAuthFilterForV2.java @@ -23,8 +23,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/pom.xml index 725d8c5bc3..9891e0a53a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/pom.xml @@ -121,7 +121,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml index 55cb3b31fe..b5490524f9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/pom.xml @@ -138,7 +138,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestNMTimelineCollectorManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestNMTimelineCollectorManager.java index 0f2af21ae4..b109be5fa4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestNMTimelineCollectorManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestNMTimelineCollectorManager.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestPerNodeTimelineCollectorsAuxService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestPerNodeTimelineCollectorsAuxService.java index 04b89d666f..811465f7f9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestPerNodeTimelineCollectorsAuxService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestPerNodeTimelineCollectorsAuxService.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java index 88e4f25f72..f95154032e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/collector/TestTimelineCollector.java @@ -41,7 +41,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWhitelistAuthorizationFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWhitelistAuthorizationFilter.java index 6f0a83d1f3..9ab9b27762 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWhitelistAuthorizationFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWhitelistAuthorizationFilter.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.timelineservice.reader; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml index d08c25f941..21854c7b98 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml @@ -66,7 +66,7 @@ org.mockito - mockito-all + mockito-core test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java index 6eb4d4844b..8b0c1a4c2f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java @@ -285,8 +285,7 @@ public void doFilter(ServletRequest servletRequest, // "127.0.0.1" contains in host list. Without cookie Mockito.when(request.getRemoteAddr()).thenReturn("127.0.0.1"); testFilter.doFilter(request, response, chain); - assertTrue(doFilterRequest - .contains("javax.servlet.http.HttpServletRequest")); + assertTrue(doFilterRequest.contains("HttpServletRequest")); // cookie added Cookie[] cookies = new Cookie[] {