insert values into root node
This commit is contained in:
@@ -35,8 +35,9 @@ public class PersistentMap {
|
||||
}
|
||||
}
|
||||
|
||||
public void put(final String key, final long value) throws IOException {
|
||||
put(key.getBytes(UTF8), VariableByteEncoder.encode(value));
|
||||
public Long put(final String key, final long value) throws IOException {
|
||||
final byte[] oldValue = put(key.getBytes(UTF8), VariableByteEncoder.encode(value));
|
||||
return oldValue == null ? null : VariableByteEncoder.decodeFirstValue(oldValue);
|
||||
}
|
||||
|
||||
public long getAsLong(final String key) throws IOException {
|
||||
@@ -44,8 +45,9 @@ public class PersistentMap {
|
||||
return buffer == null ? null : VariableByteEncoder.decodeFirstValue(buffer);
|
||||
}
|
||||
|
||||
public void put(final String key, final String value) throws IOException {
|
||||
put(key.getBytes(UTF8), value.getBytes(UTF8));
|
||||
public String put(final String key, final String value) throws IOException {
|
||||
final byte[] oldValue = put(key.getBytes(UTF8), value.getBytes(UTF8));
|
||||
return oldValue == null ? null : new String(oldValue, UTF8);
|
||||
}
|
||||
|
||||
public String getAsString(final String key) throws IOException {
|
||||
|
||||
@@ -26,17 +26,21 @@ public class PersistentMapTest {
|
||||
FileUtils.delete(dataDirectory);
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
public void testSingleValue() throws Exception {
|
||||
final Path file = dataDirectory.resolve("map.db");
|
||||
|
||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
||||
final PersistentMap map = new PersistentMap(ds);
|
||||
|
||||
final String value1 = "value1";
|
||||
map.put("key1", value1);
|
||||
final String actualValue1 = map.getAsString("key1");
|
||||
final String value = "value1";
|
||||
final String key = "key1";
|
||||
|
||||
Assert.assertEquals(actualValue1, value1);
|
||||
Assert.assertNull(map.getAsString(key));
|
||||
|
||||
Assert.assertNull(map.put(key, value));
|
||||
final String actualValue = map.getAsString(key);
|
||||
|
||||
Assert.assertEquals(actualValue, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user