-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to
.NET6
. Add CONTRIBUTING.md
.
- Loading branch information
1 parent
3a7a429
commit abb6677
Showing
10 changed files
with
286 additions
and
281 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# How to contribute | ||
|
||
We'd love to accept your patches and contributions to this project. There are | ||
just a few small guidelines you need to follow. | ||
|
||
## Branching Model | ||
|
||
This repository uses the [Gitflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) branching model. | ||
|
||
## Code reviews | ||
|
||
All submissions, including submissions by project members, require review. We | ||
use GitHub pull requests for this purpose. Consult | ||
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more | ||
information on using pull requests. |
52 changes: 29 additions & 23 deletions
52
Kafka.OffsetManagement.Tests/Kafka.OffsetManagement.Tests.csproj
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 |
---|---|---|
@@ -1,29 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>9.0</LangVersion> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<WarningsAsErrors>nullable</WarningsAsErrors> | ||
<LangVersion>10.0</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.1.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.1.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Kafka.OffsetManagement\Kafka.OffsetManagement.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Using Include="FluentAssertions" /> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Kafka.OffsetManagement\Kafka.OffsetManagement.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 |
---|---|---|
@@ -1,87 +1,81 @@ | ||
using FluentAssertions; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
namespace Kafka.OffsetManagement.Tests; | ||
|
||
namespace Kafka.OffsetManagement.Tests | ||
public sealed class OffsetManagerTests | ||
{ | ||
public sealed class OffsetManagerTests | ||
[Theory] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 5, 6 }, 7)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 5, 7 }, 6)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 7 }, 5)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 6, 7 }, 5)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { }, 5)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 7, 5 }, 6)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 5, 7, 6 }, 8)] | ||
[InlineData(new long[] { }, new long[] { }, null)] | ||
public async Task Getting_commitable_offset(long[] offsets, long[] ackOffsets, long? expectedOffset) | ||
{ | ||
[Theory] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 5, 6 }, 7)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 5, 7 }, 6)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 7 }, 5)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 6, 7 }, 5)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { }, 5)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 7, 5 }, 6)] | ||
[InlineData(new long[] { 5, 6, 7 }, new long[] { 5, 7, 6 }, 8)] | ||
[InlineData(new long[] { }, new long[] { }, null)] | ||
public async Task Getting_commitable_offset(long[] offsets, long[] ackOffsets, long? expectedOffset) | ||
{ | ||
using var sut = new OffsetManager(100); | ||
|
||
var offsetAckIds = new Dictionary<long, AckId>(); | ||
using var sut = new OffsetManager(100); | ||
|
||
foreach (var offset in offsets) | ||
offsetAckIds[offset] = await sut.GetAckIdAsync(offset); | ||
var offsetAckIds = new Dictionary<long, AckId>(); | ||
|
||
foreach (var offset in ackOffsets) | ||
sut.Ack(offsetAckIds[offset]); | ||
foreach (var offset in offsets) | ||
offsetAckIds[offset] = await sut.GetAckIdAsync(offset); | ||
|
||
var commitOffset = sut.GetCommitOffset(); | ||
foreach (var offset in ackOffsets) | ||
sut.Ack(offsetAckIds[offset]); | ||
|
||
commitOffset.Should().Be(expectedOffset); | ||
} | ||
var commitOffset = sut.GetCommitOffset(); | ||
|
||
[Fact] | ||
public async Task Getting_out_of_order_offset_ack_id() | ||
{ | ||
using var sut = new OffsetManager(100); | ||
await sut.GetAckIdAsync(5); | ||
commitOffset.Should().Be(expectedOffset); | ||
} | ||
|
||
KafkaOffsetManagementException? ex = null; | ||
[Fact] | ||
public async Task Getting_out_of_order_offset_ack_id() | ||
{ | ||
using var sut = new OffsetManager(100); | ||
await sut.GetAckIdAsync(5); | ||
|
||
try | ||
{ | ||
await sut.GetAckIdAsync(4); | ||
} | ||
catch (KafkaOffsetManagementException e) | ||
{ | ||
ex = e; | ||
} | ||
KafkaOffsetManagementException? ex = null; | ||
|
||
ex?.ErrorCode.Should().Be(KafkaOffsetManagementErrorCode.OffsetOutOfOrder); | ||
try | ||
{ | ||
await sut.GetAckIdAsync(4); | ||
} | ||
|
||
[Fact] | ||
public void Marking_offset_as_acked() | ||
catch (KafkaOffsetManagementException e) | ||
{ | ||
using var sut = new OffsetManager(100); | ||
ex = e; | ||
} | ||
|
||
ex?.ErrorCode.Should().Be(KafkaOffsetManagementErrorCode.OffsetOutOfOrder); | ||
} | ||
|
||
sut.MarkAsAcked(5); | ||
[Fact] | ||
public void Marking_offset_as_acked() | ||
{ | ||
using var sut = new OffsetManager(100); | ||
|
||
var commitOffset = sut.GetCommitOffset(); | ||
commitOffset.Should().Be(6); | ||
} | ||
sut.MarkAsAcked(5); | ||
|
||
[Fact] | ||
public async Task Marking_out_of_order_offset_as_acked() | ||
{ | ||
using var sut = new OffsetManager(100); | ||
await sut.GetAckIdAsync(5); | ||
var commitOffset = sut.GetCommitOffset(); | ||
commitOffset.Should().Be(6); | ||
} | ||
|
||
KafkaOffsetManagementException? ex = null; | ||
[Fact] | ||
public async Task Marking_out_of_order_offset_as_acked() | ||
{ | ||
using var sut = new OffsetManager(100); | ||
await sut.GetAckIdAsync(5); | ||
|
||
try | ||
{ | ||
sut.MarkAsAcked(4); | ||
} | ||
catch (KafkaOffsetManagementException e) | ||
{ | ||
ex = e; | ||
} | ||
KafkaOffsetManagementException? ex = null; | ||
|
||
ex?.ErrorCode.Should().Be(KafkaOffsetManagementErrorCode.OffsetOutOfOrder); | ||
try | ||
{ | ||
sut.MarkAsAcked(4); | ||
} | ||
catch (KafkaOffsetManagementException e) | ||
{ | ||
ex = e; | ||
} | ||
|
||
ex?.ErrorCode.Should().Be(KafkaOffsetManagementErrorCode.OffsetOutOfOrder); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,49 +1,46 @@ | ||
using System; | ||
namespace Kafka.OffsetManagement; | ||
|
||
namespace Kafka.OffsetManagement | ||
public struct AckId : IEquatable<AckId> | ||
{ | ||
public struct AckId : IEquatable<AckId> | ||
{ | ||
public int Value { get; } | ||
|
||
public AckId(int value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static implicit operator int(AckId ackId) | ||
{ | ||
return ackId.Value; | ||
} | ||
|
||
public static implicit operator AckId(int value) | ||
{ | ||
return new(value); | ||
} | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
return obj is AckId ackId && Equals(ackId); | ||
} | ||
|
||
public bool Equals(AckId other) | ||
{ | ||
return other.Value == Value; | ||
} | ||
|
||
public static bool operator ==(AckId a, AckId b) | ||
{ | ||
return a.Equals(b); | ||
} | ||
|
||
public static bool operator !=(AckId a, AckId b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Value.GetHashCode(); | ||
} | ||
} | ||
} | ||
public int Value { get; } | ||
|
||
public AckId(int value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static implicit operator int(AckId ackId) | ||
{ | ||
return ackId.Value; | ||
} | ||
|
||
public static implicit operator AckId(int value) | ||
{ | ||
return new(value); | ||
} | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
return obj is AckId ackId && Equals(ackId); | ||
} | ||
|
||
public bool Equals(AckId other) | ||
{ | ||
return other.Value == Value; | ||
} | ||
|
||
public static bool operator ==(AckId a, AckId b) | ||
{ | ||
return a.Equals(b); | ||
} | ||
|
||
public static bool operator !=(AckId a, AckId b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Value.GetHashCode(); | ||
} | ||
} |
Oops, something went wrong.