Skip to content

Commit

Permalink
Merge pull request #24715 from dotnwat/storage-tests
Browse files Browse the repository at this point in the history
storage: build tests with bazel
  • Loading branch information
dotnwat authored Jan 8, 2025
2 parents f6f74c2 + 4bee0f2 commit c12269f
Show file tree
Hide file tree
Showing 8 changed files with 546 additions and 11 deletions.
61 changes: 61 additions & 0 deletions src/v/storage/mvlog/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
load("//bazel:build.bzl", "redpanda_cc_library")

package(
default_visibility = [
"//src/v/storage/mvlog/tests:__pkg__",
],
)

redpanda_cc_library(
name = "mvlog",
srcs = [
"batch_collecting_stream_utils.cc",
"batch_collector.cc",
"entry.cc",
"entry_stream.cc",
"entry_stream_utils.cc",
"file.cc",
"logger.cc",
"readable_segment.cc",
"segment_appender.cc",
"segment_reader.cc",
"skipping_data_source.cc",
"versioned_log.cc",
],
hdrs = [
"batch_collecting_stream_utils.h",
"batch_collector.h",
"entry.h",
"entry_stream.h",
"entry_stream_utils.h",
"errc.h",
"file.h",
"file_gap.h",
"logger.h",
"readable_segment.h",
"reader_outcome.h",
"segment_appender.h",
"segment_identifier.h",
"segment_reader.h",
"skipping_data_source.h",
"versioned_log.h",
],
include_prefix = "storage/mvlog",
deps = [
"//src/v/base",
"//src/v/bytes:iobuf",
"//src/v/bytes:iostream",
"//src/v/container:fragmented_vector",
"//src/v/container:interval_set",
"//src/v/hashing:crc32c",
"//src/v/io",
"//src/v/model",
"//src/v/serde",
"//src/v/storage",
"//src/v/storage:record_batch_utils",
"//src/v/utils:mutex",
"//src/v/utils:named_type",
"@fmt",
"@seastar",
],
)
161 changes: 161 additions & 0 deletions src/v/storage/mvlog/tests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
load("//bazel:test.bzl", "redpanda_cc_gtest")

redpanda_cc_gtest(
name = "active_segment_test",
timeout = "short",
srcs = [
"active_segment_test.cc",
],
deps = [
"//src/v/base",
"//src/v/model/tests:random",
"//src/v/random:generators",
"//src/v/storage",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "batch_collecting_stream_utils_test",
timeout = "short",
srcs = [
"batch_collecting_stream_utils_test.cc",
],
deps = [
"//src/v/bytes:iostream",
"//src/v/hashing:crc32",
"//src/v/model",
"//src/v/model/tests:random",
"//src/v/storage",
"//src/v/storage:record_batch_utils",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "batch_collector_test",
timeout = "short",
srcs = [
"batch_collector_test.cc",
],
deps = [
"//src/v/model",
"//src/v/storage",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "entry_stream_utils_test",
timeout = "short",
srcs = [
"entry_stream_utils_test.cc",
],
deps = [
"//src/v/bytes:iostream",
"//src/v/bytes:random",
"//src/v/random:generators",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "file_test",
timeout = "short",
srcs = [
"file_test.cc",
],
deps = [
"//src/v/bytes:random",
"//src/v/container:fragmented_vector",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "segment_appender_test",
timeout = "short",
srcs = [
"segment_appender_test.cc",
],
deps = [
"//src/v/model",
"//src/v/model/tests:random",
"//src/v/storage:record_batch_utils",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "segment_io_test",
timeout = "short",
srcs = [
"segment_io_test.cc",
],
deps = [
"//src/v/model/tests:random",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "segment_reader_test",
timeout = "short",
srcs = [
"segment_reader_test.cc",
],
deps = [
"//src/v/random:generators",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_gtest(
name = "skipping_data_source_test",
timeout = "short",
srcs = [
"skipping_data_source_test.cc",
],
deps = [
"//src/v/base",
"//src/v/bytes:iostream",
"//src/v/bytes:random",
"//src/v/random:generators",
"//src/v/storage/mvlog",
"//src/v/test_utils:gtest",
"@googletest//:gtest",
"@seastar",
"@seastar//:testing",
],
)
2 changes: 1 addition & 1 deletion src/v/storage/mvlog/tests/entry_stream_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TEST(EntryStream, TestShortHeader) {
entry_header hdr{0, 0, entry_type::record_batch};
hdr_buf.append(entry_header_to_iobuf(hdr));
ASSERT_GT(hdr_buf.size_bytes(), 1);
for (int i = 1; i < hdr_buf.size_bytes(); i++) {
for (size_t i = 1; i < hdr_buf.size_bytes(); i++) {
auto copy_buf = hdr_buf.copy();
copy_buf.trim_back(i);
auto short_stream = make_iobuf_input_stream(std::move(copy_buf));
Expand Down
12 changes: 6 additions & 6 deletions src/v/storage/mvlog/tests/segment_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TEST_F(SegmentReaderTest, TestBasicReads) {
buf.append(data.data(), data.size());
paging_file_->append(std::move(buf)).get();
readable_segment readable_seg(paging_file_.get());
for (int i = 0; i < data.size(); i++) {
for (size_t i = 0; i < data.size(); i++) {
auto reader = readable_seg.make_reader();
auto stream = reader->make_stream(i);
auto buf = stream.read_up_to(data.size()).get();
Expand Down Expand Up @@ -194,7 +194,7 @@ TEST_F(SegmentReaderTest, TestReadVersionBeforeGaps) {
expectations_map_t expected_per_version;
auto reader = readable_seg.make_reader();
readable_seg.add_gap(file_gap(1, 3));
for (int i = 0; i < data.size(); i++) {
for (size_t i = 0; i < data.size(); i++) {
// Reading below the gapped version should ignore the gap entirely.
ASSERT_NO_FATAL_FAILURE(
validate_reader_exactly(*reader, i, data.substr(i)));
Expand Down Expand Up @@ -285,7 +285,7 @@ TEST_F(SegmentReaderTest, TestReadsWithRandomGaps) {
}
// Rebuild the expected string, removing all gaps.
ss::sstring expected;
for (int d = 0; d < data.size(); d++) {
for (size_t d = 0; d < data.size(); d++) {
if (removed_pos.contains(d)) {
continue;
}
Expand Down Expand Up @@ -317,12 +317,12 @@ TEST_F(SegmentReaderTest, TestRandomReadsWithGaps) {
for (int i = 0; i < 10; i++) {
auto gap_start = random_generators::get_int(size);
auto gap_len = random_generators::get_int(size_t{1}, size);
for (int l = 0; l < gap_len; l++) {
for (size_t l = 0; l < gap_len; l++) {
removed_pos.emplace(gap_start + l);
}
// Rebuild the expected string, removing all gaps.
ss::sstring expected;
for (int d = 0; d < data.size(); d++) {
for (size_t d = 0; d < data.size(); d++) {
if (removed_pos.contains(d)) {
continue;
}
Expand All @@ -333,7 +333,7 @@ TEST_F(SegmentReaderTest, TestRandomReadsWithGaps) {
expected_per_version.emplace_back(readable_seg.make_reader(), expected);
for (const auto& [reader, full_expected_str] : expected_per_version) {
// Read starting at every position, and ensure nothing funny.
for (int i = 0; i < size; i++) {
for (size_t i = 0; i < size; i++) {
auto stream = reader->make_stream(i);
auto buf = stream.read_exactly(size).get();

Expand Down
Loading

0 comments on commit c12269f

Please sign in to comment.