public void EnableAzureMemcacheRoleProcessOnWorkerRoleSuccess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName     = "AzureService";
                string rootPath        = files.CreateNewService(serviceName);
                string cacheRoleName   = "CacheWorkerRole";
                string workerRoleName  = "WorkerRole";
                string expectedMessage = string.Format(Resources.EnableMemcacheMessage, workerRoleName, cacheRoleName, Resources.MemcacheEndpointPort);

                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand()
                {
                    RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName
                };
                addNodeWorkerCmdlet.ExecuteCmdlet();
                addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
                mockCommandRuntime.ResetPipelines();
                enableCacheCmdlet.PassThru = true;
                enableCacheCmdlet.EnableAzureMemcacheRoleProcess(workerRoleName, cacheRoleName, rootPath);

                WorkerRole workerRole = AzureAssert.GetWorkerRole(rootPath, workerRoleName);

                AzureAssert.RuntimeUrlAndIdExists(workerRole.Startup.Task, Resources.CacheRuntimeValue);

                AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, workerRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WorkerRole));
                AzureAssert.StartupTaskExists(workerRole.Startup.Task, Resources.CacheStartupCommand);

                AzureAssert.InternalEndpointExists(workerRole.Endpoints.InternalEndpoint,
                                                   new InternalEndpoint {
                    name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort
                });

                LocalStore localStore = new LocalStore
                {
                    name = Resources.CacheDiagnosticStoreName,
                    cleanOnRoleRecycle = false
                };

                AzureAssert.LocalResourcesLocalStoreExists(localStore, workerRole.LocalResources);

                DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting {
                    name = Resources.CacheClientDiagnosticLevelAssemblyName
                };
                AzureAssert.ConfigurationSettingExist(diagnosticLevel, workerRole.ConfigurationSettings);

                ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting {
                    name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue
                };
                AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, AzureAssert.GetCloudRole(rootPath, workerRoleName).ConfigurationSettings);
                AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, AzureAssert.GetLocalRole(rootPath, workerRoleName).ConfigurationSettings);

                string workerConfigPath  = string.Format(@"{0}\{1}\{2}", rootPath, workerRoleName, "web.config");
                string workerCloudConfig = File.ReadAllText(workerConfigPath);
                Assert.True(workerCloudConfig.Contains("configSections"));
                Assert.True(workerCloudConfig.Contains("dataCacheClients"));

                Assert.Equal <string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
                Assert.Equal <string>(workerRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue <string>(Parameters.RoleName));
            }
        }
Ejemplo n.º 2
0
        private void UpdateCacheWorkerRolesCloudConfiguration(PublishContext context)
        {
            string connectionString    = GetStorageServiceConnectionString(context.ServiceSettings.StorageServiceName);
            var    cloudServiceProject = new CloudServiceProject(context.RootPath, null);

            var connectionStringConfig = new ConfigConfigurationSetting
            {
                name  = Resources.CachingConfigStoreConnectionStringSettingName,
                value = string.Empty
            };

            cloudServiceProject.Components.ForEachRoleSettings(
                r => Array.Exists(r.ConfigurationSettings, c => c.Equals(connectionStringConfig)),
                r =>
            {
                int index = Array.IndexOf(r.ConfigurationSettings, connectionStringConfig);
                r.ConfigurationSettings[index] = new ConfigConfigurationSetting
                {
                    name  = Resources.CachingConfigStoreConnectionStringSettingName,
                    value = connectionString
                };
            });

            cloudServiceProject.Components.Save(cloudServiceProject.Paths);
        }
        private static void AddClientDiagnosticLevelToConfig(RoleSettings roleSettings)
        {
            ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting {
                name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue
            };

            roleSettings.ConfigurationSettings = GeneralUtilities.ExtendArray <ConfigConfigurationSetting>(roleSettings.ConfigurationSettings, clientDiagnosticLevel);
        }
        private void AssertCachingEnabled(
            FileSystemHelper files,
            string serviceName,
            string rootPath,
            string webRoleName,
            string expectedMessage)
        {
            WebRole      webRole      = AzureAssert.GetWebRole(rootPath, webRoleName);
            RoleSettings roleSettings = AzureAssert.GetCloudRole(rootPath, webRoleName);

            AzureAssert.RuntimeUrlAndIdExists(webRole.Startup.Task, Resources.CacheRuntimeValue);

            Assert.Equal <string>(Resources.CacheRuntimeVersionKey, webRole.Startup.Task[0].Environment[0].name);
            Assert.Equal <string>(enableCacheCmdlet.CacheRuntimeVersion, webRole.Startup.Task[0].Environment[0].value);

            Assert.Equal <string>(Resources.EmulatedKey, webRole.Startup.Task[2].Environment[0].name);
            Assert.Equal <string>("/RoleEnvironment/Deployment/@emulated", webRole.Startup.Task[2].Environment[0].RoleInstanceValue.xpath);

            Assert.Equal <string>(Resources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].name);
            Assert.Equal <string>(TestResources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].value);
            Assert.Equal(1, webRole.Startup.Task.Count(t => t.commandLine.Equals(Resources.CacheStartupCommand)));


            AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, webRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WebRole));
            AzureAssert.StartupTaskExists(webRole.Startup.Task, Resources.CacheStartupCommand);

            AzureAssert.InternalEndpointExists(webRole.Endpoints.InternalEndpoint,
                                               new InternalEndpoint {
                name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort
            });

            LocalStore localStore = new LocalStore
            {
                name = Resources.CacheDiagnosticStoreName,
                cleanOnRoleRecycle = false
            };

            AzureAssert.LocalResourcesLocalStoreExists(localStore, webRole.LocalResources);

            DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting {
                name = Resources.CacheClientDiagnosticLevelAssemblyName
            };

            AzureAssert.ConfigurationSettingExist(diagnosticLevel, webRole.ConfigurationSettings);

            ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting {
                name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue
            };

            AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, roleSettings.ConfigurationSettings);

            AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebCloudConfig));
            AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebConfigTemplateFileName));

            Assert.Equal <string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
            Assert.Equal <string>(webRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue <string>(Parameters.RoleName));
        }
        public void EnableAzureMemcacheRoleProcessOnWorkerRoleSuccess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string cacheRoleName = "CacheWorkerRole";
                string workerRoleName = "WorkerRole";
                string expectedMessage = string.Format(Resources.EnableMemcacheMessage, workerRoleName, cacheRoleName, Resources.MemcacheEndpointPort);

                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName };
                addNodeWorkerCmdlet.ExecuteCmdlet();
                addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
                mockCommandRuntime.ResetPipelines();
                enableCacheCmdlet.PassThru = true;
                enableCacheCmdlet.EnableAzureMemcacheRoleProcess(workerRoleName, cacheRoleName, rootPath);

                WorkerRole workerRole = AzureAssert.GetWorkerRole(rootPath, workerRoleName);

                AzureAssert.RuntimeUrlAndIdExists(workerRole.Startup.Task, Resources.CacheRuntimeValue);

                AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, workerRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WorkerRole));
                AzureAssert.StartupTaskExists(workerRole.Startup.Task, Resources.CacheStartupCommand);

                AzureAssert.InternalEndpointExists(workerRole.Endpoints.InternalEndpoint,
                    new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort });

                LocalStore localStore = new LocalStore
                {
                    name = Resources.CacheDiagnosticStoreName,
                    cleanOnRoleRecycle = false
                };

                AzureAssert.LocalResourcesLocalStoreExists(localStore, workerRole.LocalResources);

                DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName };
                AzureAssert.ConfigurationSettingExist(diagnosticLevel, workerRole.ConfigurationSettings);

                ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue };
                AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, AzureAssert.GetCloudRole(rootPath, workerRoleName).ConfigurationSettings);
                AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, AzureAssert.GetLocalRole(rootPath, workerRoleName).ConfigurationSettings);

                string workerConfigPath = string.Format(@"{0}\{1}\{2}", rootPath, workerRoleName, "web.config");
                string workerCloudConfig = File.ReadAllText(workerConfigPath);
                Assert.True(workerCloudConfig.Contains("configSections"));
                Assert.True(workerCloudConfig.Contains("dataCacheClients"));

                Assert.Equal<string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
                Assert.Equal<string>(workerRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue<string>(Parameters.RoleName));
            }
        }
        private void AssertCachingEnabled(
            FileSystemHelper files,
            string serviceName,
            string rootPath,
            string webRoleName,
            string expectedMessage)
        {
            WebRole webRole = AzureAssert.GetWebRole(rootPath, webRoleName);
            RoleSettings roleSettings = AzureAssert.GetCloudRole(rootPath, webRoleName);

            AzureAssert.RuntimeUrlAndIdExists(webRole.Startup.Task, Resources.CacheRuntimeValue);

            Assert.Equal<string>(Resources.CacheRuntimeVersionKey, webRole.Startup.Task[0].Environment[0].name);
            Assert.Equal<string>(enableCacheCmdlet.CacheRuntimeVersion, webRole.Startup.Task[0].Environment[0].value);
            
            Assert.Equal<string>(Resources.EmulatedKey, webRole.Startup.Task[2].Environment[0].name);
            Assert.Equal<string>("/RoleEnvironment/Deployment/@emulated", webRole.Startup.Task[2].Environment[0].RoleInstanceValue.xpath);
            
            Assert.Equal<string>(Resources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].name);
            Assert.Equal<string>(TestResources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].value);
            Assert.Equal(1, webRole.Startup.Task.Count(t => t.commandLine.Equals(Resources.CacheStartupCommand)));
            

            AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, webRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WebRole));
            AzureAssert.StartupTaskExists(webRole.Startup.Task, Resources.CacheStartupCommand);

            AzureAssert.InternalEndpointExists(webRole.Endpoints.InternalEndpoint,
                new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort });

            LocalStore localStore = new LocalStore
            {
                name = Resources.CacheDiagnosticStoreName,
                cleanOnRoleRecycle = false
            };

            AzureAssert.LocalResourcesLocalStoreExists(localStore, webRole.LocalResources);

            DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName };
            AzureAssert.ConfigurationSettingExist(diagnosticLevel, webRole.ConfigurationSettings);

            ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue };
            AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, roleSettings.ConfigurationSettings);

            AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebCloudConfig));
            AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebConfigTemplateFileName));

            Assert.Equal<string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
            Assert.Equal<string>(webRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue<string>(Parameters.RoleName));
        }
Ejemplo n.º 7
0
 public static void ConfigurationSettingExist(ConfigConfigurationSetting expected, ConfigConfigurationSetting[] actual)
 {
     Assert.IsTrue(Array.Exists <ConfigConfigurationSetting>(actual, c => c.name == expected.name));
 }
Ejemplo n.º 8
0
        private void UpdateCacheWorkerRolesCloudConfiguration(PublishContext context)
        {
            string connectionString = GetStorageServiceConnectionString(context.ServiceSettings.StorageServiceName);
            var cloudServiceProject = new CloudServiceProject(context.RootPath, null);

            var connectionStringConfig = new ConfigConfigurationSetting
            {
                name = Resources.CachingConfigStoreConnectionStringSettingName,
                value = string.Empty
            };

            cloudServiceProject.Components.ForEachRoleSettings(
                r => Array.Exists(r.ConfigurationSettings, c => c.Equals(connectionStringConfig)),
                r =>
                    {
                        int index = Array.IndexOf(r.ConfigurationSettings, connectionStringConfig);
                        r.ConfigurationSettings[index] = new ConfigConfigurationSetting
                        {
                            name = Resources.CachingConfigStoreConnectionStringSettingName,
                            value = connectionString
                        };
                    });

            cloudServiceProject.Components.Save(cloudServiceProject.Paths);
        }
 private static void AddClientDiagnosticLevelToConfig(RoleSettings roleSettings)
 {
     ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue };
     roleSettings.ConfigurationSettings = GeneralUtilities.ExtendArray<ConfigConfigurationSetting>(roleSettings.ConfigurationSettings, clientDiagnosticLevel);
 }
Ejemplo n.º 10
0
 public static void ConfigurationSettingExist(ConfigConfigurationSetting expected, ConfigConfigurationSetting[] actual)
 {
     Assert.IsTrue(Array.Exists<ConfigConfigurationSetting>(actual, c => c.name == expected.name));
 }