/// <exception cref="System.Exception"/> public virtual void TestMyShutdown() { Log.Info("in test Shutdown"); 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 = Org.Mockito.Mockito.Mock <TestContainerLauncherImpl.ContainerManagementProtocolClient>(); 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(mockCM.StartContainers(Matchers.Any <StartContainersRequest >())).ThenReturn(startResp); Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerToken()).ThenReturn(CreateNewContainerToken (contId, cmAddress)); ut.Handle(mockLaunchEvent); ut.WaitForPoolToIdle(); Org.Mockito.Mockito.Verify(mockCM).StartContainers(Matchers.Any <StartContainersRequest >()); } finally { // skip cleanup and make sure stop kills the container ut.Stop(); Org.Mockito.Mockito.Verify(mockCM).StopContainers(Matchers.Any <StopContainersRequest >()); } }
/// <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(); } }