Skip to content

Commit bde80c2

Browse files
author
jasper-schneider
committed
Stop-AzureBatchPoolResize with tests and help
1 parent 7af0782 commit bde80c2

File tree

13 files changed

+1626
-4
lines changed

13 files changed

+1626
-4
lines changed

src/ResourceManager/Batch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
<Compile Include="Pools\NewBatchPoolCommandTests.cs" />
168168
<Compile Include="Pools\RemoveBatchPoolCommandTests.cs" />
169169
<Compile Include="Pools\StartBatchPoolResizeCommandTests.cs" />
170+
<Compile Include="Pools\StopBatchPoolResizeCommandTests.cs" />
170171
<Compile Include="Properties\AssemblyInfo.cs" />
171172
<Compile Include="ScenarioTests\BatchAccountTests.cs" />
172173
<Compile Include="ScenarioTests\BatchController.cs" />
@@ -346,6 +347,12 @@
346347
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestResizePoolByPipeline.json">
347348
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
348349
</None>
350+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestStopResizePoolByName.json">
351+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
352+
</None>
353+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestStopResizePoolByPipeline.json">
354+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
355+
</None>
349356
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestCreateTask.json">
350357
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
351358
</None>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Batch.Protocol;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Moq;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Management.Automation;
23+
using System.Threading.Tasks;
24+
using Xunit;
25+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
26+
27+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
28+
{
29+
public class StopBatchPoolResizeCommandTests
30+
{
31+
private StopBatchPoolResizeCommand cmdlet;
32+
private Mock<BatchClient> batchClientMock;
33+
private Mock<ICommandRuntime> commandRuntimeMock;
34+
35+
public StopBatchPoolResizeCommandTests()
36+
{
37+
batchClientMock = new Mock<BatchClient>();
38+
commandRuntimeMock = new Mock<ICommandRuntime>();
39+
cmdlet = new StopBatchPoolResizeCommand()
40+
{
41+
CommandRuntime = commandRuntimeMock.Object,
42+
BatchClient = batchClientMock.Object,
43+
};
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
public void StopPoolResizeParametersTest()
49+
{
50+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
51+
cmdlet.BatchContext = context;
52+
cmdlet.Name = null;
53+
54+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
55+
56+
cmdlet.Name = "testPool";
57+
58+
// Don't go to the service on a StopPoolResize call
59+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
60+
{
61+
if (request is StopPoolResizeRequest)
62+
{
63+
StopPoolResizeResponse response = new StopPoolResizeResponse();
64+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
65+
return task;
66+
}
67+
return null;
68+
});
69+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
70+
71+
// Verify no exceptions when required parameter is set
72+
cmdlet.ExecuteCmdlet();
73+
}
74+
}
75+
}

src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/PoolTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,42 @@ public void TestResizePoolByPipeline()
270270
TestUtilities.GetCallingClass(),
271271
TestUtilities.GetCurrentMethodName());
272272
}
273+
274+
[Fact]
275+
[Trait(Category.AcceptanceType, Category.CheckIn)]
276+
public void TestStopResizePoolByName()
277+
{
278+
BatchController controller = BatchController.NewInstance;
279+
BatchAccountContext context = null;
280+
controller.RunPsTestWorkflow(
281+
() => { return new string[] { string.Format("Test-StopResizePoolByName '{0}' '{1}'", commonAccountName, testPoolName) }; },
282+
() =>
283+
{
284+
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
285+
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolName);
286+
},
287+
null,
288+
TestUtilities.GetCallingClass(),
289+
TestUtilities.GetCurrentMethodName());
290+
}
291+
292+
[Fact]
293+
[Trait(Category.AcceptanceType, Category.CheckIn)]
294+
public void TestStopResizePoolByPipeline()
295+
{
296+
BatchController controller = BatchController.NewInstance;
297+
BatchAccountContext context = null;
298+
controller.RunPsTestWorkflow(
299+
() => { return new string[] { string.Format("Test-StopResizePoolByPipeline '{0}' '{1}'", commonAccountName, testPoolName) }; },
300+
() =>
301+
{
302+
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
303+
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, testPoolName);
304+
},
305+
null,
306+
TestUtilities.GetCallingClass(),
307+
TestUtilities.GetCurrentMethodName());
308+
}
273309
}
274310

275311
// Cmdlets that use the HTTP Recorder interceptor for use with scenario tests
@@ -312,4 +348,14 @@ public override void ExecuteCmdlet()
312348
base.ExecuteCmdlet();
313349
}
314350
}
351+
352+
[Cmdlet(VerbsLifecycle.Stop, "AzureBatchPoolResize_ST")]
353+
public class StopBatchPoolResizeScenarioTestCommand : StopBatchPoolResizeCommand
354+
{
355+
public override void ExecuteCmdlet()
356+
{
357+
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
358+
base.ExecuteCmdlet();
359+
}
360+
}
315361
}

src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/PoolTests.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,50 @@ function Test-ResizePoolByPipeline
228228
# Verify the TargetDedicated property was updated
229229
$pool = Get-AzureBatchPool_ST -Name $poolName -BatchContext $context
230230
Assert-AreEqual $newTargetDedicated $pool.TargetDedicated
231+
}
232+
233+
<#
234+
.SYNOPSIS
235+
Tests stopping a pool resize operation using the pool name
236+
#>
237+
function Test-StopResizePoolByName
238+
{
239+
param([string]$accountName, [string]$poolName)
240+
241+
$context = Get-AzureBatchAccountKeys -Name $accountName
242+
243+
# Start a resize and then stop it
244+
$pool = Get-AzureBatchPool_ST -Name $poolName -BatchContext $context
245+
$initialTargetDedicated = $pool.TargetDedicated
246+
247+
$newTargetDedicated = $initialTargetDedicated + 5
248+
Start-AzureBatchPoolResize_ST -Name $poolName -TargetDedicated $newTargetDedicated -BatchContext $context
249+
Stop-AzureBatchPoolResize_ST -Name $poolName -BatchContext $context
250+
251+
# Verify the AllocationState changed to Stopping
252+
$pool = Get-AzureBatchPool_ST -Name $poolName -BatchContext $context
253+
Assert-AreEqual 'Stopping' $pool.AllocationState
254+
}
255+
256+
<#
257+
.SYNOPSIS
258+
Tests stopping a pool resize operation using the pipeline
259+
#>
260+
function Test-StopResizePoolByPipeline
261+
{
262+
param([string]$accountName, [string]$poolName)
263+
264+
$context = Get-AzureBatchAccountKeys -Name $accountName
265+
266+
# Start a resize and then stop it
267+
$pool = Get-AzureBatchPool_ST -Name $poolName -BatchContext $context
268+
$initialTargetDedicated = $pool.TargetDedicated
269+
270+
$newTargetDedicated = $initialTargetDedicated + 5
271+
$pool | Start-AzureBatchPoolResize_ST -TargetDedicated $newTargetDedicated -BatchContext $context
272+
$pool | Stop-AzureBatchPoolResize_ST -BatchContext $context
273+
274+
# Verify the AllocationState changed to Stopping
275+
$pool = Get-AzureBatchPool_ST -Name $poolName -BatchContext $context
276+
Assert-AreEqual 'Stopping' $pool.AllocationState
231277
}

0 commit comments

Comments
 (0)