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); }
public async Task ReleaseDecreasesCount() { var manager = new SessionPoolManager(new SessionPoolOptions(), SessionPoolManager.CreateDefaultSpannerSettings(), 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); }
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(), SessionPoolManager.CreateDefaultSpannerSettings(), 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); }