public async Task EqualOptions_SameSessionPool()
        {
            int           factoryCalls = 0;
            ClientFactory factory      = (options, settings, logger) =>
            {
                factoryCalls++;
                return(Task.FromResult <SpannerClient>(new FailingSpannerClient()));
            };
            var manager = new SessionPoolManager(new SessionPoolOptions(), Logger.DefaultLogger, factory);

            var options1 = new SpannerClientCreationOptions(new SpannerConnectionStringBuilder(ConnectionString));
            var options2 = new SpannerClientCreationOptions(new SpannerConnectionStringBuilder(ConnectionString));

            var pool1 = await manager.AcquireSessionPoolAsync(options1);

            var pool2 = await manager.AcquireSessionPoolAsync(options2);

            Assert.Same(pool1, pool2);
            Assert.Equal(1, factoryCalls);
            Assert.Equal(1, manager.GetStatistics().Count);
        }
Exemple #2
0
        public async Task UsesSpannerSettings()
        {
            ClientFactory factory = (options, settings, logger) =>
            {
                return(Task.FromResult <SpannerClient>(new FailingSpannerClient(settings)));
            };
            var customSettings = new SpannerSettings();
            var manager        = new SessionPoolManager(new SessionPoolOptions(), customSettings, Logger.DefaultLogger, factory);

            var pool = await manager.AcquireSessionPoolAsync(new SpannerClientCreationOptions(new SpannerConnectionStringBuilder(ConnectionString)));

            Assert.Same(customSettings, pool.Client.Settings);
        }
        public async Task DifferentOptions_DifferentSessionPools()
        {
            int           factoryCalls = 0;
            ClientFactory factory      = options =>
            {
                factoryCalls++;
                return(Task.FromResult <SpannerClient>(new FailingSpannerClient()));
            };
            var manager = new SessionPoolManager(new SessionPoolOptions(), Logger.DefaultLogger, factory);

            var options1 = new SpannerClientCreationOptions(new SpannerConnectionStringBuilder(ConnectionString));
            var options2 = new SpannerClientCreationOptions(new SpannerConnectionStringBuilder(ConnectionString)
            {
                Port = 1234
            });

            var pool1 = await manager.AcquireSessionPoolAsync(options1);

            var pool2 = await manager.AcquireSessionPoolAsync(options2);

            Assert.NotSame(pool1, pool2);
            Assert.Equal(2, factoryCalls);
            Assert.Equal(2, manager.GetStatistics().Count);
        }
        public async Task ReleaseDecreasesCount()
        {
            var manager = new SessionPoolManager(new SessionPoolOptions(), Logger.DefaultLogger, FailingSpannerClient.Factory);

            var options = new SpannerClientCreationOptions(new SpannerConnectionStringBuilder(ConnectionString));
            var pool    = await manager.AcquireSessionPoolAsync(options);

            var stats = manager.GetStatistics().Single();

            Assert.Equal(1, stats.ActiveConnectionCount);

            manager.Release(pool);

            stats = manager.GetStatistics().Single();
            Assert.Equal(0, stats.ActiveConnectionCount);
        }
Exemple #5
0
        public async Task EmulatorDetection_AlwaysUsesRegularOptions(string emulatorHost)
        {
            var regularOptions = new SessionPoolOptions();
            var manager        = new SessionPoolManager(regularOptions, SessionPoolManager.CreateDefaultSpannerSettings(), Logger.DefaultLogger, FailingSpannerClient.Factory);

            var builder = new SpannerConnectionStringBuilder(ConnectionString)
            {
                EmulatorDetection = EmulatorDetection.EmulatorOrProduction,
                // Effectively "there are no environment variables"
                EnvironmentVariableProvider = key => key == "SPANNER_EMULATOR_HOST" ? emulatorHost: null
            };
            var clientCreationOptions = new SpannerClientCreationOptions(new SpannerConnectionStringBuilder(ConnectionString));
            var pool = await manager.AcquireSessionPoolAsync(clientCreationOptions);

            Assert.Same(regularOptions, pool.Options);
        }