private void VerifyCapturedArguments(ArgumentCaptor <StorageBlockReport[]> captor, int expectedReportsPerCall, int expectedTotalBlockCount) { IList <StorageBlockReport[]> listOfReports = captor.GetAllValues(); int numBlocksReported = 0; foreach (StorageBlockReport[] reports in listOfReports) { Assert.AssertThat(reports.Length, IS.Is(expectedReportsPerCall)); foreach (StorageBlockReport report in reports) { BlockListAsLongs blockList = report.GetBlocks(); numBlocksReported += blockList.GetNumberOfBlocks(); } } System.Diagnostics.Debug.Assert((numBlocksReported >= expectedTotalBlockCount)); }
public virtual void TestRsrcUnused() { DeletionService delService = Org.Mockito.Mockito.Mock <DeletionService>(); long TargetMb = 10 << 20; ResourceRetentionSet rss = new ResourceRetentionSet(delService, TargetMb); // 3MB files @{10, 15} LocalResourcesTracker pubTracker = CreateMockTracker(null, 3 * 1024 * 1024, 2, 10 , 5); // 1MB files @{3, 6, 9, 12} LocalResourcesTracker trackerA = CreateMockTracker("A", 1 * 1024 * 1024, 4, 3, 3); // 4MB file @{1} LocalResourcesTracker trackerB = CreateMockTracker("B", 4 * 1024 * 1024, 1, 10, 5 ); // 2MB files @{7, 9, 11} LocalResourcesTracker trackerC = CreateMockTracker("C", 2 * 1024 * 1024, 3, 7, 2); // Total cache: 20MB; verify removed at least 10MB rss.AddResources(pubTracker); rss.AddResources(trackerA); rss.AddResources(trackerB); rss.AddResources(trackerC); long deleted = 0L; ArgumentCaptor <LocalizedResource> captor = ArgumentCaptor.ForClass <LocalizedResource >(); Org.Mockito.Mockito.Verify(pubTracker, Org.Mockito.Mockito.AtMost(2)).Remove(captor .Capture(), IsA <DeletionService>()); Org.Mockito.Mockito.Verify(trackerA, Org.Mockito.Mockito.AtMost(4)).Remove(captor .Capture(), IsA <DeletionService>()); Org.Mockito.Mockito.Verify(trackerB, Org.Mockito.Mockito.AtMost(1)).Remove(captor .Capture(), IsA <DeletionService>()); Org.Mockito.Mockito.Verify(trackerC, Org.Mockito.Mockito.AtMost(3)).Remove(captor .Capture(), IsA <DeletionService>()); foreach (LocalizedResource rem in captor.GetAllValues()) { deleted += rem.GetSize(); } NUnit.Framework.Assert.IsTrue(deleted >= 10 * 1024 * 1024); NUnit.Framework.Assert.IsTrue(deleted < 15 * 1024 * 1024); }
public virtual void TestMutativeOperationsWithAutoHaEnabled() { Org.Mockito.Mockito.DoReturn(StandbyReadyResult).When(mockProtocol).GetServiceStatus (); // Turn on auto-HA in the config HdfsConfiguration conf = GetHAConf(); conf.SetBoolean(DFSConfigKeys.DfsHaAutoFailoverEnabledKey, true); conf.Set(DFSConfigKeys.DfsHaFenceMethodsKey, GetFencerTrueCommand()); tool.SetConf(conf); // Should fail without the forcemanual flag NUnit.Framework.Assert.AreEqual(-1, RunTool("-transitionToActive", "nn1")); NUnit.Framework.Assert.IsTrue(errOutput.Contains("Refusing to manually manage")); NUnit.Framework.Assert.AreEqual(-1, RunTool("-transitionToStandby", "nn1")); NUnit.Framework.Assert.IsTrue(errOutput.Contains("Refusing to manually manage")); Org.Mockito.Mockito.Verify(mockProtocol, Org.Mockito.Mockito.Never()).TransitionToActive (AnyReqInfo()); Org.Mockito.Mockito.Verify(mockProtocol, Org.Mockito.Mockito.Never()).TransitionToStandby (AnyReqInfo()); // Force flag should bypass the check and change the request source // for the RPC SetupConfirmationOnSystemIn(); NUnit.Framework.Assert.AreEqual(0, RunTool("-transitionToActive", "-forcemanual", "nn1")); SetupConfirmationOnSystemIn(); NUnit.Framework.Assert.AreEqual(0, RunTool("-transitionToStandby", "-forcemanual" , "nn1")); Org.Mockito.Mockito.Verify(mockProtocol, Org.Mockito.Mockito.Times(1)).TransitionToActive (reqInfoCaptor.Capture()); Org.Mockito.Mockito.Verify(mockProtocol, Org.Mockito.Mockito.Times(1)).TransitionToStandby (reqInfoCaptor.Capture()); // All of the RPCs should have had the "force" source foreach (HAServiceProtocol.StateChangeRequestInfo ri in reqInfoCaptor.GetAllValues ()) { NUnit.Framework.Assert.AreEqual(HAServiceProtocol.RequestSource.RequestByUserForced , ri.GetSource()); } }
/// <exception cref="System.IO.IOException"/> private void RunTest(TestNNStorageRetentionManager.TestCaseDescription tc) { NNStorageRetentionManager.StoragePurger mockPurger = Org.Mockito.Mockito.Mock <NNStorageRetentionManager.StoragePurger >(); ArgumentCaptor <FSImageStorageInspector.FSImageFile> imagesPurgedCaptor = ArgumentCaptor .ForClass <FSImageStorageInspector.FSImageFile>(); ArgumentCaptor <FileJournalManager.EditLogFile> logsPurgedCaptor = ArgumentCaptor. ForClass <FileJournalManager.EditLogFile>(); // Ask the manager to purge files we don't need any more new NNStorageRetentionManager(conf, tc.MockStorage(), tc.MockEditLog(mockPurger), mockPurger).PurgeOldStorage(NNStorage.NameNodeFile.Image); // Verify that it asked the purger to remove the correct files Org.Mockito.Mockito.Verify(mockPurger, Org.Mockito.Mockito.AtLeast(0)).PurgeImage (imagesPurgedCaptor.Capture()); Org.Mockito.Mockito.Verify(mockPurger, Org.Mockito.Mockito.AtLeast(0)).PurgeLog(logsPurgedCaptor .Capture()); // Check images ICollection <string> purgedPaths = Sets.NewLinkedHashSet(); foreach (FSImageStorageInspector.FSImageFile purged in imagesPurgedCaptor.GetAllValues ()) { purgedPaths.AddItem(FileToPath(purged.GetFile())); } NUnit.Framework.Assert.AreEqual(Joiner.On(",").Join(FilesToPaths(tc.expectedPurgedImages )), Joiner.On(",").Join(purgedPaths)); // Check images purgedPaths.Clear(); foreach (FileJournalManager.EditLogFile purged_1 in logsPurgedCaptor.GetAllValues ()) { purgedPaths.AddItem(FileToPath(purged_1.GetFile())); } NUnit.Framework.Assert.AreEqual(Joiner.On(",").Join(FilesToPaths(tc.expectedPurgedLogs )), Joiner.On(",").Join(purgedPaths)); }
/// <exception cref="System.Exception"/> public virtual void TestContainerCleaned() { Log.Info("STARTING testContainerCleaned"); CyclicBarrier startLaunchBarrier = new CyclicBarrier(2); CyclicBarrier completeLaunchBarrier = new CyclicBarrier(2); AppContext mockContext = Org.Mockito.Mockito.Mock <AppContext>(); EventHandler mockEventHandler = Org.Mockito.Mockito.Mock <EventHandler>(); Org.Mockito.Mockito.When(mockContext.GetEventHandler()).ThenReturn(mockEventHandler ); TestContainerLauncherImpl.ContainerManagementProtocolClient mockCM = new TestContainerLauncherImpl.ContainerManagerForTest (startLaunchBarrier, completeLaunchBarrier); TestContainerLauncherImpl.ContainerLauncherImplUnderTest ut = new TestContainerLauncherImpl.ContainerLauncherImplUnderTest (mockContext, mockCM); Configuration conf = new Configuration(); ut.Init(conf); ut.Start(); try { ContainerId contId = MakeContainerId(0l, 0, 0, 1); TaskAttemptId taskAttemptId = MakeTaskAttemptId(0l, 0, 0, TaskType.Map, 0); string cmAddress = "127.0.0.1:8000"; StartContainersResponse startResp = recordFactory.NewRecordInstance <StartContainersResponse >(); startResp.SetAllServicesMetaData(serviceResponse); Log.Info("inserting launch event"); ContainerRemoteLaunchEvent mockLaunchEvent = Org.Mockito.Mockito.Mock <ContainerRemoteLaunchEvent >(); Org.Mockito.Mockito.When(mockLaunchEvent.GetType()).ThenReturn(ContainerLauncher.EventType .ContainerRemoteLaunch); Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerID()).ThenReturn(contId); Org.Mockito.Mockito.When(mockLaunchEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId ); Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerMgrAddress()).ThenReturn(cmAddress ); Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerToken()).ThenReturn(CreateNewContainerToken (contId, cmAddress)); ut.Handle(mockLaunchEvent); startLaunchBarrier.Await(); Log.Info("inserting cleanup event"); ContainerLauncherEvent mockCleanupEvent = Org.Mockito.Mockito.Mock <ContainerLauncherEvent >(); Org.Mockito.Mockito.When(mockCleanupEvent.GetType()).ThenReturn(ContainerLauncher.EventType .ContainerRemoteCleanup); Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerID()).ThenReturn(contId); Org.Mockito.Mockito.When(mockCleanupEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId ); Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerMgrAddress()).ThenReturn(cmAddress ); ut.Handle(mockCleanupEvent); completeLaunchBarrier.Await(); ut.WaitForPoolToIdle(); ArgumentCaptor <Org.Apache.Hadoop.Yarn.Event.Event> arg = ArgumentCaptor.ForClass < Org.Apache.Hadoop.Yarn.Event.Event>(); Org.Mockito.Mockito.Verify(mockEventHandler, Org.Mockito.Mockito.AtLeast(2)).Handle (arg.Capture()); bool containerCleaned = false; for (int i = 0; i < arg.GetAllValues().Count; i++) { Log.Info(arg.GetAllValues()[i].ToString()); Org.Apache.Hadoop.Yarn.Event.Event currentEvent = arg.GetAllValues()[i]; if (currentEvent.GetType() == TaskAttemptEventType.TaContainerCleaned) { containerCleaned = true; } } System.Diagnostics.Debug.Assert((containerCleaned)); } finally { ut.Stop(); } }
/// <summary>Check that this metric was captured exactly once.</summary> private static void CheckCaptured <_T0>(ArgumentCaptor <_T0> captor, string name) { Assert.Equal("Expected exactly one metric for name " + name, 1 , captor.GetAllValues().Count); }