Skip to content

Commit f37727a

Browse files
committed
[DEVEX-222] Added Tombstone method with options and made the old obsolete
1 parent e896283 commit f37727a

File tree

4 files changed

+75
-18
lines changed

4 files changed

+75
-18
lines changed

src/KurrentDB.Client/Streams/KurrentDBClient.Delete.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ CancellationToken cancellationToken
5252

5353
public class DeleteOptions : OperationOptions;
5454

55-
public static class KurrentDBClientObsoleteDeleteExtensions {
55+
[Obsolete("Those extensions may be removed in the future versions", false)]
56+
public static class ObsoleteKurrentDBClientDeleteExtensions {
5657
/// <summary>
5758
/// Deletes a stream asynchronously.
5859
/// </summary>

src/KurrentDB.Client/Streams/KurrentDBClient.Tombstone.cs

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,80 @@ public partial class KurrentDBClient {
88
/// </summary>
99
/// <param name="streamName">The name of the stream to tombstone.</param>
1010
/// <param name="expectedState">The expected <see cref="StreamState"/> of the stream being deleted.</param>
11-
/// <param name="deadline"></param>
12-
/// <param name="userCredentials">The optional <see cref="UserCredentials"/> to perform operation with.</param>
11+
/// <param name="options">Optional settings for the tombstone operation, e.g. deadline, user credentials etc.</param>
1312
/// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
1413
/// <returns></returns>
1514
public Task<DeleteResult> TombstoneAsync(
1615
string streamName,
1716
StreamState expectedState,
18-
TimeSpan? deadline = null,
19-
UserCredentials? userCredentials = null,
20-
CancellationToken cancellationToken = default) => TombstoneInternal(new TombstoneReq {
21-
Options = new TombstoneReq.Types.Options {
22-
StreamIdentifier = streamName
23-
}
24-
}.WithAnyStreamRevision(expectedState), deadline, userCredentials, cancellationToken);
17+
TombstoneOptions? options = null,
18+
CancellationToken cancellationToken = default
19+
) =>
20+
TombstoneInternal(
21+
new TombstoneReq {
22+
Options = new TombstoneReq.Types.Options {
23+
StreamIdentifier = streamName
24+
}
25+
}.WithAnyStreamRevision(expectedState),
26+
options,
27+
cancellationToken
28+
);
2529

26-
private async Task<DeleteResult> TombstoneInternal(TombstoneReq request, TimeSpan? deadline,
27-
UserCredentials? userCredentials, CancellationToken cancellationToken) {
30+
async Task<DeleteResult> TombstoneInternal(
31+
TombstoneReq request,
32+
TombstoneOptions? options,
33+
CancellationToken cancellationToken
34+
) {
2835
_log.LogDebug("Tombstoning stream {streamName}.", request.Options.StreamIdentifier);
2936

3037
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
31-
using var call = new EventStore.Client.Streams.Streams.StreamsClient(
32-
channelInfo.CallInvoker).TombstoneAsync(request,
33-
KurrentDBCallOptions.CreateNonStreaming(Settings, deadline, userCredentials, cancellationToken));
38+
using var call = new Streams.StreamsClient(channelInfo.CallInvoker).TombstoneAsync(
39+
request,
40+
KurrentDBCallOptions.CreateNonStreaming(
41+
Settings,
42+
options?.Deadline,
43+
options?.UserCredentials,
44+
cancellationToken
45+
)
46+
);
47+
3448
var result = await call.ResponseAsync.ConfigureAwait(false);
3549

3650
return new DeleteResult(new Position(result.Position.CommitPosition, result.Position.PreparePosition));
3751
}
3852
}
53+
54+
[Obsolete("Those extensions may be removed in the future versions", false)]
55+
public static class ObsoleteKurrentDBClientTombstoneExtensions {
56+
/// <summary>
57+
/// Tombstones a stream asynchronously. Note: Tombstoned streams can never be recreated.
58+
/// </summary>
59+
/// <param name="dbClient"></param>
60+
/// <param name="streamName">The name of the stream to tombstone.</param>
61+
/// <param name="expectedState">The expected <see cref="StreamState"/> of the stream being deleted.</param>
62+
/// <param name="deadline"></param>
63+
/// <param name="userCredentials">The optional <see cref="UserCredentials"/> to perform operation with.</param>
64+
/// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param>
65+
/// <returns></returns>
66+
[Obsolete(
67+
"This method may be removed in future releases. Use the overload with TombstoneOptions parameter",
68+
false
69+
)]
70+
public static Task<DeleteResult> TombstoneAsync(
71+
KurrentDBClient dbClient,
72+
string streamName,
73+
StreamState expectedState,
74+
TimeSpan? deadline = null,
75+
UserCredentials? userCredentials = null,
76+
CancellationToken cancellationToken = default
77+
) =>
78+
dbClient.TombstoneAsync(
79+
streamName,
80+
expectedState,
81+
new TombstoneOptions { Deadline = deadline, UserCredentials = userCredentials },
82+
cancellationToken
83+
);
84+
}
85+
86+
public class TombstoneOptions : OperationOptions;
3987
}

test/KurrentDB.Client.Tests/Security/SecurityFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,6 @@ await Streams.SetStreamMetadataAsync(
258258
}
259259

260260
public Task<DeleteResult> DeleteStream(string streamId, UserCredentials? userCredentials = null) =>
261-
Streams.TombstoneAsync(streamId, StreamState.Any, userCredentials: userCredentials)
261+
Streams.TombstoneAsync(streamId, StreamState.Any, new TombstoneOptions { UserCredentials = userCredentials })
262262
.WithTimeout(TimeSpan.FromMilliseconds(TimeoutMs));
263263
}

test/KurrentDB.Client.Tests/Streams/DeleteTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ public async Task with_timeout_stream_revision_delete_fails_when_operation_expir
113113
public async Task with_timeout_any_stream_revision_tombstoning_fails_when_operation_expired() {
114114
var stream = Fixture.GetStreamName();
115115
var rpcException = await Assert.ThrowsAsync<RpcException>(
116-
() => Fixture.Streams.TombstoneAsync(stream, StreamState.Any, TimeSpan.Zero)
116+
() => Fixture.Streams.TombstoneAsync(
117+
stream,
118+
StreamState.Any,
119+
new TombstoneOptions { Deadline = TimeSpan.Zero }
120+
)
117121
);
118122

119123
Assert.Equal(StatusCode.DeadlineExceeded, rpcException.StatusCode);
@@ -124,7 +128,11 @@ public async Task with_timeout_stream_revision_tombstoning_fails_when_operation_
124128
var stream = Fixture.GetStreamName();
125129

126130
var rpcException = await Assert.ThrowsAsync<RpcException>(
127-
() => Fixture.Streams.TombstoneAsync(stream, StreamState.StreamRevision(0), TimeSpan.Zero)
131+
() => Fixture.Streams.TombstoneAsync(
132+
stream,
133+
StreamState.StreamRevision(0),
134+
new TombstoneOptions { Deadline = TimeSpan.Zero }
135+
)
128136
);
129137

130138
Assert.Equal(StatusCode.DeadlineExceeded, rpcException.StatusCode);

0 commit comments

Comments
 (0)