|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.util; |
| 19 | + |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.Arrays; |
| 22 | + |
| 23 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 24 | +import org.apache.hadoop.hbase.testclassification.SmallTests; |
| 25 | +import org.junit.ClassRule; |
| 26 | +import org.junit.Test; |
| 27 | +import org.junit.experimental.categories.Category; |
| 28 | + |
| 29 | +import static org.junit.Assert.assertEquals; |
| 30 | +import static org.junit.Assert.assertArrayEquals; |
| 31 | + |
| 32 | +@Category({SmallTests.class}) |
| 33 | +public class TestByteRangeUtils { |
| 34 | + |
| 35 | + @ClassRule |
| 36 | + public static final HBaseClassTestRule CLASS_RULE = |
| 37 | + HBaseClassTestRule.forClass(TestByteRangeUtils.class); |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testNumEqualPrefixBytes() { |
| 41 | + assertEquals(0, ByteRangeUtils.numEqualPrefixBytes( |
| 42 | + new SimpleByteRange(new byte[]{1, 2, 3}), |
| 43 | + new SimpleByteRange(new byte[]{4, 5, 6}), 1)); |
| 44 | + assertEquals(2, ByteRangeUtils.numEqualPrefixBytes( |
| 45 | + new SimpleByteRange(new byte[]{1, 2, 3}), |
| 46 | + new SimpleByteRange(new byte[]{0, 1, 2}), 1)); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testCopyToNewArrays() { |
| 51 | + assertEquals(new ArrayList<>(), |
| 52 | + ByteRangeUtils.copyToNewArrays(null)); |
| 53 | + assertArrayEquals(new byte[]{1, 2, 3}, |
| 54 | + ByteRangeUtils.copyToNewArrays(new ArrayList<>(Arrays.asList( |
| 55 | + new SimpleByteRange(new byte[]{1, 2, 3}), |
| 56 | + new SimpleByteRange(new byte[]{4, 5, 6})))).get(0)); |
| 57 | + assertArrayEquals(new byte[]{4, 5, 6}, |
| 58 | + ByteRangeUtils.copyToNewArrays(new ArrayList<>(Arrays.asList( |
| 59 | + new SimpleByteRange(new byte[]{1, 2, 3}), |
| 60 | + new SimpleByteRange(new byte[]{4, 5, 6})))).get(1)); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testFromArrays() { |
| 65 | + assertEquals(new ArrayList<>(), ByteRangeUtils.fromArrays(null)); |
| 66 | + assertEquals(new ArrayList<>(Arrays.asList( |
| 67 | + new SimpleMutableByteRange(new byte[]{1, 2, 3}), |
| 68 | + new SimpleMutableByteRange(new byte[]{4, 5, 6}))), |
| 69 | + ByteRangeUtils.fromArrays(new ArrayList<>( |
| 70 | + Arrays.asList(new byte[]{1, 2, 3}, new byte[]{4, 5, 6})))); |
| 71 | + } |
| 72 | +} |
0 commit comments