Skip to content

Commit

Permalink
Merge aea2b46 into 845f426
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelCemus committed Sep 1, 2019
2 parents 845f426 + aea2b46 commit c6da354
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 56 deletions.
24 changes: 15 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: scala

jdk:
- oraclejdk8
dist: trusty
jdk: oraclejdk8

branches:
only:
Expand All @@ -13,23 +13,29 @@ cache:

env:
global:
# supported scala version
- SCALA_211=2.11.12
- SCALA_212=2.12.7
# Sonatype credentials
- secure: ozghyo5Yp3enkBx53MzQaD0LeqhBNbGFC3vkkZAcQbele4tR5GrOzR4xjTH0oHhVj7NUHq7WGu4nUDj1h43fJW7uCViepUARrBMPLaUc8ba036IX1OXTU7e2ilGKnOsFeOGfgOo9tb5HnisgfhSXAfMBCgigc+oCtL0HTBdxn9CqjqsUo23c/fnG2UKyLk0Hv5vp91Z/3+kMNkxQTMdJs+ywpKRbMHdIwkghJIqSVfezGxmqhi1wSfoh0xMjOQjaHC0NpTWUs+gmD0hENzV/THwtkeLNcIsdkMIJPoPKruOlfGeTnCFHF3ojNgrUEEDwulrwpLTLoQJeDU6P60JSwUdtzu9hSxwTZLgndwmaE77r2cVsiD5xM5AGB4jVQbd9oOFMW7TIErUemg53qFAiix1W5KtgGv6vW9qT7Z/CRpYC2LG99BUnNzdTKu9e2oBsCY1QbYrXHORSqefnzihAlwJ/6lAGDLnAFw4pgYb779oo8GIhQQdCDMqELSunhP8uJ6G3dpY5p5ubrsSA7yS6tRcaQ+iB1410iTNfMAoD0tKIjgbpR4Zs8lg/5bpiO914f3Xf0KKwFM7lXdajMdN5z5iDnOGgAgtwXB1a/QT2phHqKQ/DFLUbqVUdE2tmuycJ9iAUtVVsyOXZggtOun6o04hfBG1NK/tc1ifGUPigjXw=
- secure: b1gPGCnIdQPqvztIFzM1JkVqYhgDSx5KC273sg9/I2f9zAP+YqPgJ9WjdUBj2Wp2pzQdggakdBgAj36cpEhpylr4W2t4aMzHitvmu/BvHW9+vpjzMhqpLP/6GG8N+Szbhm3nj4BDA/BjelTnN2SyvKrxWGrD6QJuU33AakWM3v/b/Og5L2Sb2E63X80i2iZk9qTdOHCoTxizkTtB/DEgt9PpzUfMJmn8Ww1Gs1mbou3fPUPOVO88iBjn5JmF6iJ+sIRY0MQuPHhDnk98z6BvITg8GycQBc27OWzJFxK0Zu78MVV3t8WRjZ0sxyJNwdGSBBdz5L1jEzP5J5GtgRZiCcCOVZ4j04kdd2/2/4RaZX2jdZAyr1uzIEuBY+xwKhg6J0386HGrQVUu+IvgPQbpFOtmDeyIBRRAXW11KXR2+cNH6RFF8wA274G8l3SAfvvpWKUwussj9j3h1T/37xdCL2igaOmbOEIQYL1Mpo5cnN8lI080LoCc5vL9XHqCVlE7Hr+VUhoagmuiMMUzrTW0Rg81fI+I8dswyy6QTaqY8EYg8KdxQhDoFnkRtHAdaJyjWrL7IuM5G1Poto9UkW8Gg4YwK5HHeg9xDaLMD/OBnup2DVIqwsi2walsM6OlLB0WkEaDa2VG8WVKFOrTOLTAmfWFCscg+qutgTrfasF12EM=

matrix:
include:
- name: "Test Scala 2.11"
env: SCRIPT=test-2.11
env:
- SCALA_VERSION=2.11.12
- SCRIPT=test
- name: "Test Scala 2.12"
env: SCRIPT=test-2.12
env:
- SCALA_VERSION=2.12.9
- SCRIPT=test
- name: "Test Scala 2.13"
env:
- SCALA_VERSION=2.13.0
- SCRIPT=test
- name: "Test Scala Code Style"
env: SCRIPT=test-code-style
env:
- SCRIPT=test-code-style

script: bin/$SCRIPT
script: bin/$SCRIPT $SCALA_VERSION

services:
- redis-server
Expand Down
6 changes: 4 additions & 2 deletions bin/test-2.11 → bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

. "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/config"

runSbt ++$SCALA_211 $SBT_CMD
SCALA_VERSION="$1"

runSbt ++$SCALA_VERSION $SBT_CMD

result=$?

doAfterSuccess $result $SCALA_211
doAfterSuccess $result $SCALA_VERSION

exit $result
11 changes: 0 additions & 11 deletions bin/test-2.12

This file was deleted.

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

organization := "com.github.karelcemus"

scalaVersion := "2.12.8"
scalaVersion := "2.13.0"

crossScalaVersions := Seq( "2.11.12", scalaVersion.value )
crossScalaVersions := Seq( "2.11.12", "2.12.9", scalaVersion.value )

playVersion := "2.7.0"

connectorVersion := "1.8.4"
connectorVersion := "1.9.1"

specs2Version := "4.4.1"
specs2Version := "4.7.0"

libraryDependencies ++= Seq(
// play framework cache API
"com.typesafe.play" %% "play-cache" % playVersion.value % Provided,
// redis connector
"com.github.Ma27" %% "rediscala" % connectorVersion.value,
"com.github.karelcemus" %% "rediscala" % connectorVersion.value,
// test framework
"org.specs2" %% "specs2-core" % specs2Version.value % Test,
// with mockito extension
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ addSbtPlugin( "com.jsuereth" % "sbt-pgp" % "1.1.2" )
addSbtPlugin( "com.timushev.sbt" % "sbt-updates" % "0.4.0" )

// code coverage
addSbtPlugin( "org.scoverage" % "sbt-scoverage" % "1.5.1" )
addSbtPlugin( "org.scoverage" % "sbt-scoverage" % "1.6.0" )

// uploads the coverage results into the coveralls.io
addSbtPlugin( "org.scoverage" % "sbt-coveralls" % "1.2.2" )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package play.api.cache.redis

import scala.collection.convert.{DecorateAsJava, DecorateAsScala}

private[redis] trait JavaCompatibilityBase extends DecorateAsScala with DecorateAsJava

private[redis] object JavaCompatibilityBase extends JavaCompatibilityBase

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package play.api.cache.redis

import scala.collection.convert.{DecorateAsJava, DecorateAsScala}

private[redis] trait JavaCompatibilityBase extends DecorateAsScala with DecorateAsJava

private[redis] object JavaCompatibilityBase extends JavaCompatibilityBase

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package play.api.cache.redis

import scala.collection.convert.{AsJavaExtensions, AsScalaExtensions}

private[redis] trait JavaCompatibilityBase extends AsJavaExtensions with AsScalaExtensions

private[redis] object JavaCompatibilityBase extends JavaCompatibilityBase
4 changes: 2 additions & 2 deletions src/main/scala/play/api/cache/redis/RedisList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ trait RedisList[Elem, Result[_]] extends RedisCollection[List[Elem], Result] {
* @param elements element to be prepended
* @return this collection to chain commands
*/
def ++:(elements: Traversable[Elem]): Result[This]
def ++:(elements: Iterable[Elem]): Result[This]

/**
* Insert all the specified values at the tail of the list stored at key.
Expand All @@ -119,7 +119,7 @@ trait RedisList[Elem, Result[_]] extends RedisCollection[List[Elem], Result] {
* @param elements to be apended
* @return this collection to chain commands
*/
def :++(elements: Traversable[Elem]): Result[This]
def :++(elements: Iterable[Elem]): Result[This]

/**
* Returns the element at index index in the list stored at key.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package play.api.cache.redis.configuration

import scala.collection.JavaConverters._

import play.api.ConfigLoader
import play.api.cache.redis.JavaCompatibilityBase

import com.typesafe.config.Config

Expand All @@ -16,7 +15,7 @@ import com.typesafe.config.Config
* the application is running, there should be no need to use this
* manager.
*/
trait RedisInstanceManager extends Traversable[RedisInstanceProvider] {
trait RedisInstanceManager extends Iterable[RedisInstanceProvider] {

/** names of all known redis caches */
def caches: Set[String]
Expand All @@ -32,8 +31,7 @@ trait RedisInstanceManager extends Traversable[RedisInstanceProvider] {
/** returns the default instance */
def defaultInstance: RedisInstanceProvider

/** traverse all binders */
def foreach[U](f: RedisInstanceProvider => U) = caches.view.flatMap(instanceOfOption).foreach(f)
def iterator: Iterator[RedisInstanceProvider] = caches.view.flatMap(instanceOfOption).iterator

// $COVERAGE-OFF$
override def equals(obj: scala.Any) = obj match {
Expand Down Expand Up @@ -61,6 +59,7 @@ private[redis] object RedisInstanceManager extends ConfigLoader[RedisInstanceMan
* Redis manager reading 'play.cache.redis.instances' tree for cache definitions.
*/
class RedisInstanceManagerImpl(config: Config, path: String)(implicit defaults: RedisSettings) extends RedisInstanceManager {
import JavaCompatibilityBase._
import RedisConfigLoader._

/** names of all known redis caches */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package play.api.cache.redis.configuration

import scala.collection.JavaConverters._
import play.api.cache.redis.JavaCompatibilityBase

import com.typesafe.config.{Config, ConfigOrigin}

trait RedisInstanceResolver {
Expand Down Expand Up @@ -90,6 +91,7 @@ private[configuration] object RedisInstanceStandalone extends RedisConfigInstanc
* Statically configured redis cluster
*/
private[configuration] object RedisInstanceCluster extends RedisConfigInstanceLoader[RedisInstanceProvider] {
import JavaCompatibilityBase._
import RedisConfigLoader._

def load(config: Config, path: String, instanceName: String)(implicit defaults: RedisSettings) = new ResolvedRedisInstance(
Expand Down Expand Up @@ -121,6 +123,7 @@ private[configuration] object RedisInstanceEnvironmental extends RedisConfigInst
* Statically configures redis sentinel
*/
private[configuration] object RedisInstanceSentinel extends RedisConfigInstanceLoader[RedisInstanceProvider] {
import JavaCompatibilityBase._
import RedisConfigLoader._

def load(config: Config, path: String, instanceName: String)(implicit defaults: RedisSettings) = new ResolvedRedisInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private[connector] trait ExpectedFuture[T] {
private[connector] object ExpectedFuture {

/** converts future to Future[Unit] */
@inline implicit def futureToUnit[T](future: Future[T])(implicit context: ExecutionContext): Future[Unit] = future.map(_ => Unit)
@inline implicit def futureToUnit[T](future: Future[T])(implicit context: ExecutionContext): Future[Unit] = future.map(_ => ())
}

private[connector] class ExpectedFutureWithoutKey[T](protected val future: Future[T], protected val cmd: String) extends ExpectedFuture[T] {
Expand All @@ -55,7 +55,7 @@ private[connector] class ExpectedFutureWithoutKey[T](protected val future: Futur

def withKey(key: String): ExpectedFutureWithKey[T] = new ExpectedFutureWithKey[T](future, cmd, key, s"$cmd $key")

def withKeys(keys: Traversable[String]): ExpectedFutureWithKey[T] = withKey(keys mkString " ")
def withKeys(keys: Iterable[String]): ExpectedFutureWithKey[T] = withKey(keys mkString " ")

override def toString = s"ExpectedFuture($cmd)"
}
Expand All @@ -71,7 +71,7 @@ private[connector] class ExpectedFutureWithKey[T](protected val future: Future[T

def andParameter(param: => Any): ExpectedFutureWithKey[T] = andParameters(param.toString)

def andParameters(params: Traversable[Any]): ExpectedFutureWithKey[T] = andParameters(params mkString " ")
def andParameters(params: Iterable[Any]): ExpectedFutureWithKey[T] = andParameters(params mkString " ")

def andParameters(params: => String): ExpectedFutureWithKey[T] = new ExpectedFutureWithKey(future, cmd, key, s"$statement $params")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ private[connector] class RedisConnectorImpl(serializer: AkkaSerializer, redis: R
case removed => log.debug(s"Remove on keys ${keys.mkString("'", ",", "'")} removed $removed values.")
}
} else {
Future.successful(Unit) // otherwise return immediately
Future.successful(()) // otherwise return immediately
}

def ping(): Future[Unit] =
redis.ping() executing "PING" logging {
case "PONG" => Unit
case "PONG" => ()
}

def increment(key: String, by: Long): Future[Long] =
Expand Down Expand Up @@ -334,7 +334,7 @@ private[connector] class RedisConnectorImpl(serializer: AkkaSerializer, redis: R
Map.empty
case encoded =>
log.debug(s"Collection at '$key' has ${encoded.size} items.")
encoded.mapValues(decode[T](key, _))
encoded.map { case (itemKey, value) => itemKey -> decode[T](itemKey, value) }
}

def hashSize(key: String) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package play.api.cache.redis.impl

import scala.collection.convert.{DecorateAsJava, DecorateAsScala}
import scala.concurrent.{ExecutionContext, Future}
import scala.language.implicitConversions
import scala.reflect.ClassTag

import play.api.Environment
import play.api.cache.redis.JavaCompatibilityBase

import akka.Done

private[impl] object JavaCompatibility extends DecorateAsScala with DecorateAsJava {
private[impl] object JavaCompatibility extends JavaCompatibilityBase {
import scala.compat.java8.{FutureConverters, OptionConverters}

type CompletionStage[T] = java.util.concurrent.CompletionStage[T]
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/play/api/cache/redis/impl/RedisCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private[impl] class RedisCache[Result[_]](redis: RedisConnector, builder: Builde
redis.append(key, value).flatMap { result =>
// if the new string length is equal to the appended string, it means they should equal
// when the finite duration is required, set it
if (result == value.length && expiration.isFinite()) redis.expire(key, expiration) else Future.successful[Unit](Unit)
if (result == value.length && expiration.isFinite) redis.expire(key, expiration) else Future.successful[Unit](())
}.recoverWithDone
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/play/api/cache/redis/impl/RedisListImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ private[impl] class RedisListImpl[Elem: ClassTag, Result[_]](key: String, redis:

def :+(element: Elem) = appendAll(element)

def ++:(elements: Traversable[Elem]) = prependAll(elements.toSeq: _*)
def ++:(elements: Iterable[Elem]) = prependAll(elements.toSeq: _*)

def :++(elements: Traversable[Elem]) = appendAll(elements.toSeq: _*)
def :++(elements: Iterable[Elem]) = appendAll(elements.toSeq: _*)

private def prependAll(elements: Elem*) =
redis.listPrepend(key, elements: _*).map(_ => This).recoverWithDefault(This)
Expand Down
6 changes: 5 additions & 1 deletion src/test/scala/play/api/cache/redis/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package play.api.cache.redis

import java.util.concurrent.Callable

import scala.collection.mutable
import scala.concurrent._
import scala.concurrent.duration._
import scala.language.implicitConversions
Expand All @@ -10,6 +11,7 @@ import scala.util._
import play.api.cache.redis.configuration._

import akka.actor.ActorSystem

import org.specs2.execute.{AsResult, Result}
import org.specs2.matcher.Expectations
import org.specs2.mock.mockito._
Expand All @@ -27,6 +29,8 @@ object Implicits {

val defaultInstance = RedisStandalone(defaultCacheName, RedisHost(localhost, defaultPort), defaults)

implicit def implicitlyImmutableSeq[T](value: mutable.ListBuffer[T]): Seq[T] = value.toSeq

implicit def implicitlyAny2Some[T](value: T): Option[T] = Some(value)

implicit def implicitlyAny2future[T](value: T): Future[T] = Future.successful(value)
Expand Down Expand Up @@ -59,7 +63,7 @@ object Implicits {
}

def after(seconds: Int)(implicit system: ActorSystem, ec: ExecutionContext): Future[Unit] = {
after(seconds, Unit)
after(seconds, ())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object RedisCacheImplicits {

class MockedList extends MockedCache {
protected val data = new mutable.ListBuffer[String]
data.append(other, value, value)
data.appendAll(Iterable(other, value, value))

protected val list = cache.list[String]("key")
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/play/api/cache/redis/impl/RedisListSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,25 @@ class RedisListSpec(implicit ee: ExecutionEnv) extends Specification with Reduce
}

"view all" in new MockedList {
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns data
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns (data: Seq[String])
list.view.all must beEqualTo(data).await
there were one(connector).listSlice[String](key, 0, -1)
}

"view take" in new MockedList {
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns data
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns (data: Seq[String])
list.view.take(2) must beEqualTo(data).await
there were one(connector).listSlice[String](key, 0, 1)
}

"view drop" in new MockedList {
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns data
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns (data: Seq[String])
list.view.drop(2) must beEqualTo(data).await
there were one(connector).listSlice[String](key, 2, -1)
}

"view slice" in new MockedList {
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns data
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns (data: Seq[String])
list.view.slice(1, 2) must beEqualTo(data).await
there were one(connector).listSlice[String](key, 1, 2)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ class RedisListSpec(implicit ee: ExecutionEnv) extends Specification with Reduce
}

"toList" in new MockedList {
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns data
connector.listSlice[String](anyString, anyInt, anyInt)(anyClassTag) returns (data: Seq[String])
list.toList must beEqualTo(data).await
there were one(connector).listSlice[String](key, 0, -1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import akka.event.slf4j.Slf4jLogger
class RedisLogger extends Slf4jLogger {

private def doReceive: PartialFunction[Any, Unit] = {
case InitializeLogger(_) sender() ! LoggerInitialized
case InitializeLogger(_) => sender() ! LoggerInitialized
}

override def receive = {
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "2.4.1-SNAPSHOT"
version in ThisBuild := "2.5.0-SNAPSHOT"

0 comments on commit c6da354

Please sign in to comment.