This is an automated email from the ASF dual-hosted git repository. jinglun pushed a commit to branch HADOOP-19236 in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit a39a6113efb2c806aae3af8e9ae08adfb7b7c064 Author: lijinglun <lijing...@bytedance.com> AuthorDate: Thu Aug 15 18:11:48 2024 +0800 Integration of TOS: Add ObjectUtils UUIDUtils and Range. --- .../org/apache/hadoop/fs/tosfs/util/TestRange.java | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/hadoop-cloud-storage-project/hadoop-tos/src/test/java/org/apache/hadoop/fs/tosfs/util/TestRange.java b/hadoop-cloud-storage-project/hadoop-tos/src/test/java/org/apache/hadoop/fs/tosfs/util/TestRange.java new file mode 100644 index 00000000000..104be636494 --- /dev/null +++ b/hadoop-cloud-storage-project/hadoop-tos/src/test/java/org/apache/hadoop/fs/tosfs/util/TestRange.java @@ -0,0 +1,87 @@ +/* + * 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.hadoop.fs.tosfs.util; + +import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList; +import org.junit.Assert; +import org.junit.Test; + +public class TestRange { + + @Test + public void testInclude() { + Object[][] inputs = new Object[][]{ + new Object[]{Range.of(0, 0), 0L, false}, + new Object[]{Range.of(0, 1), 0L, true}, + new Object[]{Range.of(1, 1), 0L, false}, + new Object[]{Range.of(1, 1), 1L, true}, + new Object[]{Range.of(1, 1), 2L, false}, + new Object[]{Range.of(1, 99), 0L, false}, + new Object[]{Range.of(1, 99), 1L, true}, + new Object[]{Range.of(1, 99), 99L, true}, + new Object[]{Range.of(1, 99), 100L, false} + }; + + for (Object[] input : inputs) { + Range r = (Range) input[0]; + long pos = (long) input[1]; + boolean expected = (boolean) input[2]; + + Assert.assertEquals(expected, r.include(pos)); + } + } + + @Test + public void testOverlap() { + Object[][] inputs = new Object[][]{ + new Object[]{Range.of(0, 0), Range.of(0, 0), false}, + new Object[]{Range.of(0, 1), Range.of(0, 1), true}, + new Object[]{Range.of(0, 1), Range.of(1, 0), false}, + new Object[]{Range.of(0, 1), Range.of(1, 1), false}, + new Object[]{Range.of(0, 2), Range.of(1, 1), true}, + new Object[]{Range.of(0, 2), Range.of(0, 1), true}, + new Object[]{Range.of(0, 2), Range.of(1, 2), true}, + new Object[]{Range.of(0, 2), Range.of(2, 0), false}, + new Object[]{Range.of(0, 2), Range.of(2, 1), false}, + new Object[]{Range.of(5, 9), Range.of(0, 5), false}, + new Object[]{Range.of(5, 9), Range.of(0, 6), true} + }; + + for (Object[] input : inputs) { + Range l = (Range) input[0]; + Range r = (Range) input[1]; + boolean expect = (boolean) input[2]; + + Assert.assertEquals(expect, l.overlap(r)); + } + } + + @Test + public void testSplit() { + Assert.assertEquals(Range.split(10, 3), + ImmutableList.of(Range.of(0, 3), Range.of(3, 3), Range.of(6, 3), Range.of(9, 1))); + Assert.assertEquals(Range.split(10, 5), + ImmutableList.of(Range.of(0, 5), Range.of(5, 5))); + Assert.assertEquals(Range.split(10, 12), + ImmutableList.of(Range.of(0, 10))); + Assert.assertEquals(Range.split(2, 1), + ImmutableList.of(Range.of(0, 1), Range.of(1, 1))); + } +} + --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org