public void ExecuteAsyncTest() { IRetryPolicy retryPolicy = new LinearRetryPolicyFactory( TraceType, 500, 3, IsRetriableException).Create(); int retryCount = 0; try { retryPolicy .ExecuteAsync(async(token) => { retryCount++; if (retryCount < 10) { throw new TimeoutException("timeout"); } return(await Task.FromResult(true)); }, "func1", CancellationToken.None) .GetAwaiter() .GetResult(); } catch (AggregateException ae) { AggregateException flatEx = ae.Flatten(); flatEx.Handle(e => e is TimeoutException); Assert.AreEqual(retryCount, 3, "retry policy allowed retry 3 times as expected"); } }
public IInfrastructureCoordinator Create() { var repairManager = new ServiceFabricRepairManagerFactory(env, activityLogger).Create(); if (repairManager == null) { const string message = "Unable to create Repair Manager client; cannot continue further."; TraceType.WriteWarning(message); throw new ManagementException(message); } var policyAgentClient = new PolicyAgentClient(env, policyAgentServiceWrapper, activityLogger); var retryPolicyFactory = new LinearRetryPolicyFactory( env.DefaultTraceType, InfrastructureService.Constants.BackoffPeriodInMilliseconds, InfrastructureService.Constants.MaxRetryAttempts, AzureHelper.IsRetriableException); string tenantSpecificStoreName = "{0}/{1}".ToString(InfrastructureService.Constants.StoreName, configSection.Name); var tenantSpecificVersionedPropertyStore = VersionedPropertyStore.CreateAsync( Guid.NewGuid(), env.CreateTraceType("PropertyStore"), new Uri(tenantSpecificStoreName), new PropertyManagerWrapper(), retryPolicyFactory).GetAwaiter().GetResult(); // if this exists, job blocking policy manager will migrate job blocking policy properties // from this one to the tenant-specific store. var versionedPropertyStore = VersionedPropertyStore.CreateAsync( Guid.NewGuid(), env.CreateTraceType("PropertyStoreOld"), new Uri(InfrastructureService.Constants.StoreName), new PropertyManagerWrapper(), retryPolicyFactory).GetAwaiter().GetResult(); var jobBlockingPolicyManager = JobBlockingPolicyManager.CreateAsync( env.CreateTraceType("JobBlockingPolicyManager"), tenantSpecificVersionedPropertyStore, versionedPropertyStore).GetAwaiter().GetResult(); var allowActionMap = new AllowActionMap(); var coordinatorCommandProcessor = new CoordinatorCommandProcessor( env, policyAgentClient, jobBlockingPolicyManager, allowActionMap); var mappedPolicyFactory = new DefaultActionPolicyFactory(env, jobBlockingPolicyManager, allowActionMap); var coordinator = new AzureParallelInfrastructureCoordinator( env, tenantId, policyAgentClient, repairManager, new ServiceFabricHealthClient(), coordinatorCommandProcessor, jobBlockingPolicyManager, mappedPolicyFactory, activityLogger, partitionId, replicaId); return(coordinator); }