From ca2b00277e1eb3bfd74f213ed425f04eabf891de Mon Sep 17 00:00:00 2001 From: fyrz Date: Sun, 25 Jan 2015 00:24:44 +0100 Subject: [PATCH] [RocksJava] Cleanup portal.h & tests Summary: Simple Java Native Objects usually are represented using the same functionality but within different classes. With this commit a template class was introduced to remove the redundant impelementation to a certain extent. [RocksJava] Removed todo comment in portal.h As jclass instances shall not be cached, both todos are obsolete and can be removed. [RocksJava] Add missing test to Makefile [RocksJava] Added tests for uncovered methods Test Plan: make rocksdbjava make jtest mvn -f rocksjni.pom package Reviewers: adamretter, yhchiang, ankgup87 Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D32145 --- java/org/rocksdb/test/ColumnFamilyTest.java | 10 +++++++++- java/org/rocksdb/test/DirectSliceTest.java | 4 +++- java/org/rocksdb/test/FlushTest.java | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/java/org/rocksdb/test/ColumnFamilyTest.java b/java/org/rocksdb/test/ColumnFamilyTest.java index fb95e8010..bf568b5e8 100644 --- a/java/org/rocksdb/test/ColumnFamilyTest.java +++ b/java/org/rocksdb/test/ColumnFamilyTest.java @@ -259,7 +259,8 @@ public class ColumnFamilyTest { new ArrayList<>(); List columnFamilyHandleList = new ArrayList<>(); - cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); + cfNames.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, + new ColumnFamilyOptions().setMergeOperator(new StringAppendOperator()))); cfNames.add(new ColumnFamilyDescriptor("new_cf".getBytes())); db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath(), @@ -268,6 +269,10 @@ public class ColumnFamilyTest { WriteBatch writeBatch = new WriteBatch(); WriteOptions writeOpt = new WriteOptions(); writeBatch.put("key".getBytes(), "value".getBytes()); + writeBatch.put(db.getDefaultColumnFamily(), + "mergeKey".getBytes(), "merge".getBytes()); + writeBatch.merge(db.getDefaultColumnFamily(), "mergeKey".getBytes(), + "merge".getBytes()); writeBatch.put(columnFamilyHandleList.get(1), "newcfkey".getBytes(), "value".getBytes()); writeBatch.put(columnFamilyHandleList.get(1), "newcfkey2".getBytes(), @@ -283,6 +288,9 @@ public class ColumnFamilyTest { assertThat(new String(db.get(columnFamilyHandleList.get(1), "newcfkey2".getBytes()))).isEqualTo("value2"); assertThat(new String(db.get("key".getBytes()))).isEqualTo("value"); + // check if key is merged + assertThat(new String(db.get(db.getDefaultColumnFamily(), + "mergeKey".getBytes()))).isEqualTo("merge,merge"); } finally { if (db != null) { db.close(); diff --git a/java/org/rocksdb/test/DirectSliceTest.java b/java/org/rocksdb/test/DirectSliceTest.java index a50664867..20a44a904 100644 --- a/java/org/rocksdb/test/DirectSliceTest.java +++ b/java/org/rocksdb/test/DirectSliceTest.java @@ -48,8 +48,10 @@ public class DirectSliceTest { DirectSlice directSlice = null; try { byte[] data = "Some text".getBytes(); - ByteBuffer buffer = ByteBuffer.allocateDirect(data.length); + ByteBuffer buffer = ByteBuffer.allocateDirect(data.length + 1); buffer.put(data); + buffer.put(data.length, (byte)0); + directSlice = new DirectSlice(buffer); assertThat(directSlice.toString()).isEqualTo("Some text"); } finally { diff --git a/java/org/rocksdb/test/FlushTest.java b/java/org/rocksdb/test/FlushTest.java index 9dea7e753..3bfdb3114 100644 --- a/java/org/rocksdb/test/FlushTest.java +++ b/java/org/rocksdb/test/FlushTest.java @@ -36,6 +36,7 @@ public class FlushTest { wOpt = new WriteOptions(); flushOptions = new FlushOptions(); flushOptions.setWaitForFlush(true); + assertThat(flushOptions.waitForFlush()).isTrue(); wOpt.setDisableWAL(true); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); db.put(wOpt, "key1".getBytes(), "value1".getBytes());