public async Task should_throw_exception_when_trying_to_reopen_closed_connection() { ClientApiLoggerBridge.Default.Info("Starting '{0}' test...", "should_throw_exception_when_trying_to_reopen_closed_connection"); var closed = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); var settings = ConnectionSettings.Create() .EnableVerboseLogging() .UseCustomLogger(ClientApiLoggerBridge.Default) .LimitReconnectionsTo(0) .WithConnectionTimeoutOf(TimeSpan.FromSeconds(10)) .SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0)) .FailOnNoServerResponse(); if (_tcpType == TcpType.Ssl) { settings.UseSslConnection("ES", false); } var ip = IPAddress.Loopback; int port = PortsHelper.GetAvailablePort(ip); using var connection = EventStoreConnection.Create(settings, new IPEndPoint(ip, port).ToESTcpUri()); connection.Closed += (s, e) => closed.TrySetResult(true); await connection.ConnectAsync(); await closed.Task.WithTimeout( TimeSpan.FromSeconds(120)); // TCP connection timeout might be even 60 seconds await AssertEx.ThrowsAsync <ObjectDisposedException>(() => connection.ConnectAsync().WithTimeout()); }
private int GetFreePort(IPAddress ip) { var port = PortsHelper.GetAvailablePort(ip); _portsUsed.Add(port); return(port); }
public ping_controller_should() { var port = PortsHelper.GetAvailablePort(IPAddress.Loopback); _serverEndPoint = new IPEndPoint(IPAddress.Loopback, port); _portableServer = new PortableServer(_serverEndPoint); }
public http_service_should() { var port = PortsHelper.GetAvailablePort(IPAddress.Loopback); _serverEndPoint = new IPEndPoint(IPAddress.Loopback, port); _portableServer = new PortableServer(_serverEndPoint); }
public when_http_service_has_no_controllers() { var port = PortsHelper.GetAvailablePort(IPAddress.Loopback); _serverEndPoint = new IPEndPoint(IPAddress.Loopback, port); _portableServer = new PortableServer(_serverEndPoint); }
public async Task should_not_throw_exception_when_server_is_down() { var ip = IPAddress.Loopback; int port = PortsHelper.GetAvailablePort(ip); using var connection = TestConnection.Create(new IPEndPoint(ip, port), _tcpType); await connection.ConnectAsync(); }
public when_http_request_times_out() { _timeout = 2000; var port = PortsHelper.GetAvailablePort(IPAddress.Loopback); _serverEndPoint = new IPEndPoint(IPAddress.Loopback, port); _portableServer = new PortableServer(_serverEndPoint, _timeout); }
public override void TestFixtureSetUp() { base.TestFixtureSetUp(); #if DEBUG QueueStatsCollector.InitializeIdleDetection(); #else throw new NotSupportedException("These tests require DEBUG conditional"); #endif _nodeEndpoints[0] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); _nodeEndpoints[1] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); _nodeEndpoints[2] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); PortsHelper.GetAvailablePort(IPAddress.Loopback); _nodes[0] = CreateNode(0, _nodeEndpoints[0], new IPEndPoint[] { _nodeEndpoints[1].InternalHttp, _nodeEndpoints[2].InternalHttp }); _nodes[1] = CreateNode(1, _nodeEndpoints[1], new IPEndPoint[] { _nodeEndpoints[0].InternalHttp, _nodeEndpoints[2].InternalHttp }); _nodes[2] = CreateNode(2, _nodeEndpoints[2], new IPEndPoint[] { _nodeEndpoints[0].InternalHttp, _nodeEndpoints[1].InternalHttp }); _nodes[0].Start(); _nodes[1].Start(); _nodes[2].Start(); WaitHandle.WaitAll(new[] { _nodes[0].StartedEvent, _nodes[1].StartedEvent, _nodes[2].StartedEvent }); QueueStatsCollector.WaitIdle(waitForNonEmptyTf: true); _conn = EventStoreConnection.Create(_nodes[0].ExternalTcpEndPoint); _conn.ConnectAsync().Wait(); _manager = new ProjectionsManager( new ConsoleLogger(), _nodes[0].ExternalHttpEndPoint, TimeSpan.FromMilliseconds(10000)); if (GivenStandardProjectionsRunning()) { EnableStandardProjections(); } QueueStatsCollector.WaitIdle(); Given(); When(); }
public void should_close_connection_after_configured_amount_of_failed_reconnections() { var closed = new ManualResetEventSlim(); var settings = ConnectionSettings.Create() .EnableVerboseLogging() .UseCustomLogger(ClientApiLoggerBridge.Default) .LimitReconnectionsTo(1) .WithConnectionTimeoutOf(TimeSpan.FromSeconds(10)) .SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0)) .FailOnNoServerResponse(); if (_tcpType == TcpType.Ssl) { settings.UseSslConnection("ES", false); } var ip = IPAddress.Loopback; int port = PortsHelper.GetAvailablePort(ip); try { using (var connection = EventStoreConnection.Create(settings, new IPEndPoint(ip, port).ToESTcpUri())) { connection.Closed += (s, e) => closed.Set(); connection.Connected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': connected to [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint); connection.Reconnecting += (s, e) => Console.WriteLine("EventStoreConnection '{0}': reconnecting...", e.Connection.ConnectionName); connection.Disconnected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': disconnected from [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint); connection.ErrorOccurred += (s, e) => Console.WriteLine("EventStoreConnection '{0}': error = {1}", e.Connection.ConnectionName, e.Exception); connection.ConnectAsync().Wait(); if (!closed.Wait(TimeSpan.FromSeconds(120))) // TCP connection timeout might be even 60 seconds { Assert.Fail("Connection timeout took too long."); } Assert.That( () => connection .AppendToStreamAsync("stream", ExpectedVersion.EmptyStream, TestEvent.NewTestEvent()) .Wait(), Throws.Exception.InstanceOf <AggregateException>() .With.InnerException.InstanceOf <InvalidOperationException>()); } } finally { PortsHelper.ReturnPort(port); } }
public void should_not_throw_exception_when_server_is_down() { var ip = IPAddress.Loopback; int port = PortsHelper.GetAvailablePort(ip); try { using (var connection = TestConnection.Create(new IPEndPoint(ip, port), _tcpType)) { Assert.DoesNotThrow(() => connection.ConnectAsync().Wait()); } } finally { PortsHelper.ReturnPort(port); } }
public override void TestFixtureSetUp() { base.TestFixtureSetUp(); #if DEBUG QueueStatsCollector.InitializeIdleDetection(); #endif _nodeEndpoints[0] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); _nodeEndpoints[1] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); _nodeEndpoints[2] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); PortsHelper.GetAvailablePort(IPAddress.Loopback); _nodeCreationFactory.Add(0, (wait) => CreateNode(0, _nodeEndpoints[0], new IPEndPoint[] { _nodeEndpoints[1].InternalHttp, _nodeEndpoints[2].InternalHttp }, wait)); _nodeCreationFactory.Add(1, (wait) => CreateNode(1, _nodeEndpoints[1], new IPEndPoint[] { _nodeEndpoints[0].InternalHttp, _nodeEndpoints[2].InternalHttp }, wait)); _nodeCreationFactory.Add(2, (wait) => CreateNode(2, _nodeEndpoints[2], new IPEndPoint[] { _nodeEndpoints[0].InternalHttp, _nodeEndpoints[1].InternalHttp }, wait)); _nodes[0] = _nodeCreationFactory[0](true); _nodes[1] = _nodeCreationFactory[1](true); _nodes[2] = _nodeCreationFactory[2](true); BeforeNodesStart(); _nodes[0].Start(); _nodes[1].Start(); _nodes[2].Start(); WaitHandle.WaitAll(new[] { _nodes[0].StartedEvent, _nodes[1].StartedEvent, _nodes[2].StartedEvent }); QueueStatsCollector.WaitIdle(waitForNonEmptyTf: true); _conn = EventStoreConnection.Create(_nodes[0].ExternalTcpEndPoint); _conn.ConnectAsync().Wait(); QueueStatsCollector.WaitIdle(); Given(); }
protected ScenarioBase(Action <IPEndPoint, byte[]> directSendOverTcp, int maxConcurrentRequests, int connections, int streams, int eventsPerStream, int streamDeleteStep, string dbParentPath, NodeConnectionInfo customNodeConnection) { DirectSendOverTcp = directSendOverTcp; MaxConcurrentRequests = maxConcurrentRequests; Connections = connections; Streams = streams; EventsPerStream = eventsPerStream; StreamDeleteStep = streamDeleteStep; _customNodeConnection = customNodeConnection; _startedNodesProcIds = new HashSet <int>(); var ipAddress = IPAddress.Loopback; if (_customNodeConnection != null) { _nodeConnection = _customNodeConnection; _dbPath = null; } else { _dbPath = CreateNewDbPath(dbParentPath); _nodeConnection = new NodeConnectionInfo(ipAddress, PortsHelper.GetAvailablePort(ipAddress), PortsHelper.GetAvailablePort(ipAddress)); } _connections = new IEventStoreConnection[connections]; Log.Information("Projection manager points to {nodeConnection}.", _nodeConnection); _projectionsManager = new ProjectionsManager(new ConsoleLogger(), new IPEndPoint(_nodeConnection.IpAddress, _nodeConnection.HttpPort), TimeSpan.FromMilliseconds(5000)); _writeHandlers = new Dictionary <WriteMode, Func <string, int, Func <int, EventData>, Task> > { { WriteMode.SingleEventAtTime, WriteSingleEventAtTime }, { WriteMode.Bucket, WriteBucketOfEventsAtTime }, { WriteMode.Transactional, WriteEventsInTransactionalWay } }; }
protected override void Given() { _serverEndPoint = new IPEndPoint(IPAddress.Loopback, PortsHelper.GetAvailablePort(IPAddress.Loopback)); _url = _HttpEndPoint.ToHttpUrl("/stats/tcp"); var settings = ConnectionSettings.Create(); _connection = EventStoreConnection.Create(settings, _node.TcpEndPoint, _clientConnectionName); _connection.ConnectAsync().Wait(); var testEvent = new EventData(Guid.NewGuid(), "TestEvent", true, Encoding.ASCII.GetBytes("{'Test' : 'OneTwoThree'}"), null); _connection.AppendToStreamAsync("tests", ExpectedVersion.Any, testEvent).Wait(); _portableServer = new PortableServer(_serverEndPoint); _portableServer.SetUp(); }
public async Task should_close_connection_after_configured_amount_of_failed_reconnections() { var closed = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); var settings = ConnectionSettings.Create() .EnableVerboseLogging() .UseCustomLogger(ClientApiLoggerBridge.Default) .LimitReconnectionsTo(1) .WithConnectionTimeoutOf(TimeSpan.FromSeconds(10)) .SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0)) .FailOnNoServerResponse(); if (_tcpType == TcpType.Ssl) { settings.DisableServerCertificateValidation(); } else { settings.DisableTls(); } var ip = IPAddress.Loopback; int port = PortsHelper.GetAvailablePort(ip); using var connection = EventStoreConnection.Create(settings, new IPEndPoint(ip, port).ToESTcpUri()); connection.Closed += (s, e) => closed.TrySetResult(true); connection.Connected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': connected to [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint); connection.Reconnecting += (s, e) => Console.WriteLine("EventStoreConnection '{0}': reconnecting...", e.Connection.ConnectionName); connection.Disconnected += (s, e) => Console.WriteLine("EventStoreConnection '{0}': disconnected from [{1}]...", e.Connection.ConnectionName, e.RemoteEndPoint); connection.ErrorOccurred += (s, e) => Console.WriteLine("EventStoreConnection '{0}': error = {1}", e.Connection.ConnectionName, e.Exception); await connection.ConnectAsync(); await closed.Task.WithTimeout( TimeSpan.FromSeconds(120)); // TCP connection timeout might be even 60 seconds await AssertEx.ThrowsAsync <ObjectDisposedException>(() => connection .AppendToStreamAsync("stream", ExpectedVersion.NoStream, TestEvent.NewTestEvent()) .WithTimeout()); }
public void should_throw_exception_when_trying_to_reopen_closed_connection() { ClientApiLoggerBridge.Default.Info("Starting '{0}' test...", "should_throw_exception_when_trying_to_reopen_closed_connection"); var closed = new ManualResetEventSlim(); var settings = ConnectionSettings.Create() .EnableVerboseLogging() .UseCustomLogger(ClientApiLoggerBridge.Default) .LimitReconnectionsTo(0) .WithConnectionTimeoutOf(TimeSpan.FromSeconds(10)) .SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0)) .FailOnNoServerResponse(); if (_tcpType == TcpType.Ssl) { settings.UseSslConnection("ES", false); } var ip = IPAddress.Loopback; int port = PortsHelper.GetAvailablePort(ip); try { using (var connection = EventStoreConnection.Create(settings, new IPEndPoint(ip, port).ToESTcpUri())) { connection.Closed += (s, e) => closed.Set(); connection.ConnectAsync().Wait(); if (!closed.Wait(TimeSpan.FromSeconds(120))) // TCP connection timeout might be even 60 seconds { Assert.Fail("Connection timeout took too long."); } Assert.That(() => connection.ConnectAsync().Wait(), Throws.Exception.InstanceOf <AggregateException>() .With.InnerException.InstanceOf <InvalidOperationException>()); } } finally { PortsHelper.ReturnPort(port); } }
public override async Task TestFixtureSetUp() { await base.TestFixtureSetUp(); #if (!DEBUG) Assert.Ignore("These tests require DEBUG conditional"); #else _nodeEndpoints[0] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); _nodeEndpoints[1] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); _nodeEndpoints[2] = new Endpoints( PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback), PortsHelper.GetAvailablePort(IPAddress.Loopback)); _nodes[0] = CreateNode(0, _nodeEndpoints[0], new[] { _nodeEndpoints[1].InternalHttp, _nodeEndpoints[2].InternalHttp }); _nodes[1] = CreateNode(1, _nodeEndpoints[1], new[] { _nodeEndpoints[0].InternalHttp, _nodeEndpoints[2].InternalHttp }); _nodes[2] = CreateNode(2, _nodeEndpoints[2], new[] { _nodeEndpoints[0].InternalHttp, _nodeEndpoints[1].InternalHttp }); WaitIdle(); var projectionsStarted = _projections.Select(p => SystemProjections.Created(p.LeaderMainBus)).ToArray(); foreach (var node in _nodes) { node.Start(); node.WaitIdle(); } await Task.WhenAll(_nodes.Select(x => x.Started)).WithTimeout(TimeSpan.FromSeconds(30)); _conn = EventStoreConnection.Create(_nodes[0].ExternalTcpEndPoint); await _conn.ConnectAsync().WithTimeout(); _manager = new ProjectionsManager( new ConsoleLogger(), _nodes.Single(x => x.NodeState == VNodeState.Leader).ExternalHttpEndPoint, TimeSpan.FromMilliseconds(10000)); if (GivenStandardProjectionsRunning()) { await Task.WhenAny(projectionsStarted).WithTimeout(TimeSpan.FromSeconds(10)); await EnableStandardProjections().WithTimeout(TimeSpan.FromMinutes(2)); } WaitIdle(); try { await Given().WithTimeout(); } catch (Exception ex) { throw new Exception("Given Failed", ex); } try { await When().WithTimeout(); } catch (Exception ex) { throw new Exception("When Failed", ex); } #endif }
public void SetUp() { _ip = IPAddress.Loopback; _port = PortsHelper.GetAvailablePort(_ip); }
public void should_connect_to_each_other_and_send_data() { var ip = IPAddress.Loopback; var port = PortsHelper.GetAvailablePort(ip); var serverEndPoint = new IPEndPoint(ip, port); X509Certificate cert = GetCertificate(); var sent = new byte[1000]; new Random().NextBytes(sent); var received = new MemoryStream(); var done = new ManualResetEventSlim(); var listener = new TcpServerListener(serverEndPoint); listener.StartListening((endPoint, socket) => { var ssl = TcpConnectionSsl.CreateServerFromSocket(Guid.NewGuid(), endPoint, socket, cert, verbose: true); ssl.ConnectionClosed += (x, y) => done.Set(); if (ssl.IsClosed) { done.Set(); } Action <ITcpConnection, IEnumerable <ArraySegment <byte> > > callback = null; callback = (x, y) => { foreach (var arraySegment in y) { received.Write(arraySegment.Array, arraySegment.Offset, arraySegment.Count); Log.Info("Received: {0} bytes, total: {1}.", arraySegment.Count, received.Length); } if (received.Length >= sent.Length) { Log.Info("Done receiving..."); done.Set(); } else { Log.Info("Receiving..."); ssl.ReceiveAsync(callback); } }; Log.Info("Receiving..."); ssl.ReceiveAsync(callback); }, "Secure"); var clientSsl = TcpConnectionSsl.CreateConnectingConnection( Guid.NewGuid(), serverEndPoint, "ES", false, new TcpClientConnector(), TcpConnectionManager.ConnectionTimeout, conn => { Log.Info("Sending bytes..."); conn.EnqueueSend(new[] { new ArraySegment <byte>(sent) }); }, (conn, err) => { Log.Error("Connecting failed: {0}.", err); done.Set(); }, verbose: true); Assert.IsTrue(done.Wait(20000), "Took too long to receive completion."); Log.Info("Stopping listener..."); listener.Stop(); Log.Info("Closing client ssl connection..."); clientSsl.Close("Normal close."); Log.Info("Checking received data..."); Assert.AreEqual(sent, received.ToArray()); }