public async Task GetSetManagerTests(string storageConnectionString, string siteName) { if (string.IsNullOrEmpty(storageConnectionString)) { return; } AppServiceSettings.StorageConnectionString = storageConnectionString; AppServiceSettings.SiteName = siteName; AppServiceSettings.WorkerName = "127.0.0.1"; AppServiceSettings.HomeStampName = "waws-prod-stamp-001"; AppServiceSettings.CurrentStampName = "waws-prod-stamp-001"; var worker = new AppServiceWorkerInfo { PartitionKey = AppServiceSettings.WorkerPartitionKey, RowKey = AppServiceSettings.GetWorkerRowKey(AppServiceSettings.CurrentStampName, AppServiceSettings.WorkerName), StampName = AppServiceSettings.CurrentStampName, WorkerName = AppServiceSettings.WorkerName, LoadFactor = 55 }; try { var table = AppServiceWorkerTable.Instance; // intialize await DeleteAllWorkers(table); var current = await table.GetManager(); Assert.Null(current); // set manager await table.AddOrUpdate(worker); await table.SetManager(worker); current = await table.GetManager(); Assert.True(ScaleUtils.WorkerEquals(worker, current)); // delete await table.Delete(worker); current = await table.GetManager(); Assert.Null(current); } finally { ResetEnvironment(); } }
public async Task PingWorkerTests(HttpStatusCode statusCode, string reasonPhrase, bool expected, HttpRequestException expectedException) { var activityId = Guid.NewGuid().ToString(); var mockHttpMessageHandler = new MockHttpMessageHandler(statusCode, reasonPhrase); AppServiceSettings.SiteName = Environment.MachineName.ToLower(); AppServiceSettings.HostName = Environment.MachineName.ToLower() + ".azurewebsites.net"; AppServiceSettings.WorkerName = "127.0.0.1"; AppServiceSettings.HomeStampName = "waws-prod-home-stamp"; AppServiceSettings.CurrentStampName = "waws-prod-slave-stamp"; AppServiceSettings.RuntimeEncryptionKey = ScaleUtilsTests.GenerateEncryptionKey(); try { AppServiceScaleHandler.HttpMessageHandler = mockHttpMessageHandler; var worker = new AppServiceWorkerInfo { StampName = AppServiceSettings.CurrentStampName, WorkerName = AppServiceSettings.WorkerName }; var handler = AppServiceScaleHandler.Instance; // test if (expectedException == null) { var actual = await handler.PingWorker(activityId, worker); Assert.Equal(expected, actual); } else { var exception = await Assert.ThrowsAsync <HttpRequestException>(async() => await handler.PingWorker(activityId, worker)); Assert.Contains(expectedException.Message, exception.Message); } Assert.Equal(activityId, mockHttpMessageHandler.ActivityId); Assert.Equal(AppServiceSettings.HostName, mockHttpMessageHandler.Host); Assert.Equal(worker.StampName + ".cloudapp.net", mockHttpMessageHandler.Uri.Host); Assert.Equal("https", mockHttpMessageHandler.Uri.Scheme); Assert.Equal("/operations/keepalive/" + AppServiceSettings.SiteName + "/" + worker.WorkerName, mockHttpMessageHandler.Uri.AbsolutePath); } finally { ResetEnvironment(); } }
public async Task CRUDTests(string storageConnectionString, string siteName) { if (string.IsNullOrEmpty(storageConnectionString)) { return; } AppServiceSettings.StorageConnectionString = storageConnectionString; AppServiceSettings.SiteName = siteName; AppServiceSettings.WorkerName = "127.0.0.1"; AppServiceSettings.HomeStampName = "waws-prod-stamp-001"; AppServiceSettings.CurrentStampName = "waws-prod-stamp-001"; var worker = new AppServiceWorkerInfo { PartitionKey = AppServiceSettings.WorkerPartitionKey, RowKey = AppServiceSettings.GetWorkerRowKey(AppServiceSettings.CurrentStampName, AppServiceSettings.WorkerName), StampName = AppServiceSettings.CurrentStampName, WorkerName = AppServiceSettings.WorkerName, LoadFactor = 55 }; try { var table = AppServiceWorkerTable.Instance; // intialize await DeleteAllWorkers(table); var workers = await table.List(); Assert.Equal(0, workers.Count()); // insert await table.AddOrUpdate(worker); workers = await table.List(); Assert.Equal(1, workers.Count()); var entity1 = workers.FirstOrDefault(); Assert.True(ScaleUtils.WorkerEquals(entity1, worker)); Assert.True(DateTime.UtcNow >= entity1.LastModifiedTimeUtc); Assert.True(DateTime.UtcNow - entity1.LastModifiedTimeUtc <= TimeSpan.FromSeconds(30)); Assert.Equal(worker.LoadFactor, entity1.LoadFactor); Assert.False(entity1.IsStale); Assert.Equal(worker.IsHomeStamp, entity1.IsHomeStamp); // update worker.LoadFactor = 45; await table.AddOrUpdate(worker); workers = await table.List(); Assert.Equal(1, workers.Count()); var entity2 = workers.FirstOrDefault(); Assert.True(ScaleUtils.WorkerEquals(entity1, entity2)); Assert.True(entity2.LastModifiedTimeUtc > entity1.LastModifiedTimeUtc); Assert.Equal(worker.LoadFactor, entity2.LoadFactor); Assert.NotEqual(entity1.LoadFactor, entity2.LoadFactor); // delete await table.Delete(worker); workers = await table.List(); Assert.Equal(0, workers.Count()); } finally { ResetEnvironment(); } }