Exemplo n.º 1
0
        protected EventStoreClientFixtureBase(EventStoreClientSettings?clientSettings,
                                              IDictionary <string, string>?env = null)
        {
            _disposables = new List <IDisposable>();
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            Settings = clientSettings ?? new EventStoreClientSettings {
                CreateHttpMessageHandler = () => new SocketsHttpHandler {
                    SslOptions =
                    {
                        RemoteCertificateValidationCallback = delegate { return(true); }
                    }
                },
                OperationOptions =
                {
                    TimeoutAfter = Debugger.IsAttached
                                                ? new TimeSpan?()
                                                : TimeSpan.FromSeconds(30)
                },
                ConnectivitySettings =
                {
                    Address    = new UriBuilder {
                        Scheme = Uri.UriSchemeHttps,
                        Port   = 2113
                    }.Uri
                },
                LoggerFactory = new SerilogLoggerFactory()
            };

            TestServer = new EventStoreTestServer(Settings.ConnectivitySettings.Address, env);
        }
 public EventStoreUserManagementClient(EventStoreClientSettings?settings = null) :
     base(settings, ExceptionMap)
 {
     _client = new Users.Users.UsersClient(CallInvoker);
     _log    = Settings.LoggerFactory?.CreateLogger <EventStoreUserManagementClient>() ??
               new NullLogger <EventStoreUserManagementClient>();
 }
        protected EventStoreClientBase(EventStoreClientSettings?settings,
                                       IDictionary <string, Func <RpcException, Exception> > exceptionMap)
        {
            Settings     = settings ?? new EventStoreClientSettings();
            _httpHandler = Settings.CreateHttpMessageHandler?.Invoke() ?? new HttpClientHandler();

            var connectionName = Settings.ConnectionName ?? $"ES-{Guid.NewGuid()}";
            Action <Exception>?exceptionNotificationHook = null;

            if (Settings.ConnectivitySettings.GossipSeeds.Length > 0)
            {
                _httpHandler = ClusterAwareHttpHandler.Create(Settings, _httpHandler);
            }

            _channel = GrpcChannel.ForAddress(Settings.ConnectivitySettings.Address, new GrpcChannelOptions {
                HttpClient = new HttpClient(_httpHandler)
                {
                    Timeout = Timeout.InfiniteTimeSpan,
                    DefaultRequestVersion = new Version(2, 0),
                },
                LoggerFactory = Settings.LoggerFactory
            });

            CallInvoker = (Settings.Interceptors ?? Array.Empty <Interceptor>()).Aggregate(
                _channel.CreateCallInvoker()
                .Intercept(new TypedExceptionInterceptor(exceptionMap, exceptionNotificationHook))
                .Intercept(new ConnectionNameInterceptor(connectionName)),
                (invoker, interceptor) => invoker.Intercept(interceptor));
        }
 public EventStoreProjectionManagementClient(EventStoreClientSettings?settings) : base(settings,
                                                                                       new Dictionary <string, Func <RpcException, Exception> >())
 {
     _client = new Projections.Projections.ProjectionsClient(CallInvoker);
     _log    = settings?.LoggerFactory?.CreateLogger <EventStoreProjectionManagementClient>() ??
               new NullLogger <EventStoreProjectionManagementClient>();
 }
        protected EventStoreClientBase(EventStoreClientSettings?settings,
                                       IDictionary <string, Func <RpcException, Exception> > exceptionMap)
        {
            Settings = settings ?? new EventStoreClientSettings();

            var connectionName = Settings.ConnectionName ?? $"ES-{Guid.NewGuid()}";

            if (Settings.ConnectivitySettings.Address.Scheme == Uri.UriSchemeHttp ||
                !Settings.ConnectivitySettings.GossipOverHttps)
            {
                //this must be switched on before creation of the HttpMessageHandler
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            }

#if NETCOREAPP3_1
            _innerHttpHandler = Settings.CreateHttpMessageHandler?.Invoke() ?? new SocketsHttpHandler();
#elif NETSTANDARD2_1
            _innerHttpHandler = Settings.CreateHttpMessageHandler?.Invoke() ?? new HttpClientHandler();
#endif

            _httpHandler = Settings.ConnectivitySettings.IsSingleNode
                                ? (HttpMessageHandler) new SingleNodeHttpHandler(Settings)
            {
                InnerHandler = _innerHttpHandler
            }
                                : ClusterAwareHttpHandler.Create(Settings, _innerHttpHandler);

#if NETSTANDARD2_1
            _httpHandler = new DefaultRequestVersionHandler(_httpHandler);
#endif

            _channel = GrpcChannel.ForAddress(new UriBuilder(Settings.ConnectivitySettings.Address)
            {
                Scheme = Uri.UriSchemeHttps
            }.Uri, new GrpcChannelOptions {
                HttpClient = new HttpClient(_httpHandler)
                {
                    Timeout = Timeout.InfiniteTimeSpan,
#if NETCOREAPP3_1
                    DefaultRequestVersion = new Version(2, 0),
#endif
                },
                LoggerFactory = Settings.LoggerFactory,
                Credentials   = Settings.ChannelCredentials
            });

            Action <Exception>?exceptionNotificationHook =
                _httpHandler is ClusterAwareHttpHandler h
                                        ? h.ExceptionOccurred
                                        : new Action <Exception>(ex => { });

            CallInvoker = (Settings.Interceptors ?? Array.Empty <Interceptor>()).Aggregate(
                _channel.CreateCallInvoker()
                .Intercept(new TypedExceptionInterceptor(exceptionMap, exceptionNotificationHook))
                .Intercept(new ConnectionNameInterceptor(connectionName)),
                (invoker, interceptor) => invoker.Intercept(interceptor));
        }
Exemplo n.º 6
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);
 }
        protected EventStoreClientBase(EventStoreClientSettings?settings,
                                       IDictionary <string, Func <RpcException, Exception> > exceptionMap)
        {
            _exceptionMap = exceptionMap;
            Settings      = settings ?? new EventStoreClientSettings();

            ConnectionName = Settings.ConnectionName ?? $"ES-{Guid.NewGuid()}";

            _channels = new MultiChannel(Settings);
        }
Exemplo n.º 8
0
        protected EventStoreClientFixtureBase(EventStoreClientSettings?clientSettings,
                                              IDictionary <string, string>?env = null)
        {
            _disposables = new List <IDisposable>();
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

            Settings = clientSettings ?? EventStoreClientSettings.Create(ConnectionString);

            Settings.OperationOptions.TimeoutAfter = Debugger.IsAttached
                                ? new TimeSpan?()
                                : TimeSpan.FromSeconds(30);

#if GRPC_CORE
            Settings.ChannelCredentials ??= GetServerCertificate();
 public EventStorePersistentSubscriptionsClient(EventStoreClientSettings?settings) : base(settings,
                                                                                          new Dictionary <string, Func <RpcException, Exception> > {
     [Constants.Exceptions.PersistentSubscriptionDoesNotExist] = ex => new
                                                                 PersistentSubscriptionNotFoundException(
         ex.Trailers.First(x => x.Key == Constants.Exceptions.StreamName).Value,
         ex.Trailers.First(x => x.Key == Constants.Exceptions.GroupName).Value, ex),
     [Constants.Exceptions.MaximumSubscribersReached] = ex => new
                                                        MaximumSubscribersReachedException(
         ex.Trailers.First(x => x.Key == Constants.Exceptions.StreamName).Value,
         ex.Trailers.First(x => x.Key == Constants.Exceptions.GroupName).Value, ex),
     [Constants.Exceptions.PersistentSubscriptionDropped] = ex => new
                                                            PersistentSubscriptionDroppedByServerException(
         ex.Trailers.First(x => x.Key == Constants.Exceptions.StreamName).Value,
         ex.Trailers.First(x => x.Key == Constants.Exceptions.GroupName).Value, ex)
 })
 {
     _log = Settings.LoggerFactory?.CreateLogger <EventStorePersistentSubscriptionsClient>()
            ?? new NullLogger <EventStorePersistentSubscriptionsClient>();
 }
        protected EventStoreClientFixtureBase(EventStoreClientSettings?clientSettings,
                                              IDictionary <string, string>?env = null)
        {
            _disposables = new List <IDisposable>();

            Settings = clientSettings ?? new EventStoreClientSettings {
                OperationOptions =
                {
                    TimeoutAfter = Debugger.IsAttached
                                                ? new TimeSpan?()
                                                : TimeSpan.FromSeconds(30)
                },
                CreateHttpMessageHandler = () => new SocketsHttpHandler {
                    SslOptions = new SslClientAuthenticationOptions {
                        RemoteCertificateValidationCallback = delegate { return(true); }
                    }
                }
            };

            TestServer = new EventStoreTestServer(env);
        }
Exemplo n.º 11
0
        protected EventStoreClientFixtureBase(EventStoreClientSettings?clientSettings,
                                              IDictionary <string, string>?env = null)
        {
            _disposables = new List <IDisposable>();
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

            var connectionString = GlobalEnvironment.UseCluster ? ConnectionStringCluster : ConnectionStringSingle;

            Settings = clientSettings ?? EventStoreClientSettings.Create(connectionString);

            Settings.OperationOptions.TimeoutAfter = Debugger.IsAttached
                                ? new TimeSpan?()
                                : TimeSpan.FromSeconds(30);

            var hostCertificatePath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory,
                                                                    "..", "..", "..", "..", GlobalEnvironment.UseCluster ? "certs-cluster" : "certs"));

#if GRPC_CORE
            Settings.ChannelCredentials ??= GetServerCertificate();

            SslCredentials GetServerCertificate() => new SslCredentials(
                File.ReadAllText(Path.Combine(hostCertificatePath, "ca", "ca.crt")), null, _ => true);
#endif

            Settings.LoggerFactory ??= new SerilogLoggerFactory();

            Settings.ConnectivitySettings.MaxDiscoverAttempts = 20;
            Settings.ConnectivitySettings.DiscoveryInterval   = TimeSpan.FromSeconds(1);

            if (GlobalEnvironment.UseExternalServer)
            {
                TestServer = new EventStoreTestServerExternal();
            }
            else
            {
                TestServer = GlobalEnvironment.UseCluster
                                        ? (IEventStoreTestServer) new EventStoreTestServerCluster(hostCertificatePath, Settings.ConnectivitySettings.Address, env)
                                        : new EventStoreTestServer(hostCertificatePath, Settings.ConnectivitySettings.Address, env);
            }
        }
        protected EventStoreClientFixtureBase(EventStoreClientSettings?clientSettings,
                                              IDictionary <string, string>?env = null)
        {
            _disposables = new List <IDisposable>();

            Settings = clientSettings ?? new EventStoreClientSettings {
                OperationOptions =
                {
                    TimeoutAfter = Debugger.IsAttached
                                                ? new TimeSpan?()
                                                : TimeSpan.FromSeconds(30)
                },
                ConnectivitySettings =
                {
                    Address    = new UriBuilder {
                        Scheme = Uri.UriSchemeHttp,
                        Port   = 2113
                    }.Uri
                },
                LoggerFactory = new SerilogLoggerFactory()
            };

            TestServer = new EventStoreTestServer(Settings.ConnectivitySettings.Address, env);
        }
Exemplo n.º 13
0
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null) : base(settings)
 {
     Client               = new EventStorePersistentSubscriptionsClient(Settings);
     StreamsClient        = new EventStoreClient(Settings);
     UserManagementClient = new EventStoreUserManagementClient(Settings);
 }
Exemplo n.º 14
0
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null,
                                   IDictionary <string, string>?env  = null) : base(settings, env)
 {
     Client = new EventStoreClient(Settings);
 }
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null) : base(settings)
 {
     Client = new EventStoreUserManagementClient(Settings);
 }
 protected EventStoreClientFixture(EventStoreClientSettings?settings = null) : base(settings)
 {
     Client = new EventStoreOperationsClient(Settings);
 }
 public EventStoreOperationsClient(EventStoreClientSettings?settings = null) : base(settings, ExceptionMap)
 {
     _client = new Operations.Operations.OperationsClient(CallInvoker);
     _log    = Settings.LoggerFactory?.CreateLogger <EventStoreOperationsClient>() ??
               new NullLogger <EventStoreOperationsClient>();
 }