blankensteiner commented on code in PR #162:
URL: https://github.com/apache/pulsar-dotpulsar/pull/162#discussion_r1285705463
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,153 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task
GetLastMessageId_GivenPartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName =
$"persistent://public/default/consumer-tests-{testRunId}";
+
+ _fixture.CreatePartitionedTopic(topicName, partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ //Act
+ var exception = await Record.ExceptionAsync(() =>
consumer.GetLastMessageId().AsTask());
+
+ //Assert
+ exception.Should().BeOfType<NotSupportedException>();
+ }
+
+ [Theory]
+ [InlineData(10000)]
Review Comment:
Fact?
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,153 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task
GetLastMessageId_GivenPartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName =
$"persistent://public/default/consumer-tests-{testRunId}";
+
+ _fixture.CreatePartitionedTopic(topicName, partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ //Act
+ var exception = await Record.ExceptionAsync(() =>
consumer.GetLastMessageId().AsTask());
+
+ //Assert
+ exception.Should().BeOfType<NotSupportedException>();
+ }
+
+ [Theory]
+ [InlineData(10000)]
+ public async Task
Messages_GivenPartitionedTopicWithMessages_ShouldConsumeAll(int
numberOfMessages)
Review Comment:
This test isn't testing "Messages", which is an extension method, but is
testing a Partitioned consumer
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,153 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task
GetLastMessageId_GivenPartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName =
$"persistent://public/default/consumer-tests-{testRunId}";
+
+ _fixture.CreatePartitionedTopic(topicName, partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ //Act
+ var exception = await Record.ExceptionAsync(() =>
consumer.GetLastMessageId().AsTask());
+
+ //Assert
+ exception.Should().BeOfType<NotSupportedException>();
+ }
+
+ [Theory]
+ [InlineData(10000)]
+ public async Task
Messages_GivenPartitionedTopicWithMessages_ShouldConsumeAll(int
numberOfMessages)
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-with-3-partitions-test";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ //Act
+ await using var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ await using var producer = client.NewProducer(Schema.ByteArray)
+ .ProducerName($"producer-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
+
+ var produced = await ProduceMessages(producer, numberOfMessages,
cts.Token);
+ var consumed = await ConsumeMessages(consumer, numberOfMessages,
cts.Token);
+
+ //Assert
+ consumed.Should().BeEquivalentTo(produced);
+ }
+
+ [Fact]
+ public async Task
GetLastMessageIds_GivenMessageIdsFrom3Partitions_ShouldHave3Partitions()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ const int numberOfMessages = 10;
+ var topicName = $"consumer_get_last_message_ids_should_have_3_topics";
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ await using var producer = client.NewProducer(Schema.String)
+ .Topic(topicName)
+ .Create();
+
+ await using var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ const string content = "test-message";
+ for (var i = 0; i < numberOfMessages; i++)
+ {
+ await producer.Send(content);
+ }
+
+ string[] expected = {
"consumer_get_last_message_ids_should_have_3_topics-partition-0",
"consumer_get_last_message_ids_should_have_3_topics-partition-1",
"consumer_get_last_message_ids_should_have_3_topics-partition-2" };
+
+ //Act
+ var actual = await consumer.GetLastMessageIds();
+
+ //Assert
+ actual.Select(x =>
x.Topic).Should().HaveCount(3).And.Contain(expected);
+ }
+
+ [Fact]
+ public async Task
GetLastMessageIds_Given3Partitions_ShouldHave3lastMessageIds()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ const int numberOfMessages = 10;
+ var topicName =
$"consumer_get_last_message_ids_should_have_3_last_message_ids";
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ await using var producer = client.NewProducer(Schema.String)
+ .Topic(topicName)
+ .Create();
+
+ await using var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ const string content = "test-message";
+ for (var i = 0; i < numberOfMessages; i++)
+ {
+ await producer.Send(content);
+ }
+
+ //Act
+ var lastMessageIds = await consumer.GetLastMessageIds();
+
+ //Assert
+ lastMessageIds.Should().HaveCount(3);
Review Comment:
Just any 3 or are we looking for 3 specific messageids?
##########
CHANGELOG.md:
##########
@@ -18,6 +20,9 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/)
- Calling `await Send(...)` on a producer did not correctly terminate with an
exception when a send operation failed (e.g. because the producer faulted)
- The 'Partition' in 'MessageId' will now be set to the correct partition when
producing to partitioned topics
+### Deprecated
Review Comment:
Space between lines 23 and 24
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,153 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task
GetLastMessageId_GivenPartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName =
$"persistent://public/default/consumer-tests-{testRunId}";
+
+ _fixture.CreatePartitionedTopic(topicName, partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ //Act
+ var exception = await Record.ExceptionAsync(() =>
consumer.GetLastMessageId().AsTask());
+
+ //Assert
+ exception.Should().BeOfType<NotSupportedException>();
+ }
+
+ [Theory]
+ [InlineData(10000)]
+ public async Task
Messages_GivenPartitionedTopicWithMessages_ShouldConsumeAll(int
numberOfMessages)
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-with-3-partitions-test";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ //Act
+ await using var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ await using var producer = client.NewProducer(Schema.ByteArray)
+ .ProducerName($"producer-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
+
+ var produced = await ProduceMessages(producer, numberOfMessages,
cts.Token);
+ var consumed = await ConsumeMessages(consumer, numberOfMessages,
cts.Token);
+
+ //Assert
+ consumed.Should().BeEquivalentTo(produced);
+ }
+
+ [Fact]
+ public async Task
GetLastMessageIds_GivenMessageIdsFrom3Partitions_ShouldHave3Partitions()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ const int numberOfMessages = 10;
+ var topicName = $"consumer_get_last_message_ids_should_have_3_topics";
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ await using var producer = client.NewProducer(Schema.String)
+ .Topic(topicName)
+ .Create();
+
+ await using var consumer = client.NewConsumer(Schema.ByteArray)
+ .ConsumerName($"consumer-{testRunId}")
+ .InitialPosition(SubscriptionInitialPosition.Earliest)
+ .SubscriptionName($"subscription-{testRunId}")
+ .Topic(topicName)
+ .Create();
+
+ const string content = "test-message";
+ for (var i = 0; i < numberOfMessages; i++)
+ {
+ await producer.Send(content);
+ }
+
+ string[] expected = {
"consumer_get_last_message_ids_should_have_3_topics-partition-0",
"consumer_get_last_message_ids_should_have_3_topics-partition-1",
"consumer_get_last_message_ids_should_have_3_topics-partition-2" };
+
+ //Act
+ var actual = await consumer.GetLastMessageIds();
+
+ //Assert
+ actual.Select(x =>
x.Topic).Should().HaveCount(3).And.Contain(expected);
Review Comment:
Should contain or should be exactly like expected?
--
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]