public async Task UpdateAnExistingPoolWithNewApplicationPackageReferences_AndChecksTheApplicationPackageReferencesIsOnThePool()
        {
            var poolId = "app-ref-test-2-" + Guid.NewGuid();

            Func <Task> test = async() =>
            {
                using (BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync())
                {
                    try
                    {
                        CloudPool pool = client.PoolOperations.CreatePool(poolId, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily));
                        await pool.CommitAsync().ConfigureAwait(false);

                        pool = await client.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(false);

                        Assert.Null(pool.ApplicationPackageReferences);

                        pool.ApplicationPackageReferences = new[] { new ApplicationPackageReference {
                                                                        ApplicationId = ApplicationId, Version = Version
                                                                    } };

                        await pool.CommitAsync().ConfigureAwait(false);

                        CloudPool updatedPool = await client.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(false);

                        ApplicationPackageReference apr = updatedPool.ApplicationPackageReferences.First();

                        Assert.Equal(ApplicationId, apr.ApplicationId);
                        Assert.Equal(Version, apr.Version);
                    }
                    finally
                    {
                        TestUtilities.DeletePoolIfExistsAsync(client, poolId).Wait();
                    }
                }
            };

            await SynchronizationContextHelper.RunTestAsync(test, LongTestTimeout);
        }
Beispiel #2
0
        public async Task IfAPoolSpecifiesANonExistentApplicationPackage_ThenCommittingThePoolThrowsAnException()
        {
            await SynchronizationContextHelper.RunTestAsync(async() =>
            {
                var poolId = "app-ref-test-3-" + Guid.NewGuid();
                using BatchClient client = TestUtilities.OpenBatchClientFromEnvironmentAsync().Result;
                CloudPool pool           = client.PoolOperations.CreatePool(poolId, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily));

                pool.ApplicationPackageReferences = new[] { new ApplicationPackageReference {
                                                                ApplicationId = "dud", Version = Version
                                                            } };

                await TestUtilities.AssertThrowsAsync <BatchException>(() => pool.CommitAsync()).ConfigureAwait(false);
            }, LongTestTimeout);
        }
Beispiel #3
0
        public async Task IfAPoolIsCommittedWithApplicationPackageReferences_ThenThoseReferencesArePersistedInTheService()
        {
            var poolId = "app-ref-test-1-" + Guid.NewGuid();

            async Task test()
            {
                using BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync();

                CloudPool newPool = null;

                try
                {
                    List <ApplicationSummary> applicationSummaries = await client.ApplicationOperations.ListApplicationSummaries().ToListAsync().ConfigureAwait(false);

                    foreach (var applicationSummary in applicationSummaries.Where(app => app.Id == ApplicationId))
                    {
                        Assert.True(true, string.Format("{0} was found.", applicationSummary.Id));
                    }
                    CloudPool pool = client.PoolOperations.CreatePool(poolId, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily));

                    pool.ApplicationPackageReferences = new[] { new ApplicationPackageReference {
                                                                    ApplicationId = ApplicationId, Version = Version
                                                                } };

                    await pool.CommitAsync().ConfigureAwait(false);

                    newPool = await client.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(false);

                    ApplicationPackageReference apr = newPool.ApplicationPackageReferences.First();

                    Assert.Equal(ApplicationId, apr.ApplicationId);
                    Assert.Equal(Version, apr.Version);
                }
                finally
                {
                    TestUtilities.DeletePoolIfExistsAsync(client, poolId).Wait();
                }
            }

            await SynchronizationContextHelper.RunTestAsync(test, LongTestTimeout);
        }
Beispiel #4
0
        public async Task UpdateAPoolWithNewApplicationPackages()
        {
            const string applicationId = "blender";
            const string version       = "beta";
            const string poolId        = "mock-pool";
            const string osFamily      = "3";

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(
                    baseRequest =>
                {
                    Protocol.BatchRequests.PoolGetBatchRequest request = (Protocol.BatchRequests.PoolGetBatchRequest)baseRequest;

                    request.ServiceRequestFunc = (token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders>
                        {
                            Body = new Protocol.Models.CloudPool
                            {
                                CurrentDedicatedNodes     = 4,
                                CloudServiceConfiguration = new Models.CloudServiceConfiguration(osFamily),
                                Id = poolId
                            }
                        };
                        return(Task.FromResult(response));
                    };
                });

                Microsoft.Azure.Batch.CloudPool cloudPool = client.PoolOperations.GetPool("pool-id", additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });

                // At this point the pool shouldn't have any application packages
                Assert.Null(cloudPool.ApplicationPackageReferences);

                cloudPool.ApplicationPackageReferences = new[]
                {
                    new Microsoft.Azure.Batch.ApplicationPackageReference()
                    {
                        ApplicationId = applicationId,
                        Version       = version
                    }
                };

                interceptor = new Protocol.RequestInterceptor(
                    baseRequest =>
                {
                    Protocol.BatchRequests.PoolUpdatePropertiesBatchRequest request =
                        (Protocol.BatchRequests.PoolUpdatePropertiesBatchRequest)baseRequest;

                    // Need to check to see if ApplicationPackageReferences is being populated.
                    Assert.Equal(applicationId, request.Parameters.ApplicationPackageReferences[0].ApplicationId);
                    Assert.Equal(version, request.Parameters.ApplicationPackageReferences[0].Version);

                    request.ServiceRequestFunc = token => Task.FromResult(new AzureOperationHeaderResponse <Models.PoolUpdatePropertiesHeaders>()
                    {
                        Response = new HttpResponseMessage(HttpStatusCode.NoContent)
                    });
                });

                // Updating application pool to contain packages.
                await cloudPool.CommitAsync(additionalBehaviors : new List <BatchClientBehavior> {
                    interceptor
                });
            }
        }