Skip to content

Commit

Permalink
Merge pull request #3 from halibobor/dev
Browse files Browse the repository at this point in the history
release:1.23.2: add test for WriteBatch
  • Loading branch information
halibobo1205 committed Sep 1, 2022
2 parents 5ab1cd0 + 5023dc1 commit 764d2ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions leveldb-api/src/main/java/org/iq80/leveldb/WriteBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public interface WriteBatch
* The size of the database changes caused by this batch.
* Note: This number is tied to implementation details, and may change across
* releases. It is intended for LevelDB usage metrics.
* WriteBatch header has an 8-byte sequence number followed by a 4-byte count.
* @return size
*/
long approximateSize();
Expand Down
14 changes: 13 additions & 1 deletion leveldb/src/test/java/org/iq80/leveldb/impl/DbImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,20 @@ public void testEmptyBatch()

// write an empty batch
WriteBatch batch = db.createWriteBatch();
batch.close();
batch.put("foobar".getBytes(UTF_8), "tgz".getBytes(UTF_8));
batch.put("bob".getBytes(UTF_8), "tar".getBytes(UTF_8));
WriteBatch source = db.createWriteBatch();
source.put("foobar".getBytes(UTF_8), "tgz".getBytes(UTF_8));
source.put("bob".getBytes(UTF_8), "tar".getBytes(UTF_8));
batch.clear();
assertEquals(12, batch.approximateSize());
batch.append(source);
batch.append(source);
assertEquals(source.approximateSize() * 2 -12, batch.approximateSize());
batch.clear();
assertEquals(12, batch.approximateSize());
db.write(batch);
batch.close();

// close the db
db.close();
Expand Down

0 comments on commit 764d2ab

Please sign in to comment.