protected EventStoreGrpcFixture(
            Action <VNodeBuilder> configureVNode      = default,
            Action <IWebHostBuilder> configureWebHost = default)
        {
            var webHostBuilder = new WebHostBuilder();

            configureWebHost?.Invoke(webHostBuilder);

            var vNodeBuilder = new TestVNodeBuilder();

            vNodeBuilder.RunInMemory().WithTfChunkSize(1024 * 1024);
            configureVNode?.Invoke(vNodeBuilder);

            Node = vNodeBuilder.Build();
            _db  = vNodeBuilder.GetDb();

            _testServer = new TestServer(
                webHostBuilder
                .UseStartup(new TestClusterVNodeStartup(Node)));

            Client = new EventStoreGrpcClient(new UriBuilder().Uri, () => new HttpClient(new ResponseVersionHandler {
                InnerHandler = _testServer.CreateHandler()
            })
            {
                Timeout = Timeout.InfiniteTimeSpan
            });
        }
 public static Task SetSystemSettingsAsync(
     this EventStoreGrpcClient client,
     SystemSettings settings,
     UserCredentials userCredentials = default, CancellationToken cancellationToken = default)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     return(client.AppendToStreamAsync(SystemStreams.SettingsStream, AnyStreamRevision.Any,
                                       new[] {
         new EventData(Uuid.NewUuid(), SystemEventTypes.Settings,
                       JsonSerializer.SerializeToUtf8Bytes(settings, SystemSettingsJsonSerializerOptions))
     }, userCredentials, cancellationToken));
 }
Exemplo n.º 3
0
        public StandaloneKestrelServerFixture()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",
                                     true);    //TODO JPB Remove this sadness when dotnet core supports kestrel + http2 on macOS
            }

            using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
            var port = ((IPEndPoint)socket.LocalEndPoint).Port;

            var vNodeBuilder = new TestVNodeBuilder();

            vNodeBuilder.RunInMemory();
            _node = vNodeBuilder.Build();
            _db   = vNodeBuilder.GetDb();

            _host = new WebHostBuilder()
                    .UseKestrel(serverOptions => {
                serverOptions.Listen(IPAddress.Loopback, port, listenOptions => {
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    {
                        listenOptions.Protocols = HttpProtocols.Http2;
                    }
                    else
                    {
                        listenOptions.UseHttps();
                    }
                });
            })
                    .UseStartup(new ClusterVNodeStartup(_node))
                    .Build();

            Client = new EventStoreGrpcClient(new UriBuilder {
                Port   = port,
                Scheme = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? Uri.UriSchemeHttp : Uri.UriSchemeHttps
            }.Uri, () => new HttpClient(new SocketsHttpHandler {
                SslOptions = new SslClientAuthenticationOptions {
                    RemoteCertificateValidationCallback = delegate { return(true); }
                }
            })
            {
                DefaultRequestVersion = new Version(2, 0),
                Timeout = Timeout.InfiniteTimeSpan
            });
        }
        public static async Task <ConditionalWriteResult> ConditionalAppendToStreamAsync(
            this EventStoreGrpcClient client,
            string streamName,
            AnyStreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            UserCredentials userCredentials     = default,
            CancellationToken cancellationToken = default)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            try {
                var result = await client.AppendToStreamAsync(streamName, expectedRevision, eventData, userCredentials,
                                                              cancellationToken);

                return(ConditionalWriteResult.FromWriteResult(result));
            } catch (StreamDeletedException) {
                return(ConditionalWriteResult.StreamDeleted);
            } catch (WrongExpectedVersionException ex) {
                return(ConditionalWriteResult.FromWrongExpectedVersion(ex));
            }
        }