public void ListComputeNodesMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list compute nodes without filters and a max count BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.Id = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] idsOfConstructedComputeNodes = new[] { "computeNode1", "computeNode2", "computeNode3" }; // Build some compute nodes instead of querying the service on a List ComputeNodes call RequestInterceptor interceptor = new RequestInterceptor((baseRequest) => { BatchRequest <ComputeNodeListParameters, ComputeNodeListResponse> request = (BatchRequest <ComputeNodeListParameters, ComputeNodeListResponse>)baseRequest; request.ServiceRequestFunc = (cancellationToken) => { ComputeNodeListResponse response = BatchTestHelpers.CreateComputeNodeListResponse(idsOfConstructedComputeNodes); Task <ComputeNodeListResponse> task = Task.FromResult(response); return(task); }; }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSComputeNode> pipeline = new List <PSComputeNode>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSComputeNode>())) .Callback <object>(c => pipeline.Add((PSComputeNode)c)); cmdlet.ExecuteCmdlet(); // Verify that the max count was respected Assert.Equal(maxCount, pipeline.Count); // Verify setting max count <= 0 doesn't return nothing cmdlet.MaxCount = -5; pipeline.Clear(); cmdlet.ExecuteCmdlet(); Assert.Equal(idsOfConstructedComputeNodes.Length, pipeline.Count); }
public void ListBatchComputeNodesByODataFilterTest() { // Setup cmdlet to list vms using an OData filter. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "pool"; cmdlet.Id = null; cmdlet.Filter = "state -eq 'idle'"; string[] idsOfConstructedComputeNodes = new[] { "computeNode1", "computeNode2" }; // Build some compute nodes instead of querying the service on a List ComputeNodes call RequestInterceptor interceptor = new RequestInterceptor((baseRequest) => { BatchRequest <ComputeNodeListParameters, ComputeNodeListResponse> request = (BatchRequest <ComputeNodeListParameters, ComputeNodeListResponse>)baseRequest; request.ServiceRequestFunc = (cancellationToken) => { ComputeNodeListResponse response = BatchTestHelpers.CreateComputeNodeListResponse(idsOfConstructedComputeNodes); Task <ComputeNodeListResponse> task = Task.FromResult(response); return(task); }; }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSComputeNode> pipeline = new List <PSComputeNode>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSComputeNode>())) .Callback <object>(c => pipeline.Add((PSComputeNode)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed compute nodes to the pipeline Assert.Equal(2, pipeline.Count); int computeNodeCount = 0; foreach (PSComputeNode c in pipeline) { Assert.True(idsOfConstructedComputeNodes.Contains(c.Id)); computeNodeCount++; } Assert.Equal(idsOfConstructedComputeNodes.Length, computeNodeCount); }
public void ListBatchComputeNodesWithoutFiltersTest() { // Setup cmdlet to list compute nodes without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.Id = null; cmdlet.Filter = null; string[] idsOfConstructedComputeNodes = new[] { "computeNode1", "computeNode2", "computeNode3" }; // Build some compute nodes instead of querying the service on a List ComputeNodes call AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> response = BatchTestHelpers.CreateComputeNodeListResponse(idsOfConstructedComputeNodes); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeListOptions, AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSComputeNode> pipeline = new List <PSComputeNode>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSComputeNode>())) .Callback <object>(c => pipeline.Add((PSComputeNode)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed compute nodes to the pipeline Assert.Equal(3, pipeline.Count); int computeNodeCount = 0; foreach (PSComputeNode c in pipeline) { Assert.Contains(c.Id, idsOfConstructedComputeNodes); computeNodeCount++; } Assert.Equal(idsOfConstructedComputeNodes.Length, computeNodeCount); }
public void WhenStartBatchComputeNodeServiceLogUploadCommandIsCalledWithComputeNode_ShouldSucceed() { // First get a fake tvm BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); getComputeNodeCommand.BatchContext = context; getComputeNodeCommand.PoolId = "Pool1"; getComputeNodeCommand.Id = null; getComputeNodeCommand.Filter = null; AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> response1 = BatchTestHelpers.CreateComputeNodeListResponse(new[] { "tvm1" }); RequestInterceptor interceptor1 = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeListOptions, AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> >(response1); var computeNodes = new List <PSComputeNode>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSComputeNode>())) .Callback <object>(c => computeNodes.Add((PSComputeNode)c)); getComputeNodeCommand.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor1 }; getComputeNodeCommand.ExecuteCmdlet(); // test StartBatchComputeNodeServiceLogUploadCommand startComputeNodeServiceLogUploadCommand.BatchContext = context; startComputeNodeServiceLogUploadCommand.ComputeNode = computeNodes[0]; startComputeNodeServiceLogUploadCommand.ContainerUrl = fakeUrl; var utcNow = DateTime.UtcNow; startComputeNodeServiceLogUploadCommand.StartTime = utcNow.AddDays(-1); startComputeNodeServiceLogUploadCommand.EndTime = utcNow; const int numberOfFilesUploaded = 2; const string virtualDirectoryName = "pool1/tvm"; AzureOperationResponse <ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders> response2 = BatchTestHelpers.CreateComputeNodeServiceLogsAddResponse(numberOfFilesUploaded, virtualDirectoryName); RequestInterceptor interceptor2 = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeUploadBatchServiceLogsOptions, AzureOperationResponse <ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders> >(response2); startComputeNodeServiceLogUploadCommand.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor2 }; // Setup the cmdlet to write pipeline output to a list that can be examined later PSStartComputeNodeServiceLogUploadResult result = null; commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSStartComputeNodeServiceLogUploadResult>())).Callback <object>(c => result = (PSStartComputeNodeServiceLogUploadResult)c); startComputeNodeServiceLogUploadCommand.ExecuteCmdlet(); Assert.NotNull(result); Assert.Equal(result.NumberOfFilesUploaded, numberOfFilesUploaded); Assert.Equal(result.VirtualDirectoryName, virtualDirectoryName); }
public void ListComputeNodesMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list compute nodes without filters and a max count BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.Id = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] idsOfConstructedComputeNodes = new[] { "computeNode1", "computeNode2", "computeNode3" }; // Build some compute nodes instead of querying the service on a List ComputeNodes call AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> response = BatchTestHelpers.CreateComputeNodeListResponse(idsOfConstructedComputeNodes); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeListOptions, AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSComputeNode> pipeline = new List <PSComputeNode>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSComputeNode>())) .Callback <object>(c => pipeline.Add((PSComputeNode)c)); cmdlet.ExecuteCmdlet(); // Verify that the max count was respected Assert.Equal(maxCount, pipeline.Count); // Verify setting max count <= 0 doesn't return nothing cmdlet.MaxCount = -5; pipeline.Clear(); cmdlet.ExecuteCmdlet(); Assert.Equal(idsOfConstructedComputeNodes.Length, pipeline.Count); }