PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/v2.0.0/tests/Microsoft/WindowsAzure/Diagnostics/ManagerTest.php

#
PHP | 201 lines | 108 code | 30 blank | 63 comment | 11 complexity | 4ec4569c1e7fa3415ceb9168096aa822 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Copyright (c) 2009 - 2010, RealDolmen
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of RealDolmen nor the
  14. * names of its contributors may be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * @category Microsoft
  29. * @package Microsoft_WindowsAzure
  30. * @subpackage UnitTests
  31. * @version $Id$
  32. * @copyright Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
  33. * @license http://phpazure.codeplex.com/license
  34. */
  35. if (!defined('PHPUnit_MAIN_METHOD')) {
  36. define('PHPUnit_MAIN_METHOD', 'Microsoft_WindowsAzure_Diagnostics_ManagerTest::main');
  37. }
  38. /**
  39. * Test helpers
  40. */
  41. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  42. require_once dirname(__FILE__) . '/../../../TestConfiguration.php';
  43. require_once 'PHPUnit/Framework/TestCase.php';
  44. /** Microsoft_WindowsAzure_Storage_Blob */
  45. require_once 'Microsoft/WindowsAzure/Storage/Blob.php';
  46. /** Microsoft_WindowsAzure_Diagnostics_Manager */
  47. require_once 'Microsoft/WindowsAzure/Diagnostics/Manager.php';
  48. /** Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance */
  49. require_once 'Microsoft/WindowsAzure/Diagnostics/ConfigurationInstance.php';
  50. /**
  51. * @category Microsoft
  52. * @package Microsoft_WindowsAzure
  53. * @subpackage UnitTests
  54. * @version $Id$
  55. * @copyright Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
  56. * @license http://phpazure.codeplex.com/license
  57. */
  58. class Microsoft_WindowsAzure_Diagnostics_ManagerTest extends PHPUnit_Framework_TestCase
  59. {
  60. public static function main()
  61. {
  62. $suite = new PHPUnit_Framework_TestSuite("Microsoft_WindowsAzure_Diagnostics_ManagerTest");
  63. $result = PHPUnit_TextUI_TestRunner::run($suite);
  64. }
  65. /**
  66. * Test teardown
  67. */
  68. protected function tearDown()
  69. {
  70. $storageClient = $this->createStorageInstance();
  71. for ($i = 1; $i <= self::$uniqId; $i++)
  72. {
  73. try { $storageClient->deleteContainer(TESTS_DIAGNOSTICS_CONTAINER_PREFIX . $i); } catch (Exception $e) { }
  74. }
  75. }
  76. protected function createStorageInstance()
  77. {
  78. $storageClient = null;
  79. if (TESTS_DIAGNOSTICS_RUNONPROD)
  80. {
  81. $storageClient = new Microsoft_WindowsAzure_Storage_Blob(TESTS_BLOB_HOST_PROD, TESTS_STORAGE_ACCOUNT_PROD, TESTS_STORAGE_KEY_PROD, false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
  82. } else {
  83. $storageClient = new Microsoft_WindowsAzure_Storage_Blob(TESTS_BLOB_HOST_DEV, TESTS_STORAGE_ACCOUNT_DEV, TESTS_STORAGE_KEY_DEV, true, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
  84. }
  85. if (TESTS_STORAGE_USEPROXY) {
  86. $storageClient->setProxy(TESTS_STORAGE_USEPROXY, TESTS_STORAGE_PROXY, TESTS_STORAGE_PROXY_PORT, TESTS_STORAGE_PROXY_CREDENTIALS);
  87. }
  88. return $storageClient;
  89. }
  90. protected static $uniqId = 0;
  91. protected function generateName()
  92. {
  93. self::$uniqId++;
  94. return TESTS_DIAGNOSTICS_CONTAINER_PREFIX . self::$uniqId;
  95. }
  96. /**
  97. * Test manager initialize
  98. */
  99. public function testManagerInitialize()
  100. {
  101. if (TESTS_DIAGNOSTICS_RUNTESTS) {
  102. $controlContainer = $this->generateName();
  103. $storageClient = $this->createStorageInstance();
  104. $manager = new Microsoft_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  105. $result = $storageClient->containerExists($controlContainer);
  106. $this->assertTrue($result);
  107. }
  108. }
  109. /**
  110. * Test manager default configuration
  111. */
  112. public function testManagerDefaultConfiguration()
  113. {
  114. if (TESTS_DIAGNOSTICS_RUNTESTS) {
  115. $controlContainer = $this->generateName();
  116. $storageClient = $this->createStorageInstance();
  117. $manager = new Microsoft_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  118. $configuration = $manager->getDefaultConfiguration();
  119. $manager->setConfigurationForRoleInstance('test', $configuration);
  120. $this->assertEquals($configuration->toXml(), $manager->getConfigurationForRoleInstance('test')->toXml());
  121. }
  122. }
  123. /**
  124. * Test manager custom configuration
  125. */
  126. public function testManagerCustomConfiguration()
  127. {
  128. if (TESTS_DIAGNOSTICS_RUNTESTS) {
  129. $controlContainer = $this->generateName();
  130. $storageClient = $this->createStorageInstance();
  131. $manager = new Microsoft_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  132. $configuration = $manager->getDefaultConfiguration();
  133. $configuration->DataSources->OverallQuotaInMB = 1;
  134. $configuration->DataSources->Logs->BufferQuotaInMB = 1;
  135. $configuration->DataSources->Logs->ScheduledTransferPeriodInMinutes = 1;
  136. $configuration->DataSources->PerformanceCounters->BufferQuotaInMB = 1;
  137. $configuration->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes = 1;
  138. $configuration->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB = 1;
  139. $configuration->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes = 1;
  140. $configuration->DataSources->PerformanceCounters->addSubscription('\Processor(*)\% Processor Time', 1);
  141. $configuration->DataSources->WindowsEventLog->addSubscription('System!*');
  142. $configuration->DataSources->WindowsEventLog->addSubscription('Application!*');
  143. $manager->setConfigurationForRoleInstance('test', $configuration);
  144. $result = $manager->getConfigurationForRoleInstance('test');
  145. $this->assertEquals($configuration->toXml(), $result->toXml());
  146. $this->assertEquals(1, count($result->DataSources->PerformanceCounters->Subscriptions));
  147. $this->assertEquals(2, count($result->DataSources->WindowsEventLog->Subscriptions));
  148. }
  149. }
  150. /**
  151. * Test manager configuration exists
  152. */
  153. public function testManagerConfigurationExists()
  154. {
  155. if (TESTS_DIAGNOSTICS_RUNTESTS) {
  156. $controlContainer = $this->generateName();
  157. $storageClient = $this->createStorageInstance();
  158. $manager = new Microsoft_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  159. $result = $manager->configurationForRoleInstanceExists('test');
  160. $this->assertFalse($result);
  161. $configuration = $manager->getDefaultConfiguration();
  162. $manager->setConfigurationForRoleInstance('test', $configuration);
  163. $result = $manager->configurationForRoleInstanceExists('test');
  164. $this->assertTrue($result);
  165. }
  166. }
  167. }
  168. // Call Microsoft_WindowsAzure_Credentials_SharedKeyTest::main() if this source file is executed directly.
  169. if (PHPUnit_MAIN_METHOD == "Microsoft_WindowsAzure_Diagnostics_ManagerTest::main") {
  170. Microsoft_WindowsAzure_Diagnostics_ManagerTest::main();
  171. }