umeshdangat commented on code in PR #3434: URL: https://github.com/apache/flink-cdc/pull/3434#discussion_r1874160237
########## flink-cdc-common/src/test/java/org/apache/flink/cdc/common/data/binary/BinarySegmentUtilsTest.java: ########## @@ -0,0 +1,196 @@ +/* + * 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.cdc.common.data.binary; + +import org.apache.flink.cdc.common.data.util.BinaryRecordDataDataUtil; +import org.apache.flink.core.memory.MemorySegment; +import org.apache.flink.core.memory.MemorySegmentFactory; + +import org.junit.Test; + +import static org.apache.flink.cdc.common.data.util.BinaryRecordDataDataUtil.BYTE_ARRAY_BASE_OFFSET; +import static org.assertj.core.api.Assertions.assertThat; + +/** Utilities for binary data segments which heavily uses {@link MemorySegment}. */ +public class BinarySegmentUtilsTest { + @Test + public void testCopy() { + // test copy the content of the latter Seg + MemorySegment[] segments = new MemorySegment[2]; + segments[0] = MemorySegmentFactory.wrap(new byte[] {0, 2, 5}); + segments[1] = MemorySegmentFactory.wrap(new byte[] {6, 12, 15}); + + byte[] bytes = BinarySegmentUtils.copyToBytes(segments, 4, 2); + assertThat(bytes).isEqualTo(new byte[] {12, 15}); + } + + @Test + public void testEquals() { + // test copy the content of the latter Seg + MemorySegment[] segments1 = new MemorySegment[3]; + segments1[0] = MemorySegmentFactory.wrap(new byte[] {0, 2, 5}); + segments1[1] = MemorySegmentFactory.wrap(new byte[] {6, 12, 15}); + segments1[2] = MemorySegmentFactory.wrap(new byte[] {1, 1, 1}); + + MemorySegment[] segments2 = new MemorySegment[2]; + segments2[0] = MemorySegmentFactory.wrap(new byte[] {6, 0, 2, 5}); + segments2[1] = MemorySegmentFactory.wrap(new byte[] {6, 12, 15, 18}); + + assertThat(BinarySegmentUtils.equalsMultiSegments(segments1, 0, segments2, 0, 0)).isTrue(); + assertThat(BinarySegmentUtils.equals(segments1, 0, segments2, 1, 3)).isTrue(); + assertThat(BinarySegmentUtils.equals(segments1, 0, segments2, 1, 6)).isTrue(); + assertThat(BinarySegmentUtils.equals(segments1, 0, segments2, 1, 7)).isFalse(); + } + + @Test + public void testBoundaryByteArrayEquals() { + byte[] bytes1 = new byte[5]; + bytes1[3] = 81; + byte[] bytes2 = new byte[100]; + bytes2[3] = 81; + bytes2[4] = 81; + + assertThat(BinaryRecordDataDataUtil.byteArrayEquals(bytes1, bytes2, 4)).isTrue(); + assertThat(BinaryRecordDataDataUtil.byteArrayEquals(bytes1, bytes2, 5)).isFalse(); + assertThat(BinaryRecordDataDataUtil.byteArrayEquals(bytes1, bytes2, 0)).isTrue(); + } + + // @Test + // public void testBoundaryEquals() { Review Comment: uncommented test and added relevant utility helper code -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org