示例#1
0
        public virtual void TesAllJobs()
        {
            ApplicationClientProtocol applicationsManager = Org.Mockito.Mockito.Mock <ApplicationClientProtocol
                                                                                      >();
            GetApplicationsResponse allApplicationsResponse = Org.Apache.Hadoop.Yarn.Util.Records
                                                              .NewRecord <GetApplicationsResponse>();
            IList <ApplicationReport> applications = new AList <ApplicationReport>();

            applications.AddItem(GetApplicationReport(YarnApplicationState.Finished, FinalApplicationStatus
                                                      .Failed));
            applications.AddItem(GetApplicationReport(YarnApplicationState.Finished, FinalApplicationStatus
                                                      .Succeeded));
            applications.AddItem(GetApplicationReport(YarnApplicationState.Finished, FinalApplicationStatus
                                                      .Killed));
            applications.AddItem(GetApplicationReport(YarnApplicationState.Failed, FinalApplicationStatus
                                                      .Failed));
            allApplicationsResponse.SetApplicationList(applications);
            Org.Mockito.Mockito.When(applicationsManager.GetApplications(Org.Mockito.Mockito.
                                                                         Any <GetApplicationsRequest>())).ThenReturn(allApplicationsResponse);
            ResourceMgrDelegate resourceMgrDelegate = new _ResourceMgrDelegate_113(applicationsManager
                                                                                   , new YarnConfiguration());

            JobStatus[] allJobs = resourceMgrDelegate.GetAllJobs();
            NUnit.Framework.Assert.AreEqual(JobStatus.State.Failed, allJobs[0].GetState());
            NUnit.Framework.Assert.AreEqual(JobStatus.State.Succeeded, allJobs[1].GetState());
            NUnit.Framework.Assert.AreEqual(JobStatus.State.Killed, allJobs[2].GetState());
            NUnit.Framework.Assert.AreEqual(JobStatus.State.Failed, allJobs[3].GetState());
        }
示例#2
0
        public static ClientRMService MockClientRMService(RMContext rmContext)
        {
            ClientRMService           clientRMService = Org.Mockito.Mockito.Mock <ClientRMService>();
            IList <ApplicationReport> appReports      = new AList <ApplicationReport>();

            foreach (RMApp app in rmContext.GetRMApps().Values)
            {
                ApplicationReport appReport = ApplicationReport.NewInstance(app.GetApplicationId(
                                                                                ), (ApplicationAttemptId)null, app.GetUser(), app.GetQueue(), app.GetName(), (string
                                                                                                                                                              )null, 0, (Token)null, app.CreateApplicationState(), app.GetDiagnostics().ToString
                                                                                (), (string)null, app.GetStartTime(), app.GetFinishTime(), app.GetFinalApplicationStatus
                                                                                (), (ApplicationResourceUsageReport)null, app.GetTrackingUrl(), app.GetProgress(
                                                                                ), app.GetApplicationType(), (Token)null);
                appReports.AddItem(appReport);
            }
            GetApplicationsResponse response = Org.Mockito.Mockito.Mock <GetApplicationsResponse
                                                                         >();

            Org.Mockito.Mockito.When(response.GetApplicationList()).ThenReturn(appReports);
            try
            {
                Org.Mockito.Mockito.When(clientRMService.GetApplications(Matchers.Any <GetApplicationsRequest
                                                                                       >())).ThenReturn(response);
            }
            catch (YarnException)
            {
                NUnit.Framework.Assert.Fail("Exception is not expteced.");
            }
            return(clientRMService);
        }
        public async Task Then_data_is_fetched_via_data_repository()
        {
            // Arrange
            var query            = _fixture.Create <GetApplicationsRequest>();
            var applicationsList = _fixture.CreateMany <ApprenticeApplicationDto>().ToList();
            var expectedResponse = new GetApplicationsResponse
            {
                ApprenticeApplications      = applicationsList,
                BankDetailsStatus           = Enums.BankDetailsStatus.NotSupplied,
                FirstSubmittedApplicationId = Guid.NewGuid()
            };

            _applicationRepository.Setup(x => x.GetList(query.AccountId, query.AccountLegalEntityId)).ReturnsAsync(applicationsList);

            var account       = _fixture.Create <AccountModel>();
            var legalEntities = _fixture.CreateMany <LegalEntityModel>(1).ToList();

            legalEntities[0].AccountLegalEntityId = query.AccountLegalEntityId;
            legalEntities[0].BankDetailsStatus    = Enums.BankDetailsStatus.NotSupplied;
            account.LegalEntityModels             = new Collection <LegalEntityModel>(legalEntities);

            _accountRepository.Setup(x => x.Find(query.AccountId)).ReturnsAsync(account);

            _applicationRepository.Setup(x => x.GetFirstSubmittedApplicationId(query.AccountLegalEntityId)).ReturnsAsync(expectedResponse.FirstSubmittedApplicationId);

            // Act
            var result = await _sut.Handle(query, CancellationToken.None);

            // Assert
            result.Should().BeEquivalentTo(expectedResponse);
        }
        public async Task And_AccountId_Specified_Then_Index_Returned(
            long accountId,
            GetPledgesResponse getPledgesResponse,
            GetAccountTransferStatusResponse getAccountTransferStatusResponse,
            GetApplicationsResponse getApplicationsResponse,
            [Frozen] Mock <ILevyTransferMatchingApiClient <LevyTransferMatchingApiConfiguration> > levyTransferMatchingClient,
            GetIndexQueryHandler getIndexQueryHandler)
        {
            GetIndexQuery getIndexQuery = new GetIndexQuery()
            {
                AccountId = accountId,
            };

            levyTransferMatchingClient
            .Setup(x => x.Get <GetPledgesResponse>(It.IsAny <GetPledgesRequest>()))
            .ReturnsAsync(getPledgesResponse);

            levyTransferMatchingClient
            .Setup(x => x.Get <GetApplicationsResponse>(It.IsAny <GetApplicationsRequest>()))
            .ReturnsAsync(getApplicationsResponse);

            var results = await getIndexQueryHandler.Handle(getIndexQuery, CancellationToken.None);

            Assert.AreEqual(getPledgesResponse.TotalPledges, results.PledgesCount);
            Assert.AreEqual(getApplicationsResponse.Applications.Count(), results.ApplicationsCount);
        }
示例#5
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public override IList <ApplicationReport> GetApplications()
        {
            GetApplicationsRequest  request  = GetApplicationsRequest.NewInstance(null, null);
            GetApplicationsResponse response = ahsClient.GetApplications(request);

            return(response.GetApplicationList());
        }
示例#6
0
        public virtual void TestApplications()
        {
            ApplicationId appId = null;

            appId = ApplicationId.NewInstance(0, 1);
            ApplicationId             appId1    = ApplicationId.NewInstance(0, 2);
            GetApplicationsRequest    request   = GetApplicationsRequest.NewInstance();
            GetApplicationsResponse   response  = clientService.GetApplications(request);
            IList <ApplicationReport> appReport = response.GetApplicationList();

            NUnit.Framework.Assert.IsNotNull(appReport);
            NUnit.Framework.Assert.AreEqual(appId, appReport[1].GetApplicationId());
            NUnit.Framework.Assert.AreEqual(appId1, appReport[0].GetApplicationId());
            // Create a historyManager, and set the max_apps can be loaded
            // as 1.
            Configuration conf = new YarnConfiguration();

            conf.SetLong(YarnConfiguration.ApplicationHistoryMaxApps, 1);
            ApplicationHistoryManagerOnTimelineStore historyManager2 = new ApplicationHistoryManagerOnTimelineStore
                                                                           (dataManager, new ApplicationACLsManager(conf));

            historyManager2.Init(conf);
            historyManager2.Start();
            ApplicationHistoryClientService clientService2 = new ApplicationHistoryClientService
                                                                 (historyManager2);

            response  = clientService2.GetApplications(request);
            appReport = response.GetApplicationList();
            NUnit.Framework.Assert.IsNotNull(appReport);
            NUnit.Framework.Assert.IsTrue(appReport.Count == 1);
            // Expected to get the appReport for application with appId1
            NUnit.Framework.Assert.AreEqual(appId1, appReport[0].GetApplicationId());
        }
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual GetApplicationsResponse GetApplications(GetApplicationsRequest request
                                                               )
        {
            GetApplicationsResponse response = GetApplicationsResponse.NewInstance(new AList <
                                                                                       ApplicationReport>(history.GetApplications(request.GetLimit()).Values));

            return(response);
        }
示例#8
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public override IList <ApplicationReport> GetApplications(ICollection <string> applicationTypes
                                                                  , EnumSet <YarnApplicationState> applicationStates)
        {
            GetApplicationsRequest request = GetApplicationsRequest.NewInstance(applicationTypes
                                                                                , applicationStates);
            GetApplicationsResponse response = rmClient.GetApplications(request);

            return(response.GetApplicationList());
        }
        public void Setup()
        {
            _apiResponse = _fixture.Create <GetApplicationsResponse>();
            _apiClient   = new Mock <ILevyTransferMatchingApiClient <LevyTransferMatchingApiConfiguration> >();
            _apiClient.Setup(x => x.Get <GetApplicationsResponse>(It.IsAny <GetApplicationsRequest>())).ReturnsAsync(_apiResponse);

            _handler = new GetApplicationsQueryHandler(_apiClient.Object);

            _query = _fixture.Create <GetApplicationsQuery>();
        }
示例#10
0
        public async Task WhenAClientRequestsTheApprenticeshipApplicationsForTheAccount()
        {
            var url = $"/accounts/{_account.Id}/legalentity/{_account.AccountLegalEntityId}/applications";

            var(status, data) =
                await EmployerIncentiveApi.Client.GetValueAsync <GetApplicationsResponse>(url);

            status.Should().Be(HttpStatusCode.OK);

            _apiResponse = data;
        }
示例#11
0
                /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
                public override GetApplicationsResponse GetApplications(GetApplicationsRequest request
                                                                        )
                {
                    this._enclosing.ResetStartFailoverFlag(true);
                    // make sure failover has been triggered
                    NUnit.Framework.Assert.IsTrue(this._enclosing.WaittingForFailOver());
                    // create GetApplicationsResponse with fake applicationList
                    GetApplicationsResponse response = GetApplicationsResponse.NewInstance(this._enclosing
                                                                                           .CreateFakeAppReports());

                    return(response);
                }
示例#12
0
        // This is to test AM Host and rpc port are invalidated after the am attempt
        // is killed or failed, so that client doesn't get the wrong information.
        /// <exception cref="System.Exception"/>
        public virtual void TestInvalidateAMHostPortWhenAMFailedOrKilled()
        {
            conf.SetInt(YarnConfiguration.RmAmMaxAttempts, 1);
            MockRM rm1 = new MockRM(conf);

            rm1.Start();
            // a succeeded app
            RMApp  app1 = rm1.SubmitApp(200);
            MockNM nm1  = new MockNM("127.0.0.1:1234", 15120, rm1.GetResourceTrackerService());

            nm1.RegisterNode();
            MockAM am1 = MockRM.LaunchAndRegisterAM(app1, rm1, nm1);

            MockRM.FinishAMAndVerifyAppState(app1, rm1, nm1, am1);
            // a failed app
            RMApp  app2 = rm1.SubmitApp(200);
            MockAM am2  = MockRM.LaunchAndRegisterAM(app2, rm1, nm1);

            nm1.NodeHeartbeat(am2.GetApplicationAttemptId(), 1, ContainerState.Complete);
            am2.WaitForState(RMAppAttemptState.Failed);
            rm1.WaitForState(app2.GetApplicationId(), RMAppState.Failed);
            // a killed app
            RMApp  app3 = rm1.SubmitApp(200);
            MockAM am3  = MockRM.LaunchAndRegisterAM(app3, rm1, nm1);

            rm1.KillApp(app3.GetApplicationId());
            rm1.WaitForState(app3.GetApplicationId(), RMAppState.Killed);
            rm1.WaitForState(am3.GetApplicationAttemptId(), RMAppAttemptState.Killed);
            GetApplicationsRequest request1 = GetApplicationsRequest.NewInstance(EnumSet.Of(YarnApplicationState
                                                                                            .Finished, YarnApplicationState.Killed, YarnApplicationState.Failed));
            GetApplicationsResponse response1 = rm1.GetClientRMService().GetApplications(request1
                                                                                         );
            IList <ApplicationReport> appList1 = response1.GetApplicationList();

            NUnit.Framework.Assert.AreEqual(3, appList1.Count);
            foreach (ApplicationReport report in appList1)
            {
                // killed/failed apps host and rpc port are invalidated.
                if (report.GetApplicationId().Equals(app2.GetApplicationId()) || report.GetApplicationId
                        ().Equals(app3.GetApplicationId()))
                {
                    NUnit.Framework.Assert.AreEqual("N/A", report.GetHost());
                    NUnit.Framework.Assert.AreEqual(-1, report.GetRpcPort());
                }
                // succeeded app's host and rpc port is not invalidated
                if (report.GetApplicationId().Equals(app1.GetApplicationId()))
                {
                    NUnit.Framework.Assert.IsFalse(report.GetHost().Equals("N/A"));
                    NUnit.Framework.Assert.IsTrue(report.GetRpcPort() != -1);
                }
            }
        }
示例#13
0
        public async Task Then_an_error_is_returned_for_non_existing_account()
        {
            // Arrange
            var accountId                 = _fixture.Create <long>();
            var accountLegalEntityId      = _fixture.Create <long>();
            var apprenticeApplicationList = new GetApplicationsResponse();

            _queryDispatcher.Setup(x => x.Send <GetApplicationsRequest, GetApplicationsResponse>(
                                       It.Is <GetApplicationsRequest>(y => y.AccountId == accountId)))
            .ReturnsAsync(apprenticeApplicationList);

            // Act
            var actual = await _sut.GetApplications(accountId, accountLegalEntityId) as NotFoundResult;

            // Assert
            actual.Should().NotBeNull();
        }
        public async Task Then_The_Api_Is_Called_Returning_Applications_For_The_Account(
            long accountId,
            long accountLegalEntityId,
            GetApplicationsResponse apiResponse,
            [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client,
            EmployerIncentivesService service
            )
        {
            client.Setup(x =>
                         x.Get <GetApplicationsResponse>(
                             It.Is <GetApplicationsRequest>(c => c.GetUrl.Contains(accountId.ToString()))))
            .ReturnsAsync(apiResponse);

            var actual = await service.GetApprenticeApplications(accountId, accountLegalEntityId);

            actual.Should().BeEquivalentTo(apiResponse);
        }
        /// <exception cref="Com.Google.Protobuf.ServiceException"/>
        public virtual YarnServiceProtos.GetApplicationsResponseProto GetApplications(RpcController
                                                                                      controller, YarnServiceProtos.GetApplicationsRequestProto proto)
        {
            GetApplicationsRequestPBImpl request = new GetApplicationsRequestPBImpl(proto);

            try
            {
                GetApplicationsResponse response = real.GetApplications(request);
                return(((GetApplicationsResponsePBImpl)response).GetProto());
            }
            catch (YarnException e)
            {
                throw new ServiceException(e);
            }
            catch (IOException e)
            {
                throw new ServiceException(e);
            }
        }
        public async Task AndApplicationsExistReturnsListOfApplications(GetApplicationsQuery query,
                                                                        GetApplicationsResponse response,
                                                                        [Frozen] Mock <ILevyTransferMatchingService> levyTransferMatchingService,
                                                                        GetApplicationsQueryHandler handler)
        {
            response.Applications = new List <GetApplicationsResponse.Application>()
            {
                response.Applications.First()
            };

            levyTransferMatchingService.Setup(o => o.GetApplications(It.Is <GetApplicationsRequest>(o => o.AccountId == query.AccountId))).ReturnsAsync(
                new GetApplicationsResponse
            {
                Applications = response.Applications
            }
                );

            var result = await handler.Handle(query, CancellationToken.None);

            Assert.IsTrue(result.Applications.Any());
            Assert.AreEqual(response.Applications, response.Applications);
        }
示例#17
0
        public virtual void TestAppsRace()
        {
            // mock up an RM that returns app reports for apps that don't exist
            // in the RMApps list
            ApplicationId     appId      = ApplicationId.NewInstance(1, 1);
            ApplicationReport mockReport = Org.Mockito.Mockito.Mock <ApplicationReport>();

            Org.Mockito.Mockito.When(mockReport.GetApplicationId()).ThenReturn(appId);
            GetApplicationsResponse mockAppsResponse = Org.Mockito.Mockito.Mock <GetApplicationsResponse
                                                                                 >();

            Org.Mockito.Mockito.When(mockAppsResponse.GetApplicationList()).ThenReturn(Arrays
                                                                                       .AsList(new ApplicationReport[] { mockReport }));
            ClientRMService mockClientSvc = Org.Mockito.Mockito.Mock <ClientRMService>();

            Org.Mockito.Mockito.When(mockClientSvc.GetApplications(Matchers.IsA <GetApplicationsRequest
                                                                                 >(), Matchers.AnyBoolean())).ThenReturn(mockAppsResponse);
            ResourceManager mockRM    = Org.Mockito.Mockito.Mock <ResourceManager>();
            RMContextImpl   rmContext = new RMContextImpl(null, null, null, null, null, null, null
                                                          , null, null, null);

            Org.Mockito.Mockito.When(mockRM.GetRMContext()).ThenReturn(rmContext);
            Org.Mockito.Mockito.When(mockRM.GetClientRMService()).ThenReturn(mockClientSvc);
            RMWebServices webSvc = new RMWebServices(mockRM, new Configuration(), Org.Mockito.Mockito.Mock
                                                     <HttpServletResponse>());
            ICollection <string> emptySet = Collections.UnmodifiableSet(Collections.EmptySet <string
                                                                                              >());
            // verify we don't get any apps when querying
            HttpServletRequest mockHsr  = Org.Mockito.Mockito.Mock <HttpServletRequest>();
            AppsInfo           appsInfo = webSvc.GetApps(mockHsr, null, emptySet, null, null, null, null
                                                         , null, null, null, null, emptySet, emptySet);

            NUnit.Framework.Assert.IsTrue(appsInfo.GetApps().IsEmpty());
            // verify we don't get an NPE when specifying a final status query
            appsInfo = webSvc.GetApps(mockHsr, null, emptySet, "FAILED", null, null, null, null
                                      , null, null, null, emptySet, emptySet);
            NUnit.Framework.Assert.IsTrue(appsInfo.GetApps().IsEmpty());
        }
示例#18
0
        public async Task Then_a_list_of_applications_and_apprenticeships_is_returned()
        {
            // Arrange
            var accountId            = _fixture.Create <long>();
            var accountLegalEntityId = _fixture.Create <long>();

            var apprenticeApplicationList = new GetApplicationsResponse
            {
                ApprenticeApplications = _fixture.CreateMany <ApprenticeApplicationDto>(),
                BankDetailsStatus      = Enums.BankDetailsStatus.InProgress
            };

            _queryDispatcher.Setup(x => x.Send <GetApplicationsRequest, GetApplicationsResponse>(
                                       It.Is <GetApplicationsRequest>(y => y.AccountId == accountId && y.AccountLegalEntityId == accountLegalEntityId)))
            .ReturnsAsync(apprenticeApplicationList);

            // Act
            var result = await _sut.GetApplications(accountId, accountLegalEntityId) as OkObjectResult;

            // Assert
            result.Should().NotBeNull();
            result.Value.Should().Be(apprenticeApplicationList);
        }