示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        public async Task UpdatePolicyAsyncTest1Async()
        {
            var propertyManager = new MockPropertyManagerWrapper
            {
                SubmitPropertyBatchAsyncFunc = WorkflowForUpdatePolicyAsyncTest1
            };

            // mock a result where we return ok on initialize, then an error for the first operation
            // and return okay when an internal Read is called

            IJobBlockingPolicyManager jobPolicyManager = await CreateAsync(propertyManager).ConfigureAwait(false);

            try
            {
                await jobPolicyManager.UpdatePolicyAsync(JobBlockingPolicy.BlockNone).ConfigureAwait(false);

                Assert.Fail("Expected to throw an exception");
            }
            catch (FabricException ex)
            {
                Assert.AreEqual(
                    ex.ErrorCode,
                    FabricErrorCode.WriteConflict,
                    "Throwing FabricException as expected because of version mismatch");
            }

            Assert.AreEqual(
                jobPolicyManager.Policy,
                JobBlockingPolicy.BlockAllJobs,
                "Update policy failed as expected, but reading policy from store succeeded");
        }
示例#4
0
        public async Task InitializeTest1Async()
        {
            var propertyManager = new MockPropertyManagerWrapper
            {
                SubmitPropertyBatchAsyncFunc = WorkflowForInitializeTest1
            };

            IJobBlockingPolicyManager jobPolicyManager = await CreateAsync(propertyManager).ConfigureAwait(false);

            Assert.IsNotNull(jobPolicyManager);
            Assert.AreEqual(
                jobPolicyManager.Policy,
                JobBlockingPolicy.BlockAllJobs,
                "Verifying if new policy has been successfully read after Initialize");
        }
示例#5
0
        public async Task InitializeTest2Async()
        {
            var propertyManager = new MockPropertyManagerWrapper
            {
                SubmitPropertyBatchAsyncFunc = WorkflowForInitializeTest2
            };

            try
            {
                await CreateAsync(propertyManager).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Assert.IsTrue(
                    e is FabricException,
                    "Throwing FabricException as expected in Initialize");
            }
        }
示例#6
0
        public async Task UpdatePolicyAsyncTest3Async()
        {
            var propertyManager = new MockPropertyManagerWrapper();

            propertyManager.SubmitPropertyBatchAsyncFunc = WorkflowForUpdatePolicyAsyncTest3;

            IJobBlockingPolicyManager jobPolicyManager = await CreateAsync(propertyManager).ConfigureAwait(false);

            Assert.AreEqual(
                jobPolicyManager.Policy,
                JobBlockingPolicy.BlockNone,
                "Verifying if starting state of policy is as expected");

            await jobPolicyManager.UpdatePolicyAsync(JobBlockingPolicy.BlockAllJobs).ConfigureAwait(false);

            Assert.AreEqual(
                jobPolicyManager.Policy,
                JobBlockingPolicy.BlockAllJobs,
                "Verifying if new policy has been successfully applied");
        }
示例#7
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);
        }