Search in sources :

Example 1 with HgkvFileBuilderImpl

use of com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilderImpl 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());
    });
}
Also used : HgkvFileBuilderImpl(com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilderImpl) HgkvFileBuilder(com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilder) HgkvFile(com.baidu.hugegraph.computer.core.store.file.hgkvfile.HgkvFile) File(java.io.File) Test(org.junit.Test)

Example 2 with HgkvFileBuilderImpl

use of com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilderImpl 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;
}
Also used : HgkvFileBuilderImpl(com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilderImpl) HgkvFileBuilder(com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilder) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) File(java.io.File) IOException(java.io.IOException)

Aggregations

HgkvFileBuilder (com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilder)2 HgkvFileBuilderImpl (com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvFileBuilderImpl)2 File (java.io.File)2 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)1 HgkvFile (com.baidu.hugegraph.computer.core.store.file.hgkvfile.HgkvFile)1 IOException (java.io.IOException)1 Test (org.junit.Test)1