Skip to content

Commit e2fcc67

Browse files
lukaszzborekspetz
andauthored
refactor(csharp): change expiry handling to use TimeSpan (#2690)
- change expiery argument from ulong to TimeSpan - internal change from TimeSpan to ulong value via `DurationHelpers` BREAKING --------- Co-authored-by: Piotr Gankiewicz <piotr.gankiewicz@gmail.com>
1 parent 30f4568 commit e2fcc67

25 files changed

Lines changed: 483 additions & 73 deletions

foreign/csharp/Benchmarks/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
for (var i = 0; i < producerCount; i++)
4141
{
42-
var bus = IggyClientFactory.CreateClient(new IggyClientConfigurator()
42+
var bus = IggyClientFactory.CreateClient(new IggyClientConfigurator
4343
{
4444
BaseAddress = "127.0.0.1:8090",
4545
Protocol = Protocol.Tcp,
@@ -67,9 +67,9 @@
6767
await clients[0].CreateStreamAsync($"Test bench stream_{i}");
6868

6969
await clients[0].CreateTopicAsync(Identifier.Numeric(startingStreamId + i),
70-
name: $"Test bench topic_{i}",
70+
$"Test bench topic_{i}",
7171
compressionAlgorithm: CompressionAlgorithm.None,
72-
messageExpiry: 0,
72+
messageExpiry: TimeSpan.Zero,
7373
maxTopicSize: 2_000_000_000,
7474
replicationFactor: 3,
7575
partitionsCount: 1);

foreign/csharp/Iggy_SDK.Tests.Integration/Fixtures/FetchMessagesFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
// // under the License.
1717

1818
using System.Text;
19-
using Apache.Iggy.Contracts.Http;
2019
using Apache.Iggy.Enums;
2120
using Apache.Iggy.Headers;
2221
using Apache.Iggy.IggyClient;
2322
using Apache.Iggy.Messages;
2423
using Apache.Iggy.Tests.Integrations.Helpers;
24+
using Apache.Iggy.Tests.Integrations.Models;
2525
using TUnit.Core.Interfaces;
2626
using Partitioning = Apache.Iggy.Kinds.Partitioning;
2727

@@ -31,8 +31,8 @@ public class FetchMessagesFixture : IAsyncInitializer
3131
{
3232
internal readonly int MessageCount = 20;
3333
internal readonly string StreamId = "FetchMessagesStream";
34-
internal readonly CreateTopicRequest TopicHeadersRequest = TopicFactory.CreateTopic("HeadersTopic");
35-
internal readonly CreateTopicRequest TopicRequest = TopicFactory.CreateTopic("Topic");
34+
internal readonly CreateTestTopic TopicHeadersRequest = TopicFactory.CreateTopic("HeadersTopic");
35+
internal readonly CreateTestTopic TopicRequest = TopicFactory.CreateTopic("Topic");
3636

3737
[ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
3838
public required IggyServerFixture IggyServerFixture { get; init; }

foreign/csharp/Iggy_SDK.Tests.Integration/Fixtures/FlushMessageFixture.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
// // specific language governing permissions and limitations
1616
// // under the License.
1717

18-
using Apache.Iggy.Contracts;
19-
using Apache.Iggy.Contracts.Http;
2018
using Apache.Iggy.Enums;
2119
using Apache.Iggy.IggyClient;
2220
using Apache.Iggy.Messages;
2321
using Apache.Iggy.Tests.Integrations.Helpers;
22+
using Apache.Iggy.Tests.Integrations.Models;
2423
using TUnit.Core.Interfaces;
2524
using Partitioning = Apache.Iggy.Kinds.Partitioning;
2625

@@ -29,7 +28,7 @@ namespace Apache.Iggy.Tests.Integrations.Fixtures;
2928
public class FlushMessageFixture : IAsyncInitializer
3029
{
3130
internal readonly string StreamId = "FlushMessageStream";
32-
internal readonly CreateTopicRequest TopicRequest = TopicFactory.CreateTopic("Topic");
31+
internal readonly CreateTestTopic TopicRequest = TopicFactory.CreateTopic("Topic");
3332

3433
[ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
3534
public required IggyServerFixture IggyServerFixture { get; init; }
@@ -53,7 +52,6 @@ await client.Value.CreateTopicAsync(Identifier.String(StreamId.GetWithProtocol(c
5352
};
5453
await client.Value.SendMessagesAsync(Identifier.String(StreamId.GetWithProtocol(client.Key)),
5554
Identifier.String(TopicRequest.Name), Partitioning.None(), messages);
56-
5755
}
5856
}
5957
}

foreign/csharp/Iggy_SDK.Tests.Integration/Fixtures/IggyServerFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class IggyServerFixture : IAsyncInitializer, IAsyncDisposable
4646
{ "IGGY_ROOT_USERNAME", "iggy" },
4747
{ "IGGY_ROOT_PASSWORD", "iggy" },
4848
{ "IGGY_TCP_ADDRESS", "0.0.0.0:8090" },
49-
{ "IGGY_HTTP_ADDRESS", "0.0.0.0:3000" }
49+
{ "IGGY_HTTP_ADDRESS", "0.0.0.0:3000" },
50+
{ "IGGY_SYSTEM_TOPIC_MESSAGE_EXPIRY", "10m" }
5051
};
5152

5253
/// <summary>

foreign/csharp/Iggy_SDK.Tests.Integration/Fixtures/OffsetFixtures.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
// // specific language governing permissions and limitations
1616
// // under the License.
1717

18-
using Apache.Iggy.Contracts;
19-
using Apache.Iggy.Contracts.Http;
2018
using Apache.Iggy.Enums;
2119
using Apache.Iggy.IggyClient;
2220
using Apache.Iggy.Messages;
2321
using Apache.Iggy.Tests.Integrations.Helpers;
22+
using Apache.Iggy.Tests.Integrations.Models;
2423
using TUnit.Core.Interfaces;
2524
using Partitioning = Apache.Iggy.Kinds.Partitioning;
2625

@@ -29,7 +28,7 @@ namespace Apache.Iggy.Tests.Integrations.Fixtures;
2928
public class OffsetFixtures : IAsyncInitializer
3029
{
3130
internal readonly string StreamId = "OffsetStream";
32-
internal readonly CreateTopicRequest TopicRequest = TopicFactory.CreateTopic("Topic");
31+
internal readonly CreateTestTopic TopicRequest = TopicFactory.CreateTopic("Topic");
3332

3433
[ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
3534
public required IggyServerFixture IggyServerFixture { get; init; }
@@ -49,8 +48,7 @@ await client.Value.CreateTopicAsync(Identifier.String(StreamId.GetWithProtocol(c
4948
{
5049
new(Guid.NewGuid(), "Test message 1"u8.ToArray()),
5150
new(Guid.NewGuid(), "Test message 2"u8.ToArray()),
52-
new(Guid.NewGuid(), "Test message 3"u8.ToArray()),
53-
new(Guid.NewGuid(), "Test message 4"u8.ToArray())
51+
new(Guid.NewGuid(), "Test message 3"u8.ToArray()), new(Guid.NewGuid(), "Test message 4"u8.ToArray())
5452
};
5553
await client.Value.SendMessagesAsync(Identifier.String(StreamId.GetWithProtocol(client.Key)),
5654
Identifier.String(TopicRequest.Name), Partitioning.None(), messages);

foreign/csharp/Iggy_SDK.Tests.Integration/Fixtures/PartitionsFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
// // specific language governing permissions and limitations
1616
// // under the License.
1717

18-
using Apache.Iggy.Contracts.Http;
1918
using Apache.Iggy.Enums;
2019
using Apache.Iggy.IggyClient;
2120
using Apache.Iggy.Tests.Integrations.Helpers;
21+
using Apache.Iggy.Tests.Integrations.Models;
2222
using TUnit.Core.Interfaces;
2323

2424
namespace Apache.Iggy.Tests.Integrations.Fixtures;
2525

2626
public class PartitionsFixture : IAsyncInitializer
2727
{
2828
internal readonly string StreamId = "PartitionsStream";
29-
internal readonly CreateTopicRequest TopicRequest = TopicFactory.CreateTopic("Topic");
29+
internal readonly CreateTestTopic TopicRequest = TopicFactory.CreateTopic("Topic");
3030

3131
[ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
3232
public required IggyServerFixture IggyServerFixture { get; init; }

foreign/csharp/Iggy_SDK.Tests.Integration/Fixtures/SendMessageFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
// // specific language governing permissions and limitations
1616
// // under the License.
1717

18-
using Apache.Iggy.Contracts.Http;
1918
using Apache.Iggy.Enums;
2019
using Apache.Iggy.IggyClient;
2120
using Apache.Iggy.Tests.Integrations.Helpers;
21+
using Apache.Iggy.Tests.Integrations.Models;
2222
using TUnit.Core.Interfaces;
2323

2424
namespace Apache.Iggy.Tests.Integrations.Fixtures;
2525

2626
public class SendMessageFixture : IAsyncInitializer
2727
{
2828
internal readonly string StreamId = "SendMessageStream";
29-
internal readonly CreateTopicRequest TopicRequest = TopicFactory.CreateTopic("Topic");
29+
internal readonly CreateTestTopic TopicRequest = TopicFactory.CreateTopic("Topic");
3030

3131
[ClassDataSource<IggyServerFixture>(Shared = SharedType.PerAssembly)]
3232
public required IggyServerFixture IggyServerFixture { get; init; }

foreign/csharp/Iggy_SDK.Tests.Integration/Helpers/TopicFactory.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
// // specific language governing permissions and limitations
1616
// // under the License.
1717

18-
using Apache.Iggy.Contracts.Http;
18+
using Apache.Iggy.Tests.Integrations.Models;
1919

2020
namespace Apache.Iggy.Tests.Integrations.Helpers;
2121

2222
public static class TopicFactory
2323
{
24-
internal static CreateTopicRequest CreateTopic(string topicId, uint partitionsCount = 1, ulong messageExpiry = 0)
24+
internal static CreateTestTopic CreateTopic(string topicId, uint partitionsCount = 1,
25+
TimeSpan messageExpiry = default)
2526
{
26-
return new CreateTopicRequest
27+
return new CreateTestTopic
2728
{
2829
Name = topicId,
2930
PartitionsCount = partitionsCount,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
using System.Diagnostics.CodeAnalysis;
19+
using Apache.Iggy.Enums;
20+
21+
namespace Apache.Iggy.Tests.Integrations.Models;
22+
23+
internal class CreateTestTopic
24+
{
25+
public required string Name { get; set; }
26+
public CompressionAlgorithm CompressionAlgorithm { get; set; } = CompressionAlgorithm.None;
27+
public TimeSpan MessageExpiry { get; set; } = TimeSpan.Zero;
28+
public uint PartitionsCount { get; set; } = 1;
29+
public byte? ReplicationFactor { get; set; } = 1;
30+
public ulong MaxTopicSize { get; set; }
31+
32+
public CreateTestTopic()
33+
{
34+
}
35+
36+
[SetsRequiredMembers]
37+
public CreateTestTopic(string name,
38+
CompressionAlgorithm compressionAlgorithm,
39+
TimeSpan messageExpiry,
40+
uint partitionsCount,
41+
byte? replicationFactor,
42+
ulong maxTopicSize)
43+
{
44+
Name = name;
45+
CompressionAlgorithm = compressionAlgorithm;
46+
MessageExpiry = messageExpiry;
47+
PartitionsCount = partitionsCount;
48+
ReplicationFactor = replicationFactor;
49+
MaxTopicSize = maxTopicSize;
50+
}
51+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
using Apache.Iggy.Enums;
19+
20+
namespace Apache.Iggy.Tests.Integrations.Models;
21+
22+
internal record UpdateTestTopic(
23+
string Name,
24+
CompressionAlgorithm CompressionAlgorithm,
25+
ulong MaxTopicSize,
26+
TimeSpan MessageExpiry,
27+
byte? ReplicationFactor);

0 commit comments

Comments
 (0)