Skip to content

Commit

Permalink
fix: use logger from SpannerSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite authored and jskeet committed Jul 21, 2021
1 parent b34f6f4 commit d2025be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ public async Task UsesSpannerSettings()
Assert.Same(customSettings, pool.Client.Settings);
}

[Fact]
public void Create_UsesDefaultLogger()
{
var manager = SessionPoolManager.Create(new SessionPoolOptions());
Assert.Same(Logger.DefaultLogger, manager.Logger);
}

[Fact]
public void CreateWithNullSettings_UsesDefaultLogger()
{
var manager = SessionPoolManager.Create(new SessionPoolOptions(), null, null);
Assert.Same(Logger.DefaultLogger, manager.Logger);
}

[Fact]
public void CreateWithSettings_UsesLoggerInSettings()
{
var settings = new SpannerSettings {Logger = new DefaultLogger()};
var manager = SessionPoolManager.Create(new SessionPoolOptions(), settings);
Assert.Same(settings.Logger, manager.Logger);
}

[Fact]
public void CreateWithSettingsAndLogger_UsesLogger()
{
var settings = new SpannerSettings{Logger = new DefaultLogger()};
var logger = new DefaultLogger();
var manager = SessionPoolManager.Create(new SessionPoolOptions(), settings, logger);
Assert.Same(logger, manager.Logger);
}

[Fact]
public async Task ReleaseDecreasesCount()
{
Expand Down Expand Up @@ -128,7 +159,7 @@ public async Task EmulatorDetection_AlwaysUsesRegularOptions(string emulatorHost
private class FailingSpannerClient : SpannerClient
{
// A simple non-counting factory.
internal static ClientFactory Factory { get; } = (options, settings, logger) => Task.FromResult<SpannerClient>(new FailingSpannerClient());
internal static ClientFactory Factory { get; } = (options, settings, logger) => Task.FromResult<SpannerClient>(new FailingSpannerClient(settings));

public FailingSpannerClient(SpannerSettings settings = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ public static SessionPoolManager Create(SessionPoolOptions options, Logger logge
/// </summary>
/// <param name="spannerSettings">The SpannerSettings to use. May be null, in which case the default settings are used.</param>
/// <param name="options">The options to use. Must not be null.</param>
/// <param name="logger">The logger to use. May be null, in which case the default logger is used.</param>
/// <param name="logger">The logger to use. May be null, in which case the logger returned by spannerSettings.Logger will be used.
/// If that is also null, the default logger is used.</param>
/// <returns>A <see cref="SessionPoolManager"/> with the given options.</returns>
public static SessionPoolManager Create(SessionPoolOptions options, SpannerSettings spannerSettings, Logger logger = null) =>
new SessionPoolManager(options, spannerSettings ?? DefaultSpannerSettings(), logger ?? Logger.DefaultLogger, CreateClientAsync);
new SessionPoolManager(options, spannerSettings ?? DefaultSpannerSettings(), logger ?? spannerSettings?.Logger ?? Logger.DefaultLogger, CreateClientAsync);

internal Task<SessionPool> AcquireSessionPoolAsync(SpannerClientCreationOptions options)
{
Expand Down

0 comments on commit d2025be

Please sign in to comment.