tillrohrmann 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_r319196204
 
 

 ##########
 File path: 
flink-core/src/test/java/org/apache/flink/core/memory/ByteBufferUtilsTest.java
 ##########
 @@ -0,0 +1,101 @@
+/*
+ *
+ *  * 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.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 {
+
+       @Test
+       public void testBBWriteAndRead() {
+
+               ByteBuffer bb = ByteBuffer.allocateDirect(4096);
+               doTest(bb, 0);
+               doTest(bb, 1);
+               doTest(bb, 2);
+               doTest(bb, 3);
+               doTest(bb, 4);
+               doTest(bb, 5);
+               doTest(bb, 6);
+               doTest(bb, 7);
+
+               bb = ByteBuffer.allocate(4096);
+               doTest(bb, 0);
+               doTest(bb, 1);
+               doTest(bb, 2);
+               doTest(bb, 3);
+               doTest(bb, 4);
+               doTest(bb, 5);
+               doTest(bb, 6);
+               doTest(bb, 7);
+       }
+
+       @Test
+       public void testCompareHeapBufferWithDirectBuffer() {
+               byte[] bytes = new byte[]{'a', 'b', 'c', 'd', 'e'};
+               final int len = bytes.length;
+               ByteBuffer heapBuffer = ByteBuffer.wrap(bytes);
+               ByteBuffer directBuffer = ByteBuffer.allocateDirect(len);
+               directBuffer.put(bytes);
+               int res = ByteBufferUtils.compareTo(heapBuffer, 1, len - 1, 
directBuffer, 1, len - 1);
+               Assert.assertThat(res, is(0));
+               res = ByteBufferUtils.compareTo(heapBuffer, 0, len - 1, 
directBuffer, 1, len - 1);
+               Assert.assertThat(res, lessThan(0));
+               res = ByteBufferUtils.compareTo(heapBuffer, 1, len - 1, 
directBuffer, 0, len - 1);
+               Assert.assertThat(res, greaterThan(0));
 
 Review comment:
   I would suggest to split this test case up into three test cases. Splitting 
it up would have the benefit to create an easy value for the `ByteBuffers` 
where everyone clearly sees what the outcome is. In the current state, one 
needs to think about starting offsets to reason about whether it is smaller or 
greater.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to