Skip to content

Commit

Permalink
Update to Play 2.9, fixed integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelCemus committed Nov 11, 2023
1 parent 1f1ab55 commit a93d6c3
Show file tree
Hide file tree
Showing 41 changed files with 284 additions and 407 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,11 @@ jobs:
- name: Setup JDK
uses: coursier/[email protected]
with:
jvm: adoptium:1.8

- name: Test Code Style
run: |
sbt --client "+scalariformFormat; +test:scalariformFormat"
git diff --exit-code || (
echo "ERROR: Scalariform check failed, see differences above."
echo "To fix, format your sources using sbt scalariformFormat test:scalariformFormat before submitting a pull request."
false
)
jvm: adoptium:1.17

- name: Build
timeout-minutes: 10
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sbt --client "+clean; +compile; +Test/compile; +test;"
sbt --client "+clean; +compile; +Test/compile; +coverage; +test; +coverageReport; +coveralls;"
30 changes: 0 additions & 30 deletions .scalariform.conf

This file was deleted.

23 changes: 0 additions & 23 deletions bin/config

This file was deleted.

13 changes: 0 additions & 13 deletions bin/test

This file was deleted.

12 changes: 0 additions & 12 deletions bin/test-code-style

This file was deleted.

18 changes: 8 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ description := "Redis cache plugin for the Play framework 2"

organization := "com.github.karelcemus"

scalaVersion := "2.13.8"
crossScalaVersions := Seq("2.13.12") //, "3.3.0"

crossScalaVersions := Seq("2.12.15", scalaVersion.value)
scalaVersion := crossScalaVersions.value.head

playVersion := "2.8.13"
playVersion := "2.9.0"

libraryDependencies ++= Seq(
// play framework cache API
"com.typesafe.play" %% "play-cache" % playVersion.value % Provided,
// redis connector
"com.github.karelcemus" %% "rediscala" % "1.9.1",
"io.github.rediscala" %% "rediscala" % "1.14.0-akka",
// test framework with mockito extension
"org.specs2" %% "specs2-mock" % "4.13.2" % Test,
"org.specs2" %% "specs2-mock" % "4.20.3" % Test,
// test module for play framework
"com.typesafe.play" %% "play-specs2" % playVersion.value % Test
"com.typesafe.play" %% "play-test" % playVersion.value % Test,
// to run integration tests
"com.dimafeng" %% "testcontainers-scala-core" % "0.41.0" % Test
)

resolvers ++= Seq(
Expand All @@ -34,10 +36,6 @@ javacOptions ++= Seq("-Xlint:unchecked", "-encoding", "UTF-8")

scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked")

homepage := Some(url("https://github.com/karelcemus/play-redis"))

licenses := Seq("Apache 2" -> url("https://www.apache.org/licenses/LICENSE-2.0"))

enablePlugins(CustomReleasePlugin)

// exclude from tests coverage
Expand Down
4 changes: 3 additions & 1 deletion project/CustomReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ object CustomReleasePlugin extends AutoPlugin {
pomIncludeRepository := { _ => false },
// customized release process
releaseProcess := customizedReleaseProcess,
//
// release details
homepage := Some(url("https://github.com/karelcemus/play-redis")),
licenses := Seq("Apache 2" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
scmInfo := Some(
ScmInfo(
url("https://github.com/KarelCemus/play-i18n.git"),
Expand Down
9 changes: 3 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksamuel/sbt-plugins/"))(Resolver.ivyStylePatterns)

// checks for updates
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.1")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")

// code coverage and uploader of the coverage results into the coveralls.io
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")

// code linter
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.11")

// library release
addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1")
Expand Down

This file was deleted.

49 changes: 27 additions & 22 deletions src/main/scala/play/api/cache/redis/configuration/RedisHost.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ trait RedisHost {
def port: Int
/** redis database identifier to work with */
def database: Option[Int]
/** when enabled security, this returns username for the AUTH command */
def username: Option[String]
/** when enabled security, this returns password for the AUTH command */
def password: Option[String]
// $COVERAGE-OFF$
/** trait-specific equals */
override def equals(obj: scala.Any) = equalsAsHost(obj)
/** trait-specific equals, invokable from children */
protected def equalsAsHost(obj: scala.Any) = obj match {
case that: RedisHost => Equals.check(this, that)(_.host, _.port, _.database, _.password)
case that: RedisHost => Equals.check(this, that)(_.host, _.port, _.username, _.database, _.password)
case _ => false
}
/** to string */
override def toString = (password, database) match {
case (Some(password), Some(database)) => s"redis://redis:$password@$host:$port?db=$database"
case (Some(password), None) => s"redis://redis:$password@$host:$port"
override def toString: String = (password, database) match {
case (Some(password), Some(database)) => s"redis://${username.getOrElse("redis")}:$password@$host:$port?db=$database"
case (Some(password), None) => s"redis://${username.getOrElse("redis")}:$password@$host:$port"
case (None, Some(database)) => s"redis://$host:$port?db=$database"
case (None, None) => s"redis://$host:$port"
}
Expand All @@ -38,7 +40,7 @@ object RedisHost extends ConfigLoader[RedisHost] {
import RedisConfigLoader._

/** expected format of the environment variable */
private val ConnectionString = "redis://((?<user>[^:]+):(?<password>[^@]+)@)?(?<host>[^:]+):(?<port>[0-9]+)".r("auth", "user", "password", "host", "port")
private val ConnectionString = "redis://((?<username>[^:]+):(?<password>[^@]+)@)?(?<host>[^:]+):(?<port>[0-9]+)".r("auth", "username", "password", "host", "port")

def load(config: Config, path: String): RedisHost = apply(
host = config.getString(path / "host"),
Expand All @@ -51,29 +53,31 @@ object RedisHost extends ConfigLoader[RedisHost] {
def fromConnectionString(connectionString: String): RedisHost = ConnectionString findFirstMatchIn connectionString match {
// read the environment variable and fill missing information from the local configuration file
case Some(matcher) => new RedisHost {
val host = matcher.group("host")
val port = matcher.group("port").toInt
val database = None
val password = Option(matcher.group("password"))
override val host: String = matcher.group("host")
override val port: Int = matcher.group("port").toInt
override val database: Option[Nothing] = None
override val username: Option[String] = Option(matcher.group("username"))
override val password: Option[String] = Option(matcher.group("password"))
}
// unexpected format
case None => throw new IllegalArgumentException(s"Unexpected format of the connection string: '$connectionString'. Expected format is 'redis://[user:password@]host:port'.")
}

def apply(host: String, port: Int, database: Option[Int] = None, password: Option[String] = None): RedisHost =
create(host, port, database, password)
def apply(host: String, port: Int, database: Option[Int] = None, username: Option[String] = None, password: Option[String] = None): RedisHost =
create(host, port, database, username, password)

/** hackish method to preserve nice names of parameters in apply */
@inline private def create(_host: String, _port: Int, _database: Option[Int], _password: Option[String]) = new RedisHost {
val host = _host
val port = _port
val database = _database
val password = _password
@inline private def create(_host: String, _port: Int, _database: Option[Int], _username: Option[String], _password: Option[String]) = new RedisHost {
override val host: String = _host
override val port: Int = _port
override val database: Option[Int] = _database
override val username: Option[String] = _username
override val password: Option[String] = _password
}

// $COVERAGE-OFF$
def unapply(host: RedisHost): Option[(String, Int, Option[Int], Option[String])] = {
Some((host.host, host.port, host.database, host.password))
def unapply(host: RedisHost): Option[(String, Int, Option[Int],Option[String], Option[String])] = {
Some((host.host, host.port, host.database, host.username, host.password))
}
// $COVERAGE-ON$
}
Expand All @@ -84,8 +88,9 @@ object RedisHost extends ConfigLoader[RedisHost] {
*/
trait RedisDelegatingHost extends RedisHost {
def innerHost: RedisHost
def host = innerHost.host
def port = innerHost.port
def database = innerHost.database
def password = innerHost.password
override def host: String = innerHost.host
override def port: Int = innerHost.port
override def database: Option[Int] = innerHost.database
override def username: Option[String] = innerHost.username
override def password: Option[String] = innerHost.password
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ trait RedisSentinel extends RedisInstance {

def sentinels: List[RedisHost]
def masterGroup: String
def username: Option[String]
def password: Option[String]
def database: Option[Int]

Expand All @@ -103,23 +104,28 @@ trait RedisSentinel extends RedisInstance {

object RedisSentinel {

def apply(name: String, masterGroup: String,
sentinels: List[RedisHost],
settings: RedisSettings,
password: Option[String] = None,
database: Option[Int] = None): RedisSentinel with RedisDelegatingSettings =
create(name, masterGroup, password, database, sentinels, settings)
def apply(
name: String,
masterGroup: String,
sentinels: List[RedisHost],
settings: RedisSettings,
username: Option[String] = None,
password: Option[String] = None,
database: Option[Int] = None
): RedisSentinel with RedisDelegatingSettings =
create(name, masterGroup, username, password, database, sentinels, settings)

@inline
private def create(_name: String, _masterGroup: String, _password: Option[String], _database: Option[Int],
private def create(_name: String, _masterGroup: String, _username: Option[String], _password: Option[String], _database: Option[Int],
_sentinels: List[RedisHost], _settings: RedisSettings) =
new RedisSentinel with RedisDelegatingSettings {
val name = _name
val masterGroup = _masterGroup
val password = _password
val database = _database
val sentinels = _sentinels
val settings = _settings
override val name: String = _name
override val masterGroup: String = _masterGroup
override val username: Option[String] = _username
override val password: Option[String] = _password
override val database: Option[Int] = _database
override val sentinels: List[RedisHost] = _sentinels
override val settings: RedisSettings = _settings
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private[connector] class RedisCommandsStandalone(configuration: RedisStandalone)
host = host,
port = port,
db = database,
username = username,
password = password
) with FailEagerly with RedisRequestTimeout {

Expand Down Expand Up @@ -105,7 +106,7 @@ private[connector] class RedisCommandsCluster(configuration: RedisCluster)(impli

val client: RedisClusterClient = new RedisClusterClient(
nodes.map {
case RedisHost(host, port, database, password) => RedisServer(host.resolvedIpAddress, port, password, database)
case RedisHost(host, port, database, username, password) => RedisServer(host.resolvedIpAddress, port, username, password, database)
}
) with RedisRequestTimeout {
protected val timeout = configuration.timeout.redis
Expand All @@ -116,8 +117,8 @@ private[connector] class RedisCommandsCluster(configuration: RedisCluster)(impli
// $COVERAGE-OFF$
def start() = {
def servers = nodes.map {
case RedisHost(host, port, Some(database), _) => s" $host:$port?database=$database"
case RedisHost(host, port, None, _) => s" $host:$port"
case RedisHost(host, port, Some(database), _, _) => s" $host:$port?database=$database"
case RedisHost(host, port, None, _, _) => s" $host:$port"
}

log.info(s"Redis cluster cache actor started. It is connected to ${servers mkString ", "}")
Expand All @@ -143,9 +144,10 @@ private[connector] class RedisCommandsSentinel(configuration: RedisSentinel)(imp

val client: SentinelMonitoredRedisClient with RedisRequestTimeout = new SentinelMonitoredRedisClient(
configuration.sentinels.map {
case RedisHost(host, port, _, _) => (host.resolvedIpAddress, port)
case RedisHost(host, port, _, _, _) => (host.resolvedIpAddress, port)
},
master = configuration.masterGroup,
username = configuration.username,
password = configuration.password,
db = configuration.database
) with RedisRequestTimeout {
Expand Down
Loading

0 comments on commit a93d6c3

Please sign in to comment.