dionjansen commented on a change in pull request #67: URL: https://github.com/apache/pulsar-dotpulsar/pull/67#discussion_r558418794
########## File path: tests/DotPulsar.Tests/Internal/MessageAcksTrackerTests.cs ########## @@ -0,0 +1,158 @@ +/* + * 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 DotPulsar.Tests.Internal +{ + using AutoFixture; + using AutoFixture.AutoNSubstitute; + using DotPulsar.Abstractions; + using DotPulsar.Internal; + using NSubstitute; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Linq.Expressions; + using System.Threading; + using System.Threading.Tasks; + using Xunit; + + public class UnackedMessageTrackerTests + { + + [Fact] + public async void Start_GivenAMessageIdIsNotAcked_ShouldRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + + + var tracker = new UnackedMessageTracker( + TimeSpan.FromMilliseconds(10), + TimeSpan.FromMilliseconds(1)); + + //Act + tracker.Add(messageId); + cts.CancelAfter(20); + try { await tracker.Start(consumer, cts.Token); } + catch (TaskCanceledException) { } + + //Assert + await consumer + .Received(1) + .RedeliverUnacknowledgedMessages( + Arg.Is(EquivalentTo(new List<MessageId>() { messageId })), + Arg.Any<CancellationToken>()); + } + + [Fact] + public async void Start_GivenAMessageIdIsAckedWithinTimeout_ShouldNotRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + + + var tracker = new UnackedMessageTracker( + TimeSpan.FromMilliseconds(10), + TimeSpan.FromMilliseconds(1)); + + //Act + tracker.Add(messageId); + cts.CancelAfter(20); + var _ = Task.Delay(5).ContinueWith(_ => tracker.Ack(messageId)); + try { await tracker.Start(consumer, cts.Token); } + catch (TaskCanceledException) { } + + //Assert + await consumer + .DidNotReceive() + .RedeliverUnacknowledgedMessages( + Arg.Any<IEnumerable<MessageId>>(), + Arg.Any<CancellationToken>()); + } + + [Fact] + public async void Start_GivenAMessageIdIsNotAckedWithinTimeout_ShouldRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + + + var tracker = new UnackedMessageTracker( + TimeSpan.FromMilliseconds(10), + TimeSpan.FromMilliseconds(1)); + + //Act + tracker.Add(messageId); + cts.CancelAfter(20); + + var _ = Task.Delay(15).ContinueWith(_ => tracker.Ack(messageId)); + try { await tracker.Start(consumer, cts.Token); } + catch (TaskCanceledException) { } + + //Assert + await consumer + .Received(1) + .RedeliverUnacknowledgedMessages( + Arg.Any<IEnumerable<MessageId>>(), + Arg.Any<CancellationToken>()); + } + + [Fact] + public async void Start_GivenAMessageIdIsNotAckedWithinTimeout_ShouldRedeliverOnlyOnce() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + Review comment: Done: ddfd374 ########## File path: tests/DotPulsar.Tests/Internal/MessageAcksTrackerTests.cs ########## @@ -0,0 +1,158 @@ +/* + * 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 DotPulsar.Tests.Internal +{ + using AutoFixture; + using AutoFixture.AutoNSubstitute; + using DotPulsar.Abstractions; + using DotPulsar.Internal; + using NSubstitute; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Linq.Expressions; + using System.Threading; + using System.Threading.Tasks; + using Xunit; + + public class UnackedMessageTrackerTests + { + + [Fact] + public async void Start_GivenAMessageIdIsNotAcked_ShouldRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + + + var tracker = new UnackedMessageTracker( + TimeSpan.FromMilliseconds(10), + TimeSpan.FromMilliseconds(1)); + + //Act + tracker.Add(messageId); + cts.CancelAfter(20); + try { await tracker.Start(consumer, cts.Token); } + catch (TaskCanceledException) { } + + //Assert + await consumer + .Received(1) + .RedeliverUnacknowledgedMessages( + Arg.Is(EquivalentTo(new List<MessageId>() { messageId })), + Arg.Any<CancellationToken>()); + } + + [Fact] + public async void Start_GivenAMessageIdIsAckedWithinTimeout_ShouldNotRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + + + var tracker = new UnackedMessageTracker( + TimeSpan.FromMilliseconds(10), + TimeSpan.FromMilliseconds(1)); + + //Act + tracker.Add(messageId); + cts.CancelAfter(20); + var _ = Task.Delay(5).ContinueWith(_ => tracker.Ack(messageId)); + try { await tracker.Start(consumer, cts.Token); } + catch (TaskCanceledException) { } + + //Assert + await consumer + .DidNotReceive() + .RedeliverUnacknowledgedMessages( + Arg.Any<IEnumerable<MessageId>>(), + Arg.Any<CancellationToken>()); + } + + [Fact] + public async void Start_GivenAMessageIdIsNotAckedWithinTimeout_ShouldRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + Review comment: Done: ddfd374 ########## File path: tests/DotPulsar.Tests/Internal/MessageAcksTrackerTests.cs ########## @@ -0,0 +1,158 @@ +/* + * 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 DotPulsar.Tests.Internal +{ + using AutoFixture; + using AutoFixture.AutoNSubstitute; + using DotPulsar.Abstractions; + using DotPulsar.Internal; + using NSubstitute; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Linq.Expressions; + using System.Threading; + using System.Threading.Tasks; + using Xunit; + + public class UnackedMessageTrackerTests + { + + [Fact] + public async void Start_GivenAMessageIdIsNotAcked_ShouldRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + + + var tracker = new UnackedMessageTracker( + TimeSpan.FromMilliseconds(10), + TimeSpan.FromMilliseconds(1)); + + //Act + tracker.Add(messageId); + cts.CancelAfter(20); + try { await tracker.Start(consumer, cts.Token); } + catch (TaskCanceledException) { } + + //Assert + await consumer + .Received(1) + .RedeliverUnacknowledgedMessages( + Arg.Is(EquivalentTo(new List<MessageId>() { messageId })), + Arg.Any<CancellationToken>()); + } + + [Fact] + public async void Start_GivenAMessageIdIsAckedWithinTimeout_ShouldNotRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + Review comment: Done: ddfd374 ########## File path: tests/DotPulsar.Tests/Internal/MessageAcksTrackerTests.cs ########## @@ -0,0 +1,158 @@ +/* + * 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 DotPulsar.Tests.Internal +{ + using AutoFixture; + using AutoFixture.AutoNSubstitute; + using DotPulsar.Abstractions; + using DotPulsar.Internal; + using NSubstitute; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Linq.Expressions; + using System.Threading; + using System.Threading.Tasks; + using Xunit; + + public class UnackedMessageTrackerTests + { + Review comment: Done: ddfd374 ########## File path: src/DotPulsar/Internal/InactiveUnackedMessageTracker.cs ########## @@ -0,0 +1,42 @@ +/* + * 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 DotPulsar.Internal +{ + using Abstractions; + using DotPulsar.Abstractions; + using System.Threading; + using System.Threading.Tasks; + + public class InactiveUnackedMessageTracker : IUnackedMessageTracker Review comment: Done: ddfd374 ########## File path: tests/DotPulsar.Tests/Internal/MessageAcksTrackerTests.cs ########## @@ -0,0 +1,158 @@ +/* + * 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 DotPulsar.Tests.Internal +{ + using AutoFixture; + using AutoFixture.AutoNSubstitute; + using DotPulsar.Abstractions; + using DotPulsar.Internal; + using NSubstitute; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Linq.Expressions; + using System.Threading; + using System.Threading.Tasks; + using Xunit; + + public class UnackedMessageTrackerTests + { + + [Fact] + public async void Start_GivenAMessageIdIsNotAcked_ShouldRedeliver() + { + //Arrange + var fixture = new Fixture(); + fixture.Customize(new AutoNSubstituteCustomization()); + var consumer = Substitute.For<IConsumer>(); + var messageId = MessageId.Latest; + var cts = new CancellationTokenSource(); + Review comment: Done: ddfd374 ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org