diff --git a/.travis.yml b/.travis.yml index c308f00..a83c3a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,15 @@ group: edge matrix: include: - - jdk: oraclejdk8 - scala: 2.10.6 - env: COMMAND=ci PUBLISH= - jdk: oraclejdk8 scala: 2.11.11 env: COMMAND=ci PUBLISH= - jdk: oraclejdk8 scala: 2.12.3 env: COMMAND=ci PUBLISH=true + - jdk: oraclejdk8 + scala: 2.13.5 + env: COMMAND=ci PUBLISH=true env: global: diff --git a/README.md b/README.md index 20c8e35..4b7de48 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ architecture, choices that made sense in the context of Java, but don't make so much sense in the context of Scala (TODO: add details). The client is production quality. -Supported for Scala versions: 2.10, 2.11 and 2.12. +Supported for Scala versions: 2.11, 2.12 and 2.13. ## Release Notes diff --git a/build.sbt b/build.sbt index 2a30555..06bf9d9 100644 --- a/build.sbt +++ b/build.sbt @@ -4,8 +4,8 @@ organization := "io.monix" addCommandAlias("ci", ";clean ;compile ;test ;package") addCommandAlias("release", ";+publishSigned ;sonatypeReleaseAll") -scalaVersion := "2.11.11" -crossScalaVersions := Seq("2.10.6", "2.11.11", "2.12.3") +scalaVersion := "2.12.3" +crossScalaVersions := Seq("2.11.11", "2.12.3", "2.13.5") compileOrder in ThisBuild := CompileOrder.JavaThenScala scalacOptions ++= { @@ -16,8 +16,7 @@ scalacOptions ++= { "-deprecation", // emit warning for usages of deprecated APIs "-feature", // emit warning usages of features that should be imported explicitly // possibly deprecated options - "-Ywarn-dead-code", - "-Ywarn-inaccessible" + "-Ywarn-dead-code" ) CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, majorVersion)) if majorVersion >= 12 => baseOptions @@ -33,7 +32,6 @@ scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { "-Xlint:adapted-args", // warn if an argument list is modified to match the receiver "-Xlint:nullary-unit", // warn when nullary methods return Unit "-Xlint:inaccessible", // warn about inaccessible types in method signatures - "-Xlint:nullary-override", // warn when non-nullary `def f()' overrides nullary `def f' "-Xlint:infer-any", // warn when a type argument is inferred to be `Any` "-Xlint:missing-interpolator", // a string literal appears to be missing an interpolator id "-Xlint:doc-detached", // a ScalaDoc comment appears to be detached from its element @@ -42,28 +40,39 @@ scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { "-Xlint:poly-implicit-overload", // parameterized overloaded implicit methods are not visible as view bounds "-Xlint:option-implicit", // Option.apply used implicit view "-Xlint:delayedinit-select", // Selecting member of DelayedInit - "-Xlint:by-name-right-associative", // By-name parameter of right associative operator "-Xlint:package-object-classes", // Class or object defined in package object - "-Xlint:unsound-match" // Pattern match may not be typesafe ) case _ => Seq.empty }) +scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, majorVersion)) if majorVersion <= 12 => + Seq( + "-Ywarn-inaccessible", + "-Xlint:nullary-override", // warn when non-nullary `def f()' overrides nullary `def f' + "-Xlint:by-name-right-associative", // By-name parameter of right associative operator + "-Xlint:unsound-match" // Pattern match may not be typesafe + ) + case _ => Seq.empty +}) + // Turning off fatal warnings for ScalaDoc, otherwise we can't release. scalacOptions in (Compile, doc) ~= (_ filterNot (_ == "-Xfatal-warnings")) resolvers ++= Seq( - "Spy" at "http://files.couchbase.com/maven2/" + ("Spy" at "http://files.couchbase.com/maven2/").withAllowInsecureProtocol(true) ) libraryDependencies ++= Seq( - "net.spy" % "spymemcached" % "2.12.3", - "org.slf4j" % "slf4j-api" % "1.7.23", - "io.monix" %% "monix-eval" % "2.3.0", - "ch.qos.logback" % "logback-classic" % "1.1.7" % Test, - "org.scalatest" %% "scalatest" % "3.0.1" % Test, - "org.scalacheck" %% "scalacheck" % "1.13.4" % Test + "net.spy" % "spymemcached" % "2.12.3", + "org.slf4j" % "slf4j-api" % "1.7.30", + "io.monix" %% "monix-eval" % "3.3.0", + "ch.qos.logback" % "logback-classic" % "1.2.3" % Test, + "org.scalatest" %% "scalatest" % "3.2.6" % Test, + "org.scalatest" %% "scalatest-funsuite" % "3.2.6" % Test, + "org.scalacheck" %% "scalacheck" % "1.15.2" % Test, + "org.scalatestplus" %% "scalacheck-1-14" % "3.2.2.0" % Test ) libraryDependencies += ("org.scala-lang" % "scala-reflect" % scalaVersion.value % "compile") @@ -120,7 +129,7 @@ publishTo := Some( publishArtifact in Test := false pomIncludeRepository := { _ => false } // removes optional dependencies -scalariformSettings +scalariformSettings(true) licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")) homepage := Some(url("https://github.com/monix/shade")) diff --git a/project/build.properties b/project/build.properties index 96ee9fb..14ad00c 100644 --- a/project/build.properties +++ b/project/build.properties @@ -9,4 +9,4 @@ # https://github.com/monix/shade/blob/master/LICENSE.txt # -sbt.version=0.13.15 +sbt.version=1.4.6 diff --git a/project/plugins.sbt b/project/plugins.sbt index a29f8ca..6165184 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ resolvers += Classpaths.sbtPluginReleases -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.1") -addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0") -addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.18") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.1.1") +addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3") +addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.5") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.7") +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") diff --git a/src/main/scala/shade/inmemory/InMemoryCache.scala b/src/main/scala/shade/inmemory/InMemoryCache.scala index 2d0d64e..17e737a 100644 --- a/src/main/scala/shade/inmemory/InMemoryCache.scala +++ b/src/main/scala/shade/inmemory/InMemoryCache.scala @@ -54,7 +54,7 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e private[this] val scheduler = Scheduler(ec) def get[T](key: String): Option[T] = { - val currentState = stateRef.get + val currentState = stateRef.get() currentState.values.get(key) match { case Some(value) if value.expiresAt > System.currentTimeMillis() => @@ -74,7 +74,7 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e def add[T](key: String, value: T, expiry: Duration = Duration.Inf): Boolean = { val ts = getExpiryTS(expiry) val currentTS = System.currentTimeMillis() - val currentState = stateRef.get + val currentState = stateRef.get() val itemExists = currentState.values.get(key) match { case Some(item) if item.expiresAt > currentTS => @@ -109,7 +109,7 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e @tailrec def delete(key: String): Boolean = { - val currentState = stateRef.get + val currentState = stateRef.get() currentState.values.get(key) match { case Some(value) => @@ -127,7 +127,7 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e @tailrec def cachedFuture[T](key: String, expiry: Duration = Duration.Inf)(cb: => Future[T]): Future[T] = { - val currentState = stateRef.get + val currentState = stateRef.get() val currentValue = currentState.values.get(key) match { case Some(value) if value.expiresAt > System.currentTimeMillis() => @@ -157,7 +157,7 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e } def compareAndSet[T](key: String, expected: Option[T], update: T, expiry: Duration): Boolean = { - val current = stateRef.get + val current = stateRef.get() val ts = getExpiryTS(expiry) val currentValue = current.values.get(key) match { @@ -239,10 +239,10 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e def size: Int = { val ts = System.currentTimeMillis() - stateRef.get.values.count(_._2.expiresAt <= ts) + stateRef.get().values.count(_._2.expiresAt <= ts) } - def realSize: Int = stateRef.get.values.size + def realSize: Int = stateRef.get().values.size /** * Future that completes when a maintenance window has run, @@ -250,7 +250,7 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e * @return */ def maintenance: Future[Int] = - stateRef.get.maintenancePromise.future + stateRef.get().maintenancePromise.future def close(): Unit = { Try(task.cancel()) @@ -259,7 +259,7 @@ private[inmemory] final class InMemoryCacheImpl(implicit ec: ExecutionContext) e } protected def getExpiryTS(expiry: Duration): Long = - if (expiry.isFinite()) + if (expiry.isFinite) System.currentTimeMillis() + expiry.toMillis else System.currentTimeMillis() + 365.days.toMillis diff --git a/src/main/scala/shade/memcached/Codec.scala b/src/main/scala/shade/memcached/Codec.scala index 74994c2..9a3e149 100644 --- a/src/main/scala/shade/memcached/Codec.scala +++ b/src/main/scala/shade/memcached/Codec.scala @@ -37,8 +37,7 @@ trait BaseCodecs { (value >>> 24).asInstanceOf[Byte], (value >>> 16).asInstanceOf[Byte], (value >>> 8).asInstanceOf[Byte], - value.asInstanceOf[Byte] - ) + value.asInstanceOf[Byte]) def deserialize(data: Array[Byte]): Int = (data(0).asInstanceOf[Int] & 255) << 24 | @@ -83,8 +82,7 @@ trait BaseCodecs { (value >>> 24).asInstanceOf[Byte], (value >>> 16).asInstanceOf[Byte], (value >>> 8).asInstanceOf[Byte], - value.asInstanceOf[Byte] - ) + value.asInstanceOf[Byte]) def deserialize(data: Array[Byte]): Long = (data(0).asInstanceOf[Long] & 255) << 56 | @@ -108,8 +106,7 @@ trait BaseCodecs { implicit object CharBinaryCodec extends Codec[Char] { def serialize(value: Char): Array[Byte] = Array( (value >>> 8).asInstanceOf[Byte], - value.asInstanceOf[Byte] - ) + value.asInstanceOf[Byte]) def deserialize(data: Array[Byte]): Char = ((data(0).asInstanceOf[Int] & 255) << 8 | @@ -120,8 +117,7 @@ trait BaseCodecs { implicit object ShortBinaryCodec extends Codec[Short] { def serialize(value: Short): Array[Byte] = Array( (value >>> 8).asInstanceOf[Byte], - value.asInstanceOf[Byte] - ) + value.asInstanceOf[Byte]) def deserialize(data: Array[Byte]): Short = ((data(0).asInstanceOf[Short] & 255) << 8 | @@ -153,8 +149,8 @@ trait GenericCodec { } def serialize(value: S): Array[Byte] = - using (new ByteArrayOutputStream()) { buf => - using (new ObjectOutputStream(buf)) { out => + using(new ByteArrayOutputStream()) { buf => + using(new ObjectOutputStream(buf)) { out => out.writeObject(value) out.close() buf.toByteArray @@ -162,9 +158,9 @@ trait GenericCodec { } def deserialize(data: Array[Byte]): S = - using (new ByteArrayInputStream(data)) { buf => + using(new ByteArrayInputStream(data)) { buf => val in = new GenericCodecObjectInputStream(classTag, buf) - using (in) { inp => + using(in) { inp => inp.readObject().asInstanceOf[S] } } diff --git a/src/main/scala/shade/memcached/FakeMemcached.scala b/src/main/scala/shade/memcached/FakeMemcached.scala index f15411a..273105a 100644 --- a/src/main/scala/shade/memcached/FakeMemcached.scala +++ b/src/main/scala/shade/memcached/FakeMemcached.scala @@ -67,8 +67,8 @@ class FakeMemcached(context: ExecutionContext) extends Memcached { def increment(key: String, by: Long, default: Option[Long], exp: Duration): Future[Long] = { def toBigInt(bytes: Seq[Byte]): BigInt = BigInt(new String(bytes.toArray)) Future.successful(cache.transformAndGet[Seq[Byte]](key, exp) { - case Some(current) => (toBigInt(current) + by).toString.getBytes - case None if default.isDefined => default.get.toString.getBytes + case Some(current) => (toBigInt(current) + by).toString.getBytes.toIndexedSeq + case None if default.isDefined => default.get.toString.getBytes.toIndexedSeq case None => throw new UnhandledStatusException(s"For key $key - CASNotFoundStatus") }).map(toBigInt).map(_.toLong) } @@ -76,8 +76,8 @@ class FakeMemcached(context: ExecutionContext) extends Memcached { def decrement(key: String, by: Long, default: Option[Long], exp: Duration): Future[Long] = { def toBigInt(bytes: Seq[Byte]): BigInt = BigInt(new String(bytes.toArray)) Future.successful(cache.transformAndGet[Seq[Byte]](key, exp) { - case Some(current) => (toBigInt(current) - by).max(0).toString.getBytes - case None if default.isDefined => default.get.toString.getBytes + case Some(current) => (toBigInt(current) - by).max(0).toString.getBytes.toIndexedSeq + case None if default.isDefined => default.get.toString.getBytes.toIndexedSeq case None => throw new UnhandledStatusException(s"For key $key - CASNotFoundStatus") }).map(toBigInt).map(_.toLong) } diff --git a/src/main/scala/shade/memcached/GenericCodecObjectInputStream.scala b/src/main/scala/shade/memcached/GenericCodecObjectInputStream.scala index 6ed242b..0b616c8 100644 --- a/src/main/scala/shade/memcached/GenericCodecObjectInputStream.scala +++ b/src/main/scala/shade/memcached/GenericCodecObjectInputStream.scala @@ -26,7 +26,7 @@ import scala.util.control.NonFatal * Play's test/run modes. */ class GenericCodecObjectInputStream(classTag: ClassTag[_], in: InputStream) - extends ObjectInputStream(in) { + extends ObjectInputStream(in) { private def classTagClassLoader = classTag.runtimeClass.getClassLoader diff --git a/src/main/scala/shade/memcached/Memcached.scala b/src/main/scala/shade/memcached/Memcached.scala index 1ff4e21..7e06f5f 100644 --- a/src/main/scala/shade/memcached/Memcached.scala +++ b/src/main/scala/shade/memcached/Memcached.scala @@ -40,7 +40,7 @@ trait Memcached extends java.io.Closeable { */ def set[T](key: String, value: T, exp: Duration)(implicit codec: Codec[T]): CancelableFuture[Unit] - def awaitSet[T](key: String, value: T, exp: Duration)(implicit codec: Codec[T]) { + def awaitSet[T](key: String, value: T, exp: Duration)(implicit codec: Codec[T]): Unit = { Await.result(set(key, value, exp), Duration.Inf) } diff --git a/src/main/scala/shade/memcached/MemcachedImpl.scala b/src/main/scala/shade/memcached/MemcachedImpl.scala index ab7de5d..2f6a90b 100644 --- a/src/main/scala/shade/memcached/MemcachedImpl.scala +++ b/src/main/scala/shade/memcached/MemcachedImpl.scala @@ -300,8 +300,7 @@ class MemcachedImpl(config: Configuration, ec: ExecutionContext) extends Memcach throw new CancelledException(withoutPrefix(k)) case FailedResult(k, unhandled) => throw new UnhandledStatusException( - s"For key ${withoutPrefix(k)} - ${unhandled.getClass.getName}" - ) + s"For key ${withoutPrefix(k)} - ${unhandled.getClass.getName}") } @inline @@ -324,8 +323,7 @@ class MemcachedImpl(config: Configuration, ec: ExecutionContext) extends Memcach if (System.getProperty("net.spy.log.LoggerImpl") == null) { System.setProperty( "net.spy.log.LoggerImpl", - "shade.memcached.internals.Slf4jLogger" - ) + "shade.memcached.internals.Slf4jLogger") } val conn = { @@ -334,8 +332,7 @@ class MemcachedImpl(config: Configuration, ec: ExecutionContext) extends Memcach if (config.protocol == Protocol.Binary) SpyProtocol.BINARY else - SpyProtocol.TEXT - ) + SpyProtocol.TEXT) .setDaemon(true) .setFailureMode(config.failureMode match { case FailureMode.Retry => @@ -369,9 +366,7 @@ class MemcachedImpl(config: Configuration, ec: ExecutionContext) extends Memcach withTimeoutThreshold.setAuthDescriptor( new AuthDescriptor( Array("PLAIN"), - new PlainCallbackHandler(credentials.username, credentials.password) - ) - ) + new PlainCallbackHandler(credentials.username, credentials.password))) case None => withTimeoutThreshold } @@ -379,9 +374,9 @@ class MemcachedImpl(config: Configuration, ec: ExecutionContext) extends Memcach withAuth } - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ val addresses = AddrUtil.getAddresses(config.addresses).asScala - new SpyMemcachedIntegration(conn.build(), addresses, Scheduler(context)) + new SpyMemcachedIntegration(conn.build(), addresses.toSeq, Scheduler(context)) } } diff --git a/src/main/scala/shade/memcached/internals/PartialResult.scala b/src/main/scala/shade/memcached/internals/PartialResult.scala index ac36c55..7405e56 100644 --- a/src/main/scala/shade/memcached/internals/PartialResult.scala +++ b/src/main/scala/shade/memcached/internals/PartialResult.scala @@ -29,11 +29,11 @@ final class MutablePartialResult[T] { _result.compareAndSet(NoResultAvailable, FutureResult(result)) def completePromise(key: String, promise: Promise[Result[T]]): Unit = { - _result.get match { + _result.get() match { case FinishedResult(result) => promise.tryComplete(result) case FutureResult(result) => - promise.tryCompleteWith(result) + promise.completeWith(result) case NoResultAvailable => promise.tryComplete(Success(FailedResult(key, IllegalCompleteStatus))) } diff --git a/src/main/scala/shade/memcached/internals/SpyMemcachedIntegration.scala b/src/main/scala/shade/memcached/internals/SpyMemcachedIntegration.scala index 41d49f9..9791916 100644 --- a/src/main/scala/shade/memcached/internals/SpyMemcachedIntegration.scala +++ b/src/main/scala/shade/memcached/internals/SpyMemcachedIntegration.scala @@ -23,7 +23,7 @@ import net.spy.memcached.compat.SpyObject import net.spy.memcached.ops._ import shade.UnhandledStatusException -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.duration.{ Duration, FiniteDuration } import scala.concurrent.{ ExecutionContext, Promise } import scala.util.control.NonFatal @@ -37,7 +37,7 @@ import scala.util.{ Failure, Success, Try } * @param scheduler is for making timeouts work */ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddress], scheduler: Scheduler) - extends SpyObject with ConnectionObserver { + extends SpyObject with ConnectionObserver { require(cf != null, "Invalid connection factory") require(addrs != null && addrs.nonEmpty, "Invalid addresses list") @@ -67,7 +67,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val rv = mconn.addObserver(obs) if (rv) - for (node <- mconn.getLocator.getAll.asScala) + for (node <- mconn.getLocator.getAll().asScala) if (node.isActive) obs.connectionEstablished(node.getSocketAddress, -1) rv @@ -105,11 +105,11 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val blatch: CountDownLatch = broadcastOp(new BroadcastOpFactory { def newOp(n: MemcachedNode, latch: CountDownLatch): Operation = { opFact.noop(new OperationCallback { - def complete() { + def complete(): Unit = { latch.countDown() } - def receivedStatus(s: OperationStatus) {} + def receivedStatus(s: OperationStatus): Unit = {} }) } }, mconn.getLocator.getAll, checkShuttingDown = false) @@ -132,13 +132,13 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres * Broadcast an operation to a specific collection of nodes. */ private def broadcastOp(of: BroadcastOpFactory, nodes: java.util.Collection[MemcachedNode], checkShuttingDown: Boolean): CountDownLatch = { - if (checkShuttingDown && shuttingDown.get) + if (checkShuttingDown && shuttingDown.get()) throw new IllegalStateException("Shutting down") mconn.broadcastOperation(of, nodes) } private def findNode(sa: SocketAddress): MemcachedNode = { - val node = mconn.getLocator.getAll.asScala.find(_.getSocketAddress == sa) + val node = mconn.getLocator.getAll().asScala.find(_.getSocketAddress == sa) assert(node.isDefined, s"Couldn't find node connected to $sa") node.get } @@ -153,7 +153,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres def shutdown(timeout: Long, unit: TimeUnit): Boolean = { // Guard against double shutdowns (bug 8). if (!shuttingDown.compareAndSet(expect = false, update = true)) { - getLogger.info("Suppressing duplicate attempt to shut down") + getLogger.info("Suppressing duplicate attempt to shut down", Nil) false } else { val baseName: String = mconn.getName @@ -183,7 +183,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val result = new MutablePartialResult[Option[Array[Byte]]] val op: GetOperation = opFact.get(key, new GetOperation.Callback { - def receivedStatus(opStatus: OperationStatus) { + def receivedStatus(opStatus: OperationStatus): Unit = { handleStatus(opStatus, key, result) { case CASNotFoundStatus => result.tryComplete(Success(SuccessfulResult(key, None))) @@ -191,12 +191,12 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres } } - def gotData(k: String, flags: Int, data: Array[Byte]) { + def gotData(k: String, flags: Int, data: Array[Byte]): Unit = { assert(key == k, "Wrong key returned") result.tryComplete(Success(SuccessfulResult(key, Option(data)))) } - def complete() { + def complete(): Unit = { result.completePromise(key, promise) } }) @@ -210,17 +210,17 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val result = new MutablePartialResult[Long] val op: Operation = opFact.store(StoreType.set, key, flags, expiryToSeconds(exp).toInt, data, new StoreOperation.Callback { - def receivedStatus(opStatus: OperationStatus) { + def receivedStatus(opStatus: OperationStatus): Unit = { handleStatus(opStatus, key, result) { case CASSuccessStatus => } } - def gotData(key: String, cas: Long) { + def gotData(key: String, cas: Long): Unit = { result.tryComplete(Success(SuccessfulResult(key, cas))) } - def complete() { + def complete(): Unit = { result.completePromise(key, promise) } }) @@ -234,7 +234,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val result = new MutablePartialResult[Option[Long]] val op: Operation = opFact.store(StoreType.add, key, flags, expiryToSeconds(exp).toInt, data, new StoreOperation.Callback { - def receivedStatus(opStatus: OperationStatus) { + def receivedStatus(opStatus: OperationStatus): Unit = { handleStatus(opStatus, key, result) { case CASExistsStatus => result.tryComplete(Success(SuccessfulResult(key, None))) @@ -242,11 +242,11 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres } } - def gotData(key: String, cas: Long) { + def gotData(key: String, cas: Long): Unit = { result.tryComplete(Success(SuccessfulResult(key, Some(cas)))) } - def complete() { + def complete(): Unit = { result.completePromise(key, promise) } }) @@ -262,11 +262,11 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val op = opFact.delete(key, new DeleteOperation.Callback { def gotData(cas: Long): Unit = () - def complete() { + def complete(): Unit = { result.completePromise(key, promise) } - def receivedStatus(opStatus: OperationStatus) { + def receivedStatus(opStatus: OperationStatus): Unit = { handleStatus(opStatus, key, result) { case CASSuccessStatus => result.tryComplete(Success(SuccessfulResult(key, true))) @@ -285,7 +285,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val result = new MutablePartialResult[Option[(Array[Byte], Long)]] val op: Operation = opFact.gets(key, new GetsOperation.Callback { - def receivedStatus(opStatus: OperationStatus) { + def receivedStatus(opStatus: OperationStatus): Unit = { handleStatus(opStatus, key, result) { case CASNotFoundStatus => result.tryComplete(Success(SuccessfulResult(key, None))) @@ -293,7 +293,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres } } - def gotData(receivedKey: String, flags: Int, cas: Long, data: Array[Byte]) { + def gotData(receivedKey: String, flags: Int, cas: Long, data: Array[Byte]): Unit = { assert(key == receivedKey, "Wrong key returned") assert(cas > 0, s"CAS was less than zero: $cas") @@ -302,7 +302,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres }) } - def complete() { + def complete(): Unit = { result.completePromise(key, promise) } }) @@ -316,7 +316,7 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres val result = new MutablePartialResult[Boolean] val op = opFact.cas(StoreType.set, key, casID, flags, expiryToSeconds(exp).toInt, data, new StoreOperation.Callback { - def receivedStatus(opStatus: OperationStatus) { + def receivedStatus(opStatus: OperationStatus): Unit = { handleStatus(opStatus, key, result) { case CASSuccessStatus => result.tryComplete(Success(SuccessfulResult(key, true))) @@ -327,11 +327,11 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres } } - def gotData(k: String, cas: Long) { + def gotData(k: String, cas: Long): Unit = { assert(key == k, "Wrong key returned") } - def complete() { + def complete(): Unit = { result.completePromise(key, promise) } }) @@ -350,14 +350,14 @@ class SpyMemcachedIntegration(cf: ConnectionFactory, addrs: Seq[InetSocketAddres } val op: Operation = opFact.mutate(mutator, key, by, default.getOrElse(0L), expiry, new OperationCallback { - def receivedStatus(opStatus: OperationStatus) { + def receivedStatus(opStatus: OperationStatus): Unit = { handleStatus(opStatus, key, result) { case CASSuccessStatus => result.tryComplete(Success(SuccessfulResult(key, opStatus.getMessage.toLong))) } } - def complete() { + def complete(): Unit = { result.completePromise(key, promise) } }) diff --git a/src/test/scala/shade/memcached/internals/MutablePartialResultSuite.scala b/src/test/scala/shade/memcached/internals/MutablePartialResultSuite.scala index dd24a2d..d79bf38 100644 --- a/src/test/scala/shade/memcached/internals/MutablePartialResultSuite.scala +++ b/src/test/scala/shade/memcached/internals/MutablePartialResultSuite.scala @@ -11,16 +11,16 @@ package shade.memcached.internals -import org.scalatest.FunSuite +import org.scalatest.funsuite.AnyFunSuite import org.scalatest.concurrent.{ IntegrationPatience, ScalaFutures } import scala.concurrent.{ Future, Promise } import scala.util.Success class MutablePartialResultSuite - extends FunSuite - with ScalaFutures - with IntegrationPatience { + extends AnyFunSuite + with ScalaFutures + with IntegrationPatience { def assertCompletePromise(toCheck: MutablePartialResult[Boolean], expected: Boolean): Unit = { val promise = Promise[Result[Boolean]]() @@ -66,4 +66,4 @@ class MutablePartialResultSuite assertCompletePromise(toCheck = pResult, expected = false) } -} \ No newline at end of file +} diff --git a/src/test/scala/shade/testModels/Offer.scala b/src/test/scala/shade/testModels/Offer.scala index 7450a3f..b4773d3 100644 --- a/src/test/scala/shade/testModels/Offer.scala +++ b/src/test/scala/shade/testModels/Offer.scala @@ -14,26 +14,26 @@ package shade.testModels import java.util.UUID case class Offer( - id: Option[Int], - name: String, + id: Option[Int], + name: String, - advertiser: Advertiser, - offerType: String, + advertiser: Advertiser, + offerType: String, - liveDeal: LiveDealInfo, - creative: OfferCreative, + liveDeal: LiveDealInfo, + creative: OfferCreative, - deliveryMechanisms: Seq[String], + deliveryMechanisms: Seq[String], - servedURL: String, - realURL: Option[String], + servedURL: String, + realURL: Option[String], - // is_active and is_valid - isRunning: Boolean, - isDynamic: Boolean, - isGlobal: Boolean, + // is_active and is_valid + isRunning: Boolean, + isDynamic: Boolean, + isGlobal: Boolean, - countries: Seq[String]) { + countries: Seq[String]) { def uniqueToken = { val token = id.toString + "-" + advertiser.serviceID + diff --git a/src/test/scala/shade/testModels/package.scala b/src/test/scala/shade/testModels/package.scala index d235447..e7e1640 100644 --- a/src/test/scala/shade/testModels/package.scala +++ b/src/test/scala/shade/testModels/package.scala @@ -35,18 +35,14 @@ package object testModels { Some(703), None, Some("VA"), - Some(511) - ) - ) - ), + Some(511)))), Some("aac636be-e42b-01d6-449b-6a0c2e5e7b09"), Some("something-65"), Some("71.89.145.102"), None, None, - Some("us") - ), + Some("us")), List( Offer( Some(3352251), @@ -54,38 +50,32 @@ package object testModels { Advertiser( Some(137), Some("something"), - "something" - ), + "something"), "cpa", LiveDealInfo( Some(""), None, None, - None - ), + None), OfferCreative( "So Many Dresses!", "Daily Deals For Moms, Babies and Kids. Up to 90% OFF! Shop Now!", Some("Something.com"), Some(""), - None - ), + None), - ArrayBuffer("viewnow"), + ArrayBuffer("viewnow").toSeq, "http://something.com/track?clickID=242323&pubID=982345&something=219&subID=something", None, true, false, false, - List("us") - ) - ), + List("us"))), 112, true, - Some("light-fullscreen") - ) + Some("light-fullscreen")) val bigInstance2 = Impression( "96298b14-1e13-a162-662b-969bd3b41ca4", @@ -108,23 +98,18 @@ package object testModels { Some(703), None, Some("VA"), - Some(511) - ) - ) - ), + Some(511)))), Some("aac636be-e42b-01d6-449b-6a0c2e5e7b09"), Some("something-65"), Some("71.89.145.102"), None, None, - Some("us") - ), + Some("us")), List.empty, 112, true, - Some("light-fullscreen") - ) + Some("light-fullscreen")) val contentSeq = Vector( ContentPiece.Article( @@ -136,8 +121,7 @@ package object testModels { excerptHtml = "Hello world", contentHtml = Some("