Skip to content

Commit

Permalink
fix(test): fix issue with aws tests (#3012)
Browse files Browse the repository at this point in the history
* fix(test): fix issue with aws tests
* A bit more async-y in the messagemapper
  • Loading branch information
holytshirt authored Feb 8, 2024
1 parent 432550e commit d5c946e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using Paramore.Brighter.Transforms.Attributes;

namespace Paramore.Brighter.AWS.Tests.TestDoubles;
Expand All @@ -21,3 +23,23 @@ public MyLargeCommand MapToRequest(Message message)
return JsonSerializer.Deserialize<MyLargeCommand>(message.Body.Value);
}
}

public class MyLargeCommandMessageMapperAsync : IAmAMessageMapperAsync<MyLargeCommand>
{
[ClaimCheck(0, thresholdInKb: 5)]
public async Task<Message> MapToMessage(MyLargeCommand request)
{
using var memoryContentStream = new MemoryStream();
await JsonSerializer.SerializeAsync(memoryContentStream, request, new JsonSerializerOptions(JsonSerializerDefaults.General));
return new Message(
new MessageHeader(request.Id, "transform.event", MessageType.MT_COMMAND, DateTime.UtcNow),
new MessageBody(memoryContentStream.ToArray()));
}

[RetrieveClaim(0, retain:false)]
public async Task<MyLargeCommand> MapToRequest(Message message)
{
using MemoryStream stream = new(message.Body.Bytes);
return await JsonSerializer.DeserializeAsync<MyLargeCommand>(stream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public class LargeMessagePayloadWrapTests : IDisposable
public LargeMessagePayloadWrapTests()
{
//arrange
TransformPipelineBuilder.ClearPipelineCache();
TransformPipelineBuilderAsync.ClearPipelineCache();

var mapperRegistry =
new MessageMapperRegistry(new SimpleMessageMapperFactory(
_ => new MyLargeCommandMessageMapper()),
null);
mapperRegistry.Register<MyLargeCommand, MyLargeCommandMessageMapper>();
new MessageMapperRegistry(null, new SimpleMessageMapperFactoryAsync(
_ => new MyLargeCommandMessageMapperAsync())
);

mapperRegistry.RegisterAsync<MyLargeCommand, MyLargeCommandMessageMapperAsync>();

_myCommand = new MyLargeCommand(6000);

Expand Down Expand Up @@ -69,9 +70,9 @@ public LargeMessagePayloadWrapTests()
.GetAwaiter()
.GetResult();

var messageTransformerFactory = new SimpleMessageTransformerFactoryAsync(_ => new ClaimCheckTransformerAsync(_luggageStore));
var transformerFactoryAsync = new SimpleMessageTransformerFactoryAsync(_ => new ClaimCheckTransformerAsync(_luggageStore));

_pipelineBuilder = new TransformPipelineBuilderAsync(mapperRegistry, messageTransformerFactory);
_pipelineBuilder = new TransformPipelineBuilderAsync(mapperRegistry, transformerFactoryAsync);
}

[Fact]
Expand Down

0 comments on commit d5c946e

Please sign in to comment.