From 9cc5d91fdd0aa23a328fb2092576a1681d0bce5b Mon Sep 17 00:00:00 2001 From: Karel Cemus Date: Sun, 5 May 2024 16:26:16 +0200 Subject: [PATCH] Scala 3 fixes --- .../api/cache/redis/connector/RedisClientFactory.scala | 10 ++++++---- .../api/cache/redis/connector/RedisConnectorImpl.scala | 6 +++--- ...ommandsMock.java => AbstractRedisCommandsMock.java} | 2 +- .../api/cache/redis/connector/RedisCommandsMock.scala | 3 +++ .../redis/connector/RedisConnectorFailureSpec.scala | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) rename src/test/java/play/api/cache/redis/connector/{RedisCommandsMock.java => AbstractRedisCommandsMock.java} (97%) create mode 100644 src/test/scala/play/api/cache/redis/connector/RedisCommandsMock.scala diff --git a/src/main/scala/play/api/cache/redis/connector/RedisClientFactory.scala b/src/main/scala/play/api/cache/redis/connector/RedisClientFactory.scala index 59e89a4..7c79d9b 100644 --- a/src/main/scala/play/api/cache/redis/connector/RedisClientFactory.scala +++ b/src/main/scala/play/api/cache/redis/connector/RedisClientFactory.scala @@ -147,12 +147,14 @@ private object RedisClientFactory { @SuppressWarnings(Array("org.wartremover.warts.IsInstanceOf")) override def afterChannelInitialized(channel: Channel): Unit = { - channel.pipeline.addLast(new IdleStateHandler(afterChannelTime, 0, 0)): Unit - channel.pipeline.addLast(new ChannelDuplexHandler() { + val _ = channel.pipeline.addLast(new IdleStateHandler(afterChannelTime, 0, 0)) + val _ =channel.pipeline.addLast(new ChannelDuplexHandler() { @throws[Exception] override def userEventTriggered(ctx: ChannelHandlerContext, evt: Object): Unit = - if (evt.isInstanceOf[IdleStateEvent]) ctx.disconnect().sync(): Unit - }): Unit + if (evt.isInstanceOf[IdleStateEvent]) { + val _ = ctx.disconnect().sync() + } + }) } }, diff --git a/src/main/scala/play/api/cache/redis/connector/RedisConnectorImpl.scala b/src/main/scala/play/api/cache/redis/connector/RedisConnectorImpl.scala index ee61832..dc03941 100644 --- a/src/main/scala/play/api/cache/redis/connector/RedisConnectorImpl.scala +++ b/src/main/scala/play/api/cache/redis/connector/RedisConnectorImpl.scala @@ -91,8 +91,8 @@ private[connector] class RedisConnectorImpl( key, value, new SetArgs() - .when(expiration.isFinite, _.px(expiration.toMillis)) - .when(ifNotExists, _.nx()), + .mapWhen(expiration.isFinite, _.px(expiration.toMillis)) + .mapWhen(ifNotExists, _.nx()), ) .toScala[Option[String]] .map(_ contains "OK") @@ -485,7 +485,7 @@ private[connector] object RedisConnectorImpl { implicit private class ConditionalCall[T](private val thiz: T) extends AnyVal { - def when(condition: Boolean, f: T => T): T = + def mapWhen(condition: Boolean, f: T => T): T = if (condition) f(thiz) // mutable side effect else thiz diff --git a/src/test/java/play/api/cache/redis/connector/RedisCommandsMock.java b/src/test/java/play/api/cache/redis/connector/AbstractRedisCommandsMock.java similarity index 97% rename from src/test/java/play/api/cache/redis/connector/RedisCommandsMock.java rename to src/test/java/play/api/cache/redis/connector/AbstractRedisCommandsMock.java index 1870905..4f2a713 100644 --- a/src/test/java/play/api/cache/redis/connector/RedisCommandsMock.java +++ b/src/test/java/play/api/cache/redis/connector/AbstractRedisCommandsMock.java @@ -6,7 +6,7 @@ import java.util.List; -public abstract class RedisCommandsMock implements RedisClusterAsyncCommands { +public abstract class AbstractRedisCommandsMock implements RedisClusterAsyncCommands { @Override final public RedisFuture set(String key, String value, SetArgs setArgs) { diff --git a/src/test/scala/play/api/cache/redis/connector/RedisCommandsMock.scala b/src/test/scala/play/api/cache/redis/connector/RedisCommandsMock.scala new file mode 100644 index 0000000..3990eb4 --- /dev/null +++ b/src/test/scala/play/api/cache/redis/connector/RedisCommandsMock.scala @@ -0,0 +1,3 @@ +package play.api.cache.redis.connector + +abstract class RedisCommandsMock extends AbstractRedisCommandsMock diff --git a/src/test/scala/play/api/cache/redis/connector/RedisConnectorFailureSpec.scala b/src/test/scala/play/api/cache/redis/connector/RedisConnectorFailureSpec.scala index b2a4a9f..7840599 100644 --- a/src/test/scala/play/api/cache/redis/connector/RedisConnectorFailureSpec.scala +++ b/src/test/scala/play/api/cache/redis/connector/RedisConnectorFailureSpec.scala @@ -314,7 +314,7 @@ class RedisConnectorFailureSpec extends AsyncUnitSpec with ImplicitFutureMateria @SuppressWarnings(Array("org.wartremover.warts.Equals")) override def equals(obj: Any): Boolean = obj match { - case that: Array[?] => that.length == expected.length && that.zip(expected).forall { case (a, b) => a == b } + case that: Array[?] => that.length == expected.length && expected.zip(that).forall { case (a, b) => a == b } case _ => false }