blankensteiner commented on code in PR #162:
URL: https://github.com/apache/pulsar-dotpulsar/pull/162#discussion_r1284328544
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,151 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task GetLastMessageId_PartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-tests-{testRunId}";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ //Act
+ 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();
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
+ //Assert
+ Assert.ThrowsAsync<NotSupportedException>(async () => await
consumer.GetLastMessageId(cts.Token));
+ }
+
+ [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);
+
+ //Act
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ 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));
+
+ //Act
Review Comment:
Assert
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,151 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task GetLastMessageId_PartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-tests-{testRunId}";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ //Act
+ 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();
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
+ //Assert
+ Assert.ThrowsAsync<NotSupportedException>(async () => await
consumer.GetLastMessageId(cts.Token));
+ }
+
+ [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);
+
+ //Act
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ 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));
+
+ //Act
+ var produced = await ProduceMessages(producer, numberOfMessages,
cts.Token);
+ var consumed = await ConsumeMessages(consumer, numberOfMessages,
cts.Token);
+
+ consumed.Should().BeEquivalentTo(produced);
+ }
+
+ [Theory]
+ [InlineData(10)]
+ public async Task
GetLastMessageIds_MessageIdsFrom3Partitions_ShouldHave3Partitions(int
numberOfMessages)
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ 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);
+ }
+
+ //Act
+ var lastMessageIds = await consumer.GetLastMessageIds();
+
+ string[] shouldHave = {
"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" };
+
+ //Assert
+ lastMessageIds.Select(x =>
x.Topic).ToArray().Should().Contain(shouldHave);
Review Comment:
FluentAssertions can handle this.
Consider renaming "shouldHave" to "expected" (and move to "Arrange") and
"lastMessageIds" to "actual"
##########
tests/DotPulsar.Tests/ReaderTests.cs:
##########
@@ -0,0 +1,278 @@
+namespace DotPulsar.Tests;
Review Comment:
Need apache header
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,151 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task GetLastMessageId_PartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-tests-{testRunId}";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ //Act
+ 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();
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
+ //Assert
+ Assert.ThrowsAsync<NotSupportedException>(async () => await
consumer.GetLastMessageId(cts.Token));
+ }
+
+ [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);
+
+ //Act
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ 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));
+
+ //Act
+ var produced = await ProduceMessages(producer, numberOfMessages,
cts.Token);
+ var consumed = await ConsumeMessages(consumer, numberOfMessages,
cts.Token);
+
+ consumed.Should().BeEquivalentTo(produced);
+ }
+
+ [Theory]
+ [InlineData(10)]
+ public async Task
GetLastMessageIds_MessageIdsFrom3Partitions_ShouldHave3Partitions(int
numberOfMessages)
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ 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);
+ }
+
+ //Act
+ var lastMessageIds = await consumer.GetLastMessageIds();
+
+ string[] shouldHave = {
"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" };
+
+ //Assert
+ lastMessageIds.Select(x =>
x.Topic).ToArray().Should().Contain(shouldHave);
+ }
+
+ [Theory]
+ [InlineData(10)]
+ public async Task
GetLastMessageIds_Given3Partitions_ShouldHave3lastMessageIds(int
numberOfMessages)
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ 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.Count().Should().Be(3);
Review Comment:
I think FluentAssertion also has a method for how many elements you expect
in a collection
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,151 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task GetLastMessageId_PartitionedTopic_ShouldThrowException()
Review Comment:
WhenTopicIsPartitioned or GivenPartitionedTopic
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,151 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task GetLastMessageId_PartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-tests-{testRunId}";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ //Act
+ 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();
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
+ //Assert
+ Assert.ThrowsAsync<NotSupportedException>(async () => await
consumer.GetLastMessageId(cts.Token));
+ }
+
+ [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);
+
+ //Act
+ await using var client = PulsarClient.Builder()
+ .ServiceUrl(_fixture.ServiceUrl)
+ .Authentication(AuthenticationFactory.Token(ct =>
ValueTask.FromResult(_fixture.CreateToken(Timeout.InfiniteTimeSpan))))
+ .Build();
+
+ 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));
+
+ //Act
+ var produced = await ProduceMessages(producer, numberOfMessages,
cts.Token);
Review Comment:
These are part of the "act"
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,151 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task GetLastMessageId_PartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-tests-{testRunId}";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ //Act
+ 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();
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
+ //Assert
+ Assert.ThrowsAsync<NotSupportedException>(async () => await
consumer.GetLastMessageId(cts.Token));
Review Comment:
Use Record.ExceptionAsync from xUnit (for the "Act") and Should().BeOfType
from FluentAssertion for the "Assert".
##########
tests/DotPulsar.Tests/ConsumerTests.cs:
##########
@@ -70,6 +71,151 @@ public async Task
Messages_GivenTopicWithMessages_ShouldConsumeAll(int numberOfM
consumed.Should().BeEquivalentTo(produced);
}
+ [Fact]
+ public async Task GetLastMessageId_PartitionedTopic_ShouldThrowException()
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+ const int partitions = 3;
+ var topicName = $"consumer-tests-{testRunId}";
+
+
_fixture.CreatePartitionedTopic($"persistent://public/default/{topicName}",
partitions);
+
+ //Act
+ 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();
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
Review Comment:
Not needed
--
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]