use of com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilder in project hugegraph-computer by hugegraph.
the class HgkvFileTest method testExceptionCase.
@Test
public void testExceptionCase() throws IOException {
// Exception to add key/value
String filePath = StoreTestUtil.availablePathById("1");
try (HgkvFileBuilder builder = new HgkvFileBuilderImpl(CONFIG, filePath)) {
Assert.assertThrows(IllegalArgumentException.class, () -> {
builder.add(null);
}, e -> {
Assert.assertContains("Parameter entry can't be null", e.getMessage());
});
builder.finish();
Assert.assertThrows(IllegalStateException.class, () -> {
builder.add(null);
}, e -> {
Assert.assertContains("builder is finished", e.getMessage());
});
}
// Open not exists file.
File tempFile = new File(StoreTestUtil.availablePathById("2"));
Assert.assertThrows(IllegalArgumentException.class, () -> {
HgkvFileImpl.open(tempFile);
}, e -> {
Assert.assertContains("file does not exists", e.getMessage());
});
}
use of com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilder in project hugegraph-computer by hugegraph.
the class StoreTestUtil method mapToHgkvFile.
public static File mapToHgkvFile(Config config, List<Integer> map, String path) throws IOException {
File file = new File(path);
try (HgkvFileBuilder builder = new HgkvFileBuilderImpl(config, path)) {
List<KvEntry> entries = StoreTestUtil.kvEntriesFromMap(map);
for (KvEntry entry : entries) {
builder.add(entry);
}
builder.finish();
/*
* Some fields are written in a variable-length way,
* so it's not recommended to assert length value.
*/
Assert.assertEquals(19, builder.headerLength());
} catch (Exception e) {
FileUtils.deleteQuietly(file);
throw e;
}
return file;
}
Aggregations