public void GetBalancesSafelyUnavailableRecognizedDataProviderRequestWorks() { // Se habilitan los proveedores conocidos para la aplicación... IAppIdentity appIdentity = AutonomousAppIdentity.Master; TestContext.CurrentContext.DatabaseHelper().SetAppSettingsKey(appIdentity.ApiKey, "DataProvider:SubsystemEnabled", "TUP|Bancor"); IAutonomousApp client = this.GetAutonomousClient(); IUserIdentity userIdentity = RecognizedUserIdentity.Master; string docType = userIdentity.DocType; string docNumber = userIdentity.DocNumber; IList <AccountInfo> accounts = client.Inquiries.GetAccounts(docType, docNumber); CollectionAssert.IsNotEmpty(accounts); AccountInfo accountInfo = accounts.FirstOrDefault(account => account.Source == Subsystem.Tup); Assert.IsNotNull(accountInfo); string accountId = accountInfo.SourceAccountId; // Se configura una conexión inválida para el proveedor de datos de TUP para esperar que falle la consulta de saldos... TestContext.CurrentContext.DatabaseHelper().SetAppSettingsKey(appIdentity.ApiKey, "Bifrost:ConnectionStringName", "RabbitMQ:Broken:Tests"); TestContext.CurrentContext.DatabaseHelper().SetAppSettingsKey(appIdentity.ApiKey, "TUP:ConnectionStringName", "Aspen"); IList <BalanceResultInfo> inquiryResults = client.InquiriesV11.GetBalances(docType, docNumber, accountId); CollectionAssert.IsNotEmpty(inquiryResults); Assert.That(inquiryResults.Count, Is.EqualTo(2)); // El proveedor de datos de TUP debe indicar que no está disponible para procesar la consulta requerida... BalanceResultInfo tupInquiryResult = inquiryResults.First(info => info.Subsystem == Subsystem.Tup); CollectionAssert.IsEmpty(tupInquiryResult.Data); Assert.IsNotEmpty(tupInquiryResult.Reason); Assert.That(tupInquiryResult.Status, Is.EqualTo(SubsystemStatus.Unavailable)); // El proveedor de datos de BANCOR debe indicar que no implementa la característica de saldos... BalanceResultInfo bancorInquiryResult = inquiryResults.First(info => info.Subsystem == Subsystem.Bancor); CollectionAssert.IsEmpty(bancorInquiryResult.Data); Assert.IsNotEmpty(bancorInquiryResult.Reason); Assert.That(bancorInquiryResult.Status, Is.EqualTo(SubsystemStatus.MissingFeature)); // Se reestablece la aplicación para usar el proveedor de datos predeterminando para pruebas... TestContext.CurrentContext.DatabaseHelper().SetAppSettingsKey(appIdentity.ApiKey, "DataProvider:SubsystemEnabled", "TUP"); // Se reestablece las conexión valida al proveedor de datos de TUP... TestContext.CurrentContext.DatabaseHelper().SetAppSettingsKey(appIdentity.ApiKey, "Bifrost:ConnectionStringName", "RabbitMQ:Bifrost:Tests"); TestContext.CurrentContext.DatabaseHelper().SetAppSettingsKey(appIdentity.ApiKey, "TUP:ConnectionStringName", "Sql:TupCompensar"); }
/// <summary> /// Get the dispatchers to shutdown to meet the preemption requirement. /// If the requirement cannot be met before the dispatcher count is less than min units, /// it will set the cancel job to true. /// If the requirement is met before all idle dispatchers are shutdown /// it will set the resume flag to resume the stopped dispatchers. /// </summary> /// <param name="idleDispatchers">the idle dispatcher list</param> /// <param name="schedulerAdapter">the adapter to the scheduler</param> /// <param name="minDispatchers">the minimum dispatchers count</param> /// <param name="shouldCancelJob">true if we need cancel the job</param> /// <param name="shouldResumeRemaining">true if we need resume the dispatchers.</param> /// <returns>the dispatchers to shutdown</returns> public BalanceResultInfo GetDispatchersToShutdown( List <DispatcherInfo> idleDispatchers, int minDispatchers, bool balanceRequestRefreshed) { idleDispatchers.Sort((d1, d2) => d2.CoreCount.CompareTo(d1.CoreCount)); bool shouldCancelJob = false; int activeDispatcherCount = this.dispatcherManager.ActiveDispatcherCount; BalanceInfo info = this.BalanceInfo; BrokerTracing.TraceVerbose( "[GracefulPreemptionHandler].GetDispatchersToShutdown: UseFastBalance = {0}, Request count = {1}, dispatcherCount = {2}, maxAllowedCoreCount = {3}, minDispatcherCount = {4}, balanceRequestRefreshed = {5}", info.UseFastBalance, info.BalanceRequests.Count, activeDispatcherCount, info.AllowedCoreCount, minDispatchers, balanceRequestRefreshed); var resultInfo = new BalanceResultInfo(info.UseFastBalance); if (info.UseFastBalance) { List <string> emptyRunningList = new List <string>(); foreach (var request in info.BalanceRequests) { resultInfo.GracefulPreemptionResults.Add( this.GetDispatchersToShutdownAux( idleDispatchers, request.AllowedCoreCount, true, balanceRequestRefreshed, minDispatchers, request.TaskIds, emptyRunningList, ref activeDispatcherCount, out shouldCancelJob)); if (shouldCancelJob) { break; } } } else { Debug.Assert(info.BalanceRequests.Count == 1); Debug.Assert(info.BalanceRequests.First().TaskIds == null); var request = info.BalanceRequests.First(); resultInfo.GracefulPreemptionResults.Add( this.GetDispatchersToShutdownAux( idleDispatchers, request.AllowedCoreCount, false, balanceRequestRefreshed, minDispatchers, this.exitingTaskIds, this.runningTaskIds, ref activeDispatcherCount, out shouldCancelJob)); } if (shouldCancelJob) { resultInfo.ShouldCancelJob = true; this.StopAllDispatchers(); } Debug.Assert( resultInfo.ShouldCancelJob || resultInfo.GracefulPreemptionResults.Count == info.BalanceRequests.Count, string.Format( "[GracefulPreemptionHandler](Assert) GracefulPreemptionResults number {0} does not equal with BalanceRequests number {1}", resultInfo.GracefulPreemptionResults.Count, info.BalanceRequests.Count)); BrokerTracing.TraceVerbose( "[GracefulPreemptionHandler].GetDispatchersToShutdown: return dispatchers Count: {0}, results count: {1}", resultInfo.GracefulPreemptionResults.Sum(r => r.DispatchersToShutdown.Count), resultInfo.GracefulPreemptionResults.Count); return(resultInfo); }