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 EventStoreClient(new UriBuilder().Uri, () => new HttpClient(new ResponseVersionHandler {
                InnerHandler = TestServer.CreateHandler()
            })
            {
                Timeout = Timeout.InfiniteTimeSpan
            });
        }
        protected EventStoreGrpcFixture(
            Action <VNodeBuilder> configureVNode      = default,
            Action <IWebHostBuilder> configureWebHost = default,
            EventStoreClientSettings clientSettings   = 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();
            _disposables = new List <IDisposable>();
            TestServer   = new TestServer(webHostBuilder.UseSerilog().UseStartup(new TestClusterVNodeStartup(Node)));

            var settings = clientSettings ?? new EventStoreClientSettings {
                CreateHttpMessageHandler = () => new ResponseVersionHandler {
                    InnerHandler = TestServer.CreateHandler()
                },
                OperationOptions = { TimeoutAfter = Debugger.IsAttached ? null : (TimeSpan?)TimeSpan.FromSeconds(30) }
            };

            Client = new EventStoreClient(settings);
        }
Beispiel #3
0
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null) : base(settings,
                                                                                    new Dictionary <string, string> {
     ["EVENTSTORE_RUN_PROJECTIONS"]            = "ALL",
     ["EVENTSTORE_START_STANDARD_PROJECTIONS"] = "True"
 })
 {
     Client = new EventStoreProjectionManagementClient(Settings);
     UserManagementClient = new EventStoreUserManagementClient(Settings);
     StreamsClient        = new EventStoreClient(Settings);
 }
Beispiel #4
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();
                    }
                });
            })
                    .UseSerilog()
                    .UseStartup(_node.Startup)
                    .Build();

            Client = new EventStoreClient(new EventStoreClientSettings {
                CreateHttpMessageHandler = () => new SocketsHttpHandler {
                    SslOptions = new SslClientAuthenticationOptions {
                        RemoteCertificateValidationCallback = delegate { return(true); }
                    }
                },
                ConnectivitySettings = new EventStoreClientConnectivitySettings {
                    Address = new UriBuilder {
                        Port   = port,
                        Scheme = RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
                                                        ? Uri.UriSchemeHttp
                                                        : Uri.UriSchemeHttps
                    }.Uri,
                },
                LoggerFactory = _host.Services.GetRequiredService <ILoggerFactory>()
            });
        }
 public static Task SetSystemSettingsAsync(
     this EventStoreClient client,
     SystemSettings settings,
     UserCredentials?userCredentials = null, CancellationToken cancellationToken = default)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     return(client.AppendToStreamAsync(SystemStreams.SettingsStream, StreamState.Any,
                                       new[] {
         new EventData(Uuid.NewUuid(), SystemEventTypes.Settings,
                       JsonSerializer.SerializeToUtf8Bytes(settings, SystemSettingsJsonSerializerOptions))
     }, userCredentials: userCredentials, cancellationToken: cancellationToken));
 }
Beispiel #6
0
        public static async Task <ConditionalWriteResult> ConditionalAppendToStreamAsync(
            this EventStoreClient client,
            string streamName,
            StreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            UserCredentials?userCredentials     = null,
            CancellationToken cancellationToken = default)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            try {
                var result = await client.AppendToStreamAsync(streamName, expectedRevision, eventData,
                                                              options => options.ThrowOnAppendFailure = false, userCredentials, cancellationToken)
                             .ConfigureAwait(false);

                return(ConditionalWriteResult.FromWriteResult(result));
            } catch (StreamDeletedException) {
                return(ConditionalWriteResult.StreamDeleted);
            }
        }
Beispiel #7
0
        public static async Task WarmUpAsync(this EventStoreClient self)
        {
            // if we can read from $users then we know that 1. the users exist
            // and 2. we are connected to leader if we require it
            await Policy.Handle <Exception>()
            .WaitAndRetryAsync(10, retryCount => TimeSpan.FromSeconds(2))
            .ExecuteAsync(async() => {
                var users = await self
                            .ReadStreamAsync(
                    Direction.Forwards,
                    "$users",
                    StreamPosition.Start,
                    userCredentials: TestCredentials.Root)
                            .ToArrayAsync();

                if (users.Length == 0)
                {
                    throw new Exception("no users yet");
                }

                // the read from leader above is not enough to garantee the next write goes to leader
                await self.AppendToStreamAsync($"warmup", StreamState.Any, Enumerable.Empty <EventData>());
            });
        }
Beispiel #8
0
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null) : base(settings)
 {
     Client        = new EventStoreOperationsClient(Settings);
     StreamsClient = new EventStoreClient(Settings);
 }
Beispiel #9
0
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null) : base(settings)
 {
     Client               = new EventStorePersistentSubscriptionsClient(Settings);
     StreamsClient        = new EventStoreClient(Settings);
     UserManagementClient = new EventStoreUserManagementClient(Settings);
 }
Beispiel #10
0
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null,
                                   IDictionary <string, string>?env  = null) : base(settings, env)
 {
     Client = new EventStoreClient(Settings);
 }