Skip to content

Commit

Permalink
Removed deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelCemus committed Jul 12, 2018
1 parent 7f66901 commit 8c778e3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 72 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Support of plain arrays in JavaRedis [#176](https://github.com/KarelCemus/play-r
Connection timeout introduced in [#147](https://github.com/KarelCemus/play-redis/issues/147)
is now configurable and can be disabled [#174](https://github.com/KarelCemus/play-redis/pull/174).

Removed deprecations introduced in [2.0.0](https://github.com/KarelCemus/play-redis/tree/2.0.0)
and [2.1.0](https://github.com/KarelCemus/play-redis/tree/2.1.0).

### [:link: 2.1.2](https://github.com/KarelCemus/play-redis/tree/2.1.2)

JDK 10 compatibility. Replace deprecated com.sun.misc.BASE64* usages with jdk8 java.util.Base64 [#170](https://github.com/KarelCemus/play-redis/pull/170).
Expand Down
3 changes: 0 additions & 3 deletions src/main/scala/play/api/cache/redis/Expiration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ private[ redis ] trait ExpirationImplicits {

implicit def javaDate2AsExpiration( expireAt: Date ): Expiration = new Expiration( expireAt.getTime )

@deprecated( message = "Since Play 2.6 org.joda.time is removed and replaced ba Java 8 DateTime API. Use java.time.LocalDateTime instead.", since = "2.0.0" )
implicit def jodaDate2AsExpiration( expireAt: DateTime ): Expiration = new Expiration( expireAt.getMillis )

implicit def java8Date2AsExpiration( expireAt: LocalDateTime ): Expiration = new Expiration( expireAt.atZone( ZoneId.systemDefault() ).toEpochSecond * 1000 )
}

Expand Down
19 changes: 3 additions & 16 deletions src/main/scala/play/api/cache/redis/RedisCacheModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ object GuiceProvider extends ProviderImplicits {

private class QualifiedBindingKey[ T ]( key: BindingKey[ T ], f: impl.RedisCaches => T ) {
@inline private def provider( f: impl.RedisCaches => T )( implicit name: CacheName ): Provider[ T ] = new NamedCacheInstanceProvider( f )
@inline private def deprecatedProvider( f: impl.RedisCaches => T )( implicit name: CacheName ): Provider[ T ] = new DeprecatedNamedCacheInstanceProvider( f )
def toBindings( implicit name: CacheName ): Seq[ Binding[ _ ] ] = Seq(
key.named( name ).to( provider( f ) ),
key.qualifiedWith( name ).to( deprecatedProvider( f ) )
)
def toBindings( implicit name: CacheName ): Binding[ _ ] = key.named( name ).to( provider( f ) )
}

private def namedBinding[ T: ClassTag ]( f: impl.RedisCaches => T ) = new QualifiedBindingKey( bind[ T ], f )
Expand All @@ -80,7 +76,7 @@ object GuiceProvider extends ProviderImplicits {
namedBinding( _.scalaSync ),
namedBinding( _.javaSync ),
namedBinding( _.javaAsync )
).flatMap( _.toBindings )
).map( _.toBindings )
}

def defaults( instance: RedisInstanceProvider ) = {
Expand All @@ -103,7 +99,7 @@ object GuiceProvider extends ProviderImplicits {

class GuiceRedisCacheProvider( instance: RedisInstanceProvider ) extends Provider[ RedisCaches ] with GuiceProviderImplicits {
@Inject() var injector: Injector = _
lazy val get = new impl.RedisCachesProvider(
lazy val get: RedisCaches = new impl.RedisCachesProvider(
instance = instance.resolved( bind[ configuration.RedisInstanceResolver ] ),
serializer = bind[ connector.AkkaSerializer ],
environment = bind[ play.api.Environment ]
Expand All @@ -119,15 +115,6 @@ class NamedCacheInstanceProvider[ T ]( f: RedisCaches => T )( implicit name: Cac
lazy val get = f( bind[ RedisCaches ].named( name ) )
}

@deprecated( "Use @NamedCache instead of @Named to inject named caches.", since = "2.1.0" )
class DeprecatedNamedCacheInstanceProvider[ T ]( f: RedisCaches => T )( implicit name: CacheName ) extends Provider[ T ] with GuiceProviderImplicits {
@Inject() var injector: Injector = _
lazy val get = {
play.api.Logger( "play.api.cache.redis.deprecation" ).warn( "Named caches annotated with @Named are deprecated and will be removed in the next release. Use @NamedCache instead. See changelog for more details." )
f( bind[ RedisCaches ].named( name ) )
}
}

class CacheName( val name: String ) extends AnyVal
object CacheName {
implicit def name2string( name: CacheName ): String = name.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ case class RedisTimeoutsImpl
object RedisTimeouts {
import RedisConfigLoader._

private def log = Logger( "play.api.cache.redis" )

def requiredDefault: RedisTimeouts = new RedisTimeouts {
def sync = required( "sync-timeout" )
def redis = None
Expand All @@ -68,23 +66,9 @@ object RedisTimeouts {
connection = loadConnectionTimeout( config, path ) getOrElse default.connection
)

@scala.deprecated( "Property 'timeout' was deprecated in 2.1.0 and was replaced by the 'sync-timeout' with the identical use and meaning.", since = "2.1.0" )
private def loadTimeout( config: Config, path: String ): Option[ FiniteDuration ] =
config.getOption( path / "timeout", _.getDuration ).map { duration =>
log.warn(
"""
|Deprecated settings: Property 'timeout' was deprecated in 2.1.0 and was replaced
|by the 'sync-timeout' with the identical use and meaning. The property, the fallback,
|and this warning will be removed in 2.2.0.
""".stripMargin.replace( "\n", " " )
)
FiniteDuration( duration.getSeconds, TimeUnit.SECONDS )
}

private def loadSyncTimeout( config: Config, path: String ): Option[ FiniteDuration ] =
loadTimeout( config, path ) orElse {
config.getOption( path / "sync-timeout", _.getDuration ).map( duration => FiniteDuration( duration.getSeconds, TimeUnit.SECONDS ) )
}
private def loadSyncTimeout( config: Config, path: String ): Option[ FiniteDuration ] = {
config.getOption( path / "sync-timeout", _.getDuration ).map( duration => FiniteDuration( duration.getSeconds, TimeUnit.SECONDS ) )
}

private def loadRedisTimeout( config: Config, path: String ): Option[ Option[ FiniteDuration ] ] = {
config.getNullable( path / "redis-timeout", _.getDuration ).map {
Expand Down
4 changes: 0 additions & 4 deletions src/test/scala/play/api/cache/redis/ExpirationSpecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class ExpirationSpecs extends Specification {
new Date( expireAt.getMillis ).asExpiration must beBetween( expirationFrom, expirationTo )
}

"from org.joda.time.DateTime (deprecated)" in {
expireAt.asExpiration must beBetween( expirationFrom, expirationTo )
}

"from java.time.LocalDateTime" in {
import java.time._
LocalDateTime.ofInstant( expireAt.toInstant.toDate.toInstant, ZoneId.systemDefault() ).asExpiration must beBetween( expirationFrom, expirationTo )
Expand Down
31 changes: 11 additions & 20 deletions src/test/scala/play/api/cache/redis/RedisCacheModuleSpecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,16 @@ class RedisCacheModuleSpecs extends Specification {
"bind named cache in simple mode" in new WithApplication with Scope with Around {
override protected def builder = super.builder.bindings( new RedisCacheModule )
def around[ T: AsResult ]( t: => T ): Result = runAndStop( t )( injector )

injector.instanceOf( binding[ CacheApi ].named( defaultCacheName ) ) must beAnInstanceOf[ CacheApi ]
injector.instanceOf( binding[ CacheApi ].namedCache( defaultCacheName ) ) must beAnInstanceOf[ CacheApi ]

injector.instanceOf( binding[ CacheAsyncApi ].named( defaultCacheName ) ) must beAnInstanceOf[ CacheAsyncApi ]
injector.instanceOf( binding[ CacheAsyncApi ].namedCache( defaultCacheName ) ) must beAnInstanceOf[ CacheAsyncApi ]

injector.instanceOf( binding[ play.cache.AsyncCacheApi ].named( defaultCacheName ) ) must beAnInstanceOf[ play.cache.AsyncCacheApi ]
injector.instanceOf( binding[ play.cache.AsyncCacheApi ].namedCache( defaultCacheName ) ) must beAnInstanceOf[ play.cache.AsyncCacheApi ]

injector.instanceOf( binding[ play.cache.SyncCacheApi ].named( defaultCacheName ) ) must beAnInstanceOf[ play.cache.SyncCacheApi ]
injector.instanceOf( binding[ play.cache.SyncCacheApi ].namedCache( defaultCacheName ) ) must beAnInstanceOf[ play.cache.SyncCacheApi ]

injector.instanceOf( binding[ play.api.cache.AsyncCacheApi ].named( defaultCacheName ) ) must beAnInstanceOf[ play.api.cache.AsyncCacheApi ]
injector.instanceOf( binding[ play.api.cache.AsyncCacheApi ].namedCache( defaultCacheName ) ) must beAnInstanceOf[ play.api.cache.AsyncCacheApi ]

injector.instanceOf( binding[ play.api.cache.SyncCacheApi ].named( defaultCacheName ) ) must beAnInstanceOf[ play.api.cache.SyncCacheApi ]
injector.instanceOf( binding[ play.api.cache.SyncCacheApi ].namedCache( defaultCacheName ) ) must beAnInstanceOf[ play.api.cache.SyncCacheApi ]
def checkBinding[ T <: AnyRef : ClassTag ] = {
injector.instanceOf( binding[ T ].namedCache( defaultCacheName ) ) must beAnInstanceOf[ T ]
}

checkBinding[ CacheApi ]
checkBinding[ CacheAsyncApi ]
checkBinding[ play.cache.AsyncCacheApi ]
checkBinding[ play.cache.SyncCacheApi ]
checkBinding[ play.api.cache.AsyncCacheApi ]
checkBinding[ play.api.cache.SyncCacheApi ]
}

"bind named caches" in new WithHocon with WithApplication with Scope with Around {
Expand Down Expand Up @@ -139,9 +131,9 @@ class RedisCacheModuleSpecs extends Specification {
}

object RedisCacheModuleSpecs {
import Implicits._
import play.api.cache.redis.configuration._
import play.cache.NamedCacheImpl
import Implicits._

class AnyProvider[ T ]( instance: => T ) extends Provider[ T ] {
lazy val get = instance
Expand All @@ -150,7 +142,6 @@ object RedisCacheModuleSpecs {
def binding[ T: ClassTag ]: BindingKey[ T ] = BindingKey( implicitly[ ClassTag[ T ] ].runtimeClass.asInstanceOf[ Class[ T ] ] )

implicit class RichBindingKey[ T ]( val key: BindingKey[ T ] ) {
def named( name: String ) = key.qualifiedWith( name )
def namedCache( name: String ) = key.qualifiedWith( new NamedCacheImpl( name ) )
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ class RedisTimeoutsSpecs extends Specification {
RedisTimeouts.load( config, "play.cache.redis" )( orDefault ) mustEqual RedisTimeouts( sync = 1.second, redis = None, connection = None )
}

"load deprecated timeout option" in new WithConfiguration(
"""
|play.cache.redis {
| timeout: 5s
|}
"""
) {
RedisTimeouts.load( config, "play.cache.redis" )( orDefault ) mustEqual RedisTimeouts( 5.second, None, 500.millis )
}

"load defaults" in {
RedisTimeouts.requiredDefault.sync must throwA[ RuntimeException ]
RedisTimeouts.requiredDefault.redis must beNone
Expand Down

0 comments on commit 8c778e3

Please sign in to comment.