Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }