示例#1
0
        public void ShouldCloseIdleForTooLongConns(int sessionCount)
        {
            // Given
            var statisticsCollector = new StatisticsCollector();

            using (var driver = GraphDatabase.Driver("bolt://127.0.0.1:7687", AuthToken, new Config
            {
                DriverStatisticsCollector = statisticsCollector,
                ConnectionIdleTimeout = TimeSpan.Zero // enable but always timeout idle connections
            }))
            {
                // When
                for (var i = 0; i < sessionCount; i++)
                {
                    // should not reuse the same connection as it should timeout
                    using (var session = driver.Session())
                    {
                        var ret = session.Run("RETURN 1").Single();
                        ret[0].ValueAs <int>().Should().Be(1);
                        Thread.Sleep(1); // block to let the timer aware the timeout
                    }
                }

                // Then
                var st = ConnectionPoolStatistics.Read(statisticsCollector.CollectStatistics());
                Output.WriteLine(st.ReportStatistics().ToContentString());
                st.ConnCreated.Should().Be(sessionCount);
                st.ConnCreated.Should().Be(st.ConnClosed + 1);
            }
        }
示例#2
0
//        [InlineData(50000)] leave this to a long dedicated build
        public void SoakRun(int threadCount)
        {
            var statisticsCollector = new StatisticsCollector();
            var driver = GraphDatabase.Driver(ServerEndPoint, AuthToken, new Config
            {
                DriverStatisticsCollector = statisticsCollector,
                ConnectionTimeout         = Config.Infinite,
                EncryptionLevel           = EncryptionLevel.Encrypted
            });

            Output.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Started");

            Parallel.For(0, threadCount, i =>
            {
                if (i % 1000 == 0)
                {
                    Output.WriteLine(statisticsCollector.CollectStatistics().ToContentString());
                }

                string[] queries =
                {
                    "RETURN 1295 + 42",
                    "UNWIND range(1,10000) AS x CREATE (n {prop:x}) DELETE n RETURN sum(x)"
                };
                try
                {
                    using (var session = driver.Session())
                    {
                        session.Run(queries[i % 2]).Consume();
                    }
                }
                catch (Exception e)
                {
                    Output.WriteLine(
                        $"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Thread {i} failed to run query {queries[i % 2]} due to {e.Message}");
                }
            });

            var st = ConnectionPoolStatistics.Read(statisticsCollector.CollectStatistics());

            Output.WriteLine(st.ReportStatistics().ToContentString());
            Output.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Finished");

            st.ConnToCreate.Should().Be(st.ConnCreated + st.ConnFailedToCreate);
            st.ConnToCreate.Should().Be(st.InUseConns + st.AvailableConns + st.ConnToClose);
            st.ConnClosed.Should().Be(st.ConnClosed);
            st.ConnToCreate.Should().Be(st.ConnCreated);

            driver.Dispose();
        }