Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
2015.06.05 version 0.9.3
2015.06.25 version 0.9.4
* Added Batch cmdlets
* Start-AzureBatchPoolResize
* Stop-AzureBatchPoolResize

2015.06.05 version 0.9.3
* Fixed bug in Websites cmdlets related to slots #454
* Fix bug in Set-AzureResource cmdlet #456
* Fix for new azure resource of Microsoft.Storage #457
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
<Compile Include="Pools\GetBatchPoolCommandTests.cs" />
<Compile Include="Pools\NewBatchPoolCommandTests.cs" />
<Compile Include="Pools\RemoveBatchPoolCommandTests.cs" />
<Compile Include="Pools\StartBatchPoolResizeCommandTests.cs" />
<Compile Include="Pools\StopBatchPoolResizeCommandTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScenarioTests\BatchAccountTests.cs" />
<Compile Include="ScenarioTests\BatchController.cs" />
Expand Down Expand Up @@ -339,6 +341,18 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestNewPool.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestResizePoolByName.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestResizePoolByPipeline.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestStopResizePoolByName.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestStopResizePoolByPipeline.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestCreateTask.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Batch.Protocol.Entities;
using Microsoft.Azure.Commands.Batch.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Pools
{
public class StartBatchPoolResizeCommandTests
{
private StartBatchPoolResizeCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

public StartBatchPoolResizeCommandTests()
{
batchClientMock = new Mock<BatchClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new StartBatchPoolResizeCommand()
{
CommandRuntime = commandRuntimeMock.Object,
BatchClient = batchClientMock.Object,
};
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void StartPoolResizeParametersTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.Name = null;

Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

cmdlet.Name = "testPool";

// Don't go to the service on a ResizePool call
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
{
if (request is ResizePoolRequest)
{
ResizePoolResponse response = new ResizePoolResponse();
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
return task;
}
return null;
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Verify no exceptions when required parameter is set
cmdlet.ExecuteCmdlet();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Pools
{
public class StopBatchPoolResizeCommandTests
{
private StopBatchPoolResizeCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

public StopBatchPoolResizeCommandTests()
{
batchClientMock = new Mock<BatchClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new StopBatchPoolResizeCommand()
{
CommandRuntime = commandRuntimeMock.Object,
BatchClient = batchClientMock.Object,
};
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void StopPoolResizeParametersTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.Name = null;

Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

cmdlet.Name = "testPool";

// Don't go to the service on a StopPoolResize call
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
{
if (request is StopPoolResizeRequest)
{
StopPoolResizeResponse response = new StopPoolResizeResponse();
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
return task;
}
return null;
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Verify no exceptions when required parameter is set
cmdlet.ExecuteCmdlet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Batch;
using Microsoft.Azure.Commands.Batch.Models;
using Microsoft.Azure.Test;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System.Collections.Generic;
Expand All @@ -24,6 +25,15 @@ namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
{
public class PoolTests
{
// NOTE: To save time on VM allocation when recording, some of tests assume the following:
// - A Batch account named 'pooltests' exists under the subscription being used for recording.
// - The following commands were run to create a pool, and all 3 VMs are allocated:
// $context = Get-AzureBatchAccountKeys "pooltests"
// New-AzureBatchPool -Name "testPool" -VMSize "small" -OSFamily "4" -TargetOSVersion "*" -TargetDedicated 3 -BatchContext $context

private const string commonAccountName = "pooltests";
private const string testPoolName = "testPool";

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNewPool()
Expand Down Expand Up @@ -224,6 +234,78 @@ public void TestDeletePoolPipeline()
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestResizePoolByName()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-ResizePoolByName '{0}' '{1}'", commonAccountName, testPoolName) }; },
() =>
{
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolName);
},
null,
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestResizePoolByPipeline()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-ResizePoolByPipeline '{0}' '{1}'", commonAccountName, testPoolName) }; },
() =>
{
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolName);
},
null,
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestStopResizePoolByName()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-StopResizePoolByName '{0}' '{1}'", commonAccountName, testPoolName) }; },
() =>
{
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolName);
},
null,
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestStopResizePoolByPipeline()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-StopResizePoolByPipeline '{0}' '{1}'", commonAccountName, testPoolName) }; },
() =>
{
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolName);
},
null,
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}
}

// Cmdlets that use the HTTP Recorder interceptor for use with scenario tests
Expand Down Expand Up @@ -256,4 +338,24 @@ public override void ExecuteCmdlet()
base.ExecuteCmdlet();
}
}

[Cmdlet(VerbsLifecycle.Start, "AzureBatchPoolResize_ST")]
public class StartBatchPoolResizeScenarioTestCommand : StartBatchPoolResizeCommand
{
public override void ExecuteCmdlet()
{
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
base.ExecuteCmdlet();
}
}

[Cmdlet(VerbsLifecycle.Stop, "AzureBatchPoolResize_ST")]
public class StopBatchPoolResizeScenarioTestCommand : StopBatchPoolResizeCommand
{
public override void ExecuteCmdlet()
{
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
base.ExecuteCmdlet();
}
}
}
Loading