Esempio n. 1
0
        private static async Task EvaluateImpactAsync(string jobId, JobType jobType)
        {
            var instancesAndReasons1 = new[]
            {
                "WF_IN_0", ImpactReason.ConfigurationUpdate.ToString(),
                "WF_IN_4", ImpactReason.ConfigurationUpdate.ToString(),
                "WF_IN_8", ImpactReason.ConfigurationUpdate.ToString(),
            };

            var qc = new MockQueryClient(GetNodeList());
            var jobImpactManager = new JobImpactManager(GetConfigSection(), qc);

            var notification = GetNotification(jobId, 0, instancesAndReasons1, jobType);
            var jobImpact    = await jobImpactManager.EvaluateJobImpactAsync(notification).ConfigureAwait(false);

            Verify.AreEqual(jobImpact, JobImpactTranslationMode.Default, "Verifying published impact since no history is stored");

            var instancesAndReasons2 = new[]
            {
                "WF_IN_1", ImpactReason.ConfigurationUpdate.ToString(),
                "WF_IN_5", ImpactReason.ConfigurationUpdate.ToString(),
                "WF_IN_9", ImpactReason.ConfigurationUpdate.ToString(),
            };

            notification = GetNotification(jobId, 1, instancesAndReasons2, jobType);

            // at this time, we should reuse the saved history
            jobImpact = await jobImpactManager.EvaluateJobImpactAsync(notification).ConfigureAwait(false);

            Verify.AreEqual(jobImpact, JobImpactTranslationMode.Optimized, "Verifying published impact since there wasn't a reboot of nodes previously");

            jobImpact = await jobImpactManager.EvaluateJobImpactAsync(notification).ConfigureAwait(false);

            Verify.AreEqual(jobImpact, JobImpactTranslationMode.Optimized, "Verifying invoking again (within validity time) shouldn't change result");

            // simulate nodes going down
            await Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false);

            qc.Nodes = GetNodeList(DateTimeOffset.UtcNow);

            // for the next UD, since the nodes have gone down, don't use history
            var instancesAndReasons3 = new[]
            {
                "WF_IN_2", ImpactReason.ConfigurationUpdate.ToString(),
                "WF_IN_6", ImpactReason.ConfigurationUpdate.ToString(),
                "WF_IN_10", ImpactReason.ConfigurationUpdate.ToString(),
            };

            notification = GetNotification(jobId, 2, instancesAndReasons3, jobType);

            jobImpact = await jobImpactManager.EvaluateJobImpactAsync(notification).ConfigureAwait(false);

            Verify.AreEqual(jobImpact, JobImpactTranslationMode.Default, "Verifying published impact since nodes have rebooted after previous evaluation");
        }
        public IInfrastructureCoordinator Create()
        {
            string configSectionName = typeof(WindowsAzureInfrastructureCoordinatorTest).Name + "ConfigSection";

            const string ConfigJobPollingIntervalInSecondsKeyName = "WindowsAzure.JobPollingIntervalInSeconds";

            var configStore = new MockConfigStore();

            // loop faster in the ProcessManagementNotification loop of WindowsAzureInfrastructureCoordinator
            configStore.AddKeyValue(configSectionName, ConfigJobPollingIntervalInSecondsKeyName, "1");

            foreach (var pair in configSettings)
            {
                configStore.AddKeyValue(configSectionName, pair.Key, pair.Value);
            }

            var partitionId = Guid.NewGuid();
            var jobBlockingPolicyManager = new MockJobBlockingPolicyManager();

            var jobImpactManager = new JobImpactManager(new ConfigSection(traceType, configStore, configSectionName), queryClient);

            var coordinator = new WindowsAzureInfrastructureCoordinator(
                "mytenant",
                managementClient,
                this.agent,
                configStore,
                configSectionName,
                partitionId,
                0,
                new MockHealthClient(),
                jobBlockingPolicyManager,
                jobImpactManager,
                null);

            return(coordinator);
        }