public override void TestFixtureTearDown()
 {
     PortsHelper.ReturnPort(_serverPort);
     _portableServer.TearDown();
     _connection.Dispose();
     base.TestFixtureTearDown();
 }
        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 TestFixtureTearDown()
        {
            for (var i = 0; i < _portsUsed.Count; i++)
            {
                PortsHelper.ReturnPort(_portsUsed[i]);
            }

            _conn.Close();
            _nodes[0].Shutdown();
            _nodes[1].Shutdown();
            _nodes[2].Shutdown();
            base.TestFixtureTearDown();
        }
Exemple #5
0
        private void KillStartedNode(int processId)
        {
            Log.Information("Killing {processId}...", processId);

            Process process;

            if (TryGetProcessById(processId, out process))
            {
                process.Kill();

                var waitCount = 200;
                while (!process.HasExited && waitCount > 0)
                {
                    Thread.Sleep(250);
                    waitCount -= 1;
                }

                if (process.HasExited)
                {
                    _startedNodesProcIds.Remove(processId);

                    PortsHelper.ReturnPort(_nodeConnection.TcpPort);
                    PortsHelper.ReturnPort(_nodeConnection.HttpPort);

                    Log.Information("Killed process {processId}, wait a bit.", processId);
                    Thread.Sleep(1000);                     // wait for system to release port used by HttpListener.
                }
                else
                {
                    Process temp;
                    if (TryGetProcessById(processId, out temp))
                    {
                        Log.Error(
                            "Process {processId} did not report about exit in time and is still present in processes list.",
                            processId);
                    }
                    else
                    {
                        Log.Information("Process {processId} did not report about exit in time but is not found again.",
                                        processId);
                    }
                }
            }
            else
            {
                Log.Error("Process {processId} was not found to be killed.", processId);
            }
        }
Exemple #6
0
        public override void TestFixtureTearDown()
        {
            for (var i = 0; i < _portsUsed.Count; i++)
            {
                PortsHelper.ReturnPort(_portsUsed[i]);
            }

            _conn.Close();
            _nodes[0].Shutdown();
            _nodes[1].Shutdown();
            _nodes[2].Shutdown();
#if DEBUG
            QueueStatsCollector.DisableIdleDetection();
#endif
            base.TestFixtureTearDown();
        }
Exemple #7
0
        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 void TestFixtureTearDown()
 {
     PortsHelper.ReturnPort(_serverEndPoint.Port);
 }
 public virtual void TearDown()
 {
     PortsHelper.ReturnPort(_port);
 }