Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class TestRDBTableStore {
private DBOptions options = null;
private static byte[][] bytesOf;

@TempDir
private File tempDir;

@BeforeAll
public static void initConstants() {
bytesOf = new byte[4][];
Expand All @@ -76,7 +79,7 @@ private static boolean consume(Table.KeyValue keyValue) {
}

@BeforeEach
public void setUp(@TempDir File tempDir) throws Exception {
public void setUp() throws Exception {
options = new DBOptions();
options.setCreateIfMissing(true);
options.setCreateMissingColumnFamilies(true);
Expand Down Expand Up @@ -234,27 +237,14 @@ public void forEachAndIterator() throws Exception {
}

@Test
public void testIsExist(@TempDir File rdbLocation) throws Exception {
DBOptions rocksDBOptions = new DBOptions();
rocksDBOptions.setCreateIfMissing(true);
rocksDBOptions.setCreateMissingColumnFamilies(true);

String tableName = StringUtils.bytes2String(RocksDB.DEFAULT_COLUMN_FAMILY);

Set<TableConfig> configSet = new HashSet<>();
TableConfig newConfig = new TableConfig(tableName,
new ColumnFamilyOptions());
configSet.add(newConfig);

rdbStore.close(); // TODO: HDDS-6773
RDBStore dbStore = new RDBStore(rdbLocation, rocksDBOptions, configSet);

public void testIsExist() throws Exception {
byte[] key = RandomStringUtils.random(10, true, false)
.getBytes(StandardCharsets.UTF_8);
byte[] value = RandomStringUtils.random(10, true, false)
.getBytes(StandardCharsets.UTF_8);

try (Table<byte[], byte[]> testTable = dbStore.getTable(tableName)) {
final String tableName = families.get(0);
try (Table<byte[], byte[]> testTable = rdbStore.getTable(tableName)) {
testTable.put(key, value);

// Test if isExist returns true for a key that definitely exists.
Expand All @@ -269,50 +259,32 @@ public void testIsExist(@TempDir File rdbLocation) throws Exception {
// Test if isExist returns false for a key that is definitely not present.
Assertions.assertFalse(testTable.isExist(invalidKey));

RDBMetrics rdbMetrics = dbStore.getMetrics();
RDBMetrics rdbMetrics = rdbStore.getMetrics();
Assertions.assertEquals(3, rdbMetrics.getNumDBKeyMayExistChecks());
Assertions.assertEquals(0, rdbMetrics.getNumDBKeyMayExistMisses());

// Reinsert key for further testing.
testTable.put(key, value);
}

dbStore.close();
rocksDBOptions = new DBOptions();
rocksDBOptions.setCreateIfMissing(true);
rocksDBOptions.setCreateMissingColumnFamilies(true);
dbStore = new RDBStore(rdbLocation, rocksDBOptions, configSet);
try (Table<byte[], byte[]> testTable = dbStore.getTable(tableName)) {
rdbStore.close();
setUp();
try (Table<byte[], byte[]> testTable = rdbStore.getTable(tableName)) {
// Verify isExist works with key not in block cache.
Assertions.assertTrue(testTable.isExist(key));
} finally {
dbStore.close();
}
}


@Test
public void testGetIfExist(@TempDir File rdbLocation) throws Exception {
DBOptions rocksDBOptions = new DBOptions();
rocksDBOptions.setCreateIfMissing(true);
rocksDBOptions.setCreateMissingColumnFamilies(true);

String tableName = StringUtils.bytes2String(RocksDB.DEFAULT_COLUMN_FAMILY);

Set<TableConfig> configSet = new HashSet<>();
TableConfig newConfig = new TableConfig(tableName,
new ColumnFamilyOptions());
configSet.add(newConfig);

rdbStore.close(); // TODO: HDDS-6773
RDBStore dbStore = new RDBStore(rdbLocation, rocksDBOptions, configSet);

public void testGetIfExist() throws Exception {
byte[] key = RandomStringUtils.random(10, true, false)
.getBytes(StandardCharsets.UTF_8);
byte[] value = RandomStringUtils.random(10, true, false)
.getBytes(StandardCharsets.UTF_8);

try (Table<byte[], byte[]> testTable = dbStore.getTable(tableName)) {
final String tableName = families.get(0);
try (Table<byte[], byte[]> testTable = rdbStore.getTable(tableName)) {
testTable.put(key, value);

// Test if isExist returns value for a key that definitely exists.
Expand All @@ -327,7 +299,7 @@ public void testGetIfExist(@TempDir File rdbLocation) throws Exception {
// Test if isExist returns null for a key that is definitely not present.
Assertions.assertNull(testTable.getIfExist(invalidKey));

RDBMetrics rdbMetrics = dbStore.getMetrics();
RDBMetrics rdbMetrics = rdbStore.getMetrics();
Assertions.assertEquals(3, rdbMetrics.getNumDBKeyGetIfExistChecks());

Assertions.assertEquals(0, rdbMetrics.getNumDBKeyGetIfExistMisses());
Expand All @@ -338,16 +310,11 @@ public void testGetIfExist(@TempDir File rdbLocation) throws Exception {
testTable.put(key, value);
}

dbStore.close();
rocksDBOptions = new DBOptions();
rocksDBOptions.setCreateIfMissing(true);
rocksDBOptions.setCreateMissingColumnFamilies(true);
dbStore = new RDBStore(rdbLocation, rocksDBOptions, configSet);
try (Table<byte[], byte[]> testTable = dbStore.getTable(tableName)) {
rdbStore.close();
setUp();
try (Table<byte[], byte[]> testTable = rdbStore.getTable(tableName)) {
// Verify getIfExists works with key not in block cache.
Assertions.assertNotNull(testTable.getIfExist(key));
} finally {
dbStore.close();
}
}

Expand Down