Skip to content

Commit 8da68f1

Browse files
committed
Merge pull request #785 from jasper-schneider/batchEnableDisable
Batch cmdlets for enabling/disabling jobs and job schedules
2 parents 6cfc251 + 88443f7 commit 8da68f1

22 files changed

+10057
-3349
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@
116116
<SpecificVersion>False</SpecificVersion>
117117
<HintPath>..\..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
118118
</Reference>
119-
<Reference Include="Microsoft.WindowsAzure.Testing, Version=1.0.5417.13285, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
120-
<SpecificVersion>False</SpecificVersion>
121-
<HintPath>..\..\..\packages\Hydra.SpecTestSupport.1.0.5417.13285-prerelease\lib\net45\Microsoft.WindowsAzure.Testing.dll</HintPath>
122-
</Reference>
123119
<Reference Include="Moq">
124120
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>
125121
</Reference>
@@ -171,6 +167,10 @@
171167
<Compile Include="Files\GetBatchRemoteDesktopProtocolFileCommandTests.cs" />
172168
<Compile Include="Files\GetBatchNodeFileCommandTests.cs" />
173169
<Compile Include="Files\GetBatchNodeFileContentCommandTests.cs" />
170+
<Compile Include="JobSchedules\DisableBatchJobScheduleCommandTests.cs" />
171+
<Compile Include="JobSchedules\EnableBatchJobScheduleCommandTests.cs" />
172+
<Compile Include="Jobs\DisableBatchJobCommandTests.cs" />
173+
<Compile Include="Jobs\EnableBatchJobCommandTests.cs" />
174174
<Compile Include="Jobs\GetBatchJobCommandTests.cs" />
175175
<Compile Include="Jobs\NewBatchJobCommandTests.cs" />
176176
<Compile Include="Jobs\RemoveBatchJobCommandTests.cs" />
@@ -354,6 +354,9 @@
354354
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobScheduleTests\TestDeleteJobSchedulePipeline.json">
355355
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
356356
</None>
357+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobScheduleTests\TestDisableAndEnableJobSchedule.json">
358+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
359+
</None>
357360
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobScheduleTests\TestGetJobScheduleById.json">
358361
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
359362
</None>
@@ -375,6 +378,9 @@
375378
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestDeleteJobPipeline.json">
376379
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
377380
</None>
381+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestDisableAndEnableJob.json">
382+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
383+
</None>
378384
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestGetJobById.json">
379385
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
380386
</None>
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 DisableBatchJobScheduleCommandTests
32+
{
33+
private DisableBatchJobScheduleCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public DisableBatchJobScheduleCommandTests()
38+
{
39+
batchClientMock = new Mock<BatchClient>();
40+
commandRuntimeMock = new Mock<ICommandRuntime>();
41+
cmdlet = new DisableBatchJobScheduleCommand()
42+
{
43+
CommandRuntime = commandRuntimeMock.Object,
44+
BatchClient = batchClientMock.Object,
45+
};
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void DisableJobScheduleParametersTest()
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 = "testJobSchedule";
59+
60+
// Don't go to the service on a Disable CloudJobSchedule call
61+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
62+
{
63+
BatchRequest<CloudJobScheduleDisableParameters, CloudJobScheduleDisableResponse> request =
64+
(BatchRequest<CloudJobScheduleDisableParameters, CloudJobScheduleDisableResponse>)baseRequest;
65+
66+
request.ServiceRequestFunc = (cancellationToken) =>
67+
{
68+
CloudJobScheduleDisableResponse response = new CloudJobScheduleDisableResponse();
69+
Task<CloudJobScheduleDisableResponse> 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: 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 EnableBatchJobScheduleCommandTests
32+
{
33+
private EnableBatchJobScheduleCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public EnableBatchJobScheduleCommandTests()
38+
{
39+
batchClientMock = new Mock<BatchClient>();
40+
commandRuntimeMock = new Mock<ICommandRuntime>();
41+
cmdlet = new EnableBatchJobScheduleCommand()
42+
{
43+
CommandRuntime = commandRuntimeMock.Object,
44+
BatchClient = batchClientMock.Object,
45+
};
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void EnableJobScheduleParametersTest()
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 = "testJobSchedule";
59+
60+
// Don't go to the service on an Enable CloudJobSchedule call
61+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
62+
{
63+
BatchRequest<CloudJobScheduleEnableParameters, CloudJobScheduleEnableResponse> request =
64+
(BatchRequest<CloudJobScheduleEnableParameters, CloudJobScheduleEnableResponse>)baseRequest;
65+
66+
request.ServiceRequestFunc = (cancellationToken) =>
67+
{
68+
CloudJobScheduleEnableResponse response = new CloudJobScheduleEnableResponse();
69+
Task<CloudJobScheduleEnableResponse> 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: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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.Common;
18+
using Microsoft.Azure.Batch.Protocol;
19+
using Microsoft.Azure.Batch.Protocol.Models;
20+
using Microsoft.Azure.Commands.Batch.Models;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Moq;
23+
using System.Collections.Generic;
24+
using System.Linq;
25+
using System.Management.Automation;
26+
using System.Threading.Tasks;
27+
using Xunit;
28+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
29+
30+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
31+
{
32+
public class DisableBatchJobCommandTests
33+
{
34+
private DisableBatchJobCommand cmdlet;
35+
private Mock<BatchClient> batchClientMock;
36+
private Mock<ICommandRuntime> commandRuntimeMock;
37+
38+
public DisableBatchJobCommandTests()
39+
{
40+
batchClientMock = new Mock<BatchClient>();
41+
commandRuntimeMock = new Mock<ICommandRuntime>();
42+
cmdlet = new DisableBatchJobCommand()
43+
{
44+
CommandRuntime = commandRuntimeMock.Object,
45+
BatchClient = batchClientMock.Object,
46+
};
47+
}
48+
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void DisableJobParametersTest()
52+
{
53+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
54+
cmdlet.BatchContext = context;
55+
cmdlet.Id = null;
56+
57+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
58+
59+
cmdlet.Id = "testJob";
60+
cmdlet.DisableJobOption = DisableJobOption.Terminate;
61+
62+
// Don't go to the service on a Disable CloudJob call
63+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
64+
{
65+
BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse> request =
66+
(BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse>)baseRequest;
67+
68+
request.ServiceRequestFunc = (cancellationToken) =>
69+
{
70+
CloudJobDisableResponse response = new CloudJobDisableResponse();
71+
Task<CloudJobDisableResponse> task = Task.FromResult(response);
72+
return task;
73+
};
74+
});
75+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
76+
77+
// Verify no exceptions when required parameter is set
78+
cmdlet.ExecuteCmdlet();
79+
}
80+
81+
[Fact]
82+
[Trait(Category.AcceptanceType, Category.CheckIn)]
83+
public void DisableJobRequestTest()
84+
{
85+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
86+
cmdlet.BatchContext = context;
87+
88+
DisableJobOption disableOption = DisableJobOption.Terminate;
89+
DisableJobOption requestDisableOption = DisableJobOption.Requeue;
90+
91+
cmdlet.Id = "testJob";
92+
cmdlet.DisableJobOption = disableOption;
93+
94+
// Don't go to the service on an Enable AutoScale call
95+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
96+
{
97+
BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse> request =
98+
(BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse>)baseRequest;
99+
100+
requestDisableOption = request.TypedParameters.DisableJobOption;
101+
102+
request.ServiceRequestFunc = (cancellationToken) =>
103+
{
104+
CloudJobDisableResponse response = new CloudJobDisableResponse();
105+
Task<CloudJobDisableResponse> task = Task.FromResult(response);
106+
return task;
107+
};
108+
});
109+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
110+
111+
cmdlet.ExecuteCmdlet();
112+
113+
// Verify that the job disable option was properly set on the outgoing request
114+
Assert.Equal(disableOption, requestDisableOption);
115+
}
116+
}
117+
}
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 EnableBatchJobCommandTests
32+
{
33+
private EnableBatchJobCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public EnableBatchJobCommandTests()
38+
{
39+
batchClientMock = new Mock<BatchClient>();
40+
commandRuntimeMock = new Mock<ICommandRuntime>();
41+
cmdlet = new EnableBatchJobCommand()
42+
{
43+
CommandRuntime = commandRuntimeMock.Object,
44+
BatchClient = batchClientMock.Object,
45+
};
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void EnableJobParametersTest()
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 = "testJob";
59+
60+
// Don't go to the service on an Enable CloudJob call
61+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
62+
{
63+
BatchRequest<CloudJobEnableParameters, CloudJobEnableResponse> request =
64+
(BatchRequest<CloudJobEnableParameters, CloudJobEnableResponse>)baseRequest;
65+
66+
request.ServiceRequestFunc = (cancellationToken) =>
67+
{
68+
CloudJobEnableResponse response = new CloudJobEnableResponse();
69+
Task<CloudJobEnableResponse> 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+
}

0 commit comments

Comments
 (0)