markusthoemmes commented on a change in pull request #2531: Share bookkeeping 
data across controllers
URL: 
https://github.com/apache/incubator-openwhisk/pull/2531#discussion_r138258416
 
 

 ##########
 File path: 
tests/src/test/scala/whisk/core/loadBalancer/test/SharedDataServiceTests.scala
 ##########
 @@ -0,0 +1,113 @@
+/*
+ * 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.loadBalancer.test
+
+import akka.actor.ActorSystem
+import akka.testkit.{ImplicitSender, TestKit}
+import akka.util.Timeout
+import com.typesafe.config.ConfigValueFactory
+import com.typesafe.config.ConfigFactory
+import org.scalatest._
+import whisk.core.loadBalancer._
+
+import scala.concurrent.duration._
+
+// Define your test specific configuration here
+
+object TestKitConfig {
+  val config = """
+    akka.remote.netty.tcp {
+      hostname = "127.0.0.1"
+      port = 2555
+    }
+    """
+}
+
+class SharedDataServiceTests()
+    extends TestKit(ActorSystem("ControllerCluster", 
ConfigFactory.parseString(TestKitConfig.config)))
+    with ImplicitSender
+    with WordSpecLike
+    with Matchers
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  override def afterAll {
+    TestKit.shutdownActorSystem(system)
+  }
+
+  "A Shared Data Service" must {
+
+    val port = 2552
+    val config = ConfigFactory
+      .parseString("akka.cluster { seed-nodes = 
[\"akka.tcp://[email protected]" +
+        s".1:$port" + "\"] }")
+      .withValue("akka.remote.netty.tcp.hostname", 
ConfigValueFactory.fromAnyRef("127.0.0.1"))
+      .withValue("akka.remote.netty.tcp.port", 
ConfigValueFactory.fromAnyRef(port))
+      .withValue("akka.cluster.auto-down-unreachable-after", 
ConfigValueFactory.fromAnyRef("10s"))
+      .withValue("akka.actor.provider", 
ConfigValueFactory.fromAnyRef("cluster"))
+      .withValue("akka.remote.log-remote-lifecycle-events", 
ConfigValueFactory.fromAnyRef("off"))
+      .withFallback(ConfigFactory.load())
+
+    val system = ActorSystem("controller-actor-system", config)
+
+    val sharedDataService = 
system.actorOf(SharedDataService.props("Candidates"), name = "busyMan")
+    implicit val timeout = Timeout(5.seconds)
+
+    "retrieve an empty map after initialization" in {
+      sharedDataService ! GetTheMap()
+      expectMsgPF() {
+        case x: MapWithCounters if x.dataMap.size == 0 => true
+      }
+    }
+    "increase the counter" in {
+      sharedDataService ! (IncreaseCounter("Donald", 1))
+      sharedDataService ! ReadCounter("Donald")
+      expectMsg(1)
+    }
+    "decrease the counter" in {
+      sharedDataService ! (IncreaseCounter("Donald", 2))
+      sharedDataService ! (DecreaseCounter("Donald", 2))
+      Thread.sleep(500)
 
 Review comment:
   Those `Thread.sleeps` make me anxious. Is there a way around them?
 
----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to