public void When_expiring_some_but_not_all() { //Arrange const string contextKey = "Inbox_Cache_Expiry_Tests"; var inbox = new InMemoryInbox() { //set some aggressive outbox reclamation times for the test EntryTimeToLive = TimeSpan.FromMilliseconds(500), ExpirationScanInterval = TimeSpan.FromMilliseconds(100) }; var earlyCommands = new SimpleCommand[] { new SimpleCommand(), new SimpleCommand(), new SimpleCommand() }; //Act foreach (var command in earlyCommands) { inbox.Add(command, contextKey); } Task.Delay(2000).Wait(); //expire these items var lateCommands = new SimpleCommand[] { new SimpleCommand(), new SimpleCommand(), new SimpleCommand() }; foreach (var command in lateCommands) //This will trigger cleanup { inbox.Add(command, contextKey); } //Assert inbox.EntryCount.Should().Be(3); }
public void When_testing_for_a_message_in_the_inbox() { //Arrange var inbox = new InMemoryInbox(); const string contextKey = "Developer_Test"; var command = new SimpleCommand(); //Act inbox.Add(command, contextKey); var exists = inbox.Exists <SimpleCommand>(command.Id, contextKey); //Assert exists.Should().BeTrue(); }
public void When_storing_a_seen_message_in_the_inbox() { //Arrange var inbox = new InMemoryInbox(); const string contextKey = "Developer_Test"; var command = new SimpleCommand(); //Act inbox.Add(command, contextKey); var storedCommand = inbox.Get <SimpleCommand>(command.Id, contextKey); //Assert storedCommand.Should().NotBeNull(); storedCommand.Id.Should().Be(command.Id); }
public void When_storing_many_but_not_requested_exists_should_not_find() { //Arrange var inbox = new InMemoryInbox(); const string contextKey = "Developer_Test"; var commands = new SimpleCommand[] { new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand() }; foreach (var command in commands) { inbox.Add(command, contextKey); } //Act var firstCommandExists = inbox.Exists <SimpleCommand>(Guid.NewGuid(), contextKey); //Assert firstCommandExists.Should().BeFalse(); }
public void When_storing_multiple_entries_exists_should_find() { //Arrange var inbox = new InMemoryInbox(); const string contextKey = "Developer_Test"; var commands = new SimpleCommand[] { new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand() }; foreach (var command in commands) { inbox.Add(command, contextKey); } //Act var firstCommandExists = inbox.Exists <SimpleCommand>(commands[0].Id, contextKey); var lastCommandExists = inbox.Exists <SimpleCommand>(commands[4].Id, contextKey); //Assert firstCommandExists.Should().BeTrue(); lastCommandExists.Should().BeTrue(); }
public void When_expiring_a_cache_entry_no_longer_there() { //Arrange const string contextKey = "Inbox_Cache_Expiry_Tests"; var inbox = new InMemoryInbox() { //set some aggressive outbox reclamation times for the test EntryTimeToLive = TimeSpan.FromMilliseconds(50), ExpirationScanInterval = TimeSpan.FromMilliseconds(100) }; var command = new SimpleCommand(); //Act inbox.Add(command, contextKey); Task.Delay(500).Wait(); //give the entry to time to expire //Trigger a cache clean SimpleCommand foundCommand = null; try { foundCommand = inbox.Get <SimpleCommand>(command.Id, contextKey); } catch (Exception e) when(e is RequestNotFoundException <SimpleCommand> || e is TypeLoadException) { //early sweeper run means it doesn't exist already } Task.Delay(500).Wait(); //Give the sweep time to run var afterExpiryExists = inbox.Exists <SimpleCommand>(command.Id, contextKey); //Assert foundCommand.Should().NotBeNull(); afterExpiryExists.Should().BeFalse(); }
public void When_storing_multiple_entries_retrieve_the_right_one() { //Arrange var inbox = new InMemoryInbox(); const string contextKey = "Developer_Test"; var commands = new SimpleCommand[] { new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand() }; foreach (var command in commands) { inbox.Add(command, contextKey); } //Act var firstCommand = inbox.Get <SimpleCommand>(commands[0].Id, contextKey); var lastCommand = inbox.Get <SimpleCommand>(commands[4].Id, contextKey); //Assert firstCommand.Should().NotBeNull(); lastCommand.Should().NotBeNull(); firstCommand.Id.Should().Be(commands[0].Id, contextKey); lastCommand.Id.Should().Be(commands[4].Id, contextKey); }