|
|
|
@ -27,13 +27,23 @@ public class SstFileWriterTest { |
|
|
|
|
|
|
|
|
|
@Rule public TemporaryFolder parentFolder = new TemporaryFolder(); |
|
|
|
|
|
|
|
|
|
private File newSstFile(final TreeMap<String, String> keyValues) |
|
|
|
|
private File newSstFile(final TreeMap<String, String> keyValues, |
|
|
|
|
boolean useJavaBytewiseComparator) |
|
|
|
|
throws IOException, RocksDBException { |
|
|
|
|
final EnvOptions envOptions = new EnvOptions(); |
|
|
|
|
final ComparatorOptions comparatorOptions = new ComparatorOptions(); |
|
|
|
|
final BytewiseComparator comparator = new BytewiseComparator(comparatorOptions); |
|
|
|
|
final Options options = new Options().setComparator(comparator); |
|
|
|
|
final SstFileWriter sstFileWriter = new SstFileWriter(envOptions, options, comparator); |
|
|
|
|
final Options options = new Options(); |
|
|
|
|
SstFileWriter sstFileWriter = null; |
|
|
|
|
ComparatorOptions comparatorOptions = null; |
|
|
|
|
BytewiseComparator comparator = null; |
|
|
|
|
if (useJavaBytewiseComparator) { |
|
|
|
|
comparatorOptions = new ComparatorOptions(); |
|
|
|
|
comparator = new BytewiseComparator(comparatorOptions); |
|
|
|
|
options.setComparator(comparator); |
|
|
|
|
sstFileWriter = new SstFileWriter(envOptions, options, comparator); |
|
|
|
|
} else { |
|
|
|
|
sstFileWriter = new SstFileWriter(envOptions, options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final File sstFile = parentFolder.newFile(SST_FILE_NAME); |
|
|
|
|
try { |
|
|
|
|
sstFileWriter.open(sstFile.getAbsolutePath()); |
|
|
|
@ -50,18 +60,30 @@ public class SstFileWriterTest { |
|
|
|
|
sstFileWriter.close(); |
|
|
|
|
options.close(); |
|
|
|
|
envOptions.close(); |
|
|
|
|
comparatorOptions.close(); |
|
|
|
|
comparator.close(); |
|
|
|
|
if (comparatorOptions != null) { |
|
|
|
|
comparatorOptions.close(); |
|
|
|
|
} |
|
|
|
|
if (comparator != null) { |
|
|
|
|
comparator.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return sstFile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void generateSstFile() throws RocksDBException, IOException { |
|
|
|
|
public void generateSstFileWithJavaComparator() throws RocksDBException, IOException { |
|
|
|
|
final TreeMap<String, String> keyValues = new TreeMap<>(); |
|
|
|
|
keyValues.put("key1", "value1"); |
|
|
|
|
keyValues.put("key2", "value2"); |
|
|
|
|
newSstFile(keyValues, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void generateSstFileWithNativeComparator() throws RocksDBException, IOException { |
|
|
|
|
final TreeMap<String, String> keyValues = new TreeMap<>(); |
|
|
|
|
keyValues.put("key1", "value1"); |
|
|
|
|
keyValues.put("key2", "value2"); |
|
|
|
|
newSstFile(keyValues); |
|
|
|
|
newSstFile(keyValues, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -69,7 +91,7 @@ public class SstFileWriterTest { |
|
|
|
|
final TreeMap<String, String> keyValues = new TreeMap<>(); |
|
|
|
|
keyValues.put("key1", "value1"); |
|
|
|
|
keyValues.put("key2", "value2"); |
|
|
|
|
final File sstFile = newSstFile(keyValues); |
|
|
|
|
final File sstFile = newSstFile(keyValues, false); |
|
|
|
|
final File dbFolder = parentFolder.newFolder(DB_DIRECTORY_NAME); |
|
|
|
|
final Options options = new Options().setCreateIfMissing(true); |
|
|
|
|
final RocksDB db = RocksDB.open(options, dbFolder.getAbsolutePath()); |
|
|
|
|