Skip to content

Commit

Permalink
Migrate to .NET6. Add CONTRIBUTING.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
tautvydasversockas committed Jan 17, 2022
1 parent 3a7a429 commit abb6677
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 281 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@ name: publish-nuget
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Checkout
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
dotnet-version: 6.0.x

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --verbosity normal

- name: Publish
uses: brandedoutcast/publish-nuget@v2.5.5
with:
Expand Down
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
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 Kafka.OffsetManagement.Tests/Kafka.OffsetManagement.Tests.csproj
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>
124 changes: 59 additions & 65 deletions Kafka.OffsetManagement.Tests/OffsetManagerTests.cs
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);
}
}
91 changes: 44 additions & 47 deletions Kafka.OffsetManagement/AckId.cs
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();
}
}

0 comments on commit abb6677

Please sign in to comment.