Skip to content
Permalink
Browse files
add subKvEntry size to KvEntryWithFirstSubKv (#139)
* add subKvEntry size to KvEntryWithFirstSubKv

* bug fix and add unit test
  • Loading branch information
corgiboygsj committed Nov 4, 2021
1 parent 382130a commit 3c50af6a65137459aa38c0e5c1268df5d2e42d8a
Showing 3 changed files with 27 additions and 5 deletions.
@@ -148,12 +148,12 @@ public static KvEntryWithFirstSubKv kvEntryWithFirstSubKv(KvEntry entry) {
try {
BytesInput input = IOFactory.createBytesInput(entry.value()
.bytes());
// Skip sub-entry size
input.skip(Integer.BYTES);
// Read sub-entry size
long subKvNum = input.readFixedInt();
KvEntry firstSubKv = EntriesUtil.subKvEntryFromInput(input, true);

return new KvEntryWithFirstSubKv(entry.key(), entry.value(),
firstSubKv);
firstSubKv, subKvNum);
} catch (IOException e) {
throw new ComputerException(e.getMessage(), e);
}
@@ -24,8 +24,8 @@ public class KvEntryWithFirstSubKv extends DefaultKvEntry {
private final KvEntry firstSubKv;

public KvEntryWithFirstSubKv(Pointer key, Pointer value,
KvEntry firstSubKv) {
super(key, value);
KvEntry firstSubKv, long subKvNum) {
super(key, value, subKvNum);
this.firstSubKv = firstSubKv;
}

@@ -19,6 +19,7 @@

package com.baidu.hugegraph.computer.core.store;

import java.io.IOException;
import java.util.NoSuchElementException;

import org.junit.Test;
@@ -92,4 +93,25 @@ public void testSubKvEntriesInput() throws Exception {
Assert.assertThrows(NoSuchElementException.class, iter::next);
}
}

@Test
public void testKvEntryWithFirstSubKv() throws IOException {
BytesOutput output = IOFactory.createBytesOutput(
Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(output);
KvEntryWriter subKvWriter = entryOutput.writeEntry(BytesId.of(100));
subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
subKvWriter.writeFinish();

BytesInput input = EntriesUtil.inputFromOutput(output);

// Read entry from buffer
KvEntry entry = EntriesUtil.kvEntryFromInput(input, true, true);
entry = EntriesUtil.kvEntryWithFirstSubKv(entry);
// Assert subKvEntry size
Assert.assertEquals(4, entry.numSubEntries());
}
}

0 comments on commit 3c50af6

Please sign in to comment.