Files
Library/tests/standalone/MessagingRpc/RpcAdapter.cpp

57 lines
1.8 KiB
C++

#include <Void/Messaging/Queue.hpp>
#include <Void/MessagingRpc/RpcAdapter.hpp>
#include <Void/RPC/Rpc.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
Void::Testing::Test messaging_rpc_remote_publish_receive_ack_and_query()
{
using namespace Void::Messaging;
using namespace Void::MessagingRpc;
InMemoryQueue queue{};
Void::Testing::require(
queue.create_queue(QueueConfig{.name = "remote-q"}).has_value());
Void::Testing::require(
queue.create_group("remote-q", GroupConfig{.name = "g1"}).has_value());
Void::RPC::Server rpc_server{};
RpcQueueServer adapter{};
Void::Testing::require(adapter.mount(rpc_server, queue).has_value());
Void::Testing::require(rpc_server.start().has_value());
RpcQueueClient client{Void::RPC::ClientOptions{
.endpoint_base_url = rpc_server.base_url(),
}};
Message msg{};
msg.id = "rpc-msg-1";
msg.payload = {std::byte{'h'}, std::byte{'i'}};
msg.headers["trace"] = "abc";
auto pub = client.publish("remote-q", msg, PublishDurability::Memory);
Void::Testing::require(pub.has_value());
Void::Testing::expect_eq(pub->sequence, 1ULL);
auto del = client.try_receive("remote-q", "g1");
Void::Testing::require(del.has_value() && del->has_value());
Void::Testing::expect_eq((*del)->message.id, std::string{"rpc-msg-1"});
Void::Testing::expect_eq((*del)->message.headers.at("trace"),
std::string{"abc"});
auto st_inflight = client.query_receipt((*del)->receipt);
Void::Testing::require(st_inflight.has_value());
Void::Testing::expect(*st_inflight == DeliveryState::InFlight);
Void::Testing::require(client.ack((*del)->receipt).has_value());
auto st_acked = client.query_receipt((*del)->receipt);
Void::Testing::require(st_acked.has_value());
Void::Testing::expect(*st_acked == DeliveryState::Acked);
adapter.unmount_and_drain();
rpc_server.shutdown();
}