Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

publish caching tests

  • Loading branch information...
commit bcd84b58dcca5b9610335502d13a95593a6ec2af 1 parent b39b723
markcowl authored
View
14 WindowsAzurePowershell/src/Management.ScenarioTest/CloudServiceTests/CloudServiceTests.cs
@@ -29,11 +29,23 @@ public CloudServiceTests()
}
- #region Remove-AzureService Scenario Tests
+ #region Publish-AzureServiceProject Scenario Tests
[TestMethod]
[TestCategory(Category.All)]
[TestCategory(Category.CloudService)]
+ public void TestPublishAzureCacheService()
+ {
+ RunPowerShellTest("Test-PublishCacheService");
+ }
+
+ #endregion
+
+ #region Remove-AzureService Scenario Tests
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.CloudService)]
public void TestRemoveAzureServiceWithInvalidCredentials()
{
RunPowerShellTest("Test-WithInvalidCredentials { Remove-AzureService $(Get-CloudServiceName) -Force }");
View
20 WindowsAzurePowershell/src/Management.ScenarioTest/Management.ScenarioTest.csproj
@@ -117,6 +117,12 @@
<Resource Include="Resources\Websites\Common.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
+ <None Include="Resources\CloudService\Cache\connman.tgz">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ <None Include="Resources\CloudService\Cache\mc.tgz">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
<None Include="Resources\Credentials.ps1" />
<None Include="Resources\Credstests.ps1" />
<None Include="Resources\CredUtils.ps1" />
@@ -160,6 +166,20 @@
<Name>Management</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Content Include="Resources\CloudService\Cache\index.js">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Resources\CloudService\Cache\requestHandlers.js">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Resources\CloudService\Cache\router.js">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Resources\CloudService\Cache\server.js">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
BIN  WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/Cache/connman.tgz
Binary file not shown
View
30 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/Cache/index.js
@@ -0,0 +1,30 @@
+var http = require("http");
+var port = process.env.port || 1337;
+var url = require("url");
+var mc = require("mc");
+var mcclient = new mc.Client('localhost_ClientRole');
+mcclient.connect(function() {
+ console.log("Connected to the localhost memcache on port 11211!");
+});
+
+
+function start(route, handle) {
+ function onRequest(request, response) {
+ var postData = "";
+ var pathname = url.parse(request.url).pathname;
+ console.log("Request for " + pathname + " received.");
+
+ request.setEncoding("utf8");
+ request.addListener("data", function (postDataChunk) {
+ postData += postDataChunk;
+ console.log("Received POST data chunk '" + postDataChunk + "'.");
+ });
+ request.addListener("end", function () {
+ route(handle, pathname, response, postData,mcclient);
+ });
+ }
+
+ http.createServer(onRequest).listen(port);
+ console.log("Server has started.");
+}
+exports.start = start;
View
BIN  WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/Cache/mc.tgz
Binary file not shown
View
59 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/Cache/requestHandlers.js
@@ -0,0 +1,59 @@
+var querystring = require("querystring");
+function get(response, postData, mcclient) {
+
+ response.writeHead(200, { "Content-Type": "text/html" });
+ response.write('<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /></head><body>');
+ var key = querystring.parse(postData).key;
+ mcclient.get(key, function (err, cacheresponse) {
+ if (!err) {
+ response.write('The Value With Key <b> ' + key + '</b> Is <b> ' + cacheresponse[key] + '</b></br>');
+ response.write('<a href="additem">Add New Item</a></br><a href="getitem">Get Existing Item</a></body></html>');
+ response.end();
+
+ } else {
+ response.write('Not Found or Something Went Wrong</br>');
+ response.write('<a href="additem">Add New Item</a></br><a href="getitem">Get Existing Item</a></body></html>');
+ response.end();
+ }
+ });
+
+}
+
+function add(response,postData,mcclient) {
+ var key = querystring.parse(postData).key;
+ var value = querystring.parse(postData).value;
+ mcclient.add(key, value, { flags: 0, exptime: 0 }, function (err, status) {
+ if (!err) {
+ response.writeHead(200, { "Content-Type": "text/html" });
+ response.write('<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /></head><body>');
+ response.write('Item Saved</br>');
+ response.write('<a href="additem">Add New Item</a></br><a href="getitem">Get Existing Item</a></body></html>');
+ response.end();
+
+ } else {
+ response.writeHead(200, { "Content-Type": "text/plain" });
+ response.write("Error saving to cache");
+ response.end();
+ }
+
+ });
+}
+
+function additem(response, postData, mcclient) {
+
+ response.writeHead(200, { "Content-Type": "text/html" });
+ response.write('<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /><form action="/add" method="post">Key <input name="key" type="text"/></br>Value <input name="value" type="text"/></br><input type="submit" value="Add To Cache" /></form></html>');
+ response.end();
+
+}
+function getitem(response, postData, mcclient) {
+
+ response.writeHead(200, { "Content-Type": "text/html" });
+ response.write('<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /><form action="/get" method="post">Key <input name="key" type="text"/></br><input type="submit" value="Get From Cache" /></form></html>');
+ response.end();
+
+}
+exports.get = get;
+exports.additem = additem;
+exports.getitem = getitem;
+exports.add = add;
View
12 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/Cache/router.js
@@ -0,0 +1,12 @@
+function route(handle, pathname, response, postData,mcclient) {
+ console.log("About to route a request for " + pathname);
+ if (typeof handle[pathname] === 'function') {
+ return handle[pathname](response,postData,mcclient);
+ } else {
+ console.log("No request handler found for " + pathname);
+ response.writeHead(404, { "Content-Type": "text/plain" });
+ response.write("404 Not found");
+ response.end();
+ }
+}
+exports.route = route;
View
11 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/Cache/server.js
@@ -0,0 +1,11 @@
+var index = require("./index");
+var router = require("./router");
+var requestHandlers = require("./requestHandlers");
+
+var handle = {}
+handle["/"] = requestHandlers.additem;
+handle["/get"] = requestHandlers.get;
+handle["/additem"] = requestHandlers.additem;
+handle["/getitem"] = requestHandlers.getitem;
+handle["/add"] = requestHandlers.add;
+index.start(router.route, handle);
View
13 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/CloudServiceTests.ps1
@@ -29,6 +29,19 @@ function Test-WithInvalidCredentials
Assert-Throws $cloudCmdlet "Call Set-AzureSubscription and Select-AzureSubscription first."
}
+########################################################################### Publish-AzureServiceProject Scenario Tests ###################################################################
+
+<#
+.SYNOPSIS
+Tests Publishing a Cache Service.
+#>
+
+function Test-PublishCacheService
+{
+ Verify-CloudService 1 {New-CacheCloudServiceProject $args[0]} {Verify-CacheApp $args[0].Url.ToString()}
+}
+
+
########################################################################### Remove-AzureService Scenario Tests ###########################################################################
<#
View
57 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/CloudService/Common.ps1
@@ -52,6 +52,31 @@ function New-CloudService
<#
.SYNOPSIS
+Creates cloud services and runs validation the count specified
+
+.PARAMETER count
+The number of cloud services to create.
+#>
+function Verify-CloudService
+{
+ param([int] $count, [ScriptBlock] $cloudServiceProject, [ScriptBlock] $verifier)
+ $success = $true
+ if ($cloudServiceProject -eq $null) { $cloudServiceProject = { New-TinyCloudServiceProject $args[0] } }
+ if ($verifier -eq $null) {$verifier = {return $true}}
+ 1..$count | % {
+ $name = Get-CloudServiceName;
+ Invoke-Command -ScriptBlock $cloudServiceProject -ArgumentList $name;
+ $service = Publish-AzureServiceProject -Force;
+ $global:createdCloudServices += $name;
+ Invoke-Command -ScriptBlock $verifier -ArgumentList $service -OutVariable $worked
+ $success = $success -and $worked
+ }
+
+ return $success
+}
+
+<#
+.SYNOPSIS
Removes all cloud services/storage accounts in the current subscription.
#>
function Initialize-CloudServiceTest
@@ -70,4 +95,36 @@ function New-TinyCloudServiceProject
New-AzureServiceProject $name
Add-AzureNodeWebRole
+}
+
+<#
+.SYNOPSIS
+Creates new cloud service project with a web role connected to a cache.
+#>
+function New-CacheCloudServiceProject
+{
+ param([string] $name)
+
+ New-AzureServiceProject $name
+ Add-AzureNodeWebRole ClientRole
+ copy ..\CloudService\Cache\*.js .\ClientRole\
+ cd .\ClientRole
+ npm install ..\..\CloudService\Cache\mc.tgz ..\..\CloudService\Cache\connman.tgz
+ cd ..
+ Add-AzureCacheWorkerRole CacheRole
+ Enable-AzureMemcacheRole ClientRole CacheRole
+}
+
+<#
+.SYNOPSIS
+Places and retrieves a key value pair from a cache app
+#>
+function Verify-CacheApp
+{
+ param([string]$uri)
+ $client = New-Object System.Net.WebClient
+ $client.BaseAddress = $uri
+ $toss = $client.UploadString("/add", "key=key1&value=value1")
+ $check = $client.UploadString("/get", "key=key1")
+ return $check.Contains("key1") -and $check.Contains("value1")
}
View
4 WindowsAzurePowershell/src/Scenario.testsettings
@@ -34,6 +34,10 @@
</WebTestRunConfiguration>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
+ <DataCollectors>
+ <DataCollector uri="datacollector://microsoft/CodeCoverage/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.CodeCoverage.CoveragePlugIn, Microsoft.VisualStudio.QualityTools.Plugins.CodeCoverage, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Code Coverage (Visual Studio 2010)">
+ </DataCollector>
+ </DataCollectors>
</AgentRule>
</Execution>
</TestSettings>
View
2  WindowsAzurePowershell/src/local.runsettings
@@ -40,7 +40,7 @@
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>True</DeploymentEnabled>
<ForcedLegacyMode>True</ForcedLegacyMode>
- <SettingsFile>.\local.testsettings</SettingsFile>
+ <SettingsFile>.\Scenario.testsettings</SettingsFile>
</MSTest>
Please sign in to comment.
Something went wrong with that request. Please try again.