Skip to content

Commit

Permalink
storage: move storage_e2e_fixture to its own header file
Browse files Browse the repository at this point in the history
  • Loading branch information
WillemKauf committed Dec 11, 2024
1 parent 7a29f24 commit c0d76d1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/v/storage/disk_log_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <absl/container/flat_hash_map.h>

struct storage_e2e_fixture;
namespace storage {

/// \brief offset boundary type
Expand Down Expand Up @@ -248,6 +249,7 @@ class disk_log_impl final : public log {
private:
friend class disk_log_appender; // for multi-term appends
friend class disk_log_builder; // for tests
friend ::storage_e2e_fixture;
friend std::ostream& operator<<(std::ostream& o, const disk_log_impl& d);

/// Compute file offset of the batch inside the segment
Expand Down
50 changes: 50 additions & 0 deletions src/v/storage/tests/storage_e2e_fixture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

#include "redpanda/tests/fixture.h"
#include "storage/disk_log_impl.h"
#include "storage/segment.h"
#include "test_utils/scoped_config.h"

#include <seastar/core/future.hh>
#include <seastar/core/shared_ptr.hh>

struct storage_e2e_fixture : public redpanda_thread_fixture {
scoped_config test_local_cfg;

// Produces to the given fixture's partition for 10 seconds.
ss::future<> produce_to_fixture(model::topic topic_name, int* incomplete) {
tests::kafka_produce_transport producer(co_await make_kafka_client());
co_await producer.start();
const int cardinality = 10;
auto now = ss::lowres_clock::now();
while (ss::lowres_clock::now() < now + 5s) {
for (int i = 0; i < cardinality; i++) {
co_await producer.produce_to_partition(
topic_name,
model::partition_id(0),
tests::kv_t::sequence(i, 1));
}
}
*incomplete -= 1;
}

ss::future<> remove_segment_permanently(
storage::disk_log_impl* log, ss::lw_shared_ptr<storage::segment> seg) {
return log->remove_segment_permanently(seg, "storage_e2e_fixture")
.then([&, log, seg]() {
auto& segs = log->segments();
auto it = std::find(segs.begin(), segs.end(), seg);
if (it == segs.end()) {
return;
}
segs.erase(it, std::next(it));
});
}
};
31 changes: 5 additions & 26 deletions src/v/storage/tests/storage_e2e_fixture_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include "kafka/server/tests/produce_consume_utils.h"
#include "model/fundamental.h"
#include "random/generators.h"
#include "redpanda/tests/fixture.h"
#include "storage/disk_log_impl.h"
#include "storage/segment.h"
#include "storage/tests/storage_e2e_fixture.h"
#include "test_utils/fixture.h"
#include "test_utils/scoped_config.h"

#include <seastar/core/io_priority_class.hh>
#include <seastar/core/lowres_clock.hh>

#include <boost/test/tools/old/interface.hpp>
Expand All @@ -23,29 +25,6 @@

using namespace std::chrono_literals;

struct storage_e2e_fixture : public redpanda_thread_fixture {
scoped_config test_local_cfg;
};

namespace {

// Produces to the given fixture's partition for 10 seconds.
ss::future<> produce_to_fixture(
storage_e2e_fixture* fix, model::topic topic_name, int* incomplete) {
tests::kafka_produce_transport producer(co_await fix->make_kafka_client());
co_await producer.start();
const int cardinality = 10;
auto now = ss::lowres_clock::now();
while (ss::lowres_clock::now() < now + 5s) {
for (int i = 0; i < cardinality; i++) {
co_await producer.produce_to_partition(
topic_name, model::partition_id(0), tests::kv_t::sequence(i, 1));
}
}
*incomplete -= 1;
}
} // namespace

FIXTURE_TEST(test_compaction_segment_ms, storage_e2e_fixture) {
test_local_cfg.get("log_segment_ms_min")
.set_value(std::chrono::duration_cast<std::chrono::milliseconds>(1ms));
Expand All @@ -69,7 +48,7 @@ FIXTURE_TEST(test_compaction_segment_ms, storage_e2e_fixture) {
produces.reserve(5);
int incomplete = 5;
for (int i = 0; i < 5; i++) {
auto fut = produce_to_fixture(this, topic_name, &incomplete);
auto fut = produce_to_fixture(topic_name, &incomplete);
produces.emplace_back(std::move(fut));
}
auto partition = app.partition_manager.local().get(ntp);
Expand Down

0 comments on commit c0d76d1

Please sign in to comment.