Skip to content

Commit

Permalink
Issue debasishg#282 added unit test demonstrating that Pools support …
Browse files Browse the repository at this point in the history
…passwords - with some refactoring.
  • Loading branch information
noahlz committed Nov 3, 2021
1 parent 59645f1 commit 6edc8b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c - %m%n

# Application logging options
log4j.logger.com.redis=INFO
log4j.logger.com.redis=debug
log4j.logger.com.redis.cluster=DEBUG
log4j.logger.com.github.dockerjava=INFO
log4j.logger.com.github.dockerjava=debug
log4j.logger.org.apache.http=INFO
27 changes: 25 additions & 2 deletions src/test/scala/com/redis/PoolSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import org.scalatest.matchers.should.Matchers
import scala.concurrent._
import scala.concurrent.duration._

class PoolSpec extends AnyFunSpec
abstract class BasePoolSpec extends AnyFunSpec
with Matchers
with BeforeAndAfterEach
with RedisDocker {

implicit lazy val clients: RedisClientPool = new RedisClientPool(redisContainerHost, redisContainerPort)
implicit lazy val clients: RedisClientPool =
new RedisClientPool(redisContainerHost, redisContainerPort, secret = redisPassword)

override protected def beforeEach(): Unit = {
super.beforeEach()
Expand All @@ -32,6 +33,10 @@ class PoolSpec extends AnyFunSpec
clients.close()
super.afterAll()
}
}

trait PoolLoadTesting {
self: BasePoolSpec =>

def lp(msgs: List[String]) = {
clients.withClient {
Expand Down Expand Up @@ -63,6 +68,9 @@ class PoolSpec extends AnyFunSpec
}
}
}
}

class PoolSpec extends BasePoolSpec with PoolLoadTesting {

describe("pool test") {
it("should distribute work amongst the clients") {
Expand Down Expand Up @@ -127,3 +135,18 @@ class PoolSpec extends AnyFunSpec
}
}
}

class SecurePoolSpec extends BasePoolSpec {

override val redisPassword = Option("mayonaise")

describe("redis pools with authentication") {
it("should be able to connect as normal") {
val response = clients.withClient { client =>
client.ping
}
response should equal(Some("PONG"))
}
}
}

6 changes: 5 additions & 1 deletion src/test/scala/com/redis/common/RedisDocker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ trait RedisContainer extends DockerKit with DockerTestKit with DockerKitDockerJa

protected val redisContainerHost: String = "localhost"
protected val redisPort: Int = 6379
protected val redisPassword: Option[String] = None

protected def baseContainer(name: Option[String]) = DockerContainer("redis:latest", name=name)
// just password supported for now
private def args = redisPassword.map(password => Seq("--requirepass", password))

protected def baseContainer(name: Option[String]) = DockerContainer("redis:latest", name=name, command=args)

protected def createContainer(name: Option[String] = Some(RandomStringUtils.randomAlphabetic(10)),
ports: Map[Int, Int] = Map.empty): DockerContainer = {
Expand Down

0 comments on commit 6edc8b5

Please sign in to comment.