Search in sources :

Example 1 with UnsafeBytesInput

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

the class ValueFileTest method testDuplicate.

@Test
public void testDuplicate() throws IOException {
    File dir = createTempDir();
    final int bufferSize = 15;
    try {
        try (ValueFileOutput output = new ValueFileOutput(CONFIG, dir, bufferSize)) {
            for (int i = 0; i < 50; i++) {
                output.writeInt(i);
            }
        }
        try (ValueFileInput input = new ValueFileInput(CONFIG, dir, bufferSize)) {
            input.seek(20 * Integer.BYTES);
            Assert.assertEquals(20, input.readInt());
            UnsafeBytesInput other = input.duplicate();
            Assert.assertEquals(21, other.readInt());
            Assert.assertEquals(21, input.readInt());
        }
    } finally {
        FileUtils.deleteQuietly(dir);
    }
}
Also used : ValueFileInput(com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput) 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)

Example 2 with UnsafeBytesInput

use of com.baidu.hugegraph.computer.core.io.UnsafeBytesInput 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)2 ValueFileInput (com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput)2 ValueFileOutput (com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileOutput)2 File (java.io.File)2 Test (org.junit.Test)2 UnsafeBytesOutput (com.baidu.hugegraph.computer.core.io.UnsafeBytesOutput)1