Skip to content

Commit

Permalink
added test for writing DirectBuffer into BufferCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
krisskross committed Jan 25, 2015
1 parent f91bcc8 commit 94fc2bd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lmdbjni/src/test/java/org/fusesource/lmdbjni/BufferCursorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,34 @@ public void testWriteStrings() {
}
}

@Test
public void testWriteBuffers() {
ByteString stringKey = new ByteString("key");
ByteString stringValue = new ByteString("value");

try (BufferCursor cursor = db.bufferCursorWriter()) {
cursor.first();
DirectBuffer key = new DirectBuffer();
key.putString(0, stringKey);
// remember NULL byte
cursor.keyWrite(key, stringKey.size() + 1);
DirectBuffer value = new DirectBuffer();
value.putString(0, stringValue);
// remember NULL byte
cursor.valWrite(value, stringValue.size() + 1);
cursor.put();
debug(cursor);
}

try (BufferCursor cursor = db.bufferCursorWriter()) {
cursor.last();
ByteString string = cursor.keyUtf8(0);
assertThat(string.getString(), is("key"));
string = cursor.valUtf8(0);
assertThat(string.getString(), is("value"));
}
}

private void debug(BufferCursor cursor) {
System.out.println("----");
cursor.first();
Expand Down

0 comments on commit 94fc2bd

Please sign in to comment.