forked from microcks/microcks-testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add KAFKA mocking (microcks#13)
* ci: disable sonar for fork Signed-off-by: SebastienDegodez <[email protected]> * chore: ignore .idea Signed-off-by: SebastienDegodez <[email protected]> * chore(deps): bump FluentAssertions from 6.12.0 to 7.0.0 Bumps [FluentAssertions](https://github.com/fluentassertions/fluentassertions) from 6.12.0 to 7.0.0. - [Release notes](https://github.com/fluentassertions/fluentassertions/releases) - [Changelog](https://github.com/fluentassertions/fluentassertions/blob/develop/AcceptApiChanges.ps1) - [Commits](fluentassertions/fluentassertions@6.12.0...7.0.0) --- updated-dependencies: - dependency-name: FluentAssertions dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * chore(deps): Bump xunit from 2.9.0 to 2.9.2 Bumps [xunit](https://github.com/xunit/xunit) from 2.9.0 to 2.9.2. - [Commits](xunit/xunit@v2-2.9.0...v2-2.9.2) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * chore(deps): bump RestAssured.Net from 4.4.0 to 4.5.1 Bumps [RestAssured.Net](https://github.com/basdijkstra/rest-assured-net) from 4.4.0 to 4.5.1. - [Changelog](https://github.com/basdijkstra/rest-assured-net/blob/main/CHANGELOG.md) - [Commits](basdijkstra/rest-assured-net@rest-assured-net-4.4.0...rest-assured-net-4.5.1) --- updated-dependencies: - dependency-name: RestAssured.Net dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * chore: update RestAssured logging configuration in tests (obsolete) Signed-off-by: SebastienDegodez <[email protected]> * feat: add Kafka functionality test with TestContainers Signed-off-by: SebastienDegodez <[email protected]> * docs: Advanced Features with MicrocksContainerEnsemble Signed-off-by: SebastienDegodez <[email protected]> * refactor: adjust cancellation token handling in WaitForConditionAsync Signed-off-by: SebastienDegodez <[email protected]> * ci: add conditional check for pull request in CI workflow Signed-off-by: SebastienDegodez <[email protected]> --------- Signed-off-by: SebastienDegodez <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
04f2fb6
commit 109d930
Showing
25 changed files
with
1,224 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,6 +395,7 @@ FodyWeavers.xsd | |
*.msix | ||
*.msm | ||
*.msp | ||
*.sln.iml | ||
|
||
# JetBrains Rider | ||
*.sln.iml | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Copyright The Microcks Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// | ||
|
||
namespace Microcks.Testcontainers.Connection; | ||
|
||
/// <summary> | ||
/// Represents a connection to a Kafka broker. | ||
/// </summary> | ||
public class KafkaConnection | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="KafkaConnection"/> class with the specified bootstrap servers. | ||
/// </summary> | ||
/// <param name="bootstrapServers">The Kafka bootstrap servers.</param> | ||
public KafkaConnection(string bootstrapServers) | ||
{ | ||
this.BootstrapServers = bootstrapServers; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Kafka bootstrap servers. | ||
/// </summary> | ||
public string BootstrapServers { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/Microcks.Testcontainers/MicrocksAsyncMinionBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// Copyright The Microcks Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// | ||
|
||
|
||
using DotNet.Testcontainers.Networks; | ||
using Microcks.Testcontainers.Connection; | ||
|
||
namespace Microcks.Testcontainers; | ||
|
||
/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" /> | ||
public sealed class MicrocksAsyncMinionBuilder | ||
: ContainerBuilder<MicrocksAsyncMinionBuilder, MicrocksAsyncMinionContainer, MicrocksAsyncMinionConfiguration> | ||
{ | ||
/// <summary> | ||
/// The default HTTP port for the Microcks async minion. | ||
/// </summary> | ||
public const ushort MicrocksAsyncMinionHttpPort = 8081; | ||
|
||
private const string MicrocksAsyncMinionFullImageName = "quay.io/microcks/microcks-uber-async-minion"; | ||
|
||
private readonly HashSet<string> _extraProtocols = []; | ||
private readonly INetwork _network; | ||
|
||
/// <inheritdoc /> | ||
protected override MicrocksAsyncMinionConfiguration DockerResourceConfiguration { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MicrocksAsyncMinionBuilder"/> class with the specified network. | ||
/// </summary> | ||
/// <param name="network">The network to be used by the Microcks async minion container.</param> | ||
public MicrocksAsyncMinionBuilder(INetwork network) | ||
: this(new MicrocksAsyncMinionConfiguration()) | ||
{ | ||
this._network = network; | ||
DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MicrocksAsyncMinionBuilder"/> class with the specified resource configuration. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The resource configuration for the Microcks async minion container.</param> | ||
private MicrocksAsyncMinionBuilder(MicrocksAsyncMinionConfiguration resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
DockerResourceConfiguration = resourceConfiguration; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override MicrocksAsyncMinionContainer Build() | ||
{ | ||
Validate(); | ||
|
||
return new MicrocksAsyncMinionContainer(DockerResourceConfiguration); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MicrocksAsyncMinionBuilder Init() | ||
{ | ||
return base.Init() | ||
.WithImage(MicrocksAsyncMinionFullImageName) | ||
.WithNetwork(this._network) | ||
.WithNetworkAliases("microcks-async-minion") | ||
.WithEnvironment("MICROCKS_HOST_PORT", "microcks:" + MicrocksBuilder.MicrocksHttpPort) | ||
.WithExposedPort(MicrocksAsyncMinionHttpPort) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged(".*Profile prod activated\\..*")); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MicrocksAsyncMinionBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new MicrocksAsyncMinionConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MicrocksAsyncMinionBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new MicrocksAsyncMinionConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override MicrocksAsyncMinionBuilder Merge(MicrocksAsyncMinionConfiguration oldValue, MicrocksAsyncMinionConfiguration newValue) | ||
{ | ||
return new MicrocksAsyncMinionBuilder(new MicrocksAsyncMinionConfiguration(oldValue, newValue)); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Configures the MicrocksAsyncMinionBuilder to use a Kafka connection. | ||
/// </summary> | ||
/// <param name="kafkaConnection">The Kafka connection details.</param> | ||
/// <returns>The updated MicrocksAsyncMinionBuilder instance.</returns> | ||
public MicrocksAsyncMinionBuilder WithKafkaConnection(KafkaConnection kafkaConnection) | ||
{ | ||
_extraProtocols.Add("KAFKA"); | ||
var environments = new Dictionary<string, string> | ||
{ | ||
{ "ASYNC_PROTOCOLS", $",{string.Join(",", _extraProtocols)}" }, | ||
{ "KAFKA_BOOTSTRAP_SERVER", kafkaConnection.BootstrapServers }, | ||
}; | ||
|
||
return Merge(DockerResourceConfiguration, new MicrocksAsyncMinionConfiguration(new ContainerConfiguration(environments: environments))); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/Microcks.Testcontainers/MicrocksAsyncMinionConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Copyright The Microcks Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// | ||
|
||
namespace Microcks.Testcontainers; | ||
|
||
/// <inheritdoc cref="ContainerConfiguration" /> | ||
public sealed class MicrocksAsyncMinionConfiguration : ContainerConfiguration | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MicrocksAsyncMinionConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="config">The Microcks config.</param> | ||
public MicrocksAsyncMinionConfiguration(object config = null) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MicrocksAsyncMinionConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public MicrocksAsyncMinionConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MicrocksAsyncMinionConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public MicrocksAsyncMinionConfiguration(IContainerConfiguration resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MicrocksAsyncMinionConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public MicrocksAsyncMinionConfiguration(MicrocksAsyncMinionConfiguration resourceConfiguration) | ||
: this(new MicrocksAsyncMinionConfiguration(), resourceConfiguration) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MicrocksAsyncMinionConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="oldValue">The old Docker resource configuration.</param> | ||
/// <param name="newValue">The new Docker resource configuration.</param> | ||
public MicrocksAsyncMinionConfiguration(MicrocksAsyncMinionConfiguration oldValue, MicrocksAsyncMinionConfiguration newValue) | ||
: base(oldValue, newValue) | ||
{ | ||
} | ||
} |
Oops, something went wrong.