Skip to content

Commit 429feb3

Browse files
committed
cluster: Add topic_table test that checks
how the clear_partition_bootstrap_params_cmd command is handled Signed-off-by: Evgeny Lazin <4lazin@gmail.com>
1 parent 0a21283 commit 429feb3

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/v/cluster/tests/topic_table_test.cc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,65 @@ FIXTURE_TEST(
810810
BOOST_REQUIRE(params1.has_value());
811811
BOOST_REQUIRE_EQUAL(params1->start_offset, model::offset(2000));
812812
}
813+
814+
FIXTURE_TEST(test_clear_bootstrap_params, topic_table_fixture) {
815+
// First, set some bootstrap params for multiple topics
816+
absl::btree_map<model::partition_id, cluster::partition_bootstrap_params>
817+
params1;
818+
params1[model::partition_id(0)] = cluster::partition_bootstrap_params(
819+
model::offset(1000), model::term_id(5));
820+
params1[model::partition_id(1)] = cluster::partition_bootstrap_params(
821+
model::offset(2000), model::term_id(10));
822+
823+
cluster::set_partition_bootstrap_params_cmd_data data1{
824+
.tp_ns = make_tp_ns("topic1"), .partition_params = std::move(params1)};
825+
cluster::set_partition_bootstrap_params_cmd cmd1(
826+
make_tp_ns("topic1"), std::move(data1));
827+
828+
auto res = table.local().apply(std::move(cmd1), model::offset(0)).get();
829+
BOOST_REQUIRE_EQUAL(res, cluster::errc::success);
830+
831+
absl::btree_map<model::partition_id, cluster::partition_bootstrap_params>
832+
params2;
833+
params2[model::partition_id(0)] = cluster::partition_bootstrap_params(
834+
model::offset(3000), model::term_id(15));
835+
836+
cluster::set_partition_bootstrap_params_cmd_data data2{
837+
.tp_ns = make_tp_ns("topic2"), .partition_params = std::move(params2)};
838+
cluster::set_partition_bootstrap_params_cmd cmd2(
839+
make_tp_ns("topic2"), std::move(data2));
840+
841+
res = table.local().apply(std::move(cmd2), model::offset(1)).get();
842+
BOOST_REQUIRE_EQUAL(res, cluster::errc::success);
843+
844+
// Verify params are stored
845+
auto ntp1_0 = model::ntp(
846+
test_ns, model::topic("topic1"), model::partition_id(0));
847+
auto ntp1_1 = model::ntp(
848+
test_ns, model::topic("topic1"), model::partition_id(1));
849+
auto ntp2_0 = model::ntp(
850+
test_ns, model::topic("topic2"), model::partition_id(0));
851+
852+
BOOST_REQUIRE(
853+
table.local().get_partition_bootstrap_params(ntp1_0).has_value());
854+
BOOST_REQUIRE(
855+
table.local().get_partition_bootstrap_params(ntp1_1).has_value());
856+
BOOST_REQUIRE(
857+
table.local().get_partition_bootstrap_params(ntp2_0).has_value());
858+
859+
// Now clear all bootstrap params
860+
cluster::clear_partition_bootstrap_params_cmd_data clear_data{};
861+
cluster::clear_partition_bootstrap_params_cmd clear_cmd(
862+
int8_t{0}, std::move(clear_data));
863+
864+
res = table.local().apply(std::move(clear_cmd), model::offset(2)).get();
865+
BOOST_REQUIRE_EQUAL(res, cluster::errc::success);
866+
867+
// Verify all params have been cleared
868+
BOOST_REQUIRE(
869+
!table.local().get_partition_bootstrap_params(ntp1_0).has_value());
870+
BOOST_REQUIRE(
871+
!table.local().get_partition_bootstrap_params(ntp1_1).has_value());
872+
BOOST_REQUIRE(
873+
!table.local().get_partition_bootstrap_params(ntp2_0).has_value());
874+
}

0 commit comments

Comments
 (0)