-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add partition router tests and update xunit packages
Added unit tests for the SinglePartitionRouter and RoundRobinPartitionRouter classes. These tests check that chosen partitions return non-negative integers. Also, minor adjustments have been made to the implementation. The xUnit package versions in the project file have been updated for the latest features and bug fixes.
- Loading branch information
David Jensen
committed
Apr 17, 2024
1 parent
2540244
commit 10b4fe0
Showing
6 changed files
with
87 additions
and
7 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
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
37 changes: 37 additions & 0 deletions
37
tests/DotPulsar.Tests/Internal/RoundRobinPartitionRouterTests.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,37 @@ | ||
namespace DotPulsar.Tests.Internal; | ||
|
||
public class RoundRobinPartitionRouterTests | ||
{ | ||
[Fact] | ||
public void ChoosePartition_GivenBytes_ShouldReturnNonNegativeInteger() | ||
{ | ||
// Arrange | ||
var router = new RoundRobinPartitionRouter(); | ||
var messageMetadata = new MessageMetadata | ||
{ | ||
KeyBytes = [13, 144, 79, 245] //-179335155 | ||
}; | ||
|
||
//Act | ||
var result = router.ChoosePartition(messageMetadata, 4); | ||
|
||
//Assert | ||
result.Should().BeInRange(0, 3); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1)] | ||
[InlineData(int.MaxValue)] | ||
public void ChoosePartition_GivenNoMetadata_ShouldReturnNonNegativeInteger(int numberOfPartitions) | ||
{ | ||
// Arrange | ||
var router = new RoundRobinPartitionRouter(); | ||
var messageMetadata = new MessageMetadata(); | ||
|
||
//Act | ||
var result = router.ChoosePartition(messageMetadata, numberOfPartitions); | ||
|
||
//Assert | ||
result.Should().BeInRange(0, numberOfPartitions); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/DotPulsar.Tests/Internal/SinglePartitionRouterTests.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,37 @@ | ||
namespace DotPulsar.Tests.Internal; | ||
|
||
public class SinglePartitionRouterTests | ||
{ | ||
[Fact] | ||
public void ChoosePartition_GivenBytes_ShouldReturnNonNegativeInteger() | ||
{ | ||
// Arrange | ||
var router = new SinglePartitionRouter(); | ||
var messageMetadata = new MessageMetadata | ||
{ | ||
KeyBytes = [13, 144, 79, 245] //-179335155 | ||
}; | ||
|
||
//Act | ||
var result = router.ChoosePartition(messageMetadata, 4); | ||
|
||
//Assert | ||
result.Should().BeInRange(0, 3); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1)] | ||
[InlineData(int.MaxValue)] | ||
public void ChoosePartition_GivenNoMetadata_ShouldReturnNonNegativeInteger(int numberOfPartitions) | ||
{ | ||
// Arrange | ||
var router = new SinglePartitionRouter(); | ||
var messageMetadata = new MessageMetadata(); | ||
|
||
//Act | ||
var result = router.ChoosePartition(messageMetadata, numberOfPartitions); | ||
|
||
//Assert | ||
result.Should().BeInRange(0, numberOfPartitions); | ||
} | ||
} |