Esempio n. 1
0
        public KafkaContainer(string zookeeperAddress)
        {
            var dockerHost = Environment.GetEnvironmentVariable("DOCKER_HOST");

            if (string.IsNullOrEmpty(dockerHost))
            {
                dockerHost = "unix:/var/run/docker.sock";
            }

            Console.WriteLine($"dockerHost: {dockerHost}");

            _container = new TestcontainersBuilder <TestcontainersContainer>()
                         .WithDockerEndpoint(dockerHost)
                         .WithImage(new DockerImage("confluentinc/cp-kafka:5.5.1"))
                         .WithExposedPort(Port)
                         .WithPortBinding(Port, Port)
                         .WithEnvironment("KAFKA_ADVERTISED_LISTENERS",
                                          "PLAINTEXT://localhost:29092,PLAINTEXT_HOST://localhost:9092")
                         .WithEnvironment("KAFKA_ZOOKEEPER_CONNECT", zookeeperAddress)
                         .WithEnvironment("KAFKA_BROKER_ID", "1")
                         .WithEnvironment("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT")
                         .WithEnvironment("KAFKA_INTER_BROKER_LISTENER_NAME", "PLAINTEXT")
                         .WithEnvironment("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "1")
                         .WithName("kafka-testcontainer")
                         .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(_outStream, _errorStream))
                         .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(Port))
                         .Build();
        }
    public LoadDriver(IDockerNetwork network, NamingConvention namingConvention, TestConfig testConfig)
    {
        _network = network ?? throw new ArgumentNullException(nameof(network));
        if (namingConvention == null)
        {
            throw new ArgumentNullException(nameof(namingConvention));
        }
        if (testConfig == null)
        {
            throw new ArgumentNullException(nameof(testConfig));
        }

        _logStream    = File.Create(Path.Combine(namingConvention.ContainerLogs, "k6.txt"));
        _resultStream = File.Create(Path.Combine(namingConvention.AgentResults, K6ResultsFile));

        _hostScriptPath = Path.Combine(Directory.GetCurrentDirectory(), "K6", "basic.js");
        _container      = new TestcontainersBuilder <TestcontainersContainer>()
                          .WithImage(LoadDriveImageName)
                          .WithName($"{OverheadTest.Prefix}-k6-load")
                          .WithNetwork(_network)
                          .WithCommand("run",
                                       "-u", testConfig.ConcurrentConnections.ToString(),
                                       "-e", $"ESHOP_HOSTNAME={EshopApp.ContainerName}",
                                       "-i", testConfig.Iterations.ToString(),
                                       "--rps", testConfig.MaxRequestRate.ToString(),
                                       ContainerScriptPath,
                                       "--summary-export", ContainerResultsPath)
                          .WithBindMount(_hostScriptPath, ContainerScriptPath)
                          .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(_logStream, _logStream))
                          .Build();
    }
Esempio n. 3
0
            public async Task OutputConsumer()
            {
                // Given
                using (var consumer = Consume.RedirectStdoutAndStderrToStream(new MemoryStream(), new MemoryStream()))
                {
                    // When
                    var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                                .WithImage("nginx")
                                                .WithCommand("/bin/sh", "-c", "hostname > /dev/stdout && hostname > /dev/stderr")
                                                .WithOutputConsumer(consumer);

                    await using (IDockerContainer testcontainer = testcontainersBuilder.Build())
                    {
                        await testcontainer.StartAsync();
                    }

                    consumer.Stdout.Position = 0;
                    consumer.Stderr.Position = 0;

                    // Then
                    using (var streamReader = new StreamReader(consumer.Stdout, leaveOpen: true))
                    {
                        Assert.NotEmpty(await streamReader.ReadToEndAsync());
                    }

                    using (var streamReader = new StreamReader(consumer.Stderr, leaveOpen: true))
                    {
                        Assert.NotEmpty(await streamReader.ReadToEndAsync());
                    }
                }
            }
Esempio n. 4
0
    public LocalCollector(IDockerNetwork network, DirectoryInfo iterationResults) : base(iterationResults)
    {
        var hostCollectorConfigPath = Path.Combine(Directory.GetCurrentDirectory(), CollectorConfigPath);

        Container = new TestcontainersBuilder <TestcontainersContainer>()
                    .WithImage(ImageName)
                    .WithName(Address)
                    .WithNetwork(network)
                    .WithBindMount(hostCollectorConfigPath, ContainerCollectorConfigPath)
                    .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(Stream, Stream))
                    .Build();
    }
 public LocalSqlServer(IDockerNetwork network, NamingConvention namingConvention) : base(
         namingConvention)
 {
     Container = new TestcontainersBuilder <TestcontainersContainer>()
                 .WithImage(ImageName)
                 .WithName(Address)
                 .WithNetwork(network ?? throw new ArgumentNullException(nameof(network)))
                 .WithEnvironment("ACCEPT_EULA", "Y")
                 .WithEnvironment("SA_PASSWORD", TestPassword)
                 .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(Port))
                 .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(Stream, Stream))
                 .Build();
 }
Esempio n. 6
0
    public EshopApp(IDockerNetwork network, CollectorBase collector, SqlServerBase sqlServer,
                    NamingConvention namingConvention, AgentConfig config)
    {
        if (network == null)
        {
            throw new ArgumentNullException(nameof(network));
        }
        if (collector == null)
        {
            throw new ArgumentNullException(nameof(collector));
        }
        if (sqlServer == null)
        {
            throw new ArgumentNullException(nameof(sqlServer));
        }
        if (namingConvention == null)
        {
            throw new ArgumentNullException(nameof(namingConvention));
        }
        if (config == null)
        {
            throw new ArgumentNullException(nameof(config));
        }

        _logStream    = File.Create(Path.Combine(namingConvention.ContainerLogs, "eshop-app.txt"));
        _resultStream = File.Create(Path.Combine(namingConvention.AgentResults, CounterResultsFile));

        var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                    .WithImage(config.DockerImageName)
                                    .WithName(ContainerName)
                                    .WithNetwork(network)
                                    .WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
                                    .WithEnvironment("SIGNALFX_ENDPOINT_URL", collector.TraceReceiverUrl)
                                    .WithEnvironment("SIGNALFX_PROFILER_LOGS_ENDPOINT", collector.LogsReceiverUrl)
                                    .WithEnvironment("ConnectionStrings__CatalogConnection", sqlServer.CatalogConnection)
                                    .WithEnvironment("ConnectionStrings__IdentityConnection", sqlServer.IdentityConnection)
                                    .WithEnvironment("Logging__LogLevel__Microsoft", "Warning")
                                    .WithEnvironment("Logging__LogLevel__Default", "Warning")
                                    .WithEnvironment("Logging__LogLevel__System", "Warning")
                                    .WithEnvironment("Logging__LogLevel__Microsoft.Hosting.Lifetime", "Information")
                                    .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(AppPort))
                                    .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(_logStream, _logStream));

        foreach (var envVar in config.AdditionalEnvVars)
        {
            testcontainersBuilder = testcontainersBuilder.WithEnvironment(envVar.Name, envVar.Value);
        }
        _container = testcontainersBuilder.Build();
    }
 public RemoteSqlServer(DockerEndpoint endpoint, NamingConvention namingConvention) : base(
         namingConvention)
 {
     _endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     Container = new TestcontainersBuilder <TestcontainersContainer>()
                 .WithImage(ImageName)
                 .WithName($"{OverheadTest.Prefix}-remote-sqlserver")
                 .WithDockerEndpoint(_endpoint.Url)
                 .WithPortBinding(Port, Port)
                 .WithEnvironment("ACCEPT_EULA", "Y")
                 .WithEnvironment("SA_PASSWORD", TestPassword)
                 .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(Port))
                 .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(Stream, Stream))
                 .Build();
 }
Esempio n. 8
0
 public RemoteCollector(DockerEndpoint dockerEndpoint, DirectoryInfo iterationResults) : base(iterationResults)
 {
     _dockerEndpoint = dockerEndpoint ?? throw new ArgumentNullException(nameof(dockerEndpoint));
     Container       = new TestcontainersBuilder <TestcontainersContainer>()
                       .WithImage(ImageName)
                       .WithName($"{OverheadTest.Prefix}-remote-collector")
                       .WithDockerEndpoint(_dockerEndpoint.Url)
                       .WithExposedPort(LogReceiverPort)
                       .WithExposedPort(TraceReceiverPort)
                       .WithPortBinding(LogReceiverPort, LogReceiverPort)
                       .WithPortBinding(TraceReceiverPort, TraceReceiverPort)
                       .WithBindMount(HostCollectorConfigPath, ContainerCollectorConfigPath)
                       .WithOutputConsumer(Consume.RedirectStdoutAndStderrToStream(Stream, Stream))
                       .Build();
 }
Esempio n. 9
0
            public async Task OutputConsumer()
            {
                var unixTimeInMilliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString();

                // Given
                using (var consumer = Consume.RedirectStdoutAndStderrToStream(new MemoryStream(), new MemoryStream()))
                {
                    // When
                    var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                                .WithImage("alpine")
                                                .WithCommand("/bin/sh", "-c", $"printf \"{unixTimeInMilliseconds}\" | tee /dev/stderr")
                                                .WithOutputConsumer(consumer)
                                                .WithWaitStrategy(Wait.ForUnixContainer()
                                                                  .UntilMessageIsLogged(consumer.Stdout, unixTimeInMilliseconds)
                                                                  .UntilMessageIsLogged(consumer.Stderr, unixTimeInMilliseconds));

                    await using (IDockerContainer testcontainer = testcontainersBuilder.Build())
                    {
                        await testcontainer.StartAsync();
                    }

                    consumer.Stdout.Seek(0, SeekOrigin.Begin);
                    consumer.Stderr.Seek(0, SeekOrigin.Begin);

                    // Then
                    using (var streamReader = new StreamReader(consumer.Stdout, leaveOpen: true))
                    {
                        Assert.Equal(unixTimeInMilliseconds, await streamReader.ReadToEndAsync());
                    }

                    using (var streamReader = new StreamReader(consumer.Stderr, leaveOpen: true))
                    {
                        Assert.Equal(unixTimeInMilliseconds, await streamReader.ReadToEndAsync());
                    }
                }
            }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CouchbaseTestcontainerConfiguration" /> class.
 /// </summary>
 public CouchbaseTestcontainerConfiguration()
     : base(CouchbaseImage, BootstrapHttpPort, BootstrapHttpPort)
 {
     this.OutputConsumer = Consume.RedirectStdoutAndStderrToStream(new MemoryStream(), new MemoryStream());
     this.WaitStrategy   = Wait.ForUnixContainer().UntilMessageIsLogged(this.OutputConsumer.Stdout, WaitUntilMessageIsLogged);
 }
Esempio n. 11
0
 public MongoDbTestcontainerConfiguration(string image) : base(image, MongoDbPort)
 {
     OutputConsumer = Consume.RedirectStdoutAndStderrToStream(_stdout, _stderr);
     WaitStrategy   = Wait.ForUnixContainer().UntilMessageIsLogged(OutputConsumer.Stdout, "Waiting for connections");
 }