-
Notifications
You must be signed in to change notification settings - Fork 34
/
When_configured_error_queue_includes_catalog.cs
100 lines (85 loc) · 3.33 KB
/
When_configured_error_queue_includes_catalog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
namespace NServiceBus.Transport.SqlServer.AcceptanceTests.MultiCatalog
{
using System;
using System.Threading.Tasks;
#if SYSTEMDATASQLCLIENT
using System.Data.SqlClient;
#else
using Microsoft.Data.SqlClient;
#endif
using AcceptanceTesting;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NUnit.Framework;
public class When_configured_error_queue_includes_catalog : MultiCatalogAcceptanceTest
{
[Test]
public async Task Error_should_be_sent_to_table_in_configured_catalog()
{
// makes sure error spy queue is available to avoid race on creating the spy queue
await Scenario.Define<Context>()
.WithEndpoint<ErrorSpy>()
.Done(c => c.EndpointsStarted)
.Run();
var ctx = await Scenario.Define<Context>()
.WithEndpoint<Sender>(b =>
{
b.DoNotFailOnErrorMessages();
b.When((bus, c) => bus.SendLocal(new Message()));
})
.WithEndpoint<ErrorSpy>()
.Done(c => c.FailedMessageProcessed)
.Run();
Assert.True(ctx.FailedMessageProcessed, "Message should be moved to error queue in custom schema");
}
public class Context : ScenarioContext
{
public bool FailedMessageProcessed { get; set; }
}
public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
EndpointSetup<DefaultServer>(c =>
{
var errorSpyName = AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(ErrorSpy));
c.SendFailedMessagesTo($"{errorSpyName}@[dbo]@[nservicebus2]");
c.Recoverability()
.Immediate(i => i.NumberOfRetries(0))
.Delayed(d => d.NumberOfRetries(0));
c.UseTransport<SqlServerTransport>()
.ConnectionString(SenderConnectionString);
});
}
class Handler : IHandleMessages<Message>
{
public Task Handle(Message message, IMessageHandlerContext context)
{
throw new Exception("Simulated exception");
}
}
}
public class ErrorSpy : EndpointConfigurationBuilder
{
public ErrorSpy()
{
EndpointSetup<DefaultServer>(c =>
{
c.UseTransport<SqlServerTransport>()
.ConnectionString(SpyConnectionString);
});
}
class Handler : IHandleMessages<Message>
{
public Context Context { get; set; }
public Task Handle(Message message, IMessageHandlerContext context)
{
Context.FailedMessageProcessed = true;
return Task.FromResult(0);
}
}
}
public class Message : ICommand { }
static string SenderConnectionString => WithCustomCatalog(GetDefaultConnectionString(), "nservicebus1");
static string SpyConnectionString => WithCustomCatalog(GetDefaultConnectionString(), "nservicebus2");
}
}