-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move maxConnections into RDSClientConfig, move creation of RDSClientC…
…onfig (#2817) * Move maxConnections into RDSClientConfig * add tests for RDSBuilder
- Loading branch information
1 parent
2cb7c92
commit 657c416
Showing
5 changed files
with
120 additions
and
38 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
29 changes: 28 additions & 1 deletion
29
...line/id_minter/src/main/scala/weco/pipeline/id_minter/config/models/RDSClientConfig.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 |
---|---|---|
@@ -1,9 +1,36 @@ | ||
package weco.pipeline.id_minter.config.models | ||
|
||
import com.typesafe.config.Config | ||
import weco.typesafe.config.builders.EnrichConfig._ | ||
|
||
case class RDSClientConfig( | ||
primaryHost: String, | ||
replicaHost: String, | ||
port: Int, | ||
username: String, | ||
password: String | ||
password: String, | ||
maxConnections: Int | ||
) | ||
|
||
object RDSClientConfig { | ||
def apply(config: Config): RDSClientConfig = { | ||
val primaryHost = config.requireString("aws.rds.primary_host") | ||
val replicaHost = config.requireString("aws.rds.replica_host") | ||
|
||
val port = config | ||
.getIntOption("aws.rds.port") | ||
.getOrElse(3306) | ||
|
||
val username = config.requireString("aws.rds.username") | ||
val password = config.requireString("aws.rds.password") | ||
|
||
RDSClientConfig( | ||
primaryHost = primaryHost, | ||
replicaHost = replicaHost, | ||
port = port, | ||
username = username, | ||
password = password, | ||
maxConnections = config.requireInt("aws.rds.maxConnections") | ||
) | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...ine/id_minter/src/test/scala/weco/pipeline/id_minter/config/builders/RDSBuilderTest.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,84 @@ | ||
package weco.pipeline.id_minter.config.builders | ||
|
||
import com.typesafe.config.ConfigFactory | ||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import scalikejdbc.ConnectionPool | ||
import weco.pipeline.id_minter.config.models.RDSClientConfig | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
class RDSBuilderTest extends AnyFunSpec with Matchers { | ||
describe("Building the database client connection pools") { | ||
it("sets up a connection pool for the primary host") { | ||
RDSBuilder.buildDB( | ||
RDSClientConfig( | ||
primaryHost = "realdeal.example.com", | ||
replicaHost = "doppelganger.example.com", | ||
port = 999, | ||
username = "slartibartfast", | ||
password = "ssh_its_a_secret", | ||
maxConnections = 5 | ||
) | ||
) | ||
val p = ConnectionPool.get(name = 'primary) | ||
p.url shouldBe "jdbc:mysql://realdeal.example.com:999" | ||
p.user shouldBe "slartibartfast" | ||
p.settings.maxSize shouldBe 5 | ||
} | ||
|
||
it("sets up a connection pool for the replica host") { | ||
RDSBuilder.buildDB( | ||
RDSClientConfig( | ||
primaryHost = "primary.example.com", | ||
replicaHost = "doppelganger.example.com", | ||
port = 1234, | ||
username = "slartibartfast", | ||
password = "ssh_its_a_secret", | ||
maxConnections = 12 | ||
) | ||
) | ||
val p = ConnectionPool.get(name = 'replica) | ||
p.url shouldBe "jdbc:mysql://doppelganger.example.com:1234" | ||
p.user shouldBe "slartibartfast" | ||
p.settings.maxSize shouldBe 12 | ||
} | ||
} | ||
describe("Extracting configuration values") { | ||
val rawConfig = Map( | ||
"aws.rds.primary_host" -> "numberone", | ||
"aws.rds.replica_host" -> "numbertwo", | ||
"aws.rds.username" -> "rincewind", | ||
"aws.rds.password" -> "opensesame", | ||
"aws.rds.maxConnections" -> "678" | ||
) | ||
val config = RDSClientConfig( | ||
ConfigFactory.parseMap(rawConfig.asJava) | ||
) | ||
it("extracts the primary host") { | ||
config.primaryHost shouldBe "numberone" | ||
} | ||
it("extracts the replica host") { | ||
config.replicaHost shouldBe "numbertwo" | ||
} | ||
it("extracts the username") { | ||
config.username shouldBe "rincewind" | ||
} | ||
it("extracts the password") { | ||
config.password shouldBe "opensesame" | ||
} | ||
it("extracts the maxConnections") { | ||
config.maxConnections shouldBe 678 | ||
} | ||
it("defaults to port 3306") { | ||
config.port shouldBe 3306 | ||
} | ||
it("extracts the port value if specified") { | ||
val configWithPort = RDSClientConfig( | ||
ConfigFactory.parseMap((rawConfig + ("aws.rds.port" -> 1234)).asJava) | ||
) | ||
configWithPort.port shouldBe 1234 | ||
|
||
} | ||
} | ||
} |
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