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);
}
}
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);
}
}
Aggregations