Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extend StartStopAsync with BitcoinSAppConfig, create 'CachedAppConfig' test trait, clean up P2PClientTest * Start cleaning up after ourselves in the chainTest test suite * Call .stop() for appConfig's spun up in ChainAppConfigTest * Database configuration defaults * increase number of Postgres connections * add more logging * close connections pools in tests * update afterAll() * Fix conflict Co-authored-by: rorp <rorp@users.noreply.github.com>
- Loading branch information
1 parent
4b675db
commit f10b0e1
Showing
11 changed files
with
174 additions
and
41 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
106 changes: 106 additions & 0 deletions
106
db-commons-test/src/test/scala/org/bitcoins/db/DBConfigTest.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,106 @@ | ||
package org.bitcoins.db | ||
|
||
import java.io.{File, IOException} | ||
import java.nio.file.attribute.BasicFileAttributes | ||
import java.nio.file.{ | ||
FileVisitResult, | ||
Files, | ||
Path, | ||
SimpleFileVisitor, | ||
StandardOpenOption | ||
} | ||
|
||
import org.bitcoins.chain.config.ChainAppConfig | ||
import org.bitcoins.node.config.NodeAppConfig | ||
import org.bitcoins.wallet.config.WalletAppConfig | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class DBConfigTest extends AnyFlatSpec with Matchers { | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
it should "use sqlite as default database and set its connection pool size to 1" in { | ||
withTempDir { dataDir => | ||
val bytes = Files.readAllBytes( | ||
new File("db-commons/src/main/resources/db.conf").toPath) | ||
Files.write(dataDir.resolve("bitcoin-s.conf"), | ||
bytes, | ||
StandardOpenOption.CREATE_NEW, | ||
StandardOpenOption.WRITE) | ||
|
||
val chainConfig = ChainAppConfig(dataDir) | ||
val slickChainConfig = chainConfig.slickDbConfig | ||
assert(slickChainConfig.profileName == "slick.jdbc.SQLiteProfile") | ||
assert(slickChainConfig.config.hasPath("db.numThreads")) | ||
assert(slickChainConfig.config.getInt("db.numThreads") == 1) | ||
|
||
val nodeConfig = NodeAppConfig(dataDir) | ||
val slickNodeConfig = nodeConfig.slickDbConfig | ||
assert(slickNodeConfig.profileName == "slick.jdbc.SQLiteProfile") | ||
assert(slickNodeConfig.config.hasPath("db.numThreads")) | ||
assert(slickNodeConfig.config.getInt("db.numThreads") == 1) | ||
|
||
val walletConfig = WalletAppConfig(dataDir) | ||
val slickWalletConfig = walletConfig.slickDbConfig | ||
assert(slickWalletConfig.profileName == "slick.jdbc.SQLiteProfile") | ||
assert(slickWalletConfig.config.hasPath("db.numThreads")) | ||
assert(slickWalletConfig.config.getInt("db.numThreads") == 1) | ||
} | ||
} | ||
|
||
it should "use sqlite as default database and disable connection pool for tests" in { | ||
withTempDir { dataDir => | ||
val chainConfig = ChainAppConfig(dataDir) | ||
val slickChainConfig = chainConfig.slickDbConfig | ||
assert(slickChainConfig.profileName == "slick.jdbc.SQLiteProfile") | ||
assert(slickChainConfig.config.hasPath("db.numThreads")) | ||
assert(slickChainConfig.config.getInt("db.numThreads") == 3) | ||
assert( | ||
slickChainConfig.config.getString("db.connectionPool") == "disabled") | ||
|
||
val nodeConfig = NodeAppConfig(dataDir) | ||
val slickNodeConfig = nodeConfig.slickDbConfig | ||
assert(slickNodeConfig.profileName == "slick.jdbc.SQLiteProfile") | ||
assert(slickNodeConfig.config.hasPath("db.numThreads")) | ||
assert(slickNodeConfig.config.getInt("db.numThreads") == 3) | ||
assert( | ||
slickNodeConfig.config.getString("db.connectionPool") == "disabled") | ||
|
||
val walletConfig = WalletAppConfig(dataDir) | ||
val slickWalletConfig = walletConfig.slickDbConfig | ||
assert(slickWalletConfig.profileName == "slick.jdbc.SQLiteProfile") | ||
assert(slickWalletConfig.config.hasPath("db.numThreads")) | ||
assert(slickWalletConfig.config.getInt("db.numThreads") == 3) | ||
assert( | ||
slickWalletConfig.config.getString("db.connectionPool") == "disabled") | ||
} | ||
} | ||
|
||
def withTempDir[T](f: Path => T): T = { | ||
val dir = Files.createTempDirectory(getClass.getName) | ||
try { | ||
f(dir) | ||
} finally { | ||
Files.walkFileTree( | ||
dir, | ||
new SimpleFileVisitor[Path] { | ||
override def visitFile( | ||
file: Path, | ||
attrs: BasicFileAttributes): FileVisitResult = { | ||
Files.delete(file); | ||
FileVisitResult.CONTINUE | ||
} | ||
|
||
override def postVisitDirectory( | ||
dir: Path, | ||
exc: IOException): FileVisitResult = { | ||
Files.delete(dir); | ||
FileVisitResult.CONTINUE | ||
} | ||
} | ||
) | ||
() | ||
} | ||
} | ||
} |
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
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