Skip to content

Commit

Permalink
Added ConsumerType to Store/Get offset methods version-0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
numinnex committed Jul 27, 2023
1 parent 5d1393b commit 2faa3a2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Iggy_SDK.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<TestId>xUnit::8514D555-35CF-4538-97D3-DC42A182B694::net7.0::Iggy_SDK_Tests.MapperTests.BinaryMapper</TestId>
<TestId>xUnit::8514D555-35CF-4538-97D3-DC42A182B694::net7.0::Iggy_SDK_Tests.UtilityTests.ToSnakeCaseMessagePolicy</TestId>
<TestId>xUnit::8514D555-35CF-4538-97D3-DC42A182B694::net7.0::Iggy_SDK_Tests.ContractTests.TcpContract.TcpContracts_MessageSendRequest_HasCorrectBytes</TestId>
<TestId>xUnit::8514D555-35CF-4538-97D3-DC42A182B694::net7.0::Iggy_SDK_Tests.ContractTests.TcpContract.TcpContracts_GetOffset_HasCorrectBytes</TestId>
<TestId>xUnit::8514D555-35CF-4538-97D3-DC42A182B694::net7.0::Iggy_SDK_Tests.ContractTests.TcpContract</TestId>
</TestAncestor>
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fdae582f_002D649c_002D46a6_002D8ad5_002D876f70bf8246/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="GetTopicByIdAsync_Returns200Ok_WhenFound" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
Expand Down
3 changes: 3 additions & 0 deletions Iggy_SDK/Contracts/Http/OffsetContract.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Iggy_SDK.Enums;

namespace Iggy_SDK.Contracts.Http;

public sealed class OffsetContract
{
public required ConsumerType ConsumerType { get; init; }
public required int ConsumerId { get; init; }
public required int PartitionId { get; init; }
public required ulong Offset { get; init; }
Expand Down
3 changes: 3 additions & 0 deletions Iggy_SDK/Contracts/Http/OffsetRequest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Iggy_SDK.Enums;

namespace Iggy_SDK.Contracts.Http;

public sealed class OffsetRequest
{
public required ConsumerType ConsumerType { get; init; }
public required int StreamId { get; init; }
public required int TopicId { get; init; }
public required int ConsumerId { get; init; }
Expand Down
12 changes: 10 additions & 2 deletions Iggy_SDK/Contracts/Tcp/TcpContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ internal static byte[] DeleteTopic(int streamId, int topicId)
internal static byte[] UpdateOffset(int streamId, int topicId, OffsetContract contract)
{
Span<byte> bytes = stackalloc byte[sizeof(int) * 4 + sizeof(ulong) + 1];
bytes[0] = 0;
bytes[0] = contract.ConsumerType switch

Check warning on line 159 in Iggy_SDK/Contracts/Tcp/TcpContracts.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(Iggy_SDK.Enums.ConsumerType)2' is not covered.

Check warning on line 159 in Iggy_SDK/Contracts/Tcp/TcpContracts.cs

View workflow job for this annotation

GitHub Actions / nuget

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(Iggy_SDK.Enums.ConsumerType)2' is not covered.
{
ConsumerType.Consumer => 0,
ConsumerType.ConsumerGroup => 1,
};
BinaryPrimitives.WriteInt32LittleEndian(bytes[1..5], contract.ConsumerId);
BinaryPrimitives.WriteInt32LittleEndian(bytes[5..9], streamId);
BinaryPrimitives.WriteInt32LittleEndian(bytes[9..13], topicId);
Expand All @@ -168,7 +172,11 @@ internal static byte[] UpdateOffset(int streamId, int topicId, OffsetContract co
internal static byte[] GetOffset(OffsetRequest request)
{
Span<byte> bytes = stackalloc byte[sizeof(int) * 4 + 1];
bytes[0] = 0;
bytes[0] = request.ConsumerType switch

Check warning on line 175 in Iggy_SDK/Contracts/Tcp/TcpContracts.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(Iggy_SDK.Enums.ConsumerType)2' is not covered.

Check warning on line 175 in Iggy_SDK/Contracts/Tcp/TcpContracts.cs

View workflow job for this annotation

GitHub Actions / nuget

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(Iggy_SDK.Enums.ConsumerType)2' is not covered.
{
ConsumerType.Consumer => 0,
ConsumerType.ConsumerGroup => 1,
};
BinaryPrimitives.WriteInt32LittleEndian(bytes[1..5], request.ConsumerId);
BinaryPrimitives.WriteInt32LittleEndian(bytes[5..9], request.StreamId);
BinaryPrimitives.WriteInt32LittleEndian(bytes[9..13], request.TopicId);
Expand Down
3 changes: 3 additions & 0 deletions Iggy_SDK_Tests/Utils/Offsets/OffsetFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Iggy_SDK.Contracts;
using Iggy_SDK.Contracts.Http;
using Iggy_SDK.Enums;

namespace Iggy_SDK_Tests.Utils.Offset;

Expand All @@ -9,6 +10,7 @@ internal static OffsetRequest CreateOffsetRequest()
{
return new OffsetRequest
{
ConsumerType = ConsumerType.Consumer,
TopicId = Random.Shared.Next(1, 10),
PartitionId = Random.Shared.Next(1, 10),
ConsumerId = Random.Shared.Next(1, 10),
Expand All @@ -29,6 +31,7 @@ internal static OffsetContract CreateOffsetContract()
{
return new OffsetContract
{
ConsumerType = ConsumerType.Consumer,
Offset = (ulong)Random.Shared.Next(1, 10),
ConsumerId = Random.Shared.Next(1, 10),
PartitionId = Random.Shared.Next(1, 10),
Expand Down
10 changes: 8 additions & 2 deletions Iggy_Sample_Consumer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
var jsonOptions = new JsonSerializerOptions();
jsonOptions.PropertyNamingPolicy = new ToSnakeCaseNamingPolicy();
jsonOptions.WriteIndented = true;
var protocol = Protocol.Tcp;
// var protocol = Protocol.Tcp;
// var bus = MessageStreamFactory.CreateMessageStream(options =>
// {
// options.BaseAdress = "127.0.0.1:8090";
// options.Protocol = protocol;
// });
var protocol = Protocol.Http;
var bus = MessageStreamFactory.CreateMessageStream(options =>
{
options.BaseAdress = "127.0.0.1:8090";
options.BaseAdress = "http://127.0.0.1:3000";
options.Protocol = protocol;
});

Expand Down

0 comments on commit 2faa3a2

Please sign in to comment.