public void testCompare()

in computer-test/src/main/java/org/apache/hugegraph/computer/core/store/ValueFileTest.java [383:455]


    public void testCompare() throws IOException {
        File dir = createTempDir();
        final int bufferSize = 15;

        try {
            try (ValueFileOutput output = new ValueFileOutput(CONFIG, dir,
                                                              bufferSize)) {
                String data = "HugeGraph is a fast-speed and highly-scalable " +
                              "graph database";
                output.write(data.getBytes());
            }

            try (ValueFileInput input1 = new ValueFileInput(CONFIG, dir,
                                                            bufferSize);
                 ValueFileInput input2 = new ValueFileInput(CONFIG, dir,
                                                            bufferSize)) {
                int result;

                // All in buffer
                result = input1.compare(0, 3, input2, 1, 3);
                Assert.assertLt(0, result);

                result = input1.compare(0, 3, input2, 0, 5);
                Assert.assertLt(0, result);

                result = input1.compare(1, 3, input2, 1, 3);
                Assert.assertEquals(0, result);

                // The input1 in buffer, input2 not in buffer
                result = input1.compare(0, 3, input2, 21, 3);
                Assert.assertLt(0, result);

                result = input1.compare(1, 3, input2, 23, 3);
                Assert.assertGt(0, result);

                result = input1.compare(0, 3, input2, 23, 5);
                Assert.assertLt(0, result);

                result = input1.compare(3, 1, input2, 23, 1);
                Assert.assertEquals(0, result);

                // The input1 not in buffer, input2 in buffer
                input2.seek(20);
                result = input1.compare(23, 5, input2, 23, 5);
                Assert.assertEquals(0, result);

                result = input1.compare(23, 12, input2, 23, 5);
                Assert.assertGt(0, result);

                // All not in buffer
                input2.seek(0);
                result = input1.compare(23, 5, input2, 23, 5);
                Assert.assertEquals(0, result);

                result = input1.compare(23, 12, input2, 23, 5);
                Assert.assertGt(0, result);

                // Compare with different class
                UnsafeBytesOutput output = new UnsafeBytesOutput(20);
                output.writeBytes("banana");
                UnsafeBytesInput input = new UnsafeBytesInput(output.buffer());
                output.close();

                result = input1.compare(0, 2, input, 0, 4);
                Assert.assertLt(0, result);

                result = input1.compare(1, 5, input, 0, 4);
                Assert.assertGt(0, result);
            }
        } finally {
            FileUtils.deleteQuietly(dir);
        }
    }