Skip to content

Commit 2e70e4e

Browse files
committed
Merge pull request Azure#737 from jasper-schneider/autoscale
Batch autoscale cmdlets
2 parents c3a8174 + 801d736 commit 2e70e4e

24 files changed

+10627
-2
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,14 @@
173173
<Compile Include="Jobs\NewBatchJobCommandTests.cs" />
174174
<Compile Include="Jobs\RemoveBatchJobCommandTests.cs" />
175175
<Compile Include="Models\BatchAccountContextTest.cs" />
176+
<Compile Include="Pools\DisableBatchAutoScaleCommandTests.cs" />
177+
<Compile Include="Pools\EnableBatchAutoScaleCommandTests.cs" />
176178
<Compile Include="Pools\GetBatchPoolCommandTests.cs" />
177179
<Compile Include="Pools\NewBatchPoolCommandTests.cs" />
178180
<Compile Include="Pools\RemoveBatchPoolCommandTests.cs" />
179181
<Compile Include="Pools\StartBatchPoolResizeCommandTests.cs" />
180182
<Compile Include="Pools\StopBatchPoolResizeCommandTests.cs" />
183+
<Compile Include="Pools\TestBatchAutoScaleCommandTests.cs" />
181184
<Compile Include="Properties\AssemblyInfo.cs" />
182185
<Compile Include="ScenarioTests\BatchAccountTests.cs" />
183186
<Compile Include="ScenarioTests\BatchController.cs" />
@@ -381,6 +384,24 @@
381384
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDeletePoolPipeline.json">
382385
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
383386
</None>
387+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDisableAutoScaleById.json">
388+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
389+
</None>
390+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDisableAutoScaleByPipeline.json">
391+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
392+
</None>
393+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestEnableAutoScaleById.json">
394+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
395+
</None>
396+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestEnableAutoScaleByPipeline.json">
397+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
398+
</None>
399+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestEvaluateAutoScaleById.json">
400+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
401+
</None>
402+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestEvaluateAutoScaleByPipeline.json">
403+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
404+
</None>
384405
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestGetPoolById.json">
385406
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
386407
</None>
@@ -479,4 +500,4 @@
479500
<Target Name="AfterBuild">
480501
</Target>
481502
-->
482-
</Project>
503+
</Project>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.Azure.Batch.Protocol.Models;
19+
using Microsoft.Azure.Commands.Batch.Models;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21+
using Moq;
22+
using System.Collections.Generic;
23+
using System.Linq;
24+
using System.Management.Automation;
25+
using System.Threading.Tasks;
26+
using Xunit;
27+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
28+
29+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
30+
{
31+
public class DisableBatchAutoScaleCommandTests
32+
{
33+
private DisableBatchAutoScaleCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public DisableBatchAutoScaleCommandTests()
38+
{
39+
batchClientMock = new Mock<BatchClient>();
40+
commandRuntimeMock = new Mock<ICommandRuntime>();
41+
cmdlet = new DisableBatchAutoScaleCommand()
42+
{
43+
CommandRuntime = commandRuntimeMock.Object,
44+
BatchClient = batchClientMock.Object,
45+
};
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void DisableAutoScaleParametersTest()
51+
{
52+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
53+
cmdlet.BatchContext = context;
54+
cmdlet.Id = null;
55+
56+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
57+
58+
cmdlet.Id = "testPool";
59+
60+
// Don't go to the service on an Disable AutoScale call
61+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
62+
{
63+
BatchRequest<CloudPoolDisableAutoScaleParameters, CloudPoolDisableAutoScaleResponse> request =
64+
(BatchRequest<CloudPoolDisableAutoScaleParameters, CloudPoolDisableAutoScaleResponse>)baseRequest;
65+
66+
request.ServiceRequestFunc = (cancellationToken) =>
67+
{
68+
CloudPoolDisableAutoScaleResponse response = new CloudPoolDisableAutoScaleResponse();
69+
Task<CloudPoolDisableAutoScaleResponse> task = Task.FromResult(response);
70+
return task;
71+
};
72+
});
73+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
74+
75+
// Verify no exceptions when required parameter is set
76+
cmdlet.ExecuteCmdlet();
77+
}
78+
}
79+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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.Azure.Batch.Protocol.Models;
19+
using Microsoft.Azure.Commands.Batch.Models;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21+
using Moq;
22+
using System.Collections.Generic;
23+
using System.Linq;
24+
using System.Management.Automation;
25+
using System.Threading.Tasks;
26+
using Xunit;
27+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
28+
29+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
30+
{
31+
public class EnableBatchAutoScaleCommandTests
32+
{
33+
private EnableBatchAutoScaleCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public EnableBatchAutoScaleCommandTests()
38+
{
39+
batchClientMock = new Mock<BatchClient>();
40+
commandRuntimeMock = new Mock<ICommandRuntime>();
41+
cmdlet = new EnableBatchAutoScaleCommand()
42+
{
43+
CommandRuntime = commandRuntimeMock.Object,
44+
BatchClient = batchClientMock.Object,
45+
};
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void EnableAutoScaleParametersTest()
51+
{
52+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
53+
cmdlet.BatchContext = context;
54+
cmdlet.Id = null;
55+
56+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
57+
58+
cmdlet.Id = "testPool";
59+
60+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
61+
62+
cmdlet.AutoScaleFormula = "formula";
63+
64+
// Don't go to the service on an Enable AutoScale call
65+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
66+
{
67+
BatchRequest<CloudPoolEnableAutoScaleParameters, CloudPoolEnableAutoScaleResponse> request =
68+
(BatchRequest<CloudPoolEnableAutoScaleParameters, CloudPoolEnableAutoScaleResponse>)baseRequest;
69+
70+
request.ServiceRequestFunc = (cancellationToken) =>
71+
{
72+
CloudPoolEnableAutoScaleResponse response = new CloudPoolEnableAutoScaleResponse();
73+
Task<CloudPoolEnableAutoScaleResponse> task = Task.FromResult(response);
74+
return task;
75+
};
76+
});
77+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
78+
79+
// Verify no exceptions when required parameter is set
80+
cmdlet.ExecuteCmdlet();
81+
}
82+
83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void EnableAutoScaleRequestTest()
86+
{
87+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
88+
cmdlet.BatchContext = context;
89+
90+
string formula = "$TargetDedicated=2";
91+
string requestFormula = null;
92+
93+
cmdlet.Id = "testPool";
94+
cmdlet.AutoScaleFormula = formula;
95+
96+
// Don't go to the service on an Enable AutoScale call
97+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
98+
{
99+
BatchRequest<CloudPoolEnableAutoScaleParameters, CloudPoolEnableAutoScaleResponse> request =
100+
(BatchRequest<CloudPoolEnableAutoScaleParameters, CloudPoolEnableAutoScaleResponse>)baseRequest;
101+
102+
requestFormula = request.TypedParameters.AutoScaleFormula;
103+
104+
request.ServiceRequestFunc = (cancellationToken) =>
105+
{
106+
CloudPoolEnableAutoScaleResponse response = new CloudPoolEnableAutoScaleResponse();
107+
Task<CloudPoolEnableAutoScaleResponse> task = Task.FromResult(response);
108+
return task;
109+
};
110+
});
111+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
112+
113+
cmdlet.ExecuteCmdlet();
114+
115+
// Verify that the autoscale formula was properly set on the outgoing request
116+
Assert.Equal(formula, requestFormula);
117+
}
118+
}
119+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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.Azure.Batch.Protocol.Models;
19+
using Microsoft.Azure.Commands.Batch.Models;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21+
using Moq;
22+
using System.Collections.Generic;
23+
using System.Linq;
24+
using System.Management.Automation;
25+
using System.Threading.Tasks;
26+
using Xunit;
27+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
28+
29+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
30+
{
31+
public class TestBatchAutoScaleCommandTests
32+
{
33+
private TestBatchAutoScaleCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public TestBatchAutoScaleCommandTests()
38+
{
39+
batchClientMock = new Mock<BatchClient>();
40+
commandRuntimeMock = new Mock<ICommandRuntime>();
41+
cmdlet = new TestBatchAutoScaleCommand()
42+
{
43+
CommandRuntime = commandRuntimeMock.Object,
44+
BatchClient = batchClientMock.Object,
45+
};
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void TestAutoScaleParametersTest()
51+
{
52+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
53+
cmdlet.BatchContext = context;
54+
cmdlet.Id = null;
55+
56+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
57+
58+
cmdlet.Id = "testPool";
59+
60+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
61+
62+
cmdlet.AutoScaleFormula = "formula";
63+
64+
// Don't go to the service on an Evaluate AutoScale call
65+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
66+
{
67+
BatchRequest<CloudPoolEvaluateAutoScaleParameters, CloudPoolEvaluateAutoScaleResponse> request =
68+
(BatchRequest<CloudPoolEvaluateAutoScaleParameters, CloudPoolEvaluateAutoScaleResponse>)baseRequest;
69+
70+
request.ServiceRequestFunc = (cancellationToken) =>
71+
{
72+
CloudPoolEvaluateAutoScaleResponse response = new CloudPoolEvaluateAutoScaleResponse();
73+
Task<CloudPoolEvaluateAutoScaleResponse> task = Task.FromResult(response);
74+
return task;
75+
};
76+
});
77+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
78+
79+
// Verify no exceptions when required parameter is set
80+
cmdlet.ExecuteCmdlet();
81+
}
82+
83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void TestAutoScaleRequestTest()
86+
{
87+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
88+
cmdlet.BatchContext = context;
89+
90+
string formula = "$TargetDedicated=2";
91+
string requestFormula = null;
92+
93+
cmdlet.Id = "testPool";
94+
cmdlet.AutoScaleFormula = formula;
95+
96+
// Don't go to the service on an Evaluate AutoScale call
97+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
98+
{
99+
BatchRequest<CloudPoolEvaluateAutoScaleParameters, CloudPoolEvaluateAutoScaleResponse> request =
100+
(BatchRequest<CloudPoolEvaluateAutoScaleParameters, CloudPoolEvaluateAutoScaleResponse>)baseRequest;
101+
102+
requestFormula = request.TypedParameters.AutoScaleFormula;
103+
104+
request.ServiceRequestFunc = (cancellationToken) =>
105+
{
106+
CloudPoolEvaluateAutoScaleResponse response = new CloudPoolEvaluateAutoScaleResponse();
107+
Task<CloudPoolEvaluateAutoScaleResponse> task = Task.FromResult(response);
108+
return task;
109+
};
110+
});
111+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
112+
113+
cmdlet.ExecuteCmdlet();
114+
115+
// Verify that the autoscale formula was properly set on the outgoing request
116+
Assert.Equal(formula, requestFormula);
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)