public async Task StartAsync(CancellationToken cancellationToken = default)
        {
            try {
                // don't know why, sometimes the default network (e.g. net50_default) remains
                // from previous cluster and prevents docker-compose up from executing successfully
                Policy.Handle <FluentDockerException>()
                .WaitAndRetry(
                    retryCount: 10,
                    sleepDurationProvider: retryCount => TimeSpan.FromSeconds(2),
                    onRetry: (ex, _) => {
                    BuildCluster().Dispose();
                    _eventStoreCluster.Start();
                })
                .Execute(() => {
                    _eventStoreCluster.Start();
                });

                await Policy.Handle <Exception>()
                .WaitAndRetryAsync(10, retryCount => TimeSpan.FromSeconds(2))
                .ExecuteAsync(async() => {
                    using var response = await _httpClient.GetAsync("/health/live", cancellationToken);
                    if (response.StatusCode >= HttpStatusCode.BadRequest)
                    {
                        throw new Exception($"Health check failed with status code: {response.StatusCode}.");
                    }
                });
            } catch (Exception) {
                _eventStoreCluster.Dispose();
                throw;
            }
        }
示例#2
0
        public void KeepRunningsShallWorkForCompositeServices()
        {
            var file = Path.Combine(Directory.GetCurrentDirectory(),
                                    (TemplateString)"Resources/ComposeTests/WordPress/docker-compose.yml");

            ICompositeService svc = null;
            IContainerService c1  = null;
            IContainerService c2  = null;

            try
            {
                svc = Fd
                      .UseContainer()
                      .UseCompose()
                      .FromFile(file)
                      .RemoveOrphans()
                      .KeepRunning()
                      .Build().Start();

                c1 = svc.Containers.First();
                c2 = svc.Containers.Skip(1).First();

                svc.Dispose();

                Assert.AreEqual(ServiceRunningState.Running, c1.State);
                Assert.AreEqual(ServiceRunningState.Running, c2.State);
            }
            finally
            {
                svc?.Dispose();

                c1?.Remove(true);
                c2?.Remove(true);
            }
        }
    public static void StopTestRun()
    {
        if (!IsRunningInDocker)
        {
            return;
        }

        _compositeService.Stop();
        _compositeService.Dispose();
    }
示例#4
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _compositeService.Stop();
            _compositeService?.Dispose();
        }
        public async Task InitializeAsync()
        {
            try {
                _eventStoreCluster.Start();
            }
            catch (FluentDockerException) {
                // don't know why, sometimes the default network (e.g. net50_default) remains
                // from previous cluster and prevents docker-compose up from executing successfully
                BuildCluster().Dispose();
                _eventStoreCluster.Start();
            }

            try {
                using var httpClient = new HttpClient(new HttpClientHandler {
                    ServerCertificateCustomValidationCallback = delegate {
                        return(true);
                    }
                })
                      {
                          BaseAddress = new UriBuilder {
                              Port   = 2113,
                              Scheme = Uri.UriSchemeHttps
                          }.Uri
                      };
                await Policy.Handle <Exception>()
                .WaitAndRetryAsync(5, retryCount => TimeSpan.FromSeconds(retryCount * retryCount))
                .ExecuteAsync(async() => {
                    using var response = await httpClient.GetAsync("/health/live");
                    if (response.StatusCode >= HttpStatusCode.BadRequest)
                    {
                        throw new Exception($"Health check failed with status code: {response.StatusCode}.");
                    }
                });
            } catch (Exception) {
                _eventStoreCluster.Dispose();
                throw;
            }
            await Connection.ConnectAsync();
        }
        public void Initialize()
        {
            Service = Build().Build();
            try
            {
                Service.Start();
            }
            catch
            {
                Service.Dispose();
                throw;
            }

            OnServiceInitialized();
        }
示例#7
0
 public override void Dispose()
 {
     ComposeService?.Dispose();
     base.Dispose();
 }
示例#8
0
 public void Dispose()
 {
     _svc?.Stop();
     _svc?.Dispose();
 }
 public void Dispose()
 {
     _image?.Dispose();
     _runningImage?.Dispose();
 }
示例#10
0
 public static void DockerComposeDown()
 {
     _compositeService?.Stop();
     _compositeService?.Dispose();
 }