-
Notifications
You must be signed in to change notification settings - Fork 4k
Batch first OM based cmdlet #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6aa12e3
WORK:3301271 - Data models for Batch cmdlets
134d229
WORK:3312195 - PSH - Get-AzureBatchWorkItem cmdlet and infrastructure
14cb583
Merge changes from upstream dev branch
f903d1f
Remove XUnit NuGet reference for now
a03fd92
Remove model generator tool
52a3942
Incorporate pull request feedback
c621d10
Incorporate pull request feedback
45ba099
Merge remote-tracking branch 'upstream/dev' into firstcmd
379a4a7
Merge latest changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
src/ResourceManager/Batch/Commands.Batch.Test/WorkItems/GetBatchWorkItemCommandTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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 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; | ||
|
||
namespace Microsoft.Azure.Commands.Batch.Test.WorkItems | ||
{ | ||
public class GetBatchWorkItemCommandTests | ||
{ | ||
private GetBatchWorkItemCommand cmdlet; | ||
private Mock<BatchClient> batchClientMock; | ||
private Mock<ICommandRuntime> commandRuntimeMock; | ||
|
||
public GetBatchWorkItemCommandTests() | ||
{ | ||
batchClientMock = new Mock<BatchClient>(); | ||
commandRuntimeMock = new Mock<ICommandRuntime>(); | ||
cmdlet = new GetBatchWorkItemCommand() | ||
{ | ||
CommandRuntime = commandRuntimeMock.Object, | ||
BatchClient = batchClientMock.Object, | ||
}; | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void GetBatchWorkItemTest() | ||
{ | ||
// Setup cmdlet to get a WorkItem by name | ||
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); | ||
cmdlet.BatchContext = context; | ||
cmdlet.Name = "testWorkItem"; | ||
cmdlet.Filter = null; | ||
|
||
// Build a WorkItem instead of querying the service on a GetWorkItem call | ||
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => | ||
{ | ||
if (request is GetWorkItemRequest) | ||
{ | ||
GetWorkItemResponse response = BatchTestHelpers.CreateGetWorkItemResponse(cmdlet.Name); | ||
Task<object> task = Task<object>.Factory.StartNew(() => { return response; }); | ||
return task; | ||
} | ||
return null; | ||
}); | ||
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor }; | ||
|
||
// Setup the cmdlet to write pipeline output to a list that can be examined later | ||
List<PSCloudWorkItem> pipeline = new List<PSCloudWorkItem>(); | ||
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSCloudWorkItem>())).Callback<object>(w => pipeline.Add((PSCloudWorkItem)w)); | ||
|
||
cmdlet.ExecuteCmdlet(); | ||
|
||
// Verify that the cmdlet wrote the WorkItem returned from the OM to the pipeline | ||
Assert.Equal(1, pipeline.Count); | ||
Assert.Equal(cmdlet.Name, pipeline[0].Name); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void ListBatchWorkItemByODataFilterTest() | ||
{ | ||
// Setup cmdlet to list WorkItems using an OData filter | ||
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); | ||
cmdlet.BatchContext = context; | ||
cmdlet.Name = null; | ||
cmdlet.Filter = "startswith(name,'test')"; | ||
|
||
string[] namesOfConstructedWorkItems = new[] {"test1", "test2"}; | ||
|
||
// Build some WorkItems instead of querying the service on a ListWorkItems call | ||
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => | ||
{ | ||
if (request is ListWorkItemsRequest) | ||
{ | ||
ListWorkItemsResponse response = BatchTestHelpers.CreateListWorkItemsResponse(namesOfConstructedWorkItems); | ||
Task<object> task = Task<object>.Factory.StartNew(() => { return response; }); | ||
return task; | ||
} | ||
return null; | ||
}); | ||
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor }; | ||
|
||
// Setup the cmdlet to write pipeline output to a list that can be examined later | ||
List<PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>> pipeline = new List<PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>>(); | ||
commandRuntimeMock.Setup(r => | ||
r.WriteObject(It.IsAny<PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>>())) | ||
.Callback<object>(w => pipeline.Add((PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>)w)); | ||
|
||
cmdlet.ExecuteCmdlet(); | ||
|
||
// Verify that the cmdlet wrote the enumerator to the pipeline and that it contains the constructed WorkItems | ||
Assert.Equal(1, pipeline.Count); | ||
int workItemCount = 0; | ||
foreach (PSCloudWorkItem w in pipeline[0]) | ||
{ | ||
Assert.True(namesOfConstructedWorkItems.Contains(w.Name)); | ||
workItemCount++; | ||
} | ||
Assert.Equal(namesOfConstructedWorkItems.Length, workItemCount); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void ListBatchWorkItemWithoutFiltersTest() | ||
{ | ||
// Setup cmdlet to list WorkItems without filters | ||
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); | ||
cmdlet.BatchContext = context; | ||
cmdlet.Name = null; | ||
cmdlet.Filter = null; | ||
|
||
string[] namesOfConstructedWorkItems = new[] { "name1", "name2", "name3" }; | ||
|
||
// Build some WorkItems instead of querying the service on a ListWorkItems call | ||
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => | ||
{ | ||
if (request is ListWorkItemsRequest) | ||
{ | ||
ListWorkItemsResponse response = BatchTestHelpers.CreateListWorkItemsResponse(namesOfConstructedWorkItems); | ||
Task<object> task = Task<object>.Factory.StartNew(() => { return response; }); | ||
return task; | ||
} | ||
return null; | ||
}); | ||
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor }; | ||
|
||
// Setup the cmdlet to write pipeline output to a list that can be examined later | ||
List<PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>> pipeline = new List<PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>>(); | ||
commandRuntimeMock.Setup(r => | ||
r.WriteObject(It.IsAny<PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>>())) | ||
.Callback<object>(w => pipeline.Add((PSAsyncEnumerable<PSCloudWorkItem, ICloudWorkItem>)w)); | ||
|
||
cmdlet.ExecuteCmdlet(); | ||
|
||
// Verify that the cmdlet wrote the enumerator to the pipeline and that it contains the constructed WorkItems | ||
Assert.Equal(1, pipeline.Count); | ||
int workItemCount = 0; | ||
foreach (PSCloudWorkItem w in pipeline[0]) | ||
{ | ||
Assert.True(namesOfConstructedWorkItems.Contains(w.Name)); | ||
workItemCount++; | ||
} | ||
Assert.Equal(namesOfConstructedWorkItems.Length, workItemCount); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why such an old version of storage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Batch OM (in the Microsoft.Azure.Batch NuGet package) was built on the older version. There were breaking changes in the newest version of the storage library, so the owners of the Batch OM opted to stay on the older version for the time being.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh. There should be an issue filed to address the breaking changes there and move to something more current.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worse than this - I don't believe we can accept this without the OM upgrading to staorage 4.0. There will be confliucts with the other resources modules and too much possibility for regression