Skip to content

Commit

Permalink
Remove ILoggerFactory in constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrdk committed Apr 25, 2021
1 parent 7d48a78 commit 948a5f7
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/DiskQueue.Reactive/PersistentBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PersistentBuffer : IObservable<byte[]>, IObserver<byte[]>, IAsyncDi
private readonly IPersistentQueue queue;
private readonly int retryCount;
private CancellationTokenSource tokenSource;
private readonly List<IObserver<byte[]>> subscribers = new List<IObserver<byte[]>>();
private readonly List<IObserver<byte[]>> subscribers = new();
private Task work;

public PersistentBuffer(IPersistentQueue queue, int retryCount)
Expand Down
2 changes: 1 addition & 1 deletion src/DiskQueue.Reactive/TypedPersistentBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TypedPersistentBuffer<T> : IObserver<T>, IObservable<T>, IAsyncDisp
private readonly PersistentBuffer innerBuffer;
private readonly Func<T, byte[]> serializer;
private readonly Func<byte[], T> deserializer;
private readonly List<IObserver<byte[]>> observers = new List<IObserver<byte[]>>();
private readonly List<IObserver<byte[]>> observers = new();

public TypedPersistentBuffer(PersistentBuffer innerBuffer, Func<T, byte[]> serializer, Func<byte[], T> deserializer)
{
Expand Down
8 changes: 4 additions & 4 deletions src/DiskQueue.Tests/CountOfItemsPersistentQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class CountOfItemsPersistentQueueTests : PersistentQueueTestsBase
public async Task Can_get_count_from_queue()
{
await using var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false);
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false);
Assert.Equal(0, ((IPersistentQueueStore) queue).EstimatedCountOfItemsInQueue);
}

[Fact]
public async Task Can_enter_items_and_get_count_of_items()
{
await using var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false);
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false);
for (byte i = 0; i < 5; i++)
{
using var session = queue.OpenSession();
Expand All @@ -36,7 +36,7 @@ public async Task Can_enter_items_and_get_count_of_items()
public async Task Can_get_count_of_items_after_queue_restart()
{
await using (var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false))
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false))
{
for (byte i = 0; i < 5; i++)
{
Expand All @@ -47,7 +47,7 @@ await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAw
}

await using (var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false))
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false))
{
Assert.Equal(5, ((IPersistentQueueStore) queue).EstimatedCountOfItemsInQueue);
}
Expand Down
12 changes: 6 additions & 6 deletions src/DiskQueue.Tests/EncryptedPersistentQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task CanReadBackFromEncryptedQueue()
using var algo = CreateAlgo();
await using var queue = await PersistentQueue.Create(
Path,
Substitute.For<ILoggerFactory>(),
Substitute.For<ILogger<IPersistentQueue>>(),
paranoidFlushing: false,
symmetricAlgorithm: algo)
.ConfigureAwait(false);
Expand Down Expand Up @@ -47,7 +47,7 @@ public async Task Dequeing_from_empty_queue_will_return_null()
{
using var algo = CreateAlgo();
await using var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), symmetricAlgorithm: algo)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), symmetricAlgorithm: algo)
.ConfigureAwait(false);
using var session = queue.OpenSession();
Assert.Null(await session.Dequeue().ConfigureAwait(false));
Expand All @@ -58,20 +58,20 @@ public async Task Can_enqueue_and_dequeue_data_after_restarting_queue()
{
using var algo = CreateAlgo();
await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), symmetricAlgorithm: algo)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), symmetricAlgorithm: algo)
.ConfigureAwait(false))
using (var session = queue.OpenSession())
{
await session.Enqueue(new byte[] {1, 2, 3, 4}).ConfigureAwait(false);
await session.Enqueue(new byte[] { 1, 2, 3, 4 }).ConfigureAwait(false);
await session.Flush().ConfigureAwait(false);
}

await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), symmetricAlgorithm: algo)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), symmetricAlgorithm: algo)
.ConfigureAwait(false))
using (var session = queue.OpenSession())
{
Assert.Equal<byte>(new byte[] {1, 2, 3, 4}, await session.Dequeue().ConfigureAwait(false));
Assert.Equal<byte>(new byte[] { 1, 2, 3, 4 }, await session.Dequeue().ConfigureAwait(false));
await session.Flush().ConfigureAwait(false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DiskQueue.Tests/LongTermDequeueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LongTermDequeueTests : IDisposable
public LongTermDequeueTests()
{
_source = new CancellationTokenSource(TimeSpan.FromSeconds(10));
_q = PersistentQueue.Create("./queue", Substitute.For<ILoggerFactory>(), cancellationToken: _source.Token)
_q = PersistentQueue.Create("./queue", Substitute.For<ILogger<IPersistentQueue>>(), cancellationToken: _source.Token)
.GetAwaiter()
.GetResult();
}
Expand Down
22 changes: 11 additions & 11 deletions src/DiskQueue.Tests/MultiFileQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MultiFileQueueTests : PersistentQueueTestsBase
public async Task Entering_more_than_count_of_items_will_work()
{
await using var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false);
for (byte i = 0; i < 11; i++)
{
Expand All @@ -29,7 +29,7 @@ public async Task Entering_more_than_count_of_items_will_work()
public async Task When_creating_more_items_than_allowed_in_first_file_will_create_additional_file()
{
await using var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false);
for (byte i = 0; i < 11; i++)
{
Expand All @@ -45,7 +45,7 @@ public async Task When_creating_more_items_than_allowed_in_first_file_will_creat
public async Task Can_resume_writing_to_second_file_when_restart_queue()
{
await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 11; i++)
Expand All @@ -59,7 +59,7 @@ public async Task Can_resume_writing_to_second_file_when_restart_queue()
}

await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 2; i++)
Expand All @@ -77,7 +77,7 @@ public async Task Can_resume_writing_to_second_file_when_restart_queue()
public async Task Can_dequeue_from_all_files()
{
await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 12; i++)
Expand All @@ -91,7 +91,7 @@ public async Task Can_dequeue_from_all_files()
}

await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 12; i++)
Expand All @@ -107,7 +107,7 @@ public async Task Can_dequeue_from_all_files()
public async Task Can_dequeue_from_all_files_after_restart()
{
await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 12; i++)
Expand All @@ -121,7 +121,7 @@ public async Task Can_dequeue_from_all_files_after_restart()
}

await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 3; i++)
Expand All @@ -136,7 +136,7 @@ public async Task Can_dequeue_from_all_files_after_restart()


await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
using var session = queue.OpenSession();
Expand All @@ -158,7 +158,7 @@ public async Task Can_dequeue_from_all_files_after_restart()
public async Task After_reading_all_items_from_file_that_is_not_the_active_file_should_delete_file()
{
await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 12; i++)
Expand All @@ -172,7 +172,7 @@ public async Task After_reading_all_items_from_file_that_is_not_the_active_file_
}

await using (var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), maxFileSize: 10)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), maxFileSize: 10)
.ConfigureAwait(false))
{
for (byte i = 0; i < 12; i++)
Expand Down
4 changes: 2 additions & 2 deletions src/DiskQueue.Tests/MultipleProcessAccessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static async Task AddToQueue(byte[] data)
await Task.Delay(150).ConfigureAwait(false);
await using var queue = await PersistentQueue.Create(
SharedStorage,
Substitute.For<ILoggerFactory>(),
Substitute.For<ILogger<IPersistentQueue>>(),
TimeSpan.FromSeconds(30))
.ConfigureAwait(false);
using var session = queue.OpenSession();
Expand All @@ -73,7 +73,7 @@ static async Task<byte[]> ReadQueue()
await Task.Delay(150).ConfigureAwait(false);
await using var queue = await PersistentQueue.Create(
SharedStorage,
Substitute.For<ILoggerFactory>(),
Substitute.For<ILogger<IPersistentQueue>>(),
TimeSpan.FromSeconds(30))
.ConfigureAwait(false);
using var session = queue.OpenSession();
Expand Down
2 changes: 1 addition & 1 deletion src/DiskQueue.Tests/ParanoidFlushingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ParanoidFlushingTests
public async Task Paranoid_flushing_still_respects_session_rollback()
{
await using var queue = await PersistentQueue
.Create("./queue", Substitute.For<ILoggerFactory>(), paranoidFlushing: true)
.Create("./queue", Substitute.For<ILogger<IPersistentQueue>>(), paranoidFlushing: true)
.ConfigureAwait(false);

// Flush only `_one`
Expand Down
14 changes: 7 additions & 7 deletions src/DiskQueue.Tests/PerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class PerformanceTests : PersistentQueueTestsBase
public async Task Enqueue_million_items_with_100_flushes()
{
await using var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), paranoidFlushing: false)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), paranoidFlushing: false)
.ConfigureAwait(false);
for (var i = 0; i < 100; i++)
{
Expand All @@ -35,7 +35,7 @@ public async Task Enqueue_million_items_with_100_flushes()
public async Task Enqueue_million_items_with_single_flush()
{
await using var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), paranoidFlushing: false)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), paranoidFlushing: false)
.ConfigureAwait(false);
using var session = queue.OpenSession();
for (var i = 0; i < LargeCount; i++)
Expand All @@ -50,7 +50,7 @@ public async Task Enqueue_million_items_with_single_flush()
public async Task Enqueue_and_dequeue_million_items_same_queue()
{
await using var queue = await PersistentQueue
.Create(Path, Substitute.For<ILoggerFactory>(), paranoidFlushing: false)
.Create(Path, Substitute.For<ILogger<IPersistentQueue>>(), paranoidFlushing: false)
.ConfigureAwait(false);
using (var session = queue.OpenSession())
{
Expand All @@ -77,7 +77,7 @@ public async Task Enqueue_and_dequeue_million_items_same_queue()
public async Task Enqueue_and_dequeue_million_items_restart_queue()
{
await using (var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false))
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false))
{
using var session = queue.OpenSession();
for (var i = 0; i < LargeCount; i++)
Expand All @@ -89,7 +89,7 @@ await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAw
}

await using (var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false))
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false))
{
using var session = queue.OpenSession();
for (var i = 0; i < LargeCount; i++)
Expand All @@ -107,7 +107,7 @@ public async Task Enqueue_and_dequeue_large_items_with_restart_queue()
var random = new Random();
var itemsSizes = new List<int>();
await using (var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false))
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false))
{
using var session = queue.OpenSession();
for (var i = 0; i < SmallCount; i++)
Expand All @@ -121,7 +121,7 @@ await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAw
}

await using (var queue =
await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false))
await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false))
{
using var session = queue.OpenSession();
for (var i = 0; i < SmallCount; i++)
Expand Down
4 changes: 2 additions & 2 deletions src/DiskQueue.Tests/PersistentQueueSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task Errors_raised_during_flush_write_will_be_thrown_as_is()
[Fact]
public async Task If_data_stream_is_truncated_will_raise_error()
{
await using (var queue = await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false))
await using (var queue = await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false))
using (var session = queue.OpenSession())
{
await session.Enqueue(new byte[] { 1, 2, 3, 4 }).ConfigureAwait(false);
Expand All @@ -75,7 +75,7 @@ public async Task If_data_stream_is_truncated_will_raise_error()
var invalidOperationException = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await using var queue = await PersistentQueue.Create(Path, Substitute.For<ILoggerFactory>()).ConfigureAwait(false);
await using var queue = await PersistentQueue.Create(Path, Substitute.For<ILogger<IPersistentQueue>>()).ConfigureAwait(false);
using var session = queue.OpenSession();
await session.Dequeue().ConfigureAwait(false);
}).ConfigureAwait(false);
Expand Down
Loading

0 comments on commit 948a5f7

Please sign in to comment.