Esempio n. 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);
        }
Esempio n. 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);
        }
        /// <summary>
        /// Creates <see cref="JobBlockingPolicyManager"/>.
        /// Specify <see cref="oldVersionedPropertyStore"/> when IS is used in a multi-tenant cluster (E.g. RP cluster)
        /// where each IS service communicates with one FC. In that case, we want individual job blocking policies for each IS service.
        /// If this parameter is <c>null</c>, then the same job blocking policy is shared across all IS services in a multi-tenant cluster.
        /// </summary>
        public static async Task <IJobBlockingPolicyManager> CreateAsync(
            TraceType traceType,
            IVersionedPropertyStore versionedPropertyStore,
            IVersionedPropertyStore oldVersionedPropertyStore = null)
        {
            traceType.Validate("traceType");
            versionedPropertyStore.Validate("versionedPropertyStore");

            traceType.WriteInfo("Starting creation of {0}", typeof(JobBlockingPolicyManager).Name);

            var manager = new JobBlockingPolicyManager(versionedPropertyStore);

            var activityId = Guid.NewGuid();

            var versionedKeyValue = await ReadPropertyAsync(traceType, versionedPropertyStore, activityId).ConfigureAwait(false);

            if (versionedKeyValue == null)
            {
                string defaultPolicyValue = JobBlockingPolicy.BlockNone.ToString();

                if (oldVersionedPropertyStore != null)
                {
                    var oldVersionedKeyValue = await ReadPropertyAsync(traceType, oldVersionedPropertyStore, activityId).ConfigureAwait(false);

                    if (oldVersionedKeyValue != null)
                    {
                        defaultPolicyValue = oldVersionedKeyValue.Value;
                    }

                    traceType.WriteInfo(
                        "{0} properties '{1}={2}' and '{3}' {4} newer versioned property store.",
                        oldVersionedKeyValue != null ? "Migrating" : "Creating",
                        PolicyPropertyName, defaultPolicyValue, PolicyVersionName,
                        oldVersionedKeyValue != null ? "to" : "in");
                }

                try
                {
                    await versionedPropertyStore.UpdateValueAsync(
                        activityId,
                        PolicyPropertyName,
                        PolicyVersionName,
                        defaultPolicyValue).ConfigureAwait(false);
                }
                catch (FabricException ex)
                {
                    if (ex.ErrorCode != FabricErrorCode.WriteConflict)
                    {
                        traceType.WriteError("Properties '{0}' and '{1}' could not be updated. Exception: {2}",
                                             PolicyPropertyName, PolicyVersionName, ex);
                        throw;
                    }
                }
            }

            traceType.WriteInfo("Successfully created {0}", typeof(JobBlockingPolicyManager).Name);
            return(manager);
        }
Esempio n. 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);
        }
        private static async Task <IVersionedKeyValue> ReadPropertyAsync(
            TraceType traceType,
            IVersionedPropertyStore versionedPropertyStore,
            Guid activityId)
        {
            try
            {
                var versionedKeyValue = await versionedPropertyStore
                                        .GetValueAsync(activityId, PolicyPropertyName, PolicyVersionName, false)
                                        .ConfigureAwait(false);

                return(versionedKeyValue);
            }
            catch (FabricElementNotFoundException ex)
            {
                traceType.WriteInfo(
                    "Properties '{0}' and '{1}' not found. These need to be created. Exception: {2}",
                    PolicyPropertyName,
                    PolicyVersionName,
                    ex);
            }

            return(null);
        }
 private JobBlockingPolicyManager(IVersionedPropertyStore versionedPropertyStore)
 {
     this.versionedPropertyStore = versionedPropertyStore;
 }