-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix-2.2.6' into support-2.2
- Loading branch information
Showing
10 changed files
with
170 additions
and
29 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
73 changes: 73 additions & 0 deletions
73
src/NServiceBus.SqlServer.AcceptanceTests/When_using_unicode_characters_in_headers.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,73 @@ | ||
namespace NServiceBus.AcceptanceTests.Basic | ||
{ | ||
using System.Collections.Generic; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
|
||
public class When_using_unicode_characters_in_headers : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_support_unicode_characters() | ||
{ | ||
var context = new Context(); | ||
|
||
var sentHeaders = new Dictionary<string, string> | ||
{ | ||
{"a-B1", "a-B"}, | ||
{"a-B2", "a-ɤϡ֎ᾣ♥-b"}, | ||
{"a-ɤϡ֎ᾣ♥-B3", "a-B"}, | ||
{"a-B4", "a-\U0001F60D-b"}, | ||
{"a-\U0001F605-B5", "a-B"}, | ||
{"a-B6", "a-😍-b"}, | ||
{"a-😅-B7", "a-B"} | ||
}; | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<Endpoint>(b => b.Given(bus => | ||
{ | ||
var message = new TestMessage(); | ||
foreach (var header in sentHeaders) | ||
{ | ||
bus.SetMessageHeader(message, header.Key, header.Value); | ||
} | ||
bus.SendLocal(message); | ||
})) | ||
.Done(c => c.Done) | ||
.Run(); | ||
|
||
Assert.IsNotEmpty(context.Headers); | ||
CollectionAssert.IsSubsetOf(sentHeaders, context.Headers); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool Done { get; set; } | ||
public Dictionary<string, string> Headers { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(); | ||
} | ||
|
||
class Handler : IHandleMessages<TestMessage> | ||
{ | ||
public Context Context { get; set; } | ||
public IBus Bus { get; set; } | ||
|
||
public void Handle(TestMessage message) | ||
{ | ||
Context.Headers = new Dictionary<string, string>(Bus.CurrentMessageContext.Headers); | ||
Context.Done = true; | ||
} | ||
} | ||
} | ||
|
||
public class TestMessage : IMessage | ||
{ | ||
} | ||
} | ||
} |
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,63 @@ | ||
namespace NServiceBus.Transport.SQLServer | ||
{ | ||
using System; | ||
using System.Data.SqlClient; | ||
using NServiceBus.Logging; | ||
using NServiceBus.Transports.SQLServer; | ||
|
||
class SchemaInspector | ||
{ | ||
static readonly ILog Logger = LogManager.GetLogger<SchemaInspector>(); | ||
|
||
Func<SqlConnection> openConnection; | ||
|
||
public SchemaInspector(Func<SqlConnection> openConnection) | ||
{ | ||
this.openConnection = openConnection; | ||
} | ||
|
||
public void PerformInspection(TableBasedQueue queue) | ||
{ | ||
VerifyExpiredIndex(queue); | ||
VerifyHeadersColumnType(queue); | ||
} | ||
|
||
void VerifyExpiredIndex(TableBasedQueue queue) | ||
{ | ||
try | ||
{ | ||
using (var connection = openConnection()) | ||
{ | ||
var indexExists = queue.CheckExpiresIndexPresence(connection); | ||
if (!indexExists) | ||
{ | ||
Logger.Warn($@"Table {queue} does not contain index 'Index_Expires'.{Environment.NewLine}Adding this index will speed up the process of purging expired messages from the queue. Please consult the documentation for further information."); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.WarnFormat("Checking indexes on table {0} failed. Exception: {1}", queue, ex); | ||
} | ||
} | ||
|
||
void VerifyHeadersColumnType(TableBasedQueue queue) | ||
{ | ||
try | ||
{ | ||
using (var connection = openConnection()) | ||
{ | ||
var columnType = queue.CheckHeadersColumnType(connection); | ||
if (string.Equals(columnType, "varchar", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Logger.Warn($"Table {queue} stores headers in a non Unicode-compatible column (varchar).{Environment.NewLine}This may lead to data loss when sending non-ASCII characters in headers. SQL Server transport 3.1 and newer can take advantage of the nvarchar column type for headers. Please change the column type in the database."); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.WarnFormat("Checking column type on table {0} failed. Exception: {1}", queue, ex); | ||
} | ||
} | ||
} | ||
} |
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