PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ServiceManagement/HDInsight/Commands.HDInsight.Test/HDInsight/CommandTests/AddHDInsightConfigValuesCommandTests.cs

https://gitlab.com/jslee1/azure-powershell
C# | 228 lines | 179 code | 36 blank | 13 comment | 18 complexity | f2361ab7585056c81609b06f453073f0 MD5 | raw file
  1. // ----------------------------------------------------------------------------------
  2. //
  3. // Copyright Microsoft Corporation
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. // ----------------------------------------------------------------------------------
  14. using System;
  15. using System.Linq;
  16. using Microsoft.VisualStudio.TestTools.UnitTesting;
  17. using Microsoft.WindowsAzure.Commands.Test.HDInsight.CmdLetTests;
  18. using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.Commands.CommandInterfaces;
  19. using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.DataObjects;
  20. using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.GetAzureHDInsightClusters;
  21. using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.ServiceLocation;
  22. namespace Microsoft.WindowsAzure.Commands.Test.HDInsight.CommandTests
  23. {
  24. [TestClass]
  25. public class AddHDInsightConfigValuesCommandTests : HDInsightTestCaseBase
  26. {
  27. [TestCleanup]
  28. public override void TestCleanup()
  29. {
  30. base.TestCleanup();
  31. }
  32. [TestMethod]
  33. [TestCategory("CheckIn")]
  34. public void CanAddCoreConfigValues()
  35. {
  36. var config = new AzureHDInsightConfig();
  37. IAddAzureHDInsightConfigValuesCommand addCoreConfigValues =
  38. ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateAddConfig();
  39. addCoreConfigValues.Core.Add("hadoop.log.file.size", "12345");
  40. addCoreConfigValues.Config = config;
  41. addCoreConfigValues.EndProcessing();
  42. AzureHDInsightConfig newConfig = addCoreConfigValues.Output.First();
  43. Assert.AreEqual(config.ClusterSizeInNodes, newConfig.ClusterSizeInNodes);
  44. Assert.AreEqual(config.DefaultStorageAccount, newConfig.DefaultStorageAccount);
  45. Assert.IsTrue(
  46. newConfig.CoreConfiguration.Any(configOption => configOption.Key == "hadoop.log.file.size" && configOption.Value == "12345"));
  47. }
  48. [TestMethod]
  49. [TestCategory("CheckIn")]
  50. public void CanAddYarnConfigValues()
  51. {
  52. var config = new AzureHDInsightConfig();
  53. IAddAzureHDInsightConfigValuesCommand addYarnConfigValues =
  54. ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateAddConfig();
  55. addYarnConfigValues.Core.Add("yarn.fakekey", "12345");
  56. addYarnConfigValues.Config = config;
  57. addYarnConfigValues.EndProcessing();
  58. AzureHDInsightConfig newConfig = addYarnConfigValues.Output.First();
  59. Assert.AreEqual(config.ClusterSizeInNodes, newConfig.ClusterSizeInNodes);
  60. Assert.AreEqual(config.DefaultStorageAccount, newConfig.DefaultStorageAccount);
  61. Assert.IsTrue(
  62. newConfig.CoreConfiguration.Any(configOption => configOption.Key == "yarn.fakekey" && configOption.Value == "12345"));
  63. }
  64. [TestMethod]
  65. [TestCategory("CheckIn")]
  66. public void CanAddHdfsConfigValues()
  67. {
  68. var config = new AzureHDInsightConfig();
  69. IAddAzureHDInsightConfigValuesCommand addCoreConfigValues =
  70. ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateAddConfig();
  71. addCoreConfigValues.Hdfs.Add("hadoop.log.file.size", "12345");
  72. addCoreConfigValues.Config = config;
  73. addCoreConfigValues.EndProcessing();
  74. AzureHDInsightConfig newConfig = addCoreConfigValues.Output.First();
  75. Assert.AreEqual(config.ClusterSizeInNodes, newConfig.ClusterSizeInNodes);
  76. Assert.AreEqual(config.DefaultStorageAccount, newConfig.DefaultStorageAccount);
  77. Assert.IsTrue(
  78. newConfig.HdfsConfiguration.Any(configOption => configOption.Key == "hadoop.log.file.size" && configOption.Value == "12345"));
  79. }
  80. [TestMethod]
  81. [TestCategory("CheckIn")]
  82. public void CanAddHiveAdditionalLibrariesValues()
  83. {
  84. var config = new AzureHDInsightConfig();
  85. IAddAzureHDInsightConfigValuesCommand addCoreConfigValues =
  86. ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateAddConfig();
  87. addCoreConfigValues.Hive.AdditionalLibraries = new AzureHDInsightDefaultStorageAccount
  88. {
  89. StorageAccountKey = Guid.NewGuid().ToString(),
  90. StorageAccountName = Guid.NewGuid().ToString(),
  91. StorageContainerName = Guid.NewGuid().ToString()
  92. };
  93. addCoreConfigValues.Config = config;
  94. addCoreConfigValues.EndProcessing();
  95. AzureHDInsightConfig newConfig = addCoreConfigValues.Output.First();
  96. Assert.AreEqual(config.ClusterSizeInNodes, newConfig.ClusterSizeInNodes);
  97. Assert.AreEqual(config.DefaultStorageAccount, newConfig.DefaultStorageAccount);
  98. Assert.IsNotNull(newConfig.HiveConfiguration.AdditionalLibraries);
  99. Assert.AreEqual(
  100. newConfig.HiveConfiguration.AdditionalLibraries.Container, addCoreConfigValues.Hive.AdditionalLibraries.StorageContainerName);
  101. Assert.AreEqual(newConfig.HiveConfiguration.AdditionalLibraries.Key, addCoreConfigValues.Hive.AdditionalLibraries.StorageAccountKey);
  102. Assert.AreEqual(newConfig.HiveConfiguration.AdditionalLibraries.Name, addCoreConfigValues.Hive.AdditionalLibraries.StorageAccountName);
  103. }
  104. [TestMethod]
  105. [TestCategory("CheckIn")]
  106. public void CanAddHiveConfigValues()
  107. {
  108. var config = new AzureHDInsightConfig();
  109. IAddAzureHDInsightConfigValuesCommand addCoreConfigValues =
  110. ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateAddConfig();
  111. addCoreConfigValues.Hive.Configuration.Add("hadoop.log.file.size", "12345");
  112. addCoreConfigValues.Config = config;
  113. addCoreConfigValues.EndProcessing();
  114. AzureHDInsightConfig newConfig = addCoreConfigValues.Output.First();
  115. Assert.AreEqual(config.ClusterSizeInNodes, newConfig.ClusterSizeInNodes);
  116. Assert.AreEqual(config.DefaultStorageAccount, newConfig.DefaultStorageAccount);
  117. Assert.IsTrue(
  118. newConfig.HiveConfiguration.ConfigurationCollection.Any(
  119. configOption => configOption.Key == "hadoop.log.file.size" && configOption.Value == "12345"));
  120. }
  121. [TestMethod]
  122. [TestCategory("CheckIn")]
  123. public void CanAddMapReduceConfigValues()
  124. {
  125. var config = new AzureHDInsightConfig();
  126. IAddAzureHDInsightConfigValuesCommand addCoreConfigValues =
  127. ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateAddConfig();
  128. addCoreConfigValues.MapReduce = new AzureHDInsightMapReduceConfiguration();
  129. addCoreConfigValues.MapReduce.Configuration.Add("hadoop.log.file.size", "12345");
  130. addCoreConfigValues.Config = config;
  131. addCoreConfigValues.EndProcessing();
  132. AzureHDInsightConfig newConfig = addCoreConfigValues.Output.First();
  133. Assert.AreEqual(config.ClusterSizeInNodes, newConfig.ClusterSizeInNodes);
  134. Assert.AreEqual(config.DefaultStorageAccount, newConfig.DefaultStorageAccount);
  135. Assert.IsTrue(
  136. newConfig.MapReduceConfiguration.ConfigurationCollection.Any(
  137. configOption => configOption.Key == "hadoop.log.file.size" && configOption.Value == "12345"));
  138. }
  139. [TestMethod]
  140. [TestCategory("CheckIn")]
  141. public void CanAddOozieConfigValues()
  142. {
  143. var config = new AzureHDInsightConfig();
  144. IAddAzureHDInsightConfigValuesCommand addCoreConfigValues =
  145. ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateAddConfig();
  146. addCoreConfigValues.Oozie.AdditionalSharedLibraries = new AzureHDInsightDefaultStorageAccount
  147. {
  148. StorageAccountKey = Guid.NewGuid().ToString(),
  149. StorageAccountName = Guid.NewGuid().ToString(),
  150. StorageContainerName = Guid.NewGuid().ToString()
  151. };
  152. addCoreConfigValues.Oozie.AdditionalActionExecutorLibraries = new AzureHDInsightDefaultStorageAccount
  153. {
  154. StorageAccountKey = Guid.NewGuid().ToString(),
  155. StorageAccountName = Guid.NewGuid().ToString(),
  156. StorageContainerName = Guid.NewGuid().ToString()
  157. };
  158. addCoreConfigValues.Oozie.Configuration.Add("hadoop.log.file.size", "12345");
  159. addCoreConfigValues.Config = config;
  160. addCoreConfigValues.EndProcessing();
  161. AzureHDInsightConfig newConfig = addCoreConfigValues.Output.First();
  162. Assert.AreEqual(config.ClusterSizeInNodes, newConfig.ClusterSizeInNodes);
  163. Assert.AreEqual(config.DefaultStorageAccount, newConfig.DefaultStorageAccount);
  164. Assert.IsTrue(
  165. newConfig.OozieConfiguration.ConfigurationCollection.Any(
  166. configOption => configOption.Key == "hadoop.log.file.size" && configOption.Value == "12345"));
  167. Assert.IsNotNull(newConfig.OozieConfiguration.AdditionalSharedLibraries);
  168. Assert.AreEqual(
  169. newConfig.OozieConfiguration.AdditionalSharedLibraries.Container,
  170. addCoreConfigValues.Oozie.AdditionalSharedLibraries.StorageContainerName);
  171. Assert.AreEqual(
  172. newConfig.OozieConfiguration.AdditionalSharedLibraries.Key, addCoreConfigValues.Oozie.AdditionalSharedLibraries.StorageAccountKey);
  173. Assert.AreEqual(
  174. newConfig.OozieConfiguration.AdditionalSharedLibraries.Name, addCoreConfigValues.Oozie.AdditionalSharedLibraries.StorageAccountName);
  175. Assert.IsNotNull(newConfig.OozieConfiguration.AdditionalActionExecutorLibraries);
  176. Assert.AreEqual(
  177. newConfig.OozieConfiguration.AdditionalActionExecutorLibraries.Container,
  178. addCoreConfigValues.Oozie.AdditionalActionExecutorLibraries.StorageContainerName);
  179. Assert.AreEqual(
  180. newConfig.OozieConfiguration.AdditionalActionExecutorLibraries.Key,
  181. addCoreConfigValues.Oozie.AdditionalActionExecutorLibraries.StorageAccountKey);
  182. Assert.AreEqual(
  183. newConfig.OozieConfiguration.AdditionalActionExecutorLibraries.Name,
  184. addCoreConfigValues.Oozie.AdditionalActionExecutorLibraries.StorageAccountName);
  185. }
  186. [TestInitialize]
  187. public override void Initialize()
  188. {
  189. base.Initialize();
  190. }
  191. }
  192. }