From ac615bc6714f36ad06d510bc610eadf09ce96012 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 20:39:19 +0530 Subject: [PATCH 01/13] Switch to Scala 2.12.7 Change all scala based libs to 2.12 --- common/scala/build.gradle | 26 +++++++++++++------------- core/controller/build.gradle | 6 +++--- settings.gradle | 6 +++--- tests/build.gradle | 8 ++++---- tools/admin/build.gradle | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/common/scala/build.gradle b/common/scala/build.gradle index c6eb0051c01..46d1b4b0e40 100644 --- a/common/scala/build.gradle +++ b/common/scala/build.gradle @@ -32,18 +32,18 @@ repositories { dependencies { compile "org.scala-lang:scala-library:${gradle.scala.version}" - compile 'com.github.pureconfig:pureconfig_2.11:0.9.0' - compile 'io.spray:spray-json_2.11:1.3.4' - compile 'com.lihaoyi:fastparse_2.11:1.0.0' + compile 'com.github.pureconfig:pureconfig_2.12:0.9.0' + compile 'io.spray:spray-json_2.12:1.3.4' + compile 'com.lihaoyi:fastparse_2.12:1.0.0' - compile 'com.typesafe.akka:akka-actor_2.11:2.5.12' - compile 'com.typesafe.akka:akka-stream_2.11:2.5.12' - compile 'com.typesafe.akka:akka-slf4j_2.11:2.5.12' + compile 'com.typesafe.akka:akka-actor_2.12:2.5.12' + compile 'com.typesafe.akka:akka-stream_2.12:2.5.12' + compile 'com.typesafe.akka:akka-slf4j_2.12:2.5.12' - compile 'com.typesafe.akka:akka-http-core_2.11:10.1.1' - compile 'com.typesafe.akka:akka-http-spray-json_2.11:10.1.1' + compile 'com.typesafe.akka:akka-http-core_2.12:10.1.1' + compile 'com.typesafe.akka:akka-http-spray-json_2.12:10.1.1' - compile 'com.lightbend.akka:akka-stream-alpakka-file_2.11:0.15' + compile 'com.lightbend.akka:akka-stream-alpakka-file_2.12:0.15' compile 'ch.qos.logback:logback-classic:1.2.3' compile 'org.slf4j:jcl-over-slf4j:1.7.25' @@ -61,8 +61,8 @@ dependencies { compile 'com.github.ben-manes.caffeine:caffeine:2.6.2' compile 'com.google.code.findbugs:jsr305:3.0.2' compile 'io.fabric8:kubernetes-client:4.0.3' - compile 'io.kamon:kamon-core_2.11:0.6.7' - compile 'io.kamon:kamon-statsd_2.11:0.6.7' + compile 'io.kamon:kamon-core_2.12:0.6.7' + compile 'io.kamon:kamon-statsd_2.12:0.6.7' //for mesos compile 'com.adobe.api.platform.runtime:mesos-actor:0.0.8' @@ -73,11 +73,11 @@ dependencies { compile 'io.zipkin.reporter2:zipkin-sender-okhttp3:2.6.1' compile 'io.zipkin.reporter2:zipkin-reporter:2.6.1' - compile 'io.reactivex:rxscala_2.11:0.26.5' + compile 'io.reactivex:rxscala_2.12:0.26.5' compile 'io.reactivex:rxjava-reactive-streams:1.2.1' compile 'com.microsoft.azure:azure-cosmosdb:2.1.0' - compile ('com.lightbend.akka:akka-stream-alpakka-s3_2.11:0.19') { + compile ('com.lightbend.akka:akka-stream-alpakka-s3_2.12:0.19') { exclude group: 'commons-logging' exclude group: 'org.apache.httpcomponents' //Not used as alpakka uses akka-http exclude group: 'com.fasterxml.jackson.core' diff --git a/core/controller/build.gradle b/core/controller/build.gradle index b7cfb8ead40..4ce950f1f9f 100644 --- a/core/controller/build.gradle +++ b/core/controller/build.gradle @@ -39,9 +39,9 @@ repositories { dependencies { compile "org.scala-lang:scala-library:${gradle.scala.version}" - compile 'com.lightbend.akka.management:akka-management-cluster-bootstrap_2.11:0.11.0' - compile 'com.lightbend.akka.discovery:akka-discovery-kubernetes-api_2.11:0.11.0' - compile 'com.lightbend.akka.discovery:akka-discovery-marathon-api_2.11:0.11.0' + compile 'com.lightbend.akka.management:akka-management-cluster-bootstrap_2.12:0.11.0' + compile 'com.lightbend.akka.discovery:akka-discovery-kubernetes-api_2.12:0.11.0' + compile 'com.lightbend.akka.discovery:akka-discovery-marathon-api_2.12:0.11.0' compile project(':common:scala') scoverage gradle.scoverage.deps } diff --git a/settings.gradle b/settings.gradle index dd605004bc9..ca9b7c089c9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -33,7 +33,7 @@ include 'tools:admin' rootProject.name = 'openwhisk' gradle.ext.scala = [ - version: '2.11.11', + version: '2.12.7', compileFlags: ['-feature', '-unchecked', '-deprecation', '-Xfatal-warnings', '-Ywarn-unused-import'] ] @@ -44,8 +44,8 @@ gradle.ext.scalafmt = [ gradle.ext.scoverage = [ deps: [ - 'org.scoverage:scalac-scoverage-plugin_2.11:1.3.1', - 'org.scoverage:scalac-scoverage-runtime_2.11:1.3.1' + 'org.scoverage:scalac-scoverage-plugin_2.12:1.3.1', + 'org.scoverage:scalac-scoverage-runtime_2.12:1.3.1' ] ] diff --git a/tests/build.gradle b/tests/build.gradle index 4be83cad58f..ba893520e82 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -152,11 +152,11 @@ dependencies { compile 'org.apache.httpcomponents:httpmime:4.3.6' compile 'junit:junit:4.11' compile 'com.jayway.restassured:rest-assured:2.6.0' - compile 'org.scalatest:scalatest_2.11:3.0.1' - compile 'com.typesafe.akka:akka-testkit_2.11:2.5.12' + compile 'org.scalatest:scalatest_2.12:3.0.1' + compile 'com.typesafe.akka:akka-testkit_2.12:2.5.12' compile 'com.google.code.gson:gson:2.3.1' - compile 'org.scalamock:scalamock-scalatest-support_2.11:3.4.2' - compile 'com.typesafe.akka:akka-http-testkit_2.11:10.1.1' + compile 'org.scalamock:scalamock-scalatest-support_2.12:3.4.2' + compile 'com.typesafe.akka:akka-http-testkit_2.12:10.1.1' compile 'com.github.java-json-tools:json-schema-validator:2.2.8' compile "org.mockito:mockito-core:2.15.0" compile 'io.opentracing:opentracing-mock:0.31.0' diff --git a/tools/admin/build.gradle b/tools/admin/build.gradle index 60fbf4ee38e..2284bad9ded 100644 --- a/tools/admin/build.gradle +++ b/tools/admin/build.gradle @@ -48,7 +48,7 @@ bootJar { dependencies { compile project(':common:scala') - compile 'org.rogach:scallop_2.11:3.1.2' + compile 'org.rogach:scallop_2.12:3.1.2' scoverage gradle.scoverage.deps } From 5f4398aabb48258eb2bbea75227bb1240dbe1c51 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 20:52:15 +0530 Subject: [PATCH 02/13] Perform explicit eta expansion to disambiguate passing method as function --- common/scala/src/main/scala/whisk/core/entity/Limits.scala | 2 +- .../src/main/scala/whisk/core/mesos/MesosContainerFactory.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/scala/src/main/scala/whisk/core/entity/Limits.scala b/common/scala/src/main/scala/whisk/core/entity/Limits.scala index 5937df7c74d..0e775e49940 100644 --- a/common/scala/src/main/scala/whisk/core/entity/Limits.scala +++ b/common/scala/src/main/scala/whisk/core/entity/Limits.scala @@ -82,5 +82,5 @@ protected[core] object ActionLimits extends ArgNormalizer[ActionLimits] with Def protected[core] object TriggerLimits extends ArgNormalizer[TriggerLimits] with DefaultJsonProtocol { - override protected[core] implicit val serdes = jsonFormat0(TriggerLimits.apply) + override protected[core] implicit val serdes = jsonFormat0(TriggerLimits.apply _) } diff --git a/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala b/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala index 474361a2e51..b29bbd82c70 100644 --- a/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala +++ b/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala @@ -76,7 +76,7 @@ class MesosContainerFactory(config: WhiskConfig, loadConfigOrThrow[ContainerArgsConfig](ConfigKeys.containerArgs), mesosConfig: MesosConfig = loadConfigOrThrow[MesosConfig](ConfigKeys.mesos), clientFactory: (ActorSystem, MesosConfig) => ActorRef = MesosContainerFactory.createClient, - taskIdGenerator: () => String = MesosContainerFactory.taskIdGenerator) + taskIdGenerator: () => String = MesosContainerFactory.taskIdGenerator _) extends ContainerFactory { val subscribeTimeout = 10.seconds From db9bd1fbefbb11f5ee6766e414b58a4532b63892 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 20:57:28 +0530 Subject: [PATCH 03/13] Ensure case match covers all cases for LogLevel --- common/scala/src/main/scala/whisk/common/Logging.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/common/scala/src/main/scala/whisk/common/Logging.scala b/common/scala/src/main/scala/whisk/common/Logging.scala index d0457f879cb..c61f059305c 100644 --- a/common/scala/src/main/scala/whisk/common/Logging.scala +++ b/common/scala/src/main/scala/whisk/common/Logging.scala @@ -111,6 +111,7 @@ class PrintStreamLogging(outputStream: PrintStream = Console.out) extends Loggin case InfoLevel => "INFO" case WarningLevel => "WARN" case ErrorLevel => "ERROR" + case LogLevel(_) => "UNKNOWN" } val logMessage = Seq(message).collect { From b70e2cd047a51262b398bfff01963a9b22b6425b Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 21:41:46 +0530 Subject: [PATCH 04/13] Use mesos-actor compiled with 2.12 --- common/scala/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/scala/build.gradle b/common/scala/build.gradle index 46d1b4b0e40..aa624290b91 100644 --- a/common/scala/build.gradle +++ b/common/scala/build.gradle @@ -64,7 +64,7 @@ dependencies { compile 'io.kamon:kamon-core_2.12:0.6.7' compile 'io.kamon:kamon-statsd_2.12:0.6.7' //for mesos - compile 'com.adobe.api.platform.runtime:mesos-actor:0.0.8' + compile 'com.adobe.api.platform.runtime:mesos-actor:0.0.8_2.12' //tracing support compile 'io.opentracing:opentracing-api:0.31.0' From 9cf1122a9b8542165d030b06f033f6aafb767ac7 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 21:47:15 +0530 Subject: [PATCH 05/13] Refactor use of deprecated future methods See https://viktorklang.com/blog/Futures-in-Scala-2.12-part-5.html --- .../core/database/CouchDbRestStore.scala | 4 ++-- .../whisk/core/database/StoreUtils.scala | 4 ++-- .../cosmosdb/CosmosDBArtifactStore.scala | 6 +++--- .../database/memory/MemoryArtifactStore.scala | 19 +++++++----------- .../core/database/s3/S3AttachmentStore.scala | 20 +++++++------------ .../BasicAuthenticationDirective.scala | 2 +- 6 files changed, 22 insertions(+), 33 deletions(-) diff --git a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala index 8518a953c12..49a62906b05 100644 --- a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala +++ b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala @@ -555,10 +555,10 @@ class CouchDbRestStore[DocumentAbstraction <: DocumentSerializer](dbProtocol: St } private def reportFailure[T, U](f: Future[T], onFailure: Throwable => U): Future[T] = { - f.onFailure({ + f.failed.foreach { case _: ArtifactStoreException => // These failures are intentional and shouldn't trigger the catcher. case x => onFailure(x) - }) + } f } } diff --git a/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala b/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala index d901fde769a..21ac05aa0c8 100644 --- a/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala +++ b/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala @@ -38,11 +38,11 @@ private[database] object StoreUtils { implicit transid: TransactionId, logging: Logging, ec: ExecutionContext): Future[T] = { - f.onFailure({ + f.failed.foreach { case _: ArtifactStoreException => // These failures are intentional and shouldn't trigger the catcher. case x => transid.failed(this, start, s"${failureMessage(x)} [${x.getClass.getSimpleName}]", ErrorLevel) - }) + } f } diff --git a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala index 24dc0400087..a03dd8e43da 100644 --- a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala +++ b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala @@ -238,9 +238,9 @@ class CosmosDBArtifactStore[DocumentAbstraction <: DocumentSerializer](protected .runWith(Sink.seq) .map(_.toList) - f.onSuccess({ - case out => transid.finished(this, start, s"[QUERY] '$collName' completed: matched ${out.size}") - }) + f.foreach { out => + transid.finished(this, start, s"[QUERY] '$collName' completed: matched ${out.size}") + } reportFailure(f, start, failure => s"[QUERY] '$collName' internal error, failure: '${failure.getMessage}'") } diff --git a/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala b/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala index f01064c181f..ae320cbe711 100644 --- a/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala +++ b/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala @@ -131,14 +131,13 @@ class MemoryArtifactStore[DocumentAbstraction <: DocumentSerializer](dbName: Str val f = Future.fromTry(t) - f.onFailure({ + f.failed.foreach { case _: DocumentConflictException => transid.finished(this, start, s"[PUT] '$dbName', document: '$docinfoStr'; conflict.") - }) + case _ => + } - f.onSuccess({ - case _ => transid.finished(this, start, s"[PUT] '$dbName' completed document: '$docinfoStr'") - }) + f.foreach(_ => transid.finished(this, start, s"[PUT] '$dbName' completed document: '$docinfoStr'")) reportFailure(f, start, failure => s"[PUT] '$dbName' internal error, failure: '${failure.getMessage}'") } @@ -239,9 +238,7 @@ class MemoryArtifactStore[DocumentAbstraction <: DocumentSerializer](dbName: Str }.toList val f = Future.sequence(r).map(_.flatten) - f.onSuccess({ - case _ => transid.finished(this, start, s"[QUERY] '$dbName' completed: matched ${out.size}") - }) + f.foreach(_ => transid.finished(this, start, s"[QUERY] '$dbName' completed: matched ${out.size}")) reportFailure(f, start, failure => s"[QUERY] '$dbName' internal error, failure: '${failure.getMessage}'") } @@ -270,10 +267,8 @@ class MemoryArtifactStore[DocumentAbstraction <: DocumentSerializer](dbName: Str } else { val storedName = attachmentUri.path.toString() val f = attachmentStore.readAttachment(doc.id, storedName, sink) - f.onSuccess { - case _ => - transid.finished(this, start, s"[ATT_GET] '$dbName' completed: found attachment '$name' of document '$doc'") - } + f.foreach(_ => + transid.finished(this, start, s"[ATT_GET] '$dbName' completed: found attachment '$name' of document '$doc'")) f } } diff --git a/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala b/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala index e02f49b8430..df9056e2845 100644 --- a/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala +++ b/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala @@ -87,11 +87,9 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic .runWith(combinedSink(client.multipartUpload(bucket, objectKey(docId, name), contentType))) .map(r => AttachResult(r.digest, r.length)) - f.onSuccess({ - case _ => - transid - .finished(this, start, s"[ATT_PUT] '$prefix' completed uploading attachment '$name' of document 'id: $docId'") - }) + f.foreach(_ => + transid + .finished(this, start, s"[ATT_PUT] '$prefix' completed uploading attachment '$name' of document 'id: $docId'")) reportFailure( f, @@ -147,10 +145,8 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic .runWith(Sink.seq) .map(_ => true) - f.onSuccess { - case _ => - transid.finished(this, start, s"[ATTS_DELETE] completed: deleting attachments of document 'id: $docId'") - } + f.foreach(_ => + transid.finished(this, start, s"[ATTS_DELETE] completed: deleting attachments of document 'id: $docId'")) reportFailure( f, @@ -167,10 +163,8 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic .deleteObject(bucket, objectKey(docId, name)) .map(_ => true) - f.onSuccess { - case _ => - transid.finished(this, start, s"[ATT_DELETE] completed: deleting attachment '$name' of document 'id: $docId'") - } + f.foreach(_ => + transid.finished(this, start, s"[ATT_DELETE] completed: deleting attachment '$name' of document 'id: $docId'")) reportFailure( f, diff --git a/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala b/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala index c0e06c5724c..83233ee5d30 100644 --- a/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala +++ b/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala @@ -53,7 +53,7 @@ object BasicAuthenticationDirective extends AuthenticationDirectiveProvider { logging.debug(this, s"authentication not valid") None } - future onFailure { case t => logging.error(this, s"authentication error: $t") } + future.failed.foreach(t => logging.error(this, s"authentication error: $t")) future }.toOption } getOrElse { From 28f30bc398b2a7ecdeffe5585deb4cc36a3a31fb Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 21:50:20 +0530 Subject: [PATCH 06/13] Perform explicit eta expansion to disambiguate passing method as function --- .../mesos/test/MesosContainerFactoryTest.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala b/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala index d5187ed833b..6500859f7ce 100644 --- a/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala +++ b/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala @@ -127,7 +127,7 @@ class MesosContainerFactoryTest containerArgsConfig, mesosConfig, (_, _) => testActor, - testTaskId) + testTaskId _) expectMsg(Subscribe) factory.createContainer( @@ -173,7 +173,7 @@ class MesosContainerFactoryTest containerArgsConfig, mesosConfig, (system, mesosConfig) => probe.testActor, - testTaskId) + testTaskId _) probe.expectMsg(Subscribe) //emulate successful subscribe @@ -244,7 +244,7 @@ class MesosContainerFactoryTest new ContainerArgsConfig("bridge", Seq.empty, Map("extra1" -> Set("e1", "e2"), "extra2" -> Set("e3", "e4"))), mesosConfig, (system, mesosConfig) => probe.testActor, - testTaskId) + testTaskId _) probe.expectMsg(Subscribe) //emulate successful subscribe From 8f0ca531d1518c81d5a5758e2c4e07b8d091b36d Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 23:13:12 +0530 Subject: [PATCH 07/13] Remove unused imports --- tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala b/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala index 7569ffc4e0a..72458504c01 100644 --- a/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala +++ b/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala @@ -21,7 +21,6 @@ import java.util.Base64 import scala.concurrent.duration.DurationInt import scala.language.postfixOps -import scala.language.reflectiveCalls import scala.util.Failure import scala.util.Try import org.junit.runner.RunWith From b24dfb6d64f72db00f1e48f2b4a803e5fac0db31 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 23:40:14 +0530 Subject: [PATCH 08/13] Resolve ambiguity between gloabl and local execution context https://stackoverflow.com/questions/40442717/implicit-executioncontext-priority-in-scala-2-12 --- tests/src/test/scala/actionContainers/ActionContainer.scala | 1 - .../core/containerpool/docker/test/ProcessRunnerTests.scala | 1 - .../kubernetes/test/KubernetesClientTests.scala | 6 +++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/src/test/scala/actionContainers/ActionContainer.scala b/tests/src/test/scala/actionContainers/ActionContainer.scala index 153b6d2e724..d5826596667 100644 --- a/tests/src/test/scala/actionContainers/ActionContainer.scala +++ b/tests/src/test/scala/actionContainers/ActionContainer.scala @@ -240,7 +240,6 @@ object ActionContainer { } private def concurrentSyncPost(host: String, port: Int, endPoint: String, contents: Seq[JsValue])( implicit logging: Logging, - ec: ExecutionContext, as: ActorSystem): Seq[(Int, Option[JsObject])] = { implicit val transid = TransactionId.testing diff --git a/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala b/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala index 4527373ff7d..519e0006c9f 100644 --- a/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala +++ b/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala @@ -25,7 +25,6 @@ import org.junit.runner.RunWith import org.scalatest.FlatSpec import org.scalatest.junit.JUnitRunner -import scala.concurrent.ExecutionContext.Implicits.global import whisk.core.containerpool.docker._ import scala.concurrent.ExecutionContext diff --git a/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala b/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala index 3336e831b15..78f2d8a9065 100644 --- a/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala +++ b/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala @@ -26,7 +26,6 @@ import akka.stream.scaladsl.{Concat, Sink, Source} import scala.concurrent.Await import scala.concurrent.ExecutionContext -import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.concurrent.duration._ import org.junit.runner.RunWith @@ -79,7 +78,7 @@ class KubernetesClientTests /** Returns a KubernetesClient with a mocked result for 'executeProcess' */ def kubernetesClient(fixture: => Future[String]) = { - new KubernetesClient()(global) { + new KubernetesClient()(executionContext) { override def executeProcess(args: Seq[String], timeout: Duration)(implicit ec: ExecutionContext, as: ActorSystem) = fixture @@ -89,7 +88,7 @@ class KubernetesClientTests def kubernetesContainer(id: ContainerId) = new KubernetesContainer(id, ContainerAddress("ip"), "ip", "docker://" + id.asString)(kubernetesClient { Future.successful("") - }, actorSystem, global, logging) + }, actorSystem, executionContext, logging) behavior of "KubernetesClient" @@ -178,6 +177,7 @@ class KubernetesClientTests object KubernetesClientTests { import scala.language.implicitConversions + import scala.concurrent.ExecutionContext.Implicits.global implicit def strToDate(str: String): Option[Instant] = KubernetesClient.parseK8STimestamp(str).toOption From 5295c8084edbf70a202900838e568d3f0ae6be98 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 23:47:29 +0530 Subject: [PATCH 09/13] Switch to JavaConverters --- tests/src/test/scala/common/RunCliCmd.scala | 4 ++-- .../scala/whisk/core/connector/test/TestConnector.scala | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/src/test/scala/common/RunCliCmd.scala b/tests/src/test/scala/common/RunCliCmd.scala index aee4439711e..e3e7e447432 100644 --- a/tests/src/test/scala/common/RunCliCmd.scala +++ b/tests/src/test/scala/common/RunCliCmd.scala @@ -19,7 +19,7 @@ package common import java.io.File -import scala.collection.JavaConversions.mapAsJavaMap +import scala.collection.JavaConverters._ import scala.collection.mutable.Buffer import org.scalatest.Matchers import TestUtils._ @@ -48,7 +48,7 @@ trait RunCliCmd extends Matchers { env: Map[String, String], fileStdin: Option[File], params: Seq[String]): RunResult = { - TestUtils.runCmd(expectedExitCode, dir, TestUtils.logger, env, fileStdin.getOrElse(null), params: _*) + TestUtils.runCmd(expectedExitCode, dir, TestUtils.logger, env.asJava, fileStdin.getOrElse(null), params: _*) } /** diff --git a/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala b/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala index 8b428e5736b..67faeab0b53 100644 --- a/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala +++ b/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala @@ -22,7 +22,7 @@ import java.util.concurrent.LinkedBlockingQueue import scala.concurrent.Future import scala.concurrent.duration._ -import scala.collection.JavaConversions._ +import scala.collection.JavaConverters._ import org.apache.kafka.clients.producer.RecordMetadata import org.apache.kafka.common.TopicPartition @@ -41,7 +41,7 @@ class TestConnector(topic: String, override val maxPeek: Int, allowMoreThanMax: val msgs = new ArrayList[Message] queue.synchronized { queue.drainTo(msgs, if (allowMoreThanMax) Int.MaxValue else maxPeek) - msgs map { m => + msgs.asScala map { m => offset += 1 (topic, -1, offset, m.serialize.getBytes) } @@ -87,7 +87,7 @@ class TestConnector(topic: String, override val maxPeek: Int, allowMoreThanMax: def sendBulk(topic: String, msgs: Seq[Message]): Future[RecordMetadata] = { queue.synchronized { - if (queue.addAll(msgs)) { + if (queue.addAll(msgs.asJava)) { logging.info(this, s"put: ${msgs.length} messages") Future.successful(new RecordMetadata(new TopicPartition(topic, 0), 0, queue.size, -1, Long.box(-1L), -1, -1)) } else { From 5f9f8c9e2d4e985f3203fbba57ec2164327a7308 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Wed, 10 Oct 2018 23:47:46 +0530 Subject: [PATCH 10/13] Use Java ForkJoinPool --- .../scala/whisk/core/database/test/CacheConcurrencyTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/test/scala/whisk/core/database/test/CacheConcurrencyTests.scala b/tests/src/test/scala/whisk/core/database/test/CacheConcurrencyTests.scala index a669296a404..54811ecd831 100644 --- a/tests/src/test/scala/whisk/core/database/test/CacheConcurrencyTests.scala +++ b/tests/src/test/scala/whisk/core/database/test/CacheConcurrencyTests.scala @@ -19,7 +19,7 @@ package whisk.core.database.test import scala.collection.parallel._ import scala.concurrent.duration.DurationInt -import scala.concurrent.forkjoin.ForkJoinPool +import java.util.concurrent.ForkJoinPool import org.junit.runner.RunWith import org.scalatest.BeforeAndAfterEach import org.scalatest.FlatSpec From bd9f3f1b0bd70287c583f92a5c413dc68c09f402 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Thu, 11 Oct 2018 09:57:57 +0530 Subject: [PATCH 11/13] Use onComplete for scenario having both success and failure handling --- .../core/database/memory/MemoryArtifactStore.scala | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala b/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala index ae320cbe711..39f94c87fd9 100644 --- a/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala +++ b/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala @@ -36,7 +36,7 @@ import whisk.http.Messages import scala.collection.concurrent.TrieMap import scala.concurrent.{ExecutionContext, Future} import scala.reflect.ClassTag -import scala.util.Try +import scala.util.{Failure, Success, Try} object MemoryArtifactStoreProvider extends ArtifactStoreProvider { override def makeStore[D <: DocumentSerializer: ClassTag](useBatching: Boolean)( @@ -130,15 +130,13 @@ class MemoryArtifactStore[DocumentAbstraction <: DocumentSerializer](dbName: Str } val f = Future.fromTry(t) - - f.failed.foreach { - case _: DocumentConflictException => + f.onComplete { + case Success(_) => transid.finished(this, start, s"[PUT] '$dbName' completed document: '$docinfoStr'") + case Failure(_: DocumentConflictException) => transid.finished(this, start, s"[PUT] '$dbName', document: '$docinfoStr'; conflict.") - case _ => + case Failure(_) => } - f.foreach(_ => transid.finished(this, start, s"[PUT] '$dbName' completed document: '$docinfoStr'")) - reportFailure(f, start, failure => s"[PUT] '$dbName' internal error, failure: '${failure.getMessage}'") } From 686849cbc9c5f434eea12f70b053e18523b4d5cc Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Thu, 11 Oct 2018 12:05:04 +0530 Subject: [PATCH 12/13] Scala 2.12 in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5f06f6cc211..1a0b8ab4a9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ group: deprecated-2017Q3 language: scala scala: - - 2.11.8 + - 2.12.7 services: - docker From 52627919b17cefaba3ae0e2eabde2f351f5dde74 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Tue, 6 Nov 2018 14:21:52 +0530 Subject: [PATCH 13/13] Workaround issue related to initializing trait val in case class --- .../src/main/scala/whisk/core/connector/Message.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/scala/src/main/scala/whisk/core/connector/Message.scala b/common/scala/src/main/scala/whisk/core/connector/Message.scala index ebfb59b192f..5122ef347c7 100644 --- a/common/scala/src/main/scala/whisk/core/connector/Message.scala +++ b/common/scala/src/main/scala/whisk/core/connector/Message.scala @@ -75,8 +75,8 @@ object ActivationMessage extends DefaultJsonProtocol { * Message that is sent from the invoker to the controller after action is completed or after slot is free again for * new actions. */ -abstract class AcknowledegmentMessage() extends Message { - override val transid: TransactionId +abstract class AcknowledegmentMessage(private val tid: TransactionId) extends Message { + override val transid: TransactionId = tid override def serialize: String = { AcknowledegmentMessage.serdes.write(this).compactPrint } @@ -90,7 +90,7 @@ case class CompletionMessage(override val transid: TransactionId, activationId: ActivationId, isSystemError: Boolean, invoker: InvokerInstanceId) - extends AcknowledegmentMessage() { + extends AcknowledegmentMessage(transid) { override def toString = { activationId.asString @@ -109,7 +109,7 @@ object CompletionMessage extends DefaultJsonProtocol { * The whisk activation field will have its logs stripped. */ case class ResultMessage(override val transid: TransactionId, response: Either[ActivationId, WhiskActivation]) - extends AcknowledegmentMessage() { + extends AcknowledegmentMessage(transid) { override def toString = { response.fold(l => l, r => r.activationId).asString