Skip to content

Commit

Permalink
update proto
Browse files Browse the repository at this point in the history
  • Loading branch information
thefringeninja committed Sep 23, 2020
1 parent 7c206b2 commit 8e6e098
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
22 changes: 16 additions & 6 deletions src/EventStore.Client.Common/protos/streams.proto
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,26 @@ message AppendResp {
}

message WrongExpectedVersion {
oneof current_revision_option_20_6_0 {
uint64 current_revision_20_6_0 = 1;
event_store.client.Empty no_stream_20_6_0 = 2;
}
oneof expected_revision_option_20_6_0 {
uint64 expected_revision_20_6_0 = 3;
event_store.client.Empty any_20_6_0 = 4;
event_store.client.Empty stream_exists_20_6_0 = 5;
}
oneof current_revision_option {
uint64 current_revision = 1;
event_store.client.Empty current_no_stream = 2;
uint64 current_revision = 6;
event_store.client.Empty current_no_stream = 7;
}
oneof expected_revision_option {
uint64 expected_revision = 3;
event_store.client.Empty expected_any = 4;
event_store.client.Empty expected_stream_exists = 5;
event_store.client.Empty expected_no_stream = 6;
uint64 expected_revision = 8;
event_store.client.Empty expected_any = 9;
event_store.client.Empty expected_stream_exists = 10;
event_store.client.Empty expected_no_stream = 11;
}

}
}

Expand Down
33 changes: 17 additions & 16 deletions src/EventStore.Client.Streams/EventStoreClient.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using EventStore.Client.Streams;
using Google.Protobuf;
using Grpc.Core;
using Microsoft.Extensions.Logging;

#nullable enable
Expand Down Expand Up @@ -125,9 +124,8 @@ await call.RequestStream.WriteAsync(new AppendReq {
var response = await call.ResponseAsync.ConfigureAwait(false);

if (response.Success != null) {
writeResult = new SuccessResult(
response.Success.CurrentRevisionOptionCase ==
AppendResp.Types.Success.CurrentRevisionOptionOneofCase.NoStream
writeResult = new SuccessResult(response.Success.CurrentRevisionOptionCase ==
AppendResp.Types.Success.CurrentRevisionOptionOneofCase.NoStream
? StreamRevision.None
: new StreamRevision(response.Success.CurrentRevision),
response.Success.PositionOptionCase == AppendResp.Types.Success.PositionOptionOneofCase.Position
Expand All @@ -139,14 +137,15 @@ await call.RequestStream.WriteAsync(new AppendReq {
} else {
if (response.WrongExpectedVersion != null) {
var actualStreamRevision = response.WrongExpectedVersion.CurrentRevisionOptionCase switch {
AppendResp.Types.WrongExpectedVersion.CurrentRevisionOptionOneofCase.CurrentNoStream =>
StreamRevision.None,
_ => new StreamRevision(response.WrongExpectedVersion.CurrentRevision)
};
AppendResp.Types.WrongExpectedVersion.CurrentRevisionOptionOneofCase.CurrentNoStream =>
StreamRevision.None,
_ => new StreamRevision(response.WrongExpectedVersion.CurrentRevision)
};

_log.LogDebug(
"Append to stream failed with Wrong Expected Version - {streamName}/{expectedRevision}/{currentRevision}",
header.Options.StreamIdentifier, new StreamRevision(header.Options.Revision), actualStreamRevision);
header.Options.StreamIdentifier, new StreamRevision(header.Options.Revision),
actualStreamRevision);

if (operationOptions.ThrowOnAppendFailure) {
if (response.WrongExpectedVersion.ExpectedRevisionOptionCase == AppendResp.Types
Expand All @@ -158,25 +157,27 @@ await call.RequestStream.WriteAsync(new AppendReq {

var expectedStreamState = response.WrongExpectedVersion.ExpectedRevisionOptionCase switch {
AppendResp.Types.WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedAny =>
StreamState.Any,
StreamState.Any,
AppendResp.Types.WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedNoStream =>
StreamState.NoStream,
StreamState.NoStream,
AppendResp.Types.WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedStreamExists =>
StreamState.StreamExists,
StreamState.StreamExists,
_ => throw new InvalidOperationException()
};

throw new WrongExpectedVersionException(header.Options.StreamIdentifier,
expectedStreamState, actualStreamRevision);
}

if (response.WrongExpectedVersion.CurrentRevisionOptionCase == AppendResp.Types
.WrongExpectedVersion.CurrentRevisionOptionOneofCase.CurrentRevision) {
if (response.WrongExpectedVersion.ExpectedRevisionOptionCase == AppendResp.Types
.WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedRevision) {
writeResult = new WrongExpectedVersionResult(header.Options.StreamIdentifier,
new StreamRevision(response.WrongExpectedVersion.ExpectedRevision));
new StreamRevision(response.WrongExpectedVersion.ExpectedRevision),
actualStreamRevision);
} else {
writeResult = new WrongExpectedVersionResult(header.Options.StreamIdentifier,
StreamRevision.None);
StreamRevision.None,
actualStreamRevision);
}

} else {
Expand Down

0 comments on commit 8e6e098

Please sign in to comment.