This is an automated email from the ASF dual-hosted git repository. lzljs3620320 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 49e476251ed8aeea331f171e55bdb8a8f27214d8 Author: JingsongLi <lzljs3620...@aliyun.com> AuthorDate: Thu Jan 13 17:44:36 2022 +0800 [FLINK-25630] Add LevelsTest --- .../table/store/file/mergetree/LevelsTest.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/mergetree/LevelsTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/mergetree/LevelsTest.java new file mode 100644 index 0000000..3f6a89b --- /dev/null +++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/mergetree/LevelsTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.flink.table.store.file.mergetree; + +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.store.file.mergetree.sst.SstFileMeta; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; + +import static org.apache.flink.table.store.file.mergetree.compact.CompactManagerTest.row; +import static org.assertj.core.api.Assertions.assertThat; + +/** Test for {@link Levels}. */ +public class LevelsTest { + + private final Comparator<RowData> comparator = Comparator.comparingInt(o -> o.getInt(0)); + + @Test + public void testNonEmptyHighestLevelNo() { + Levels levels = new Levels(comparator, Collections.emptyList(), 3); + assertThat(levels.nonEmptyHighestLevel()).isEqualTo(-1); + } + + @Test + public void testNonEmptyHighestLevel0() { + + Levels levels = new Levels(comparator, Arrays.asList(newFile(0), newFile(0)), 3); + assertThat(levels.nonEmptyHighestLevel()).isEqualTo(0); + } + + @Test + public void testNonEmptyHighestLevel1() { + Levels levels = new Levels(comparator, Arrays.asList(newFile(0), newFile(1)), 3); + assertThat(levels.nonEmptyHighestLevel()).isEqualTo(1); + } + + @Test + public void testNonEmptyHighestLevel2() { + Levels levels = + new Levels(comparator, Arrays.asList(newFile(0), newFile(1), newFile(2)), 3); + assertThat(levels.nonEmptyHighestLevel()).isEqualTo(2); + } + + public static SstFileMeta newFile(int level) { + return new SstFileMeta("", 0, 1, row(0), row(0), null, 0, 1, level); + } +}