Search in sources :

Example 1 with UnsafeBytesOutput

use of com.baidu.hugegraph.computer.core.io.UnsafeBytesOutput in project hugegraph-computer by hugegraph.

the class ValueFileTest method testCompare.

@Test
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);
    }
}
Also used : ValueFileInput(com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput) UnsafeBytesOutput(com.baidu.hugegraph.computer.core.io.UnsafeBytesOutput) File(java.io.File) ValueFileOutput(com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileOutput) UnsafeBytesInput(com.baidu.hugegraph.computer.core.io.UnsafeBytesInput) Test(org.junit.Test)

Aggregations

UnsafeBytesInput (com.baidu.hugegraph.computer.core.io.UnsafeBytesInput)1 UnsafeBytesOutput (com.baidu.hugegraph.computer.core.io.UnsafeBytesOutput)1 ValueFileInput (com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput)1 ValueFileOutput (com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileOutput)1 File (java.io.File)1 Test (org.junit.Test)1