Exemplo n.º 1
0
        public void TestInitialize()
        {
            _dataRootPath            = Path.Combine(Directory.GetCurrentDirectory(), "Data", "EndToEndTest");
            _testDirPath             = Path.Combine(Directory.GetCurrentDirectory(), "EndToEndTest");
            _deploymentDirPath       = Path.Combine(_testDirPath, "Deployments");
            _applicationsInstallPath = Path.Combine(_testDirPath, Constants.ApplicationsRootFolderName);

            FileUtils.CopyDir(_dataRootPath, _deploymentDirPath, overwrite: true).Wait();

            CopyTestProcessExeToTestApps();

            _diContainer = new UnityContainer();
            DiModule.RegisterTypes(_diContainer, new YamsConfigBuilder("UseDevelopmentStorage=true", "deploymentId1", "1", "instanceId", _applicationsInstallPath).Build());

            // Replace the IRemoteDirectory default implementation (which uses Azure) with a LocalDirectory implementation
            // so we can use local test data.
            _diContainer.RegisterType <IRemoteDirectory>(new ContainerControlledLifetimeManager(),
                                                         new InjectionFactory(
                                                             c => new LocalDirectory(_deploymentDirPath)));

            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager
            {
                TryStartUpdateSessionString = applicationId => Task.FromResult(true),
                EndUpdateSessionString      = applicationId => Task.FromResult(true)
            };

            // Replace the update session manager with a stub that always starts an update session (since we don't have multiple instances
            // updating in a test)
            _diContainer.RegisterInstance(updateSessionManager);

            // we don't start yams because that will make it update based on a timer that is hard to manage in a test. Instead, we call
            // applicationUpdateManager.CheckForUpdates() manually in a test.
            _yamsEntryPoint = new YamsEntryPoint(_diContainer);
        }
Exemplo n.º 2
0
        public async Task TestThatUpdateDoesNothingIfCannotStartUpdateSession()
        {
            IEnumerable <AppIdentity> appsToDeploy = new[] { app1v2 };
            IEnumerable <string>      clusters     = new[] { "clusterId1" };

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string           path            = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));

            IUpdateSessionManager updateSessionManagerStub = new StubIUpdateSessionManager()
                                                             .TryStartUpdateSession(() => Task.FromResult(false));

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory()
                                                                             .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters))));

            const string             ClusterId  = "clusterId";
            const string             InstanceId = "instanceId";
            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager(ClusterId, InstanceId,
                                                                                             applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller,
                                                                                             deploymentStatusWriterStub, updateSessionManagerStub);
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(1, applicationPool.Applications.Count());
            Assert.True(applicationPool.HasApplication(app1v1));
        }
Exemplo n.º 3
0
        public void TestInitialize()
        {
            _dataRootPath = Path.Combine(Directory.GetCurrentDirectory(), "Data", "EndToEndTest");
            _testDirPath = Path.Combine(Directory.GetCurrentDirectory(), "EndToEndTest");
            _deploymentDirPath = Path.Combine(_testDirPath, "Deployments");
            _applicationsInstallPath = Path.Combine(_testDirPath, Constants.ApplicationsRootFolderName);

            FileUtils.CopyDir(_dataRootPath, _deploymentDirPath, overwrite: true).Wait();

            CopyTestProcessExeToTestApps();

            _diContainer = new UnityContainer();
            DiModule.RegisterTypes(_diContainer, new YamsConfigBuilder("UseDevelopmentStorage=true", "deploymentId1", "1", "instanceId", _applicationsInstallPath).Build());

            // Replace the IRemoteDirectory default implementation (which uses Azure) with a LocalDirectory implementation
            // so we can use local test data.
            _diContainer.RegisterType<IRemoteDirectory>(new ContainerControlledLifetimeManager(),
                new InjectionFactory(
                    c => new LocalDirectory(_deploymentDirPath)));

            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager
            {
                TryStartUpdateSessionString = applicationId => Task.FromResult(true),
                EndUpdateSessionString = applicationId => Task.FromResult(true)
            };

            // Replace the update session manager with a stub that always starts an update session (since we don't have multiple instances
            // updating in a test)
            _diContainer.RegisterInstance(updateSessionManager);

            // we don't start yams because that will make it update based on a timer that is hard to manage in a test. Instead, we call
            // applicationUpdateManager.CheckForUpdates() manually in a test.
            _yamsEntryPoint = new YamsEntryPoint(_diContainer);
        }
Exemplo n.º 4
0
        public async Task TestThatUpdateSessionIsNotEndedWhenUpdateFails()
        {
            IEnumerable <AppIdentity> appsToDeploy = new[] { app1v2 };
            IEnumerable <string>      clusters     = new[] { "clusterId1" };

            IApplicationPool applicationPool = new ApplicationPoolStub();
            string           path            = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));

            bool updateSessionEnded = false;
            IUpdateSessionManager updateSessionManagerStub = new StubIUpdateSessionManager()
                                                             .TryStartUpdateSession(() => Task.FromResult(true))
                                                             .EndUpdateSession(() =>
            {
                updateSessionEnded = true;
                return(Task.CompletedTask);
            });

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory()
                                                                             .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters))));

            const string             ClusterId  = "clusterId";
            const string             InstanceId = "instanceId";
            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager(ClusterId, InstanceId,
                                                                                             applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller,
                                                                                             deploymentStatusWriterStub, updateSessionManagerStub);
            await applicationUpdateManager.CheckForUpdates();

            Assert.True(updateSessionEnded);
        }
Exemplo n.º 5
0
        private void InitializeYamsService(YamsConfig yamsConfig)
        {
            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
                .TryStartUpdateSession(applicationId => Task.FromResult(true))
                .EndUpdateSession(applicationId => Task.FromResult(true));

            _yamsDiModule = new YamsDiModule(yamsConfig, new LocalDeploymentRepository(
                _deploymentDirPath, new JsonDeploymentConfigSerializer(
                    new JsonSerializer(new DiagnosticsTraceWriter()))), updateSessionManager);
            _yamsService = _yamsDiModule.YamsService;
        }
Exemplo n.º 6
0
        public async Task TestThatNotAllExceptionsAreRetried()
        {
            var updateSessionStub = new StubIUpdateSessionManager()
                                    .TryStartUpdateSession(() => AsyncUtils.AsyncTaskThatThrows <bool>(new Exception()));

            IUpdateSessionManager retryDecorator = new StorageExceptionUpdateSessionRetryDecorator(
                updateSessionStub,
                new FixedInterval(1, TimeSpan.Zero),
                new StorageExceptionErrorDetectionStrategy());
            await Assert.ThrowsAsync <Exception>(async() => await retryDecorator.TryStartUpdateSession());
        }
Exemplo n.º 7
0
        private void InitializeYamsService(YamsConfig yamsConfig)
        {
            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
                                                         .TryStartUpdateSession(applicationId => Task.FromResult(true))
                                                         .EndUpdateSession(applicationId => Task.FromResult(true));

            _yamsDiModule = new YamsDiModule(yamsConfig, new LocalDeploymentRepository(
                                                 _deploymentDirPath, new JsonDeploymentConfigSerializer(
                                                     new JsonSerializer(new DiagnosticsTraceWriter()))), updateSessionManager);
            _yamsService = _yamsDiModule.YamsService;
        }
Exemplo n.º 8
0
        private ContainerBuilder InitializeContainerBuilder(YamsConfig yamsConfig)
        {
            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
                                                         .TryStartUpdateSession(applicationId => Task.FromResult(true))
                                                         .EndUpdateSession(applicationId => Task.FromResult(true));

            IDeploymentRepository deploymentRepository = new LocalDeploymentRepository(_deploymentDirPath,
                                                                                       new JsonDeploymentConfigSerializer(new JsonSerializer(new DiagnosticsTraceWriter())));

            return(YamsDiModule.RegisterTypes(yamsConfig, deploymentRepository, updateSessionManager));
        }
        public async Task TestThatNotAllExceptionsAreRetried()
        {
            string appId = "appId";
	        var updateSessionStub = new StubIUpdateSessionManager()
		        .TryStartUpdateSession(id => AsyncUtils.AsyncTaskThatThrows<bool>(new Exception()));

            IUpdateSessionManager retryDecorator = new UpdateSessionManagerRetryDecorator(
                updateSessionStub,
                new FixedInterval(1, TimeSpan.Zero),
                new StorageExceptionErrorDetectionStrategy());
            await Assert.ThrowsAsync<Exception>(async () => await retryDecorator.TryStartUpdateSession(appId));
        }
Exemplo n.º 10
0
        public async Task TestThatExceptionIsThrownIfMaxRetryCountIsReached()
        {
            var sequence = StubsUtils.Sequence <StubIUpdateSessionManager.TryStartUpdateSession_Delegate>()
                           .Twice(() => AsyncUtils.AsyncTaskThatThrows <bool>(new StorageException()))
                           .Once(() => AsyncUtils.AsyncTaskWithResult(true));

            var updateSessionStub = new StubIUpdateSessionManager()
                                    .TryStartUpdateSession(() => sequence.Next());

            IUpdateSessionManager retryDecorator = new StorageExceptionUpdateSessionRetryDecorator(
                updateSessionStub,
                new FixedInterval(1, TimeSpan.Zero),
                new StorageExceptionErrorDetectionStrategy());
            await Assert.ThrowsAsync <StorageException>(async() => await retryDecorator.TryStartUpdateSession());
        }
Exemplo n.º 11
0
        public async Task TestThatEndUpdateSessionIsRetried()
        {
            var sequence = StubsUtils.Sequence <StubIUpdateSessionManager.EndUpdateSession_Delegate>()
                           .Once(() => AsyncUtils.AsyncTaskThatThrows(new StorageException()))
                           .Once(() => Task.CompletedTask);

            var updateSessionStub = new StubIUpdateSessionManager()
                                    .EndUpdateSession(() => sequence.Next());

            IUpdateSessionManager retryDecorator = new StorageExceptionUpdateSessionRetryDecorator(
                updateSessionStub,
                new FixedInterval(1, TimeSpan.Zero),
                new StorageExceptionErrorDetectionStrategy());
            await retryDecorator.EndUpdateSession();
        }
        public async Task TestThatEndUpdateSessionIsRetried()
        {
            string appId = "appId";
            var sequence = StubsUtils.Sequence<StubIUpdateSessionManager.EndUpdateSession_String_Delegate>()
                .Once(id => AsyncUtils.AsyncTaskThatThrows(new StorageException()))
                .Once(id => Task.CompletedTask);

	        var updateSessionStub = new StubIUpdateSessionManager()
		        .EndUpdateSession(id => sequence.Next(id));

            IUpdateSessionManager retryDecorator = new UpdateSessionManagerRetryDecorator(
                updateSessionStub,
                new FixedInterval(1, TimeSpan.Zero),
                new StorageExceptionErrorDetectionStrategy());
            await retryDecorator.EndUpdateSession(appId);
        }
Exemplo n.º 13
0
        public async Task TestUpdateApplication()
        {
            string updateSessionId = null;
            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
            {
                TryStartUpdateSessionString = id =>
                {
                    updateSessionId = id;
                    return(Task.FromResult(true));
                },
                EndUpdateSessionString = id => Task.FromResult(true)
            };

            IApplicationPool      applicationPool      = new ApplicationPoolStub();
            IApplicationInstaller applicationInstaller = new ApplicationInstaller(_applicationsRoot, updateSessionManager, new ApplicationFactoryStub(), applicationPool);

            const string appId = "test.app";

            AppIdentity[] existingApps = { new AppIdentity(appId, new Version(1, 0, 0)), new AppIdentity(appId, new Version(1, 0, 1)) };
            AppIdentity[] newApps      = { new AppIdentity(appId, new Version(1, 0, 2)), new AppIdentity(appId, new Version(2, 0, 0)) };

            foreach (var existingApp in existingApps)
            {
                string appPath = Path.Combine(_applicationsRoot, existingApp.Id, existingApp.Version.ToString());
                if (!Directory.Exists(appPath))
                {
                    Directory.CreateDirectory(appPath);
                }
                await applicationInstaller.Install(existingApp);

                Assert.IsTrue(applicationPool.HasApplication(existingApp));
            }

            await applicationInstaller.Update(appId, existingApps.Select(app => app.Version), newApps.Select(app => app.Version));

            foreach (AppIdentity app in existingApps)
            {
                Assert.IsFalse(applicationPool.HasApplication(app));
            }

            foreach (AppIdentity app in newApps)
            {
                Assert.IsTrue(applicationPool.HasApplication(app));
            }

            Assert.AreEqual(appId, updateSessionId);
        }
Exemplo n.º 14
0
        public async Task TestThatUpdateReturnsIfCannotStartUpdateSession()
        {
            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
                                                         .TryStartUpdateSession(id => Task.FromResult(false));

            IApplicationPool      applicationPool      = new ApplicationPoolStub();
            IApplicationInstaller applicationInstaller = new ApplicationInstaller(_applicationsRoot, updateSessionManager, new ApplicationFactoryStub(), applicationPool);

            AppIdentity existingApp = new AppIdentity("test.app", new SemVersion(1, 0, 0));
            await applicationInstaller.Install(new AppInstallConfig(existingApp));

            AppIdentity newApp = new AppIdentity(existingApp.Id, new SemVersion(1, 1, 0));
            await applicationInstaller.Update(new[] { existingApp }, new[] { new AppInstallConfig(newApp), });

            Assert.True(applicationPool.HasApplication(existingApp));
            Assert.False(applicationPool.HasApplication(newApp));
        }
        public async Task TestThatExceptionIsThrownIfMaxRetryCountIsReached()
        {
            string appId = "appId";

            var sequence = StubsUtils.Sequence<StubIUpdateSessionManager.TryStartUpdateSession_String_Delegate>()
                .Twice(id => AsyncUtils.AsyncTaskThatThrows<bool>(new StorageException()))
                .Once(id => AsyncUtils.AsyncTaskWithResult(true));

	        var updateSessionStub = new StubIUpdateSessionManager()
		        .TryStartUpdateSession(id => sequence.Next(id));

            IUpdateSessionManager retryDecorator = new UpdateSessionManagerRetryDecorator(
                updateSessionStub,
                new FixedInterval(1, TimeSpan.Zero),
                new StorageExceptionErrorDetectionStrategy());
            await Assert.ThrowsAsync<StorageException>(async () => await retryDecorator.TryStartUpdateSession(appId));
        }
Exemplo n.º 16
0
        public async Task TestUpdateApplication()
        {
            string updateSessionId = null;
            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
            {
                TryStartUpdateSessionString = id =>
                {
                    updateSessionId = id;
                    return Task.FromResult(true);
                },
                EndUpdateSessionString = id => Task.FromResult(true)
            };

            IApplicationPool applicationPool = new ApplicationPoolStub();
            IApplicationInstaller applicationInstaller = new ApplicationInstaller(_applicationsRoot, updateSessionManager, new ApplicationFactoryStub(), applicationPool);

            const string appId = "test.app";
            AppIdentity[] existingApps = { new AppIdentity(appId, new Version(1, 0, 0)), new AppIdentity(appId, new Version(1, 0, 1)) };
            AppIdentity[] newApps = { new AppIdentity(appId, new Version(1, 0, 2)), new AppIdentity(appId, new Version(2, 0, 0)) };

            foreach (var existingApp in existingApps)
            {
                string appPath = Path.Combine(_applicationsRoot, existingApp.Id, existingApp.Version.ToString());
                if (!Directory.Exists(appPath))
                {
                    Directory.CreateDirectory(appPath);
                }
                await applicationInstaller.Install(existingApp);
                Assert.IsTrue(applicationPool.HasApplication(existingApp));
            }

            await applicationInstaller.Update(appId, existingApps.Select(app => app.Version), newApps.Select(app => app.Version));

            foreach (AppIdentity app in existingApps)
            {
                Assert.IsFalse(applicationPool.HasApplication(app));
            }

            foreach (AppIdentity app in newApps)
            {
                Assert.IsTrue(applicationPool.HasApplication(app));   
            }
            
            Assert.AreEqual(appId, updateSessionId);
        }
        public async Task TestThatStartUpdateSessionIsRetried()
        {
            string appId = "appId";

            var sequence = StubsUtils.Sequence <StubIUpdateSessionManager.TryStartUpdateSession_String_Delegate>()
                           .Once(id => AsyncUtils.AsyncTaskThatThrows <bool>(new StorageException()))
                           .Once(id => AsyncUtils.AsyncTaskWithResult(true));

            var updateSessionStub = new StubIUpdateSessionManager()
                                    .TryStartUpdateSession(id => sequence.Next(id));

            IUpdateSessionManager retryDecorator = new StorageExceptionUpdateSessionRetryDecorator(
                updateSessionStub,
                new FixedInterval(1, TimeSpan.Zero),
                new StorageExceptionErrorDetectionStrategy());

            Assert.True(await retryDecorator.TryStartUpdateSession(appId));
        }
Exemplo n.º 18
0
        public EndToEndTest()
        {
            _dataRootPath            = Path.Combine(Directory.GetCurrentDirectory(), "Data", "EndToEndTest");
            _testDirPath             = Path.Combine(Directory.GetCurrentDirectory(), "EndToEndTest");
            _deploymentDirPath       = Path.Combine(_testDirPath, "Deployments");
            _applicationsInstallPath = Path.Combine(_testDirPath, "applications");

            FileUtils.CopyDir(_dataRootPath, _deploymentDirPath, overwrite: true).Wait();

            CopyTestProcessExeToTestApps();

            var yamsConfig = new YamsConfigBuilder("deploymentId1", "1", "instanceId",
                                                   _applicationsInstallPath).SetShowApplicationProcessWindow(false).Build();

            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
                                                         .TryStartUpdateSession(applicationId => Task.FromResult(true))
                                                         .EndUpdateSession(applicationId => Task.FromResult(true));

            _yamsDiModule = new YamsDiModule(yamsConfig, new LocalDeploymentRepository(_deploymentDirPath), updateSessionManager);
            _yamsService  = _yamsDiModule.YamsService;
        }
Exemplo n.º 19
0
        public async Task TestMultipleUpdates()
        {
            IEnumerable <AppIdentity> appsToDeploy = new[] { app1v3, app1v4, app1v5 };
            IEnumerable <string>      clusters     = new[] { "clusterId1" };

            IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory()
                                                                             .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters))));

            string path = Path.GetTempPath();
            await applicationPool.AddApplication(new ApplicationStub(app1v1, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v2, path));

            await applicationPool.AddApplication(new ApplicationStub(app1v3, path));

            IUpdateSessionManager updateSessionManagerStub = new StubIUpdateSessionManager()
                                                             .TryStartUpdateSession(() => Task.FromResult(true))
                                                             .EndUpdateSession(() => Task.CompletedTask);

            const string             ClusterId  = "clusterId";
            const string             InstanceId = "instanceId";
            ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager(ClusterId, InstanceId,
                                                                                             applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller,
                                                                                             deploymentStatusWriterStub, updateSessionManagerStub);
            await applicationUpdateManager.CheckForUpdates();

            Assert.Equal(3, applicationPool.Applications.Count());
            Assert.True(applicationPool.HasApplication(app1v3));
            Assert.True(applicationPool.HasApplication(app1v4));
            Assert.True(applicationPool.HasApplication(app1v5));

            Assert.Equal(3, instanceDeploymentStatus.Applications.Count());
            VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v3, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v4, ClusterId, InstanceId);
            VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v5, ClusterId, InstanceId);
        }
Exemplo n.º 20
0
        public async Task TestThatUpdateReturnsIfCannotStartUpdateSession()
        {
	        IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager()
		        .TryStartUpdateSession(id => Task.FromResult(false));

            IApplicationPool applicationPool = new ApplicationPoolStub();
            IApplicationInstaller applicationInstaller = new ApplicationInstaller(_applicationsRoot, updateSessionManager, new ApplicationFactoryStub(), applicationPool);

            AppIdentity existingApp = new AppIdentity("test.app", new SemVersion(1, 0, 0));
            await applicationInstaller.Install(new AppInstallConfig(existingApp));

            AppIdentity newApp = new AppIdentity(existingApp.Id, new SemVersion(1, 1, 0));
            await applicationInstaller.Update(new[] {existingApp}, new[] {new AppInstallConfig(newApp), });

            Assert.True(applicationPool.HasApplication(existingApp));
            Assert.False(applicationPool.HasApplication(newApp));
        }