-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added timestamp column to SQL message journal table to capture and fa…
…cilitate roll-off based on sent, received, or published date. Extended message journal configuration to enable prevention of sent, received, and/or published messages from being written to the journal. #25 #26
- Loading branch information
1 parent
8a868bd
commit 79c7e30
Showing
15 changed files
with
382 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
Source/Platibus.UnitTests/Mocks/FilteredMessageJournalingServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Platibus.UnitTests.Mocks | ||
{ | ||
public class FilteredMessageJournalingServiceTests : MessageJournalingServiceTests | ||
{ | ||
private readonly Mock<IMessageJournalingService> _mockMessageJournalingService; | ||
|
||
protected bool JournalSentMessages = true; | ||
protected bool JournalReceivedMessages = true; | ||
protected bool JournalPublishedMessages = true; | ||
|
||
public FilteredMessageJournalingServiceTests() | ||
: this(MockCollectionFixture.Instance) | ||
{ | ||
} | ||
|
||
public FilteredMessageJournalingServiceTests(MockCollectionFixture fixture) | ||
: base(fixture.MockMessageJournalingService.Object) | ||
{ | ||
_mockMessageJournalingService = fixture.MockMessageJournalingService; | ||
} | ||
|
||
[Test] | ||
public async Task SentMessagesNotJournaledWhenSentMessagesFilteredOut() | ||
{ | ||
GivenSentMessage(); | ||
GivenSentMessagesOmittedFromJournal(); | ||
await WhenJournalingSentMessage(); | ||
AssertSentMessageIsNotWrittenToJournal(); | ||
} | ||
|
||
[Test] | ||
public async Task ReceivedMessagesNotJournaledWhenReceivedMessagesFilteredOut() | ||
{ | ||
GivenReceivedMessage(); | ||
GivenReceivedMessagesOmittedFromJournal(); | ||
await WhenJournalingReceivedMessage(); | ||
AssertReceivedMessageIsNotWrittenToJournal(); | ||
} | ||
|
||
[Test] | ||
public async Task PublishedMessagesNotJournaledWhenPublishedMessagesFilteredOut() | ||
{ | ||
GivenPublishedMessage(); | ||
GivenPublishedMessagesOmittedFromJournal(); | ||
await WhenJournalingPublishedMessage(); | ||
AssertPublishedMessageIsNotWrittenToJournal(); | ||
} | ||
|
||
protected void GivenSentMessagesOmittedFromJournal() | ||
{ | ||
JournalSentMessages = false; | ||
} | ||
|
||
protected void GivenReceivedMessagesOmittedFromJournal() | ||
{ | ||
JournalReceivedMessages = false; | ||
} | ||
|
||
protected void GivenPublishedMessagesOmittedFromJournal() | ||
{ | ||
JournalPublishedMessages = false; | ||
} | ||
|
||
protected FilteredMessageJournalingService CreateFilteredMessageJournalingService() | ||
{ | ||
return new FilteredMessageJournalingService( | ||
MessageJournalingService, | ||
JournalSentMessages, | ||
JournalReceivedMessages, | ||
JournalPublishedMessages); | ||
} | ||
|
||
protected override Task WhenJournalingSentMessage() | ||
{ | ||
return CreateFilteredMessageJournalingService().MessageSent(Message); | ||
} | ||
|
||
protected override Task WhenJournalingReceivedMessage() | ||
{ | ||
return CreateFilteredMessageJournalingService().MessageReceived(Message); | ||
} | ||
|
||
protected override Task WhenJournalingPublishedMessage() | ||
{ | ||
return CreateFilteredMessageJournalingService().MessagePublished(Message); | ||
} | ||
|
||
protected override Task AssertSentMessageIsWrittenToJournal() | ||
{ | ||
_mockMessageJournalingService.Verify(x => x.MessageSent(Message, It.IsAny<CancellationToken>()), Times.Once()); | ||
return Task.FromResult(true); | ||
} | ||
|
||
protected override Task AssertReceivedMessageIsWrittenToJournal() | ||
{ | ||
_mockMessageJournalingService.Verify(x => x.MessageReceived(Message, It.IsAny<CancellationToken>()), Times.Once()); | ||
return Task.FromResult(true); | ||
} | ||
|
||
protected override Task AssertPublishedMessageIsWrittenToJournal() | ||
{ | ||
_mockMessageJournalingService.Verify(x => x.MessagePublished(Message, It.IsAny<CancellationToken>()), Times.Once()); | ||
return Task.FromResult(true); | ||
} | ||
|
||
protected void AssertSentMessageIsNotWrittenToJournal() | ||
{ | ||
_mockMessageJournalingService.Verify(x => x.MessageSent(Message, It.IsAny<CancellationToken>()), Times.Never); | ||
} | ||
|
||
protected void AssertReceivedMessageIsNotWrittenToJournal() | ||
{ | ||
_mockMessageJournalingService.Verify(x => x.MessageReceived(Message, It.IsAny<CancellationToken>()), Times.Never); | ||
} | ||
|
||
protected void AssertPublishedMessageIsNotWrittenToJournal() | ||
{ | ||
_mockMessageJournalingService.Verify(x => x.MessagePublished(Message, It.IsAny<CancellationToken>()), Times.Never); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Platibus.UnitTests.Mocks | ||
{ | ||
[SetUpFixture] | ||
public class MockCollectionFixture | ||
{ | ||
public static MockCollectionFixture Instance; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
Instance = new MockCollectionFixture(); | ||
} | ||
|
||
public readonly Mock<IMessageJournalingService> MockMessageJournalingService; | ||
|
||
public MockCollectionFixture() | ||
{ | ||
MockMessageJournalingService = new Mock<IMessageJournalingService>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Platibus.Config; | ||
|
||
namespace Platibus | ||
{ | ||
/// <summary> | ||
/// An <see cref="IMessageJournalingService"/> decorator that allows or inhibits | ||
/// message journaling operations based on user configuration. | ||
/// </summary> | ||
/// <see cref="JournalingElement.JournalSentMessages"/> | ||
/// <see cref="JournalingElement.JournalReceivedMessages"/> | ||
/// <see cref="JournalingElement.JournalPublishedMessages"/> | ||
public class FilteredMessageJournalingService : IMessageJournalingService | ||
{ | ||
private readonly IMessageJournalingService _messageJournalingService; | ||
private readonly bool _journalSentMessages; | ||
private readonly bool _journalReceivedMessages; | ||
private readonly bool _journalPublishedMessages; | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="FilteredMessageJournalingService"/> instance | ||
/// </summary> | ||
/// <param name="messageJournalingService">The decorated message journaling service</param> | ||
/// <param name="journalSentMessages">Whether to allow sent messages to be journaled</param> | ||
/// <param name="journalReceivedMessages">Whether to allow received messages to be journaled</param> | ||
/// <param name="journalPublishedMessages">Whether to allow published messages to be journaled</param> | ||
public FilteredMessageJournalingService(IMessageJournalingService messageJournalingService, bool journalSentMessages, bool journalReceivedMessages, bool journalPublishedMessages) | ||
{ | ||
if (messageJournalingService == null) throw new ArgumentNullException("messageJournalingService"); | ||
|
||
_messageJournalingService = messageJournalingService; | ||
_journalSentMessages = journalSentMessages; | ||
_journalReceivedMessages = journalReceivedMessages; | ||
_journalPublishedMessages = journalPublishedMessages; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task MessageSent(Message message, CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
if (_journalSentMessages) | ||
{ | ||
await _messageJournalingService.MessageSent(message, cancellationToken); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task MessageReceived(Message message, CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
if (_journalReceivedMessages) | ||
{ | ||
await _messageJournalingService.MessageReceived(message, cancellationToken); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task MessagePublished(Message message, CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
if (_journalPublishedMessages) | ||
{ | ||
await _messageJournalingService.MessagePublished(message, cancellationToken); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.