Skip to content

Commit

Permalink
c/tests/topic_table: test raft group to ntp mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
bashtanov committed Jun 7, 2024
1 parent d6fbb4a commit 8326017
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/v/cluster/tests/topic_table_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ struct topic_table_fixture {
return total;
}

void validate_group_ntp_map() {
size_t counter{};
for (const auto& nt : table.local().all_topics()) {
const auto assignments = table.local().get_topic_assignments(nt);
if (assignments) {
for (const auto& ass : *assignments) {
model::ntp expected{nt.ns, nt.tp, ass.id};
auto found = table.local().get_ntp_by_group(ass.group);
BOOST_REQUIRE_EQUAL(expected, found);
++counter;
}
}
BOOST_REQUIRE_EQUAL(table.local()._group_ntp_map.size(), counter);
}
}

ss::sharded<cluster::members_table> members;
ss::sharded<cluster::partition_allocator> allocator;
ss::sharded<cluster::topic_table> table;
Expand Down
4 changes: 4 additions & 0 deletions src/v/cluster/tests/topic_table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ FIXTURE_TEST(test_happy_path_create, topic_table_fixture) {
BOOST_REQUIRE_EQUAL(
md.find(make_tp_ns("test_tp_3"))->second.get_assignments().size(), 8);

validate_group_ntp_map();
validate_delta(deltas, 21, 0);
}

Expand Down Expand Up @@ -71,6 +72,7 @@ FIXTURE_TEST(test_happy_path_delete, topic_table_fixture) {
BOOST_REQUIRE_EQUAL(
md.find(make_tp_ns("test_tp_1"))->second.get_assignments().size(), 1);

validate_group_ntp_map();
validate_delta(deltas, 0, 20);
}

Expand All @@ -95,6 +97,7 @@ FIXTURE_TEST(test_conflicts, topic_table_fixture) {
.get0();
BOOST_REQUIRE_EQUAL(res_2, cluster::errc::topic_already_exists);
BOOST_REQUIRE_EQUAL(deltas.size(), 0);
validate_group_ntp_map();
}

FIXTURE_TEST(get_getting_config, topic_table_fixture) {
Expand Down Expand Up @@ -162,6 +165,7 @@ FIXTURE_TEST(test_adding_partition, topic_table_fixture) {
BOOST_REQUIRE_EQUAL(md->get_assignments().size(), 15);
// require 3 partition additions
validate_delta(deltas, 3, 0);
validate_group_ntp_map();
}

void validate_brokers_revisions(
Expand Down
4 changes: 4 additions & 0 deletions src/v/cluster/tests/topic_updates_dispatcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ FIXTURE_TEST(
md.find(make_tp_ns("test_tp_2"))->second.get_assignments().size(), 12);
BOOST_REQUIRE_EQUAL(
md.find(make_tp_ns("test_tp_3"))->second.get_assignments().size(), 8);
validate_group_ntp_map();

// Initial capacity
// (cpus * max_allocations_per_core) - core0_extra_weight;
// node 1, 8 cores
Expand Down Expand Up @@ -132,6 +134,8 @@ FIXTURE_TEST(
BOOST_REQUIRE_EQUAL(
md.find(make_tp_ns("test_tp_1"))->second.get_assignments().size(), 1);

validate_group_ntp_map();

BOOST_REQUIRE_EQUAL(
current_cluster_capacity(allocator.local().state().allocation_nodes()),
max_cluster_capacity() - 3);
Expand Down
4 changes: 4 additions & 0 deletions src/v/cluster/topic_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#include <type_traits>

// Forward declaration for test class that we will befriend
struct topic_table_fixture;

namespace cluster {
/**
* ## Overview
Expand Down Expand Up @@ -627,6 +630,7 @@ class topic_table {

private:
friend topic_table_probe;
friend topic_table_fixture;

struct waiter {
explicit waiter(uint64_t id)
Expand Down

0 comments on commit 8326017

Please sign in to comment.