ManagerTest.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_WindowsAzure
  17. * @subpackage UnitTests
  18. * @version $Id$
  19. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_WindowsAzure_Diagnostics_ManagerTest::main');
  24. }
  25. /**
  26. * Test helpers
  27. */
  28. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  29. require_once dirname(__FILE__) . '/../../../../TestConfiguration.php.dist';
  30. /** Zend_Service_WindowsAzure_Storage_Blob */
  31. require_once 'Zend/Service/WindowsAzure/Storage/Blob.php';
  32. /** Zend_Service_WindowsAzure_Diagnostics_Manager */
  33. require_once 'Zend/Service/WindowsAzure/Diagnostics/Manager.php';
  34. /** Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance */
  35. require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationInstance.php';
  36. /**
  37. * @category Zend
  38. * @package Zend_Service_WindowsAzure
  39. * @subpackage UnitTests
  40. * @version $Id$
  41. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. */
  44. class Zend_Service_WindowsAzure_Diagnostics_ManagerTest extends PHPUnit_Framework_TestCase
  45. {
  46. public static function main()
  47. {
  48. $suite = new PHPUnit_Framework_TestSuite("Zend_Service_WindowsAzure_Diagnostics_ManagerTest");
  49. $result = PHPUnit_TextUI_TestRunner::run($suite);
  50. }
  51. /**
  52. * Test teardown
  53. */
  54. protected function tearDown()
  55. {
  56. $storageClient = $this->createStorageInstance();
  57. for ($i = 1; $i <= self::$uniqId; $i++)
  58. {
  59. try { $storageClient->deleteContainer(TESTS_ZEND_SERVICE_WINDOWSAZURE_DIAGNOSTICS_CONTAINER_PREFIX . $i); } catch (Exception $e) { }
  60. }
  61. }
  62. protected function createStorageInstance()
  63. {
  64. $storageClient = null;
  65. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_DIAGNOSTICS_RUNONPROD)
  66. {
  67. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob(TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD, false, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
  68. } else {
  69. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob(TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV, true, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250));
  70. }
  71. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY) {
  72. $storageClient->setProxy(TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT, TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS);
  73. }
  74. return $storageClient;
  75. }
  76. protected static $uniqId = 0;
  77. protected function generateName()
  78. {
  79. self::$uniqId++;
  80. return TESTS_ZEND_SERVICE_WINDOWSAZURE_DIAGNOSTICS_CONTAINER_PREFIX . self::$uniqId;
  81. }
  82. /**
  83. * Test manager initialize
  84. */
  85. public function testManagerInitialize()
  86. {
  87. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_DIAGNOSTICS_RUNTESTS) {
  88. $controlContainer = $this->generateName();
  89. $storageClient = $this->createStorageInstance();
  90. $manager = new Zend_Service_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  91. $result = $storageClient->containerExists($controlContainer);
  92. $this->assertTrue($result);
  93. }
  94. }
  95. /**
  96. * Test manager default configuration
  97. */
  98. public function testManagerDefaultConfiguration()
  99. {
  100. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_DIAGNOSTICS_RUNTESTS) {
  101. $controlContainer = $this->generateName();
  102. $storageClient = $this->createStorageInstance();
  103. $manager = new Zend_Service_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  104. $configuration = $manager->getDefaultConfiguration();
  105. $manager->setConfigurationForRoleInstance('test', $configuration);
  106. $this->assertEquals($configuration->toXml(), $manager->getConfigurationForRoleInstance('test')->toXml());
  107. }
  108. }
  109. /**
  110. * Test manager custom configuration
  111. */
  112. public function testManagerCustomConfiguration()
  113. {
  114. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_DIAGNOSTICS_RUNTESTS) {
  115. $controlContainer = $this->generateName();
  116. $storageClient = $this->createStorageInstance();
  117. $manager = new Zend_Service_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  118. $configuration = $manager->getDefaultConfiguration();
  119. $configuration->DataSources->OverallQuotaInMB = 1;
  120. $configuration->DataSources->Logs->BufferQuotaInMB = 1;
  121. $configuration->DataSources->Logs->ScheduledTransferPeriodInMinutes = 1;
  122. $configuration->DataSources->PerformanceCounters->BufferQuotaInMB = 1;
  123. $configuration->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes = 1;
  124. $configuration->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB = 1;
  125. $configuration->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes = 1;
  126. $configuration->DataSources->PerformanceCounters->addSubscription('\Processor(*)\% Processor Time', 1);
  127. $configuration->DataSources->WindowsEventLog->addSubscription('System!*');
  128. $configuration->DataSources->WindowsEventLog->addSubscription('Application!*');
  129. $configuration->DataSources->Directories->addSubscription('X:\\', 'x', 10);
  130. $configuration->DataSources->Directories->addSubscription('Y:\\', 'y', 10);
  131. $configuration->DataSources->Directories->addSubscription('Z:\\', 'z', 10);
  132. $manager->setConfigurationForRoleInstance('test', $configuration);
  133. $result = $manager->getConfigurationForRoleInstance('test');
  134. $this->assertEquals($configuration->toXml(), $result->toXml());
  135. $this->assertEquals(1, count($result->DataSources->PerformanceCounters->Subscriptions));
  136. $this->assertEquals(2, count($result->DataSources->WindowsEventLog->Subscriptions));
  137. $this->assertEquals(3, count($result->DataSources->Directories->Subscriptions));
  138. }
  139. }
  140. /**
  141. * Test manager configuration exists
  142. */
  143. public function testManagerConfigurationExists()
  144. {
  145. if (TESTS_ZEND_SERVICE_WINDOWSAZURE_DIAGNOSTICS_RUNTESTS) {
  146. $controlContainer = $this->generateName();
  147. $storageClient = $this->createStorageInstance();
  148. $manager = new Zend_Service_WindowsAzure_Diagnostics_Manager($storageClient, $controlContainer);
  149. $result = $manager->configurationForRoleInstanceExists('test');
  150. $this->assertFalse($result);
  151. $configuration = $manager->getDefaultConfiguration();
  152. $manager->setConfigurationForRoleInstance('test', $configuration);
  153. $result = $manager->configurationForRoleInstanceExists('test');
  154. $this->assertTrue($result);
  155. }
  156. }
  157. }
  158. // Call Zend_Service_WindowsAzure_Credentials_SharedKeyTest::main() if this source file is executed directly.
  159. if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_Diagnostics_ManagerTest::main") {
  160. Zend_Service_WindowsAzure_Diagnostics_ManagerTest::main();
  161. }