use of com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput in project hugegraph-computer by hugegraph.
the class ValueFileTest method testWriteIntWithPosition.
@Test
public void testWriteIntWithPosition() throws IOException {
File dir = createTempDir();
final int bufferSize = 20;
try {
try (ValueFileOutput output = new ValueFileOutput(CONFIG, dir, bufferSize)) {
for (int i = 0; i < 50; i++) {
// Write position in buffer
if (i == 2) {
output.writeFixedInt(4, 100);
}
output.writeInt(i);
}
output.writeFixedInt(Integer.BYTES * 10, 100);
}
try (ValueFileInput input = new ValueFileInput(CONFIG, dir, bufferSize)) {
for (int i = 0; i < 50; i++) {
if (i == 1 || i == 10) {
Assert.assertEquals(100, input.readInt());
continue;
}
Assert.assertEquals(i, input.readInt());
}
}
} finally {
FileUtils.deleteQuietly(dir);
}
}
use of com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput in project hugegraph-computer by hugegraph.
the class ValueFileTest method testSkip.
@Test
public void testSkip() throws IOException {
File dir = createTempDir();
final int bufferSize = 15;
try {
try (ValueFileOutput output = new ValueFileOutput(CONFIG, dir, bufferSize)) {
// 100, 1, 2, 200, 4, 5 ......
for (int i = 0; i < 50; i++) {
output.writeInt(i);
}
output.seek(0);
output.writeInt(100);
output.skip(8);
output.writeInt(200);
}
try (ValueFileInput input = new ValueFileInput(CONFIG, dir, bufferSize)) {
Assert.assertEquals(100, input.readInt());
input.skip(8);
Assert.assertEquals(200, input.readInt());
input.seek(20 * Integer.BYTES);
Assert.assertEquals(20, input.readInt());
input.skip(10 * Integer.BYTES);
Assert.assertEquals(31, input.readInt());
Assert.assertThrows(IllegalArgumentException.class, () -> {
input.skip(500L);
}, e -> {
Assert.assertContains("because don't have enough data", e.getMessage());
});
}
} finally {
FileUtils.deleteQuietly(dir);
}
}
use of com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput 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