Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segment test framework #5150

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dbms/src/Storages/DeltaMerge/tests/DMTestEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ class DMTestEnv
DataTypePtr pk_type = EXTRA_HANDLE_COLUMN_INT_TYPE,
bool is_common_handle = false,
size_t rowkey_column_size = 1,
bool with_internal_columns = true)
bool with_internal_columns = true,
bool is_deleted = false)
{
Block block;
const size_t num_rows = (end - beg);
Expand Down Expand Up @@ -324,7 +325,7 @@ class DMTestEnv
VERSION_COLUMN_ID));
// tag_col
block.insert(DB::tests::createColumn<UInt8>(
std::vector<UInt64>(num_rows, 0),
std::vector<UInt64>(num_rows, is_deleted),
TAG_COLUMN_NAME,
TAG_COLUMN_ID));
}
Expand Down
67 changes: 67 additions & 0 deletions dbms/src/Storages/DeltaMerge/tests/gtest_segment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2022 PingCAP, Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <Common/CurrentMetrics.h>
#include <DataStreams/OneBlockInputStream.h>
#include <Storages/DeltaMerge/DeltaMergeStore.h>
#include <Storages/DeltaMerge/tests/gtest_segment_test_basic.h>
#include <TestUtils/TiFlashTestBasic.h>


namespace DB
{
namespace DM
{
namespace tests
{
class SegmentOperationTest : public SegmentTestBasic
{
protected:
static void SetUpTestCase() {}
};

TEST_F(SegmentOperationTest, TestSegment)
try
{
SegmentTestOptions options;
reloadWithOptions(options);
writeSegment(DELTA_MERGE_FIRST_SEGMENT_ID, 100);
flushSegmentCache(DELTA_MERGE_FIRST_SEGMENT_ID);
mergeSegmentDelta(DELTA_MERGE_FIRST_SEGMENT_ID);
auto segment_id = splitSegment(DELTA_MERGE_FIRST_SEGMENT_ID);
ASSERT_TRUE(segment_id.has_value());

size_t origin_rows = getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID);

writeSegment(*segment_id);
flushSegmentCache(*segment_id);
deleteRangeSegment(*segment_id);
writeSegmentWithDeletedPack(*segment_id);
mergeSegment(DELTA_MERGE_FIRST_SEGMENT_ID, *segment_id);

EXPECT_EQ(getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID), origin_rows);
}
CATCH

TEST_F(SegmentOperationTest, TestSegmentRandom)
try
{
SegmentTestOptions options;
options.is_common_handle = true;
reloadWithOptions(options);
randomSegmentTest(100);
}
CATCH
} // namespace tests
} // namespace DM
} // namespace DB
Loading