|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#include <brpc/channel.h> |
| 19 | +#include <brpc/server.h> |
| 20 | + |
| 21 | +#include "gtest/gtest_pred_impl.h" |
| 22 | +#include "io/fs/stream_sink_file_writer.h" |
| 23 | +#include "olap/olap_common.h" |
| 24 | +#include "olap/rowset/segment_v2/inverted_index_file_writer.h" |
| 25 | +#include "vec/sink/load_stream_stub.h" |
| 26 | + |
| 27 | +namespace doris { |
| 28 | + |
| 29 | +constexpr int64_t LOAD_ID_LO = 1; |
| 30 | +constexpr int64_t LOAD_ID_HI = 2; |
| 31 | +constexpr int64_t NUM_STREAM = 3; |
| 32 | +constexpr static std::string_view tmp_dir = "./ut_dir/tmp"; |
| 33 | +class EmptyIndexFileTest : public testing::Test { |
| 34 | + class MockStreamStub : public LoadStreamStub { |
| 35 | + public: |
| 36 | + MockStreamStub(PUniqueId load_id, int64_t src_id) |
| 37 | + : LoadStreamStub(load_id, src_id, std::make_shared<IndexToTabletSchema>(), |
| 38 | + std::make_shared<IndexToEnableMoW>()) {}; |
| 39 | + |
| 40 | + virtual ~MockStreamStub() = default; |
| 41 | + |
| 42 | + // APPEND_DATA |
| 43 | + virtual Status append_data(int64_t partition_id, int64_t index_id, int64_t tablet_id, |
| 44 | + int64_t segment_id, uint64_t offset, std::span<const Slice> data, |
| 45 | + bool segment_eos = false, |
| 46 | + FileType file_type = FileType::SEGMENT_FILE) override { |
| 47 | + EXPECT_TRUE(segment_eos); |
| 48 | + return Status::OK(); |
| 49 | + } |
| 50 | + }; |
| 51 | + |
| 52 | +public: |
| 53 | + EmptyIndexFileTest() = default; |
| 54 | + ~EmptyIndexFileTest() = default; |
| 55 | + |
| 56 | +protected: |
| 57 | + virtual void SetUp() { |
| 58 | + _load_id.set_hi(LOAD_ID_HI); |
| 59 | + _load_id.set_lo(LOAD_ID_LO); |
| 60 | + for (int src_id = 0; src_id < NUM_STREAM; src_id++) { |
| 61 | + _streams.emplace_back(new MockStreamStub(_load_id, src_id)); |
| 62 | + } |
| 63 | + EXPECT_TRUE(io::global_local_filesystem()->delete_directory(tmp_dir).ok()); |
| 64 | + EXPECT_TRUE(io::global_local_filesystem()->create_directory(tmp_dir).ok()); |
| 65 | + std::vector<StorePath> paths; |
| 66 | + paths.emplace_back(std::string(tmp_dir), 1024000000); |
| 67 | + auto tmp_file_dirs = std::make_unique<segment_v2::TmpFileDirs>(paths); |
| 68 | + EXPECT_TRUE(tmp_file_dirs->init().ok()); |
| 69 | + ExecEnv::GetInstance()->set_tmp_file_dir(std::move(tmp_file_dirs)); |
| 70 | + } |
| 71 | + |
| 72 | + virtual void TearDown() { |
| 73 | + EXPECT_TRUE(io::global_local_filesystem()->delete_directory(tmp_dir).ok()); |
| 74 | + } |
| 75 | + |
| 76 | + PUniqueId _load_id; |
| 77 | + std::vector<std::shared_ptr<LoadStreamStub>> _streams; |
| 78 | +}; |
| 79 | + |
| 80 | +TEST_F(EmptyIndexFileTest, test_empty_index_file) { |
| 81 | + io::FileWriterPtr file_writer = std::make_unique<io::StreamSinkFileWriter>(_streams); |
| 82 | + auto fs = io::global_local_filesystem(); |
| 83 | + std::string index_path = "/tmp/empty_index_file_test"; |
| 84 | + std::string rowset_id = "1234567890"; |
| 85 | + int64_t seg_id = 1234567890; |
| 86 | + auto index_file_writer = std::make_unique<segment_v2::InvertedIndexFileWriter>( |
| 87 | + fs, index_path, rowset_id, seg_id, InvertedIndexStorageFormatPB::V2, |
| 88 | + std::move(file_writer)); |
| 89 | + EXPECT_TRUE(index_file_writer->close().ok()); |
| 90 | +} |
| 91 | + |
| 92 | +} // namespace doris |
0 commit comments