-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#255) Move serialization into exception handled execution
So that if there is a mismatch in serializer between clients they will post to error exchange or propegate back to requester
- Loading branch information
1 parent
c66be0c
commit 15c5b52
Showing
13 changed files
with
214 additions
and
39 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
4 changes: 2 additions & 2 deletions
4
src/RawRabbit.Operations.Request/Middleware/BasicPropertiesMiddleware.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
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
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
142 changes: 142 additions & 0 deletions
142
test/RawRabbit.IntegrationTests/Enrichers/ProtobufTests.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,142 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.Serialization; | ||
using System.Threading.Tasks; | ||
using ProtoBuf; | ||
using RawRabbit.Exceptions; | ||
using RawRabbit.Instantiation; | ||
using RawRabbit.Pipe; | ||
using Xunit; | ||
|
||
namespace RawRabbit.IntegrationTests.Enrichers | ||
{ | ||
public class ProtobufTests | ||
{ | ||
[Fact] | ||
public async Task Should_Deliver_And_Recieve_Messages_Serialized_With_Protobuf() | ||
{ | ||
using (var client = RawRabbitFactory.CreateTestClient(new RawRabbitOptions{ Plugins = p => p.UseProtobuf() })) | ||
{ | ||
/** Setup **/ | ||
var tcs = new TaskCompletionSource<ProtoMessage>(); | ||
var message = new ProtoMessage | ||
{ | ||
Member = "Straight into bytes", | ||
Id = Guid.NewGuid() | ||
}; | ||
await client.SubscribeAsync<ProtoMessage>(msg => | ||
{ | ||
tcs.TrySetResult(msg); | ||
return Task.CompletedTask; | ||
}); | ||
|
||
/** Test **/ | ||
await client.PublishAsync(message); | ||
await tcs.Task; | ||
|
||
/** Assert **/ | ||
Assert.Equal(tcs.Task.Result.Id, message.Id); | ||
Assert.Equal(tcs.Task.Result.Member, message.Member); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Perform_Rpc_With_Messages_Serialized_With_Protobuf() | ||
{ | ||
using (var client = RawRabbitFactory.CreateTestClient(new RawRabbitOptions {Plugins = p => p.UseProtobuf()})) | ||
{ | ||
/* Setup */ | ||
var response = new ProtoResponse {Id = Guid.NewGuid()}; | ||
await client.RespondAsync<ProtoRequest, ProtoResponse>(request => Task.FromResult(response)); | ||
|
||
/* Test */ | ||
var recieved = await client.RequestAsync<ProtoRequest, ProtoResponse>(new ProtoRequest()); | ||
|
||
/* Assert */ | ||
Assert.Equal(recieved.Id, response.Id); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Publish_Message_To_Error_Exchange_If_Serializer_Mismatch() | ||
{ | ||
using (var protobufClient = RawRabbitFactory.CreateTestClient(new RawRabbitOptions { Plugins = p => p.UseProtobuf() })) | ||
using (var jsonClient = RawRabbitFactory.CreateTestClient()) | ||
{ | ||
/** Setup **/ | ||
var handlerInvoked = false; | ||
var tcs = new TaskCompletionSource<ProtoMessage>(); | ||
var message = new ProtoMessage | ||
{ | ||
Member = "Straight into bytes", | ||
Id = Guid.NewGuid() | ||
}; | ||
await jsonClient.SubscribeAsync<ProtoMessage>(msg => | ||
{ | ||
handlerInvoked = true; // Should never get here | ||
return Task.CompletedTask; | ||
}); | ||
await protobufClient.SubscribeAsync<ProtoMessage>(msg => | ||
{ | ||
tcs.TrySetResult(msg); | ||
return Task.CompletedTask; | ||
}, ctx => ctx.UseConsumerConfiguration(cfg => cfg | ||
.FromDeclaredQueue(q => q.WithName("error_queue")) | ||
.OnDeclaredExchange(e => e.WithName("default_error_exchange")) | ||
)); | ||
|
||
/** Test **/ | ||
await protobufClient.PublishAsync(message); | ||
await tcs.Task; | ||
|
||
/** Assert **/ | ||
Assert.False(handlerInvoked); | ||
Assert.Equal(tcs.Task.Result.Id, message.Id); | ||
Assert.Equal(tcs.Task.Result.Member, message.Member); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Throw_Exception_If_Responder_Can_Not_Deserialize_Request() | ||
{ | ||
using (var protobufClient = RawRabbitFactory.CreateTestClient(new RawRabbitOptions { Plugins = p => p.UseProtobuf() })) | ||
using (var jsonClient = RawRabbitFactory.CreateTestClient()) | ||
{ | ||
/* Setup */ | ||
await jsonClient.RespondAsync<ProtoRequest, ProtoResponse>(request => | ||
Task.FromResult(new ProtoResponse()) | ||
); | ||
|
||
/* Test */ | ||
/* Assert */ | ||
var e = await Assert.ThrowsAsync<MessageHandlerException>(() => | ||
protobufClient.RequestAsync<ProtoRequest, ProtoResponse>(new ProtoRequest()) | ||
); | ||
} | ||
} | ||
} | ||
|
||
[ProtoContract] | ||
public class ProtoMessage | ||
{ | ||
[ProtoMember(1)] | ||
public Guid Id { get; set; } | ||
|
||
[ProtoMember(2)] | ||
public string Member { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
public class ProtoRequest | ||
{ | ||
[ProtoMember(1)] | ||
public Guid Id { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
public class ProtoResponse | ||
{ | ||
[ProtoMember(1)] | ||
public Guid Id { get; set; } | ||
} | ||
} |
Oops, something went wrong.