Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Add replication destination prefix support, [PR-135](https://github.com/reductstore/reduct-cpp/pull/135)

## 1.20.0 - 2026-06-16

### Added
Expand Down
1 change: 1 addition & 0 deletions src/reduct/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class IClient {
std::string dst_bucket; // Destination bucket
std::string dst_host; // Destination host URL (e.g. https://reductstore.com)
std::optional<std::string> dst_token; // Destination access token
std::string dst_prefix; // Prefix to add to destination entry names
std::vector<std::string>
entries; // Entries to replicate. If empty, all entries are replicated. Wildcards are supported.
std::optional<std::string> when; // Replication condition
Expand Down
7 changes: 7 additions & 0 deletions src/reduct/internal/serialisation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Result<nlohmann::json> ReplicationSettingsToJsonString(IClient::ReplicationSetti
if (settings.dst_token) {
json_data["dst_token"] = *settings.dst_token;
}
if (!settings.dst_prefix.empty()) {
json_data["dst_prefix"] = settings.dst_prefix;
}
json_data["entries"] = settings.entries;
json_data["mode"] = ReplicationModeToString(settings.mode);

Expand Down Expand Up @@ -280,6 +283,10 @@ Result<IClient::FullReplicationInfo> ParseFullReplicationInfo(const nlohmann::js
info.settings.dst_token = settings.at("dst_token");
}

if (settings.contains("dst_prefix") && !settings.at("dst_prefix").is_null()) {
info.settings.dst_prefix = settings.at("dst_prefix");
}

if (settings.contains("when") && !settings.at("when").is_null()) {
info.settings.when = settings.at("when").dump();
}
Expand Down
76 changes: 76 additions & 0 deletions tests/reduct/replication_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "fixture.h"
#include "reduct/client.h"
#include "reduct/internal/serialisation.h"

using reduct::Error;
using reduct::IClient;
Expand Down Expand Up @@ -78,6 +79,81 @@ TEST_CASE("reduct::Client should update a replication", "[replication_api][1_17]
}
}

TEST_CASE("reduct::Client should serialize replication destination prefix", "[replication_api]") {
auto settings = DefaultSettings();

SECTION("omits empty destination prefix") {
auto [json, err] = reduct::internal::ReplicationSettingsToJsonString(settings);

REQUIRE(err == Error::kOk);
REQUIRE_FALSE(json.contains("dst_prefix"));
}

SECTION("serializes non-empty destination prefix") {
settings.dst_prefix = "robot-1";

auto [json, err] = reduct::internal::ReplicationSettingsToJsonString(settings);

REQUIRE(err == Error::kOk);
REQUIRE(json.at("dst_prefix") == "robot-1");
}
}

TEST_CASE("reduct::Client should parse replication destination prefix", "[replication_api]") {
auto response = nlohmann::json{
{"info",
{{"name", "test_replication"},
{"mode", "enabled"},
{"is_active", true},
{"is_provisioned", false},
{"pending_records", 0}}},
{"settings",
{{"src_bucket", "test_bucket_1"},
{"dst_bucket", "test_bucket_2"},
{"dst_host", "http://127.0.0.1:8383"},
{"entries", {"entry-1"}},
{"mode", "enabled"}}},
{"diagnostics", {{"hourly", {{"ok", 0}, {"errored", 0}, {"errors", nlohmann::json::object()}}}}},
};

SECTION("keeps destination prefix empty when absent") {
auto [replication, err] = reduct::internal::ParseFullReplicationInfo(response);

REQUIRE(err == Error::kOk);
REQUIRE(replication.settings.dst_prefix.empty());
}

SECTION("parses returned destination prefix") {
response["settings"]["dst_prefix"] = "robot-1";

auto [replication, err] = reduct::internal::ParseFullReplicationInfo(response);

REQUIRE(err == Error::kOk);
REQUIRE(replication.settings.dst_prefix == "robot-1");
}
}

TEST_CASE("reduct::Client should set replication destination prefix", "[replication_api][1_20]") {
Fixture ctx;
auto settings = DefaultSettings();
settings.dst_prefix = "robot-1";

auto err = ctx.client->CreateReplication("test_replication", settings);
REQUIRE(err == Error::kOk);

auto [replication, err_2] = ctx.client->GetReplication("test_replication");
REQUIRE(err_2 == Error::kOk);
REQUIRE(replication.settings.dst_prefix == "robot-1");

settings.dst_prefix = "line-a";
err = ctx.client->UpdateReplication("test_replication", settings);
REQUIRE(err == Error::kOk);

auto [updated_replication, err_3] = ctx.client->GetReplication("test_replication");
REQUIRE(err_3 == Error::kOk);
REQUIRE(updated_replication.settings.dst_prefix == "line-a");
}

TEST_CASE("reduct::Client should set replication mode", "[replication_api][1_18]") {
Fixture ctx;
auto settings = DefaultSettings();
Expand Down
3 changes: 2 additions & 1 deletion tests/reduct/token_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ TEST_CASE("reduct::Client should create token", "[token_api]") {
REQUIRE(token.starts_with("test_token-"));

SECTION("Conflict") {
REQUIRE(ctx.client->CreateToken(kTestTokenName, IClient::Permissions{}).error == Error{409, "Token 'test_token' already exists"});
REQUIRE(ctx.client->CreateToken(kTestTokenName, IClient::Permissions{}).error ==
Error{409, "Token 'test_token' already exists"});
}
}

Expand Down
Loading