Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try get nullable #1015

Merged
merged 6 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Polly.Benchmarks/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public MemoryCacheProvider(IMemoryCache memoryCache) =>
return (cacheHit, value);
}

public void Put(string key, object value, Ttl ttl)
public void Put(string key, object? value, Ttl ttl)
{
TimeSpan remaining = DateTimeOffset.MaxValue - DateTimeOffset.UtcNow;
var options = new MemoryCacheEntryOptions();
Expand All @@ -86,7 +86,7 @@ public void Put(string key, object value, Ttl ttl)
public Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) =>
Task.FromResult(TryGet(key));

public Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext)
public Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
Put(key, value, ttl);
return Task.CompletedTask;
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu
Policy.BulkheadAsync(maxParallelization, maxQueuingActions);

protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) =>
action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy)bulkhead);
action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy) bulkhead);

#endregion
}
10 changes: 9 additions & 1 deletion src/Polly.Specs/Bulkhead/BulkheadScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@ public BulkheadScenario(int maxParallelization, int maxQueuingActions, int total
}

public object[] ToTheoryData() =>
new object[] {_maxParallelization, _maxQueuingActions, _totalTestLoad, _cancelQueuing, _cancelExecuting, _scenario };
new object[]
{
_maxParallelization,
_maxQueuingActions,
_totalTestLoad,
_cancelQueuing,
_cancelExecuting,
_scenario
};
}
2 changes: 1 addition & 1 deletion src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu
Policy.BulkheadAsync<ResultPrimitive>(maxParallelization, maxQueuingActions);

protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) =>
action.ExecuteOnBulkheadAsync<ResultPrimitive>((AsyncBulkheadPolicy<ResultPrimitive>)bulkhead);
action.ExecuteOnBulkheadAsync<ResultPrimitive>((AsyncBulkheadPolicy<ResultPrimitive>) bulkhead);

#endregion
}
44 changes: 22 additions & 22 deletions src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void Single_generic_constructor_should_throw_on_no_wrapped_cache_provider
{
StubSerializer<object, StubSerialized> stubObjectSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => new StubSerialized(o),
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);

Action configure = () => new AsyncSerializingCacheProvider<StubSerialized>(null!, stubObjectSerializer);
Expand Down Expand Up @@ -42,7 +42,7 @@ public async Task Single_generic_SerializingCacheProvider_should_serialize_on_pu
bool serializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => { serializeInvoked = true; return new StubSerialized(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
StubCacheProvider stubCacheProvider = new StubCacheProvider();
object objectToCache = new object();
Expand All @@ -66,7 +66,7 @@ public async Task Single_generic_SerializingCacheProvider_should_serialize_on_pu
bool serializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => { serializeInvoked = true; return new StubSerialized(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
StubCacheProvider stubCacheProvider = new StubCacheProvider();
object? objectToCache = null;
Expand All @@ -90,7 +90,7 @@ public async Task Single_generic_SerializingCacheProvider_should_deserialize_on_
bool deserializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => new StubSerialized(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);

var stubCacheProvider = new StubCacheProvider();
Expand All @@ -113,7 +113,7 @@ public async Task Single_generic_SerializingCacheProvider_should_not_deserialize
bool deserializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => new StubSerialized(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);
var stubCacheProvider = new StubCacheProvider();
string key = "some key";
Expand All @@ -134,7 +134,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_
bool serializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => { serializeInvoked = true; return new StubSerialized(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
StubCacheProvider stubCacheProvider = new StubCacheProvider();
object objectToCache = new object();
Expand All @@ -158,7 +158,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_
bool serializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => { serializeInvoked = true; return new StubSerialized(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
StubCacheProvider stubCacheProvider = new StubCacheProvider();
object? objectToCache = null;
Expand All @@ -182,7 +182,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_
bool deserializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => new StubSerialized(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);
var stubCacheProvider = new StubCacheProvider();
object objectToCache = new object();
Expand All @@ -204,7 +204,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_
bool deserializeInvoked = false;
StubSerializer<object, StubSerialized> stubSerializer = new StubSerializer<object, StubSerialized>(
serialize: o => new StubSerialized(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);
var stubCacheProvider = new StubCacheProvider();
string key = "some key";
Expand All @@ -228,7 +228,7 @@ public void Double_generic_constructor_should_throw_on_no_wrapped_cache_provider
{
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => new StubSerialized<ResultPrimitive>(o),
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);

Action configure = () => new AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>>(null!, stubTResultSerializer);
Expand Down Expand Up @@ -261,7 +261,7 @@ public async Task Double_generic_SerializingCacheProvider_should_serialize_on_pu
bool serializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => { serializeInvoked = true; return new StubSerialized<ResultPrimitive>(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
var stubCacheProvider = new StubCacheProvider();
ResultPrimitive objectToCache = ResultPrimitive.Good;
Expand All @@ -285,7 +285,7 @@ public async Task Double_generic_SerializingCacheProvider_should_serialize_on_pu
bool serializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => { serializeInvoked = true; return new StubSerialized<ResultPrimitive>(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
StubCacheProvider stubCacheProvider = new StubCacheProvider();
ResultPrimitive objectToCache = default;
Expand All @@ -309,7 +309,7 @@ public async Task Double_generic_SerializingCacheProvider_should_deserialize_on_
bool deserializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => new StubSerialized<ResultPrimitive>(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);
var stubCacheProvider = new StubCacheProvider();
ResultPrimitive objectToCache = ResultPrimitive.Good;
Expand All @@ -318,7 +318,7 @@ public async Task Double_generic_SerializingCacheProvider_should_deserialize_on_
AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>> serializingCacheProvider = new AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>>(stubCacheProvider.AsyncFor<StubSerialized<ResultPrimitive>>(), stubTResultSerializer);

await stubCacheProvider.PutAsync(key, new StubSerialized<ResultPrimitive>(objectToCache), new Ttl(TimeSpan.FromMinutes(1)), CancellationToken.None, false);
(bool cacheHit, object fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);
(bool cacheHit, object? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);

cacheHit.Should().BeTrue();
deserializeInvoked.Should().BeTrue();
Expand All @@ -331,15 +331,15 @@ public async Task Double_generic_SerializingCacheProvider_should_not_deserialize
bool deserializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => new StubSerialized<ResultPrimitive>(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();

AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>> serializingCacheProvider = new AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>>(stubCacheProvider.AsyncFor<StubSerialized<ResultPrimitive>>(), stubTResultSerializer);
(bool cacheHit, ResultPrimitive fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);
(bool cacheHit, ResultPrimitive? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);

cacheHit.Should().BeFalse();
deserializeInvoked.Should().BeFalse();
Expand All @@ -352,7 +352,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_
bool serializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => { serializeInvoked = true; return new StubSerialized<ResultPrimitive>(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
var stubCacheProvider = new StubCacheProvider();
ResultPrimitive objectToCache = ResultPrimitive.Good;
Expand All @@ -376,7 +376,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_
bool serializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => { serializeInvoked = true; return new StubSerialized<ResultPrimitive>(o); },
deserialize: s => s.Original
deserialize: s => s?.Original ?? default
);
StubCacheProvider stubCacheProvider = new StubCacheProvider();
ResultPrimitive objectToCache = default;
Expand All @@ -401,7 +401,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_
bool deserializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => new StubSerialized<ResultPrimitive>(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);
var stubCacheProvider = new StubCacheProvider();
ResultPrimitive objectToCache = ResultPrimitive.Good;
Expand All @@ -411,7 +411,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_
stubCacheProvider.AsyncFor<StubSerialized<ResultPrimitive>>().WithSerializer(stubTResultSerializer);

await stubCacheProvider.PutAsync(key, new StubSerialized<ResultPrimitive>(objectToCache), new Ttl(TimeSpan.FromMinutes(1)), CancellationToken.None, false);
(bool cacheHit, ResultPrimitive fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);
(bool cacheHit, ResultPrimitive? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);

cacheHit.Should().BeTrue();
deserializeInvoked.Should().BeTrue();
Expand All @@ -424,7 +424,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_
bool deserializeInvoked = false;
StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>> stubTResultSerializer = new StubSerializer<ResultPrimitive, StubSerialized<ResultPrimitive>>(
serialize: o => new StubSerialized<ResultPrimitive>(o),
deserialize: s => { deserializeInvoked = true; return s.Original; }
deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; }
);
var stubCacheProvider = new StubCacheProvider();
string key = "some key";
Expand All @@ -433,7 +433,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_

AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>> serializingCacheProvider =
stubCacheProvider.AsyncFor<StubSerialized<ResultPrimitive>>().WithSerializer(stubTResultSerializer);
(bool cacheHit, ResultPrimitive fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);
(bool cacheHit, ResultPrimitive? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);

cacheHit.Should().BeFalse();
deserializeInvoked.Should().BeFalse();
Expand Down
Loading