Пример #1
0
        public async Task ClearCacheTest1Async()
        {
            var propertyManager = new MockPropertyManagerWrapper
            {
                SubmitPropertyBatchAsyncFunc = Workflow3
            };

            Guid activityId = Guid.NewGuid();

            IVersionedPropertyStore versionedPropertyStore = await VersionedPropertyStore.CreateAsync(
                activityId, traceType, defaultStoreName, propertyManager, retryPolicyFactory).ConfigureAwait(false);

            IVersionedKeyValue vkv = await versionedPropertyStore.GetValueAsync(activityId, "A").ConfigureAwait(false);

            VerifyVersionedKeyValue(vkv, "Apple", 2, 1, workflow3Counter);

            IVersionedKeyValue vkv2 = await versionedPropertyStore.GetValueAsync(activityId, "A").ConfigureAwait(false);

            // verify that the counter hasn't been incremented since the actual property manager hasn't been invoked
            // but the value has been obtained from the cache
            VerifyVersionedKeyValue(vkv2, "Apple", 2, 1, workflow3Counter);

            versionedPropertyStore.ClearCache();

            IVersionedKeyValue vkv3 = await versionedPropertyStore.GetValueAsync(activityId, "A").ConfigureAwait(false);

            // verify that the counter has been incremented since the actual property manager has been invoked
            // since the value has been cleared from the cache
            VerifyVersionedKeyValue(vkv3, "Apple", 2, 2, workflow3Counter);

            Assert.AreEqual(workflow3Counter, 2);
        }
Пример #2
0
        public async Task UpdateValueAsyncTest1Async()
        {
            var propertyManager = new MockPropertyManagerWrapper
            {
                SubmitPropertyBatchAsyncFunc = Workflow2
            };

            Guid activityId = Guid.NewGuid();

            IVersionedPropertyStore versionedPropertyStore = await VersionedPropertyStore.CreateAsync(
                activityId, traceType, defaultStoreName, propertyManager, retryPolicyFactory).ConfigureAwait(false);

            await versionedPropertyStore.UpdateValueAsync(activityId, "A", "Apple").ConfigureAwait(false);

            IVersionedKeyValue vkv = await versionedPropertyStore.GetValueAsync(activityId, "A");

            // Cache is updated correctly after UpdateValueAsync so hitting remote store is not needed
            VerifyVersionedKeyValue(vkv, "Apple", 0, 1, workflow2Counter);

            // now, get from the remote store. (workflow2 is modified to send appropriate return values)
            vkv = await versionedPropertyStore.GetValueAsync(activityId, "A", false);

            VerifyVersionedKeyValue(vkv, "Antelope", 25, 2, workflow2Counter);

            vkv = await versionedPropertyStore.GetValueAsync(activityId, "A");

            // verify cache is updated correctly
            VerifyVersionedKeyValue(vkv, "Antelope", 25, 2, workflow2Counter);
        }
Пример #3
0
        private async Task <IJobBlockingPolicyManager> CreateAsync(IPropertyManagerWrapper propertyManager)
        {
            var versionedPropertyStore = await VersionedPropertyStore.CreateAsync(
                Guid.NewGuid(),
                TraceType,
                new Uri(Constants.StoreName),
                propertyManager,
                retryPolicyFactory).ConfigureAwait(false);

            IJobBlockingPolicyManager jobPolicyManager =
                await JobBlockingPolicyManager.CreateAsync(
                    TraceType, versionedPropertyStore).ConfigureAwait(false);

            return(jobPolicyManager);
        }
Пример #4
0
        public async Task GetValueAsyncTest1Async()
        {
            var propertyManager = new MockPropertyManagerWrapper
            {
                SubmitPropertyBatchAsyncFunc = Workflow1
            };

            Guid activityId = Guid.NewGuid();

            IVersionedPropertyStore versionedPropertyStore = await VersionedPropertyStore.CreateAsync(
                activityId, traceType, defaultStoreName, propertyManager, retryPolicyFactory).ConfigureAwait(false);

            IVersionedKeyValue vkv = await versionedPropertyStore.GetValueAsync(activityId, "A").ConfigureAwait(false);

            VerifyVersionedKeyValue(vkv, "Apple", 2, 1, workflow1Counter);

            vkv = await versionedPropertyStore.GetValueAsync(activityId, "A").ConfigureAwait(false);

            // Verifying that remote store is not hit now and data is fetched from cache
            VerifyVersionedKeyValue(vkv, "Apple", 2, 1, workflow1Counter);
        }
        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);
        }