コード例 #1
0
            protected override async Task Given()
            {
                var node = GetFollowers()[0];
                await Task.WhenAll(node.AdminUserCreated, node.Started);

                using var channel = GrpcChannel.ForAddress(new Uri($"https://{node.HttpEndPoint}"),
                                                           new GrpcChannelOptions {
                    HttpClient = new HttpClient(new SocketsHttpHandler {
                        SslOptions =
                        {
                            RemoteCertificateValidationCallback = delegate { return(true); }
                        }
                    }, true)
                });
                var streamClient = new Streams.StreamsClient(channel);

                using var call = streamClient.Append(new CallOptions(
                                                         credentials: CallCredentials.FromInterceptor((_, metadata) => {
                    metadata.Add("authorization", AuthorizationHeaderValue);
                    return(Task.CompletedTask);
                }),
                                                         deadline: DateTime.UtcNow.AddSeconds(10)));

                await call.RequestStream.WriteAsync(new AppendReq {
                    Options = new AppendReq.Types.Options {
                        NoStream         = new Empty(),
                        StreamIdentifier = new StreamIdentifier {
                            StreamName = ByteString.CopyFromUtf8(ProtectedStream)
                        }
                    }
                });

                await call.RequestStream.WriteAsync(new AppendReq {
                    ProposedMessage = new AppendReq.Types.ProposedMessage {
                        Id = new UUID {
                            String = Uuid.FromGuid(Guid.NewGuid()).ToString()
                        },
                        CustomMetadata = ByteString.Empty,
                        Data           = ByteString.Empty,
                        Metadata       =
                        {
                            { EventStore.Core.Services.Transport.Grpc.Constants.Metadata.Type, "-" }, {
                                EventStore.Core.Services.Transport.Grpc.Constants.Metadata.ContentType,
                                EventStore.Core.Services.Transport.Grpc.Constants.Metadata.ContentTypes
                                .ApplicationOctetStream
                            }
                        }
                    }
                });

                await call.RequestStream.CompleteAsync();

                await call.ResponseHeadersAsync;
                await call.ResponseAsync;

                _status = call.GetStatus();

                await base.Given();
            }
コード例 #2
0
        private async Task AppendEvent(IPEndPoint endpoint, string stream, long expectedVersion)
        {
            using var channel = GrpcChannel.ForAddress(new Uri($"https://{endpoint}"),
                                                       new GrpcChannelOptions { HttpClient = _httpClient });
            var streamClient = new Streams.StreamsClient(channel);

            using var call = streamClient.Append(GetCallOptions());

            var optionsAppendReq = new AppendReq {
                Options = new() {
                    StreamIdentifier = new() {
                        StreamName = ByteString.CopyFromUtf8(stream)
                    },
                }
            };

            switch (expectedVersion)
            {
            case ExpectedVersion.Any:
                optionsAppendReq.Options.Any = new Empty();
                break;

            case ExpectedVersion.NoStream:
                optionsAppendReq.Options.NoStream = new Empty();
                break;

            default:
                optionsAppendReq.Options.Revision = (ulong)expectedVersion;
                break;
            }

            await call.RequestStream.WriteAsync(optionsAppendReq);

            await call.RequestStream.WriteAsync(new AppendReq {
                ProposedMessage = new() {
                    Id = new() {
                        String = Uuid.FromGuid(Guid.NewGuid()).ToString()
                    },
                    Data     = ByteString.Empty,
                    Metadata =
                    {