/** * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::_processGoalStateChange * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::_acceptLatestIncarnation * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::_raiseStoppingEvent * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::_raiseChangingEvent * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::_raiseChangedEvent */ public function testProcessGoalStateChange() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $roleEnvironmentFileName = 'roleEnvironment'; $roleEnvironmentFileContent = '<?xml version="1.0" encoding="utf-8"?>' . '<RoleEnvironment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . '<Deployment id="state1" emulated="false" />' . '<CurrentInstance id="id3" roleName="roleName" faultDomain="4" updateDomain="5">' . '<LocalResources>' . '<LocalResource name="DiagnosticStore" path="somepath.DiagnosticStore" sizeInMB="4096" />' . '</LocalResources>' . '</CurrentInstance>' . '<Roles />' . '</RoleEnvironment>'; $roleEnvironmentFile = \vfsStream::newFile($roleEnvironmentFileName); $roleEnvironmentFile->setContent($roleEnvironmentFileContent); \vfsStreamWrapper::getRoot()->addChild($roleEnvironmentFile); $currentGoalStateFileName = 'currentGoalStateFile'; $currentGoalStateFile = \vfsStream::newFile($currentGoalStateFileName); \vfsStreamWrapper::getRoot()->addChild($currentGoalStateFile); $goalStateFileName = 'goalstate'; $goalStateFileContent = '<?xml version="1.0" encoding="utf-8"?>' . '<GoalState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . '<Incarnation>1</Incarnation>' . '<ExpectedState>Started</ExpectedState>' . '<RoleEnvironmentPath>' . \vfsStream::url($rootDirectory . '/' . $roleEnvironmentFileName) . '</RoleEnvironmentPath>' . '<CurrentStateEndpoint>' . \vfsStream::url($rootDirectory . '/' . $currentGoalStateFileName) . '</CurrentStateEndpoint>' . '<Deadline>9999-12-31T23:59:59.9999999</Deadline>' . '</GoalState>'; $goalStateFileContent = dechex(strlen($goalStateFileContent)) . "\n" . $goalStateFileContent; $file = \vfsStream::newFile($goalStateFileName); $file->setContent($goalStateFileContent); \vfsStreamWrapper::getRoot()->addChild($file); $fileName = 'versionendpoint'; $fileContent = '<?xml version="1.0" encoding="utf-8"?>' . '<RuntimeServerDiscovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . '<RuntimeServerEndpoints>' . '<RuntimeServerEndpoint version="2011-03-08" path="' . \vfsStream::url($rootDirectory . '/' . $goalStateFileName) . '" />' . '</RuntimeServerEndpoints>' . '</RuntimeServerDiscovery>'; $file = \vfsStream::newFile($fileName); $file->setContent($fileContent); \vfsStreamWrapper::getRoot()->addChild($file); putenv('WaRuntimeEndpoint=' . \vfsStream::url($rootDirectory . '/' . $fileName)); // Test $this->assertEquals('state1', RoleEnvironment::getDeploymentId()); $currentGoalState = self::getStaticPropertyValue('_currentGoalState'); // Process goal state to the previous state $args = array(); $args[] = $currentGoalState; $processGoalStateChange = self::getMethod('_processGoalStateChange'); $processGoalStateChange->invokeArgs(null, $args); // Update current state this time changing things $roleEnvironmentFileContent = '<?xml version="1.0" encoding="utf-8"?>' . '<RoleEnvironment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . '<Deployment id="state3" emulated="false" />' . '<CurrentInstance id="id3" roleName="roleName" faultDomain="10" updateDomain="10">' . '</CurrentInstance>' . '<Roles />' . '</RoleEnvironment>'; $roleEnvironmentFile->setContent($roleEnvironmentFileContent); $currentGoalState = RuntimeKernel::getKernel()->getProtocol1RuntimeGoalStateClient()->getCurrentGoalState(); $processGoalStateChange = self::getMethod('_processGoalStateChange'); $processGoalStateChange->invokeArgs(null, $args); $this->assertEquals('state3', RoleEnvironment::getDeploymentId()); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\RuntimeKernel::getRuntimeVersionManager */ public function testGetRuntimeVersionManager() { // Setup $runtimeKernel = RuntimeKernel::getKernel(); // Test $this->assertInstanceOf('WindowsAzure\\ServiceRuntime\\Internal\\RuntimeVersionManager', $runtimeKernel->getRuntimeVersionManager()); }
/** * Initializes the runtime client. * * @param bool $keepOpen Boolean value indicating if the connection * should remain open. * * @static * * @return none */ private static function _initialize($keepOpen = false) { try { if (is_null(self::$_runtimeClient)) { self::$_versionEndpoint = getenv(self::VERSION_ENDPOINT_ENVIRONMENT_NAME); if (self::$_versionEndpoint == false) { self::$_versionEndpoint = self::VERSION_ENDPOINT_FIXED_PATH; } $kernel = RuntimeKernel::getKernel(); $kernel->getProtocol1RuntimeGoalStateClient()->setKeepOpen($keepOpen); self::$_runtimeClient = $kernel->getRuntimeVersionManager()->getRuntimeClient(self::$_versionEndpoint); self::$_currentGoalState = self::$_runtimeClient->getCurrentGoalState(); self::$_currentEnvironmentData = self::$_runtimeClient->getRoleEnvironmentData(); } else { self::$_currentGoalState = self::$_runtimeClient->getCurrentGoalState(); self::$_currentEnvironmentData = self::$_runtimeClient->getRoleEnvironmentData(); } } catch (ChannelNotAvailableException $ex) { throw new RoleEnvironmentNotAvailableException(); } }