jcrossley3 commented on a change in pull request #3219: Kubernetes 
ContainerFactoryProvider implementation
URL: 
https://github.com/apache/incubator-openwhisk/pull/3219#discussion_r169139888
 
 

 ##########
 File path: 
tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala
 ##########
 @@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package whisk.core.containerpool.kubernetes.test
+
+import java.time.LocalDateTime
+
+import akka.actor.ActorSystem
+import akka.stream.ActorMaterializer
+import akka.stream.scaladsl.{Concat, Flow, Framing, Sink, Source}
+import akka.util.ByteString
+
+import scala.concurrent.Await
+import scala.concurrent.ExecutionContext
+import scala.concurrent.ExecutionContext.Implicits.global
+import scala.concurrent.Future
+import scala.concurrent.duration._
+import spray.json._
+import org.junit.runner.RunWith
+import org.scalatest.BeforeAndAfterEach
+import org.scalatest.concurrent.Eventually
+import org.scalatest.FlatSpec
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.Matchers
+import org.scalatest.time.{Seconds, Span}
+import common.{StreamLogging, WskActorSystem}
+import okio.Buffer
+import whisk.common.LogMarker
+import whisk.common.LoggingMarkers.INVOKER_KUBECTL_CMD
+import whisk.common.TransactionId
+import whisk.core.containerpool.{ContainerAddress, ContainerId}
+import whisk.core.containerpool.kubernetes.{KubernetesApi, KubernetesClient, 
KubernetesRestLogSourceStage}
+import whisk.core.containerpool.docker.ProcessRunningException
+import whisk.core.containerpool.logging.LogLine
+
+import scala.collection.mutable
+import scala.util.Try
+@RunWith(classOf[JUnitRunner])
+class KubernetesClientTests
+    extends FlatSpec
+    with Matchers
+    with StreamLogging
+    with BeforeAndAfterEach
+    with Eventually
+    with WskActorSystem {
+
+  import KubernetesClientTests._
+
+  implicit val materializer: ActorMaterializer = ActorMaterializer()
+
+  /** Reads logs into memory and awaits them */
+  def awaitLogs(source: Source[ByteString, Any], timeout: FiniteDuration = 
1000.milliseconds): Vector[LogLine] =
+    Await
+      .result(
+        source
+          .via(Framing.delimiter(ByteString("\n"), 1024))
+          .via(Flow[ByteString].map(l => 
Try(l.utf8String.parseJson.convertTo[LogLine]).getOrElse(LogLine("", "", ""))))
+          .filter(_ != LogLine("", "", ""))
+          .runWith(Sink.seq[LogLine]),
+        timeout)
+      .toVector
+
+  override def beforeEach = stream.reset()
+
+  implicit override val patienceConfig = PatienceConfig(timeout = 
scaled(Span(5, Seconds)))
+
+  implicit val transid = TransactionId.testing
+  val id = 
ContainerId("55db56ee082239428b27d3728b4dd324c09068458aad9825727d5bfc1bba6d52")
+
+  val commandTimeout = 500.milliseconds
+  def await[A](f: Future[A], timeout: FiniteDuration = commandTimeout) = 
Await.result(f, timeout)
+
+  val kubectlCommand = "kubectl"
+
+  /** Returns a KubernetesClient with a mocked result for 'executeProcess' and 
'fetchHTTPLogs' */
+  def kubernetesClient(fixture: => Future[String]) = new 
KubernetesClient()(global) {
+    override def findKubectlCmd() = kubectlCommand
+    override def executeProcess(args: Seq[String], timeout: Duration)(implicit 
ec: ExecutionContext, as: ActorSystem) =
+      fixture
 
 Review comment:
   DISABLED THE TESTS WHAT!?!?! ;)
   Yeah, @bwmcadams  had to set up dummy `Source` objects to validate the log 
parsing logic. I guess we'll need to figure out something similar as we convert 
the other calls to the API.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to