diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml
index 0848e56d..7caae3e6 100644
--- a/.github/workflows/ci-e2e.yml
+++ b/.github/workflows/ci-e2e.yml
@@ -45,7 +45,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
- dotnet-version: 6.0.x
+ dotnet-version: 8.0.x
- name: Start containers
run: dotnet build && docker compose -f "docker-compose.yml" up -d && sleep 20 #allow time for mongo to start up properly
diff --git a/src/Machine/src/Serval.Machine.Shared/Configuration/MessageOutboxOptions.cs b/src/Machine/src/Serval.Machine.Shared/Configuration/MessageOutboxOptions.cs
index e2e88feb..a8b5f5fe 100644
--- a/src/Machine/src/Serval.Machine.Shared/Configuration/MessageOutboxOptions.cs
+++ b/src/Machine/src/Serval.Machine.Shared/Configuration/MessageOutboxOptions.cs
@@ -6,4 +6,14 @@ public class MessageOutboxOptions
public string OutboxDir { get; set; } = "outbox";
public TimeSpan MessageExpirationTimeout { get; set; } = TimeSpan.FromHours(48);
+
+ public static JsonSerializerOptions JsonSerializerOptions
+ {
+ get
+ {
+ JsonSerializerOptions options = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
+ options.AddProtobufSupport();
+ return options;
+ }
+ }
}
diff --git a/src/Machine/src/Serval.Machine.Shared/Serval.Machine.Shared.csproj b/src/Machine/src/Serval.Machine.Shared/Serval.Machine.Shared.csproj
index 41a037a0..57bea40c 100644
--- a/src/Machine/src/Serval.Machine.Shared/Serval.Machine.Shared.csproj
+++ b/src/Machine/src/Serval.Machine.Shared/Serval.Machine.Shared.csproj
@@ -36,6 +36,7 @@
+
diff --git a/src/Machine/src/Serval.Machine.Shared/Services/IMessageOutboxService.cs b/src/Machine/src/Serval.Machine.Shared/Services/IMessageOutboxService.cs
index d9791ec8..e1710598 100644
--- a/src/Machine/src/Serval.Machine.Shared/Services/IMessageOutboxService.cs
+++ b/src/Machine/src/Serval.Machine.Shared/Services/IMessageOutboxService.cs
@@ -2,12 +2,19 @@
public interface IMessageOutboxService
{
- public Task EnqueueMessageAsync(
+ public Task EnqueueMessageAsync(
string outboxId,
string method,
string groupId,
- string? content = null,
- Stream? contentStream = null,
+ TValue content,
+ CancellationToken cancellationToken = default
+ );
+
+ public Task EnqueueMessageStreamAsync(
+ string outboxId,
+ string method,
+ string groupId,
+ Stream contentStream,
CancellationToken cancellationToken = default
);
}
diff --git a/src/Machine/src/Serval.Machine.Shared/Services/IOutboxMessageHandler.cs b/src/Machine/src/Serval.Machine.Shared/Services/IOutboxMessageHandler.cs
index 014ab591..d1226c9b 100644
--- a/src/Machine/src/Serval.Machine.Shared/Services/IOutboxMessageHandler.cs
+++ b/src/Machine/src/Serval.Machine.Shared/Services/IOutboxMessageHandler.cs
@@ -5,6 +5,7 @@ public interface IOutboxMessageHandler
public string OutboxId { get; }
public Task HandleMessageAsync(
+ string groupId,
string method,
string? content,
Stream? contentStream,
diff --git a/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxDeliveryService.cs b/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxDeliveryService.cs
index 91776006..8c84a3be 100644
--- a/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxDeliveryService.cs
+++ b/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxDeliveryService.cs
@@ -58,7 +58,13 @@ internal async Task ProcessMessagesAsync(
{
try
{
- await ProcessGroupMessagesAsync(messages, message, outboxMessageHandler, cancellationToken);
+ await ProcessGroupMessagesAsync(
+ messages,
+ message,
+ messageGroup.Key.GroupId,
+ outboxMessageHandler,
+ cancellationToken
+ );
}
catch (RpcException e)
{
@@ -98,6 +104,7 @@ internal async Task ProcessMessagesAsync(
private async Task ProcessGroupMessagesAsync(
IRepository messages,
OutboxMessage message,
+ string groupId,
IOutboxMessageHandler outboxMessageHandler,
CancellationToken cancellationToken = default
)
@@ -109,6 +116,7 @@ private async Task ProcessGroupMessagesAsync(
try
{
await outboxMessageHandler.HandleMessageAsync(
+ groupId,
message.Method,
message.Content,
contentStream,
diff --git a/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxService.cs b/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxService.cs
index 2c5d410d..bcde1e98 100644
--- a/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxService.cs
+++ b/src/Machine/src/Serval.Machine.Shared/Services/MessageOutboxService.cs
@@ -15,22 +15,20 @@ IOptionsMonitor options
private readonly IOptionsMonitor _options = options;
internal int MaxDocumentSize { get; set; } = 1_000_000;
- public async Task EnqueueMessageAsync(
+ public async Task EnqueueMessageAsync(
string outboxId,
string method,
string groupId,
- string? content = null,
- Stream? contentStream = null,
+ TValue content,
CancellationToken cancellationToken = default
)
{
- if (content == null && contentStream == null)
- throw new ArgumentException("Either content or contentStream must be specified.");
- if (content is not null && content.Length > MaxDocumentSize)
+ string serializedContent = JsonSerializer.Serialize(content, MessageOutboxOptions.JsonSerializerOptions);
+ if (serializedContent.Length > MaxDocumentSize)
{
throw new ArgumentException(
$"The content is too large for request {method} with group ID {groupId}. "
- + $"It is {content.Length} bytes, but the maximum is {MaxDocumentSize} bytes."
+ + $"It is {serializedContent.Length} bytes, but the maximum is {MaxDocumentSize} bytes."
);
}
Outbox outbox = (
@@ -49,24 +47,52 @@ await _outboxes.UpdateAsync(
OutboxRef = outboxId,
Method = method,
GroupId = groupId,
- Content = content,
- HasContentStream = contentStream is not null
+ Content = serializedContent,
+ HasContentStream = false
+ };
+ string filePath = Path.Combine(_options.CurrentValue.OutboxDir, outboxMessage.Id);
+ await _messages.InsertAsync(outboxMessage, cancellationToken: cancellationToken);
+ return outboxMessage.Id;
+ }
+
+ public async Task EnqueueMessageStreamAsync(
+ string outboxId,
+ string method,
+ string groupId,
+ Stream contentStream,
+ CancellationToken cancellationToken = default
+ )
+ {
+ Outbox outbox = (
+ await _outboxes.UpdateAsync(
+ outboxId,
+ u => u.Inc(o => o.CurrentIndex, 1),
+ upsert: true,
+ cancellationToken: cancellationToken
+ )
+ )!;
+ OutboxMessage outboxMessage =
+ new()
+ {
+ Id = _idGenerator.GenerateId(),
+ Index = outbox.CurrentIndex,
+ OutboxRef = outboxId,
+ Method = method,
+ GroupId = groupId,
+ Content = null,
+ HasContentStream = true
};
string filePath = Path.Combine(_options.CurrentValue.OutboxDir, outboxMessage.Id);
try
{
- if (contentStream is not null)
- {
- await using Stream fileStream = _fileSystem.OpenWrite(filePath);
- await contentStream.CopyToAsync(fileStream, cancellationToken);
- }
+ await using Stream fileStream = _fileSystem.OpenWrite(filePath);
+ await contentStream.CopyToAsync(fileStream, cancellationToken);
await _messages.InsertAsync(outboxMessage, cancellationToken: cancellationToken);
return outboxMessage.Id;
}
catch
{
- if (contentStream is not null)
- _fileSystem.DeleteFile(filePath);
+ _fileSystem.DeleteFile(filePath);
throw;
}
}
diff --git a/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformOutboxMessageHandler.cs b/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformOutboxMessageHandler.cs
index 490ed650..aa1df36a 100644
--- a/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformOutboxMessageHandler.cs
+++ b/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformOutboxMessageHandler.cs
@@ -6,12 +6,12 @@ public class ServalPlatformOutboxMessageHandler(TranslationPlatformApi.Translati
: IOutboxMessageHandler
{
private readonly TranslationPlatformApi.TranslationPlatformApiClient _client = client;
- private static readonly JsonSerializerOptions JsonSerializerOptions =
- new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
+ private readonly JsonSerializerOptions _jsonSerializerOptions = MessageOutboxOptions.JsonSerializerOptions;
public string OutboxId => ServalPlatformOutboxConstants.OutboxId;
public async Task HandleMessageAsync(
+ string groupId,
string method,
string? content,
Stream? contentStream,
@@ -22,31 +22,31 @@ public async Task HandleMessageAsync(
{
case ServalPlatformOutboxConstants.BuildStarted:
await _client.BuildStartedAsync(
- JsonSerializer.Deserialize(content!),
+ JsonSerializer.Deserialize(content!, _jsonSerializerOptions),
cancellationToken: cancellationToken
);
break;
case ServalPlatformOutboxConstants.BuildCompleted:
await _client.BuildCompletedAsync(
- JsonSerializer.Deserialize(content!),
+ JsonSerializer.Deserialize(content!, _jsonSerializerOptions),
cancellationToken: cancellationToken
);
break;
case ServalPlatformOutboxConstants.BuildCanceled:
await _client.BuildCanceledAsync(
- JsonSerializer.Deserialize(content!),
+ JsonSerializer.Deserialize(content!, _jsonSerializerOptions),
cancellationToken: cancellationToken
);
break;
case ServalPlatformOutboxConstants.BuildFaulted:
await _client.BuildFaultedAsync(
- JsonSerializer.Deserialize(content!),
+ JsonSerializer.Deserialize(content!, _jsonSerializerOptions),
cancellationToken: cancellationToken
);
break;
case ServalPlatformOutboxConstants.BuildRestarting:
await _client.BuildRestartingAsync(
- JsonSerializer.Deserialize(content!),
+ JsonSerializer.Deserialize(content!, _jsonSerializerOptions),
cancellationToken: cancellationToken
);
break;
@@ -54,7 +54,7 @@ await _client.BuildRestartingAsync(
IAsyncEnumerable pretranslations = JsonSerializer
.DeserializeAsyncEnumerable(
contentStream!,
- JsonSerializerOptions,
+ _jsonSerializerOptions,
cancellationToken
)
.OfType();
@@ -66,7 +66,7 @@ await _client.BuildRestartingAsync(
await call.RequestStream.WriteAsync(
new InsertPretranslationsRequest
{
- EngineId = content!,
+ EngineId = groupId,
CorpusId = pretranslation.CorpusId,
TextId = pretranslation.TextId,
Refs = { pretranslation.Refs },
@@ -81,13 +81,16 @@ await call.RequestStream.WriteAsync(
break;
case ServalPlatformOutboxConstants.IncrementTranslationEngineCorpusSize:
await _client.IncrementTranslationEngineCorpusSizeAsync(
- JsonSerializer.Deserialize(content!),
+ JsonSerializer.Deserialize(
+ content!,
+ _jsonSerializerOptions
+ ),
cancellationToken: cancellationToken
);
break;
case ServalPlatformOutboxConstants.UpdateBuildExecutionData:
await _client.UpdateBuildExecutionDataAsync(
- JsonSerializer.Deserialize(content!),
+ JsonSerializer.Deserialize(content!, _jsonSerializerOptions),
cancellationToken: cancellationToken
);
break;
diff --git a/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformService.cs b/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformService.cs
index fece316c..6de64575 100644
--- a/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformService.cs
+++ b/src/Machine/src/Serval.Machine.Shared/Services/ServalPlatformService.cs
@@ -16,7 +16,7 @@ await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.BuildStarted,
buildId,
- JsonSerializer.Serialize(new BuildStartedRequest { BuildId = buildId }),
+ new BuildStartedRequest { BuildId = buildId },
cancellationToken: cancellationToken
);
}
@@ -32,14 +32,12 @@ await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.BuildCompleted,
buildId,
- JsonSerializer.Serialize(
- new BuildCompletedRequest
- {
- BuildId = buildId,
- CorpusSize = trainSize,
- Confidence = confidence
- }
- ),
+ new BuildCompletedRequest
+ {
+ BuildId = buildId,
+ CorpusSize = trainSize,
+ Confidence = confidence
+ },
cancellationToken: cancellationToken
);
}
@@ -50,7 +48,7 @@ await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.BuildCanceled,
buildId,
- JsonSerializer.Serialize(new BuildCanceledRequest { BuildId = buildId }),
+ new BuildCanceledRequest { BuildId = buildId },
cancellationToken: cancellationToken
);
}
@@ -61,7 +59,7 @@ await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.BuildFaulted,
buildId,
- JsonSerializer.Serialize(new BuildFaultedRequest { BuildId = buildId, Message = message }),
+ new BuildFaultedRequest { BuildId = buildId, Message = message },
cancellationToken: cancellationToken
);
}
@@ -72,7 +70,7 @@ await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.BuildRestarting,
buildId,
- JsonSerializer.Serialize(new BuildRestartingRequest { BuildId = buildId }),
+ new BuildRestartingRequest { BuildId = buildId },
cancellationToken: cancellationToken
);
}
@@ -111,13 +109,12 @@ public async Task InsertPretranslationsAsync(
CancellationToken cancellationToken = default
)
{
- await _outboxService.EnqueueMessageAsync(
+ await _outboxService.EnqueueMessageStreamAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.InsertPretranslations,
engineId,
- engineId,
pretranslationsStream,
- cancellationToken: cancellationToken
+ cancellationToken
);
}
@@ -131,9 +128,7 @@ await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.IncrementTranslationEngineCorpusSize,
engineId,
- JsonSerializer.Serialize(
- new IncrementTranslationEngineCorpusSizeRequest { EngineId = engineId, Count = count }
- ),
+ new IncrementTranslationEngineCorpusSizeRequest { EngineId = engineId, Count = count },
cancellationToken: cancellationToken
);
}
@@ -151,7 +146,7 @@ await _outboxService.EnqueueMessageAsync(
ServalPlatformOutboxConstants.OutboxId,
ServalPlatformOutboxConstants.UpdateBuildExecutionData,
engineId,
- JsonSerializer.Serialize(request),
+ request,
cancellationToken: cancellationToken
);
}
diff --git a/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxDeliveryServiceTests.cs b/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxDeliveryServiceTests.cs
index 2a5e517b..abc31219 100644
--- a/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxDeliveryServiceTests.cs
+++ b/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxDeliveryServiceTests.cs
@@ -15,9 +15,9 @@ public async Task ProcessMessagesAsync()
await env.ProcessMessagesAsync();
Received.InOrder(() =>
{
- env.Handler.HandleMessageAsync(Method2, "B", null, Arg.Any());
- env.Handler.HandleMessageAsync(Method1, "A", null, Arg.Any());
- env.Handler.HandleMessageAsync(Method2, "C", null, Arg.Any());
+ env.Handler.HandleMessageAsync(Arg.Any(), Method2, "B", null, Arg.Any());
+ env.Handler.HandleMessageAsync(Arg.Any(), Method1, "A", null, Arg.Any());
+ env.Handler.HandleMessageAsync(Arg.Any(), Method2, "C", null, Arg.Any());
});
Assert.That(env.Messages.Count, Is.EqualTo(0));
}
@@ -44,9 +44,21 @@ public async Task ProcessMessagesAsync_Timeout()
await env.ProcessMessagesAsync();
Assert.That(env.Messages.Count, Is.EqualTo(0));
_ = env.Handler.Received(1)
- .HandleMessageAsync(Method1, Arg.Any(), Arg.Any(), Arg.Any());
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method1,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ );
_ = env.Handler.Received(4)
- .HandleMessageAsync(Method2, Arg.Any(), Arg.Any(), Arg.Any());
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method2,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ );
}
[Test]
@@ -62,7 +74,13 @@ public async Task ProcessMessagesAsync_UnavailableFailure()
Assert.That(env.Messages.Get("A").Attempts, Is.EqualTo(0));
Assert.That(env.Messages.Get("C").Attempts, Is.EqualTo(0));
_ = env.Handler.Received(1)
- .HandleMessageAsync(Method2, Arg.Any(), Arg.Any(), Arg.Any());
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method2,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ );
env.Handler.ClearReceivedCalls();
env.EnableHandlerFailure(StatusCode.Internal);
@@ -71,16 +89,34 @@ public async Task ProcessMessagesAsync_UnavailableFailure()
Assert.That(env.Messages.Get("A").Attempts, Is.EqualTo(0));
Assert.That(env.Messages.Get("C").Attempts, Is.EqualTo(1));
_ = env.Handler.Received(2)
- .HandleMessageAsync(Method2, Arg.Any(), Arg.Any(), Arg.Any());
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method2,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ );
env.Handler.ClearReceivedCalls();
env.DisableHandlerFailure();
await env.ProcessMessagesAsync();
Assert.That(env.Messages.Count, Is.EqualTo(0));
_ = env.Handler.Received(1)
- .HandleMessageAsync(Method1, Arg.Any(), Arg.Any(), Arg.Any());
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method1,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ );
_ = env.Handler.Received(2)
- .HandleMessageAsync(Method2, Arg.Any(), Arg.Any(), Arg.Any());
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method2,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ );
}
[Test]
@@ -92,7 +128,13 @@ public async Task ProcessMessagesAsync_File()
await env.ProcessMessagesAsync();
Assert.That(env.Messages.Count, Is.EqualTo(0));
_ = env.Handler.Received(1)
- .HandleMessageAsync(Method1, "A", Arg.Is(s => s != null), Arg.Any());
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method1,
+ "A",
+ Arg.Is(s => s != null),
+ Arg.Any()
+ );
env.FileSystem.Received().DeleteFile(Path.Combine("outbox", "A"));
}
@@ -194,20 +236,44 @@ public void AddContentStreamMessages()
public void EnableHandlerFailure(StatusCode code)
{
Handler
- .HandleMessageAsync(Method1, Arg.Any(), Arg.Any(), Arg.Any())
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method1,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ )
.ThrowsAsync(new RpcException(new Status(code, "")));
Handler
- .HandleMessageAsync(Method2, Arg.Any(), Arg.Any(), Arg.Any())
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method2,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ )
.ThrowsAsync(new RpcException(new Status(code, "")));
}
public void DisableHandlerFailure()
{
Handler
- .HandleMessageAsync(Method1, Arg.Any(), Arg.Any(), Arg.Any())
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method1,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ )
.Returns(Task.CompletedTask);
Handler
- .HandleMessageAsync(Method2, Arg.Any(), Arg.Any(), Arg.Any())
+ .HandleMessageAsync(
+ Arg.Any(),
+ Method2,
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()
+ )
.Returns(Task.CompletedTask);
}
}
diff --git a/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxServiceTests.cs b/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxServiceTests.cs
index 876568d9..e5032bc8 100644
--- a/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxServiceTests.cs
+++ b/src/Machine/test/Serval.Machine.Shared.Tests/Services/MessageOutboxServiceTests.cs
@@ -20,7 +20,7 @@ public async Task EnqueueMessageAsync_NoContentStream()
Assert.That(message.OutboxRef, Is.EqualTo(OutboxId));
Assert.That(message.Method, Is.EqualTo(Method));
Assert.That(message.Index, Is.EqualTo(1));
- Assert.That(message.Content, Is.EqualTo("content"));
+ Assert.That(message.Content, Is.EqualTo("\"content\""));
Assert.That(message.HasContentStream, Is.False);
}
@@ -39,7 +39,7 @@ public async Task EnqueueMessageAsync_ExistingOutbox()
Assert.That(message.OutboxRef, Is.EqualTo(OutboxId));
Assert.That(message.Method, Is.EqualTo(Method));
Assert.That(message.Index, Is.EqualTo(2));
- Assert.That(message.Content, Is.EqualTo("content"));
+ Assert.That(message.Content, Is.EqualTo("\"content\""));
Assert.That(message.HasContentStream, Is.False);
}
@@ -51,13 +51,13 @@ public async Task EnqueueMessageAsync_HasContentStream()
env.FileSystem.OpenWrite(Path.Combine("outbox", "1")).Returns(fileStream);
await using MemoryStream stream = new(Encoding.UTF8.GetBytes("content"));
- await env.Service.EnqueueMessageAsync(OutboxId, Method, "A", "content", stream);
+ await env.Service.EnqueueMessageStreamAsync(OutboxId, Method, "A", stream);
OutboxMessage message = env.Messages.Get("1");
Assert.That(message.OutboxRef, Is.EqualTo(OutboxId));
Assert.That(message.Method, Is.EqualTo(Method));
Assert.That(message.Index, Is.EqualTo(1));
- Assert.That(message.Content, Is.EqualTo("content"));
+ Assert.That(message.Content, Is.EqualTo(null));
Assert.That(message.HasContentStream, Is.True);
Assert.That(fileStream.ToArray(), Is.EqualTo(stream.ToArray()));
}
diff --git a/src/Machine/test/Serval.Machine.Shared.Tests/Services/ServalPlatformOutboxMessageHandlerTests.cs b/src/Machine/test/Serval.Machine.Shared.Tests/Services/ServalPlatformOutboxMessageHandlerTests.cs
index 3bc63f98..28ad1b04 100644
--- a/src/Machine/test/Serval.Machine.Shared.Tests/Services/ServalPlatformOutboxMessageHandlerTests.cs
+++ b/src/Machine/test/Serval.Machine.Shared.Tests/Services/ServalPlatformOutboxMessageHandlerTests.cs
@@ -6,17 +6,18 @@ namespace Serval.Machine.Shared.Services;
[TestFixture]
public class ServalPlatformOutboxMessageHandlerTests
{
- private static readonly JsonSerializerOptions JsonSerializerOptions =
- new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
-
[Test]
public async Task HandleMessageAsync_BuildStarted()
{
TestEnvironment env = new();
await env.Handler.HandleMessageAsync(
+ "groupId",
ServalPlatformOutboxConstants.BuildStarted,
- JsonSerializer.Serialize(new BuildStartedRequest { BuildId = "C" }),
+ JsonSerializer.Serialize(
+ new BuildStartedRequest { BuildId = "C" },
+ MessageOutboxOptions.JsonSerializerOptions
+ ),
null
);
@@ -27,6 +28,7 @@ await env.Handler.HandleMessageAsync(
public async Task HandleMessageAsync_InsertPretranslations()
{
TestEnvironment env = new();
+
await using (MemoryStream stream = new())
{
await JsonSerializer.SerializeAsync(
@@ -41,10 +43,11 @@ await JsonSerializer.SerializeAsync(
Translation = "translation"
}
},
- JsonSerializerOptions
+ MessageOutboxOptions.JsonSerializerOptions
);
stream.Seek(0, SeekOrigin.Begin);
await env.Handler.HandleMessageAsync(
+ "engine1",
ServalPlatformOutboxConstants.InsertPretranslations,
"engine1",
stream
diff --git a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs
index 26106235..45fae1ba 100644
--- a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs
+++ b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs
@@ -125,7 +125,7 @@ public async Task NmtBatch()
true
);
_helperClient.TranslationBuildConfig.Pretranslate = [new() { CorpusId = cId2, TextIds = ["2JN.txt"] }];
- await _helperClient.BuildEngineAsync(engineId);
+ string buildId = await _helperClient.BuildEngineAsync(engineId);
await Task.Delay(1000);
IList lTrans1 = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync(
engineId,
@@ -137,7 +137,7 @@ public async Task NmtBatch()
cId2
);
- TranslationBuild build = await _helperClient.TranslationEnginesClient.GetCurrentBuildAsync(engineId);
+ TranslationBuild build = await _helperClient.TranslationEnginesClient.GetBuildAsync(engineId, buildId);
Assert.That(build.ExecutionData, Is.Not.Null);
var executionData = build.ExecutionData!;
diff --git a/src/Serval/test/Serval.E2ETests/ServalClientHelper.cs b/src/Serval/test/Serval.E2ETests/ServalClientHelper.cs
index 87f54a13..8f08f582 100644
--- a/src/Serval/test/Serval.E2ETests/ServalClientHelper.cs
+++ b/src/Serval/test/Serval.E2ETests/ServalClientHelper.cs
@@ -123,7 +123,7 @@ public async Task StartBuildAsync(string engineId)
return await TranslationEnginesClient.StartBuildAsync(engineId, TranslationBuildConfig);
}
- public async Task BuildEngineAsync(string engineId)
+ public async Task BuildEngineAsync(string engineId)
{
TranslationBuild newJob = await StartBuildAsync(engineId);
int revision = newJob.Revision;
@@ -151,6 +151,7 @@ public async Task BuildEngineAsync(string engineId)
await Task.Delay(500);
}
}
+ return newJob.Id;
}
public async Task CancelBuildAsync(string engineId, string buildId, int timeoutSeconds = 20)