lukaszzborek commented on code in PR #2710:
URL: https://github.com/apache/iggy/pull/2710#discussion_r2790318301
##########
foreign/csharp/Iggy_SDK.Tests.Integration/ConsumerGroupTests.cs:
##########
@@ -21,157 +21,183 @@
using Apache.Iggy.IggyClient;
using Apache.Iggy.Tests.Integrations.Attributes;
using Apache.Iggy.Tests.Integrations.Fixtures;
-using Apache.Iggy.Tests.Integrations.Helpers;
using Shouldly;
namespace Apache.Iggy.Tests.Integrations;
public class ConsumerGroupTests
{
- private static readonly uint GroupId = 0;
- private static readonly string GroupName = "test_consumer_group";
- private Identifier TopicId => Identifier.String(Fixture.TopicId);
+ private const uint PartitionsCount = 10;
+ private const string TopicName = "cg-topic";
+ private const string GroupName = "test_consumer_group";
- [ClassDataSource<ConsumerGroupFixture>(Shared = SharedType.PerClass)]
- public required ConsumerGroupFixture Fixture { get; init; }
+ [ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
+ public required IggyServerFixture Fixture { get; init; }
+
+ private async Task<(IIggyClient client, string streamName)>
CreateStreamAndTopic(Protocol protocol)
+ {
+ var client = protocol == Protocol.Tcp
+ ? await Fixture.CreateTcpClient()
+ : await Fixture.CreateHttpClient();
+
+ var streamName = $"cg-stream-{Guid.NewGuid():N}";
+ await client.CreateStreamAsync(streamName);
+ await client.CreateTopicAsync(Identifier.String(streamName),
TopicName, PartitionsCount);
+ return (client, streamName);
+ }
[Test]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
CreateConsumerGroup_HappyPath_Should_CreateConsumerGroup_Successfully(Protocol
protocol)
{
- var consumerGroup
- = await Fixture.Clients[protocol]
-
.CreateConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- GroupName);
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+
+ var consumerGroup = await client.CreateConsumerGroupAsync(
+ Identifier.String(streamName), Identifier.String(TopicName),
GroupName);
consumerGroup.ShouldNotBeNull();
- consumerGroup.Id.ShouldBe(GroupId);
- consumerGroup.PartitionsCount.ShouldBe(Fixture.PartitionsCount);
+ consumerGroup.Id.ShouldBeGreaterThanOrEqualTo(0u);
+ consumerGroup.PartitionsCount.ShouldBe(PartitionsCount);
consumerGroup.MembersCount.ShouldBe(0u);
consumerGroup.Name.ShouldBe(GroupName);
}
[Test]
-
[DependsOn(nameof(CreateConsumerGroup_HappyPath_Should_CreateConsumerGroup_Successfully))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
CreateConsumerGroup_Should_Throw_InvalidResponse(Protocol protocol)
{
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ await client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
await Should.ThrowAsync<IggyInvalidStatusCodeException>(() =>
- Fixture.Clients[protocol]
-
.CreateConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- GroupName));
+ client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName));
}
[Test]
- [DependsOn(nameof(CreateConsumerGroup_Should_Throw_InvalidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
GetConsumerGroupById_Should_Return_ValidResponse(Protocol protocol)
{
- var response = await Fixture.Clients[protocol]
-
.GetConsumerGroupByIdAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- Identifier.Numeric(GroupId));
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ var cg = await
client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
+ var response = await client.GetConsumerGroupByIdAsync(
+ Identifier.String(streamName), Identifier.String(TopicName),
+ Identifier.Numeric(cg!.Id));
response.ShouldNotBeNull();
- response.Id.ShouldBe(GroupId);
+ response.Id.ShouldBe(cg.Id);
response.Name.ShouldBe(GroupName);
- response.PartitionsCount.ShouldBe(Fixture.PartitionsCount);
+ response.PartitionsCount.ShouldBe(PartitionsCount);
response.MembersCount.ShouldBe(0u);
}
[Test]
- [DependsOn(nameof(GetConsumerGroupById_Should_Return_ValidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task GetConsumerGroups_Should_Return_ValidResponse(Protocol
protocol)
{
- IReadOnlyList<ConsumerGroupResponse> response
- = await Fixture.Clients[protocol]
-
.GetConsumerGroupsAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId);
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ await client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
+ IReadOnlyList<ConsumerGroupResponse> response = await
client.GetConsumerGroupsAsync(
+ Identifier.String(streamName), Identifier.String(TopicName));
response.ShouldNotBeNull();
response.Count.ShouldBe(1);
var group = response.FirstOrDefault();
group.ShouldNotBeNull();
- group.Id.ShouldBe(GroupId);
group.Name.ShouldBe(GroupName);
- group.PartitionsCount.ShouldBe(Fixture.PartitionsCount);
+ group.PartitionsCount.ShouldBe(PartitionsCount);
group.MembersCount.ShouldBe(0u);
}
[Test]
[SkipHttp]
- [DependsOn(nameof(GetConsumerGroups_Should_Return_ValidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
JoinConsumerGroup_Tcp_Should_JoinConsumerGroup_Successfully(Protocol protocol)
{
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ var cg = await
client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
await Should.NotThrowAsync(() =>
- Fixture.Clients[protocol]
-
.JoinConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- Identifier.Numeric(GroupId)));
+ client.JoinConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), Identifier.Numeric(cg!.Id)));
}
[Test]
[SkipTcp]
- [DependsOn(nameof(GetConsumerGroups_Should_Return_ValidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
JoinConsumerGroup_Http_Should_Throw_FeatureUnavailable(Protocol protocol)
{
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ var cg = await
client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
await Should.ThrowAsync<FeatureUnavailableException>(() =>
Review Comment:
After that we should run for example `GetMe` on client to check if client is
joined to consumer group on this stream and topic (`ConsumerGroups` field in
response)
##########
foreign/csharp/Iggy_SDK.Tests.Integration/UsersTests.cs:
##########
@@ -156,31 +173,47 @@ await Should.NotThrowAsync(Fixture.Clients[protocol]
}
[Test]
-
[DependsOn(nameof(UpdatePermissions_Should_UpdatePermissions_Successfully))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
ChangePassword_Should_ChangePassword_Successfully(Protocol protocol)
{
- await Should.NotThrowAsync(Fixture.Clients[protocol]
-
.ChangePassword(Identifier.String(Username.GetWithProtocol(protocol)),
"test_password_1", "user2"));
+ var client = protocol == Protocol.Tcp
+ ? await Fixture.CreateTcpClient()
+ : await Fixture.CreateHttpClient();
+
+ var username = $"chpw-{Guid.NewGuid():N}"[..20];
+ await client.CreateUser(username, "old_password", UserStatus.Active);
+
+ await
Should.NotThrowAsync(client.ChangePassword(Identifier.String(username),
"old_password", "new_password"));
Review Comment:
In this test we should login with new password to check if password was
changed
##########
foreign/csharp/Iggy_SDK.Tests.Integration/ConsumerGroupTests.cs:
##########
@@ -21,157 +21,183 @@
using Apache.Iggy.IggyClient;
using Apache.Iggy.Tests.Integrations.Attributes;
using Apache.Iggy.Tests.Integrations.Fixtures;
-using Apache.Iggy.Tests.Integrations.Helpers;
using Shouldly;
namespace Apache.Iggy.Tests.Integrations;
public class ConsumerGroupTests
{
- private static readonly uint GroupId = 0;
- private static readonly string GroupName = "test_consumer_group";
- private Identifier TopicId => Identifier.String(Fixture.TopicId);
+ private const uint PartitionsCount = 10;
+ private const string TopicName = "cg-topic";
+ private const string GroupName = "test_consumer_group";
- [ClassDataSource<ConsumerGroupFixture>(Shared = SharedType.PerClass)]
- public required ConsumerGroupFixture Fixture { get; init; }
+ [ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
+ public required IggyServerFixture Fixture { get; init; }
+
+ private async Task<(IIggyClient client, string streamName)>
CreateStreamAndTopic(Protocol protocol)
+ {
+ var client = protocol == Protocol.Tcp
Review Comment:
I think, this client creating can be extracted into IggyServerFixture, and
then in test just run for example `Fixuture.CreateClient(protocol)`. And use it
in every test
##########
foreign/csharp/Iggy_SDK.Tests.Integration/ConsumerGroupTests.cs:
##########
@@ -21,157 +21,183 @@
using Apache.Iggy.IggyClient;
using Apache.Iggy.Tests.Integrations.Attributes;
using Apache.Iggy.Tests.Integrations.Fixtures;
-using Apache.Iggy.Tests.Integrations.Helpers;
using Shouldly;
namespace Apache.Iggy.Tests.Integrations;
public class ConsumerGroupTests
{
- private static readonly uint GroupId = 0;
- private static readonly string GroupName = "test_consumer_group";
- private Identifier TopicId => Identifier.String(Fixture.TopicId);
+ private const uint PartitionsCount = 10;
+ private const string TopicName = "cg-topic";
+ private const string GroupName = "test_consumer_group";
- [ClassDataSource<ConsumerGroupFixture>(Shared = SharedType.PerClass)]
- public required ConsumerGroupFixture Fixture { get; init; }
+ [ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
+ public required IggyServerFixture Fixture { get; init; }
+
+ private async Task<(IIggyClient client, string streamName)>
CreateStreamAndTopic(Protocol protocol)
+ {
+ var client = protocol == Protocol.Tcp
+ ? await Fixture.CreateTcpClient()
+ : await Fixture.CreateHttpClient();
+
+ var streamName = $"cg-stream-{Guid.NewGuid():N}";
+ await client.CreateStreamAsync(streamName);
+ await client.CreateTopicAsync(Identifier.String(streamName),
TopicName, PartitionsCount);
+ return (client, streamName);
+ }
[Test]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
CreateConsumerGroup_HappyPath_Should_CreateConsumerGroup_Successfully(Protocol
protocol)
{
- var consumerGroup
- = await Fixture.Clients[protocol]
-
.CreateConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- GroupName);
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+
+ var consumerGroup = await client.CreateConsumerGroupAsync(
+ Identifier.String(streamName), Identifier.String(TopicName),
GroupName);
consumerGroup.ShouldNotBeNull();
- consumerGroup.Id.ShouldBe(GroupId);
- consumerGroup.PartitionsCount.ShouldBe(Fixture.PartitionsCount);
+ consumerGroup.Id.ShouldBeGreaterThanOrEqualTo(0u);
+ consumerGroup.PartitionsCount.ShouldBe(PartitionsCount);
consumerGroup.MembersCount.ShouldBe(0u);
consumerGroup.Name.ShouldBe(GroupName);
}
[Test]
-
[DependsOn(nameof(CreateConsumerGroup_HappyPath_Should_CreateConsumerGroup_Successfully))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
CreateConsumerGroup_Should_Throw_InvalidResponse(Protocol protocol)
{
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ await client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
await Should.ThrowAsync<IggyInvalidStatusCodeException>(() =>
- Fixture.Clients[protocol]
-
.CreateConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- GroupName));
+ client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName));
}
[Test]
- [DependsOn(nameof(CreateConsumerGroup_Should_Throw_InvalidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
GetConsumerGroupById_Should_Return_ValidResponse(Protocol protocol)
{
- var response = await Fixture.Clients[protocol]
-
.GetConsumerGroupByIdAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- Identifier.Numeric(GroupId));
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ var cg = await
client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
+ var response = await client.GetConsumerGroupByIdAsync(
+ Identifier.String(streamName), Identifier.String(TopicName),
+ Identifier.Numeric(cg!.Id));
response.ShouldNotBeNull();
- response.Id.ShouldBe(GroupId);
+ response.Id.ShouldBe(cg.Id);
response.Name.ShouldBe(GroupName);
- response.PartitionsCount.ShouldBe(Fixture.PartitionsCount);
+ response.PartitionsCount.ShouldBe(PartitionsCount);
response.MembersCount.ShouldBe(0u);
}
[Test]
- [DependsOn(nameof(GetConsumerGroupById_Should_Return_ValidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task GetConsumerGroups_Should_Return_ValidResponse(Protocol
protocol)
{
- IReadOnlyList<ConsumerGroupResponse> response
- = await Fixture.Clients[protocol]
-
.GetConsumerGroupsAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId);
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ await client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
+ IReadOnlyList<ConsumerGroupResponse> response = await
client.GetConsumerGroupsAsync(
+ Identifier.String(streamName), Identifier.String(TopicName));
response.ShouldNotBeNull();
response.Count.ShouldBe(1);
var group = response.FirstOrDefault();
group.ShouldNotBeNull();
- group.Id.ShouldBe(GroupId);
group.Name.ShouldBe(GroupName);
- group.PartitionsCount.ShouldBe(Fixture.PartitionsCount);
+ group.PartitionsCount.ShouldBe(PartitionsCount);
group.MembersCount.ShouldBe(0u);
}
[Test]
[SkipHttp]
- [DependsOn(nameof(GetConsumerGroups_Should_Return_ValidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
JoinConsumerGroup_Tcp_Should_JoinConsumerGroup_Successfully(Protocol protocol)
{
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ var cg = await
client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
await Should.NotThrowAsync(() =>
- Fixture.Clients[protocol]
-
.JoinConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- Identifier.Numeric(GroupId)));
+ client.JoinConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), Identifier.Numeric(cg!.Id)));
}
[Test]
[SkipTcp]
- [DependsOn(nameof(GetConsumerGroups_Should_Return_ValidResponse))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
JoinConsumerGroup_Http_Should_Throw_FeatureUnavailable(Protocol protocol)
{
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ var cg = await
client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+
await Should.ThrowAsync<FeatureUnavailableException>(() =>
- Fixture.Clients[protocol]
-
.JoinConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
TopicId,
- Identifier.Numeric(GroupId)));
+ client.JoinConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), Identifier.Numeric(cg!.Id)));
}
[Test]
[SkipHttp]
-
[DependsOn(nameof(JoinConsumerGroup_Tcp_Should_JoinConsumerGroup_Successfully))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
LeaveConsumerGroup_Tcp_Should_LeaveConsumerGroup_Successfully(Protocol protocol)
{
+ var (client, streamName) = await CreateStreamAndTopic(protocol);
+ var cg = await
client.CreateConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), GroupName);
+ await client.JoinConsumerGroupAsync(Identifier.String(streamName),
+ Identifier.String(TopicName), Identifier.Numeric(cg!.Id));
+
await Should.NotThrowAsync(() =>
Review Comment:
Like in `JoinConsumerGroupAsync` but check if not in list of joined cg
##########
foreign/csharp/Iggy_SDK.Tests.Integration/SystemTests.cs:
##########
@@ -88,64 +93,62 @@ public async Task GetMe_Tcp_Should_Return_MyClient(Protocol
protocol)
[Test]
[SkipTcp]
- [DependsOn(nameof(GetClient_Should_Return_CorrectClient))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
GetMe_HTTP_Should_Throw_FeatureUnavailableException(Protocol protocol)
{
- await Should.ThrowAsync<FeatureUnavailableException>(() =>
Fixture.Clients[protocol].GetMeAsync());
+ var client = await Fixture.CreateHttpClient();
+
+ await Should.ThrowAsync<FeatureUnavailableException>(() =>
client.GetMeAsync());
}
[Test]
- [DependsOn(nameof(GetMe_HTTP_Should_Throw_FeatureUnavailableException))]
- [DependsOn(nameof(GetMe_Tcp_Should_Return_MyClient))]
[MethodDataSource<IggyServerFixture>(nameof(IggyServerFixture.ProtocolData))]
public async Task
GetClient_WithConsumerGroup_Should_Return_CorrectClient(Protocol protocol)
{
- var client = await
Fixture.IggyServerFixture.CreateClient(Protocol.Tcp, protocol);
- await client.LoginUser("iggy", "iggy");
- var stream = await
client.CreateStreamAsync(Fixture.StreamId.GetWithProtocol(protocol));
- await
client.CreateTopicAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
"test_topic", 2);
-
- var consumerGroup
- = await
client.CreateConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
- Identifier.String("test_topic"), "test_consumer_group");
- await
client.JoinConsumerGroupAsync(Identifier.String(Fixture.StreamId.GetWithProtocol(protocol)),
+ var client = protocol == Protocol.Tcp
+ ? await Fixture.CreateTcpClient()
+ : await Fixture.CreateHttpClient();
+
+ var streamName = $"sys-cg-{Guid.NewGuid():N}";
+ var tcpClient = await Fixture.CreateClient(Protocol.Tcp);
+ await tcpClient.LoginUser("iggy", "iggy");
+
+ var stream = await tcpClient.CreateStreamAsync(streamName);
+ await tcpClient.CreateTopicAsync(Identifier.String(streamName),
"test_topic", 2);
+
+ var consumerGroup = await tcpClient.CreateConsumerGroupAsync(
+ Identifier.String(streamName), Identifier.String("test_topic"),
"test_consumer_group");
+ await tcpClient.JoinConsumerGroupAsync(Identifier.String(streamName),
Identifier.String("test_topic"),
Identifier.String("test_consumer_group"));
- var me = await client.GetMeAsync();
+ var me = await tcpClient.GetMeAsync();
- var response = await
Fixture.Clients[protocol].GetClientByIdAsync(me!.ClientId);
+ var response = await client.GetClientByIdAsync(me!.ClientId);
response.ShouldNotBeNull();
- response.UserId.ShouldBe(0u);
response.Address.ShouldNotBeNullOrEmpty();
response.Transport.ShouldBe(Protocol.Tcp);
response.ConsumerGroupsCount.ShouldBe(1);
response.ConsumerGroups.ShouldNotBeEmpty();
response.ConsumerGroups.ShouldContain(x => x.GroupId ==
consumerGroup!.Id);
- response.ConsumerGroups.ShouldContain(x => x.TopicId == 0);
Review Comment:
maybe in this tests, we should add second topic to stream and use this
second topic in consumer group. In this way we can check TopicId == 1 or > 0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]