/** * @covers WindowsAzure\ServiceRuntime\Internal\FileInputChannel::getInputStream * @covers WindowsAzure\ServiceRuntime\Internal\FileInputChannel::closeInputStream */ public function testGetInputStream() { $rootDirectory = 'root'; $fileName = 'test.txt'; $fileContent = 'somecontent'; // Setup vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory($rootDirectory)); $file = vfsStream::newFile($fileName); $file->setContent($fileContent); vfsStreamWrapper::getRoot()->addChild($file); // Test $fileInputChannel = new FileInputChannel(); $inputStream = $fileInputChannel->getInputStream(vfsStream::url($rootDirectory . '/' . $fileName)); $inputChannelContents = stream_get_contents($inputStream); $this->assertEquals($fileContent, $inputChannelContents); $fileInputChannel->closeInputStream(); // invalid file $this->setExpectedException(get_class(new ChannelNotAvailableException())); $fileInputChannel->getInputStream(vfsStream::url($rootDirectory . '/' . 'fakeinput')); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\Protocol1RuntimeCurrentStateClient::setEndpoint * @covers WindowsAzure\ServiceRuntime\Internal\Protocol1RuntimeCurrentStateClient::setCurrentState */ public function testSetCurrentState() { // Setup $rootDirectory = 'root'; $fileName = 'test'; $fileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<CurrentState>' . '<StatusLease ClientId="clientId">' . '<Acquire>' . '<Incarnation>1</Incarnation>' . '<Status>Recycle</Status>' . '<Expiration>2000-01-01T00:00:00.0000000Z</Expiration>' . '</Acquire>' . '</StatusLease>' . '</CurrentState>'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $file = \vfsStream::newFile($fileName); \vfsStreamWrapper::getRoot()->addChild($file); $serializer = new XmlCurrentStateSerializer(); $fileOutputChannel = new FileOutputChannel(); $protocol1RuntimeCurrentStateClient = new Protocol1RuntimeCurrentStateClient($serializer, $fileOutputChannel); $protocol1RuntimeCurrentStateClient->setEndpoint(\vfsStream::url($rootDirectory . '/' . $fileName)); // Test $recycleState = new AcquireCurrentState('clientId', 1, CurrentStatus::RECYCLE, new \DateTime('2000-01-01', new \DateTimeZone('UTC'))); $protocol1RuntimeCurrentStateClient->setCurrentState($recycleState); $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); $inputChannelContents = stream_get_contents($fileInputStream); $this->assertEquals($fileContents, $inputChannelContents); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\FileOutputChannel::getOutputStream */ public function testGetOutputStream() { $rootDirectory = 'root'; $fileName = 'test.txt'; $fileContents = 'Hello World!'; // Setup \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $file = \vfsStream::newFile($fileName); \vfsStreamWrapper::getRoot()->addChild($file); // Test $fileOutputChannel = new FileOutputChannel(); $outputStream = $fileOutputChannel->getOutputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); // Write content to file fwrite($outputStream, $fileContents); fclose($outputStream); // Test file content $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); $inputChannelContents = stream_get_contents($fileInputStream); $this->assertEquals($fileContents, $inputChannelContents); }
/** * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::setStatus */ public function testSetStatusReady() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $currentStateFileName = 'test'; $fileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<CurrentState>' . '<StatusLease ClientId="' . RoleEnvironment::getClientId() . '">' . '<Acquire>' . '<Incarnation>1</Incarnation>' . '<Status>Started</Status>' . '<Expiration>2000-01-01T00:00:00.0000000Z</Expiration>' . '</Acquire>' . '</StatusLease>' . '</CurrentState>'; $currentStateFile = \vfsStream::newFile($currentStateFileName); \vfsStreamWrapper::getRoot()->addChild($currentStateFile); $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="deploymentId" 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); $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 . '/' . $currentStateFileName) . '</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 RoleEnvironment::setStatus(RoleInstanceStatus::READY, new \DateTime('2000-01-01', new \DateTimeZone('UTC'))); $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $currentStateFileName)); $inputChannelContents = stream_get_contents($fileInputStream); $this->assertEquals($fileContents, $inputChannelContents); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\XmlRoleEnvironmentDataDeserializer::_translateRoles * @covers WindowsAzure\ServiceRuntime\Internal\XmlRoleEnvironmentDataDeserializer::_translateRoleInstances */ public function testTranslateRoles_OneRoles() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); // Test multiple settings $fileName = 'roleenvironmentendpoint'; $fileContent = '<?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="92f5cd71a4c048ed94e1b130bd0c4639" emulated="false" />' . '<CurrentInstance id="role1" roleName="role1" faultDomain="0" updateDomain="0">' . '</CurrentInstance>' . '<Roles>' . '<Role name="role1">' . '<Instances>' . '<Instance id="deployment16(191).test.role1_IN_0" faultDomain="0" updateDomain="0">' . '<Endpoints>' . '<Endpoint name="MyInternalEndpoint1" address="127.255.0.0" port="20000" protocol="tcp" />' . '</Endpoints>' . '</Instance>' . '</Instances>' . '</Role>' . '</Roles>' . '</RoleEnvironment>'; $file = \vfsStream::newFile($fileName); $file->setContent($fileContent); \vfsStreamWrapper::getRoot()->addChild($file); $xmlRoleEnvironmentDataDeserializer = new XmlRoleEnvironmentDataDeserializer(); $inputChannel = new FileInputChannel(); $inputStream = $inputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); $roleEnvironmentData = $xmlRoleEnvironmentDataDeserializer->deserialize($inputStream); $this->assertNotEquals(null, $roleEnvironmentData); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\ChunkedGoalStateDeserializer::__construct * @covers WindowsAzure\ServiceRuntime\Internal\ChunkedGoalStateDeserializer::initialize * @covers WindowsAzure\ServiceRuntime\Internal\ChunkedGoalStateDeserializer::deserialize */ public function testDeserializeWithNewLineStart() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $roleEnvironmentPath = 'mypath'; $currentStateEndpoint = 'endpoint'; $incarnation = 1; $expectedState = 'started'; $fileName = 'file'; $fileContent = '<?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>' . $incarnation . '</Incarnation>' . '<ExpectedState>' . $expectedState . '</ExpectedState>' . '<RoleEnvironmentPath>' . $roleEnvironmentPath . '</RoleEnvironmentPath>' . '<CurrentStateEndpoint>' . $currentStateEndpoint . '</CurrentStateEndpoint>' . '<Deadline>9999-12-31T23:59:59.9999999</Deadline>' . '</GoalState>'; $fileContent = "\n" . dechex(strlen($fileContent)) . "\n" . $fileContent; $file = \vfsStream::newFile($fileName); $file->setContent($fileContent); \vfsStreamWrapper::getRoot()->addChild($file); $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); $chunkedGoalStateDeserializer = new ChunkedGoalStateDeserializer(); $chunkedGoalStateDeserializer->initialize($fileInputStream); $goalState = $chunkedGoalStateDeserializer->deserialize(); // Test $this->assertNotEquals(null, $goalState); $this->assertEquals($roleEnvironmentPath, $goalState->getEnvironmentPath()); $this->assertNotEquals(null, $goalState->getDeadline()); $this->assertEquals($currentStateEndpoint, $goalState->getCurrentStateEndpoint()); $this->assertEquals($incarnation, $goalState->getIncarnation()); $this->assertEquals($expectedState, $goalState->getExpectedState()); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\XmlCurrentStateSerializer::serialize */ public function testSerializeRelease() { // Setup $rootDirectory = 'root'; $fileName = 'test'; $fileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<CurrentState>' . '<StatusLease ClientId="clientId">' . '<Release/>' . '</StatusLease>' . '</CurrentState>'; // Setup vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory($rootDirectory)); $file = vfsStream::newFile($fileName); vfsStreamWrapper::getRoot()->addChild($file); // Test $fileOutputChannel = new FileOutputChannel(); $outputStream = $fileOutputChannel->getOutputStream(vfsStream::url($rootDirectory . '/' . $fileName)); $recycleState = new ReleaseCurrentState('clientId'); $xmlCurrentStateSerializer = new XmlCurrentStateSerializer(); $xmlCurrentStateSerializer->serialize($recycleState, $outputStream); fclose($outputStream); $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(vfsStream::url($rootDirectory . '/' . $fileName)); $inputChannelContents = stream_get_contents($fileInputStream); $this->assertEquals($fileContents, $inputChannelContents); }