-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from scalableminds/rocksdb-configfile
optionally read rocksdb configfile
- Loading branch information
Showing
7 changed files
with
125 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/test/scala/com/scalableminds/fossildb/RocksOptionsSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2011-2018 scalable minds UG (haftungsbeschränkt) & Co. KG. <http://scm.io> | ||
*/ | ||
package com.scalableminds.fossildb | ||
|
||
import java.io.File | ||
import java.nio.file.Paths | ||
|
||
import com.scalableminds.fossildb.db.StoreManager | ||
import org.rocksdb.{ColumnFamilyDescriptor, DBOptions, Env} | ||
import org.scalatest.{BeforeAndAfterEach, FlatSpec} | ||
|
||
import scala.collection.mutable | ||
import scala.collection.JavaConverters._ | ||
import scala.io.Source | ||
|
||
class RocksOptionsSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers { | ||
|
||
val testTempDir = "testData2" | ||
val dataDir = Paths.get(testTempDir, "data") | ||
val backupDir = Paths.get(testTempDir, "backup") | ||
|
||
val collectionA = "collectionA" | ||
val collectionB = "collectionB" | ||
|
||
val columnFamilies = List(collectionA, collectionB) | ||
|
||
|
||
|
||
override def beforeEach = { | ||
deleteRecursively(new File(testTempDir)) | ||
new File(testTempDir).mkdir() | ||
} | ||
|
||
override def afterEach = { | ||
deleteRecursively(new File(testTempDir)) | ||
} | ||
|
||
|
||
|
||
"Initializing the StoreManager" should "load and use a specified config file" in { | ||
val file = new File(testTempDir, "testConfig.ini") | ||
writeToFile(file, "[Version]\n rocksdb_version=5.11.3\n options_file_version=1.1\n\n[DBOptions]\n stats_dump_period_sec=700\n\n[CFOptions \"default\"]\n\n") | ||
|
||
val storeManager = new StoreManager(dataDir, backupDir, columnFamilies, Some(file.getPath)) | ||
|
||
var options = new DBOptions() | ||
.setStatsDumpPeriodSec(100) | ||
var cfListRef: mutable.Buffer[ColumnFamilyDescriptor] = mutable.Buffer() | ||
// if successful, the rocksdb writes the loaded options to a file that can then be retreived with loadLatestOptions | ||
// we test that that one now includes the value 700 from the file above, rather than the 100 specified as a default | ||
org.rocksdb.OptionsUtil.loadLatestOptions(dataDir.toString, Env.getDefault, options, cfListRef.asJava) | ||
assert(options.statsDumpPeriodSec() == 700) | ||
storeManager.close | ||
} | ||
|
||
it should "fail if specified config file does not exist" in { | ||
assertThrows[Exception] { | ||
new StoreManager(dataDir, backupDir, columnFamilies, Some("nonExistingPath.ini")) | ||
} | ||
} | ||
|
||
it should "fail if specified config file is invalid" in { | ||
val file = new File(testTempDir, "testConfig.ini") | ||
writeToFile(file, "[Version]\n rocksdb_version=5.11.3\n options_file_version=1.1\n\n[DBOptions]\n stats_dump_period_sec=700") | ||
|
||
assertThrows[Exception] { | ||
new StoreManager(dataDir, backupDir, columnFamilies, Some(file.getPath)) | ||
} | ||
} | ||
|
||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/scala/com/scalableminds/fossildb/TestHelpers.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) 2011-2018 scalable minds UG (haftungsbeschränkt) & Co. KG. <http://scm.io> | ||
*/ | ||
package com.scalableminds.fossildb | ||
|
||
import java.io.{BufferedWriter, File, FileWriter} | ||
|
||
trait TestHelpers { | ||
|
||
protected def deleteRecursively(file: File): Unit = { | ||
if (file.isDirectory) | ||
file.listFiles.foreach(deleteRecursively) | ||
if (file.exists && !file.delete) | ||
throw new Exception(s"Unable to delete ${file.getAbsolutePath}") | ||
} | ||
|
||
protected def writeToFile(file: File, content: String): Unit = { | ||
val bw = new BufferedWriter(new FileWriter(file)) | ||
bw.write(content) | ||
bw.close() | ||
} | ||
|
||
} |