|
| 1 | +namespace ServiceControl.UnitTests.Operations; |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using NServiceBus; |
| 6 | +using NUnit.Framework; |
| 7 | +using ServiceControl.Operations; |
| 8 | +using ServiceControl.Persistence.Infrastructure; |
| 9 | + |
| 10 | +[TestFixture] |
| 11 | +public class When_deriving_a_failed_error_import_key |
| 12 | +{ |
| 13 | + [Test] |
| 14 | + public void Uses_the_unique_message_id_when_headers_are_well_formed() |
| 15 | + { |
| 16 | + var headers = new Dictionary<string, string> |
| 17 | + { |
| 18 | + { Headers.MessageId, "message-1" }, |
| 19 | + { Headers.ProcessingEndpoint, "Sales" } |
| 20 | + }; |
| 21 | + |
| 22 | + var key = FailedErrorImport.DeriveKey(headers, "native-1"); |
| 23 | + |
| 24 | + Assert.That(key, Is.EqualTo(DeterministicGuid.MakeId("message-1", "Sales"))); |
| 25 | + } |
| 26 | + |
| 27 | + [Test] |
| 28 | + public void Prefers_an_existing_retry_unique_message_id() |
| 29 | + { |
| 30 | + var uniqueMessageId = Guid.NewGuid(); |
| 31 | + var headers = new Dictionary<string, string> |
| 32 | + { |
| 33 | + { "ServiceControl.Retry.UniqueMessageId", uniqueMessageId.ToString() } |
| 34 | + }; |
| 35 | + |
| 36 | + var key = FailedErrorImport.DeriveKey(headers, "native-1"); |
| 37 | + |
| 38 | + Assert.That(key, Is.EqualTo(uniqueMessageId)); |
| 39 | + } |
| 40 | + |
| 41 | + [Test] |
| 42 | + public void Falls_back_to_the_native_id_when_no_processing_endpoint_can_be_derived() |
| 43 | + { |
| 44 | + var headers = new Dictionary<string, string> |
| 45 | + { |
| 46 | + { Headers.MessageId, "message-1" } |
| 47 | + }; |
| 48 | + |
| 49 | + var key = FailedErrorImport.DeriveKey(headers, "native-1"); |
| 50 | + |
| 51 | + Assert.That(key, Is.EqualTo(DeterministicGuid.MakeId("native-1"))); |
| 52 | + } |
| 53 | + |
| 54 | + [Test] |
| 55 | + public void Falls_back_when_the_retry_unique_message_id_is_not_a_guid() |
| 56 | + { |
| 57 | + var headers = new Dictionary<string, string> |
| 58 | + { |
| 59 | + { "ServiceControl.Retry.UniqueMessageId", "not-a-guid" } |
| 60 | + }; |
| 61 | + |
| 62 | + var key = FailedErrorImport.DeriveKey(headers, "native-1"); |
| 63 | + |
| 64 | + Assert.That(key, Is.EqualTo(DeterministicGuid.MakeId("native-1"))); |
| 65 | + } |
| 66 | + |
| 67 | + [Test] |
| 68 | + public void Is_stable_across_repeated_failures_of_the_same_malformed_message() |
| 69 | + { |
| 70 | + var first = FailedErrorImport.DeriveKey(new Dictionary<string, string>(), "native-1"); |
| 71 | + var second = FailedErrorImport.DeriveKey(new Dictionary<string, string>(), "native-1"); |
| 72 | + |
| 73 | + Assert.That(second, Is.EqualTo(first)); |
| 74 | + } |
| 75 | +} |
0 commit comments