carp84 commented on a change in pull request #9501: [FLINK-12697] [State 
Backends] Support on-disk state storage for spill-able heap backend
URL: https://github.com/apache/flink/pull/9501#discussion_r325743874
 
 

 ##########
 File path: 
flink-core/src/test/java/org/apache/flink/core/memory/ByteBufferUtilsTest.java
 ##########
 @@ -0,0 +1,195 @@
+/*
+ *
+ *  * 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.core.memory;
+
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.lessThan;
+
+/**
+ * Tests for {@link ByteBufferUtils}.
+ */
+public class ByteBufferUtilsTest extends TestLogger {
+
+       @Test
+       public void testDirectBBWriteAndRead() {
+               testWithDifferentOffset(true);
+       }
+
+       @Test
+       public void testHeapBBWriteAndRead() {
+               testWithDifferentOffset(false);
+       }
+
+       @Test
+       public void testCompareDirectBBToArray() {
+               testCompareTo(true, false, false);
+       }
+
+       @Test
+       public void testCompareDirectBBToDirectBB() {
+               testCompareTo(true, true, true);
+       }
+
+       @Test
+       public void testCompareDirectBBToHeapBB() {
+               testCompareTo(true, true, false);
+       }
+
+       @Test
+       public void testCompareHeapBBToArray() {
+               testCompareTo(false, false, false);
+       }
+
+       @Test
+       public void testCompareHeapBBToDirectBB() {
+               testCompareTo(false, true, true);
+       }
+
+       @Test
+       public void testCompareHeapBBToHeapBB() {
+               testCompareTo(false, true, false);
+       }
+
+       private void testCompareTo(boolean isLeftBBDirect, boolean 
isRightBuffer, boolean isRightDirect) {
+               testEquals(isLeftBBDirect, isRightBuffer, isRightDirect);
+               testLessThan(isLeftBBDirect, isRightBuffer, isRightDirect);
+               testGreaterThan(isLeftBBDirect, isRightBuffer, isRightDirect);
+       }
+
+       private void testEquals(boolean isLeftBBDirect, boolean isRightBuffer, 
boolean isRightDirect) {
+               byte[] leftBufferBytes = new byte[]{'a', 'b', 'c', 'd', 'e'};
+               byte[] rightBufferBytes = new byte[]{'b', 'c', 'd', 'e', 'f'};
+               ByteBuffer left = isLeftBBDirect
+                       ? 
ByteBuffer.allocateDirect(leftBufferBytes.length).put(leftBufferBytes)
+                       : ByteBuffer.wrap(leftBufferBytes);
+               ByteBuffer right = null;
+               if (isRightBuffer) {
+                       right = isRightDirect
+                               ? 
ByteBuffer.allocateDirect(rightBufferBytes.length).put(rightBufferBytes)
+                               : ByteBuffer.wrap(rightBufferBytes);
+               }
+               if (right != null) {
+                       Assert.assertThat(
+                               ByteBufferUtils.compareTo(left, 1, 4, right, 0, 
4),
 
 Review comment:
   Just to verify the `compareTo` method could correctly work with none zero 
offsets.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to