Skip to content

Commit 9f99e3c

Browse files
style95JesseStutler
authored andcommitted
Add test cases to make sure an invoker properly boots up in terms of ETCD keys. (apache#5271)
1 parent 4e63c55 commit 9f99e3c

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

tests/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ext.testSets = [
7272
"org/apache/openwhisk/core/cli/test/**",
7373
"org/apache/openwhisk/core/limits/**",
7474
"org/apache/openwhisk/core/scheduler/**",
75+
"org/apache/openwhisk/core/invoker/test/*InvokerBootUpTests*",
7576
"org/apache/openwhisk/core/loadBalancer/test/*FPCPoolBalancerTests*",
7677
"org/apache/openwhisk/common/etcd/**",
7778
"**/*CacheConcurrencyTests*",
@@ -92,6 +93,7 @@ ext.testSets = [
9293
"org/apache/openwhisk/common/etcd/**",
9394
"org/apache/openwhisk/core/containerpool/v2/test/**",
9495
"org/apache/openwhisk/core/scheduler/**",
96+
"org/apache/openwhisk/core/invoker/test/*InvokerBootUpTests*",
9597
"org/apache/openwhisk/core/loadBalancer/test/*FPCPoolBalancerTests*",
9698
"org/apache/openwhisk/core/service/**",
9799
]
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.apache.openwhisk.core.invoker.test
2+
3+
import java.nio.charset.StandardCharsets
4+
import akka.actor.ActorSystem
5+
import akka.testkit.TestKit
6+
import common.WskTestHelpers
7+
import org.apache.openwhisk.common.InvokerState.Healthy
8+
import org.apache.openwhisk.core.ConfigKeys
9+
import org.apache.openwhisk.core.connector.InvokerResourceMessage
10+
import org.apache.openwhisk.core.containerpool.v2.InvokerHealthManager.healthActionNamePrefix
11+
import org.apache.openwhisk.core.entity.InvokerInstanceId
12+
import org.apache.openwhisk.core.etcd.EtcdKV.ContainerKeys.namespacePrefix
13+
import org.apache.openwhisk.core.etcd.EtcdKV.{InstanceKeys, InvokerKeys}
14+
import org.apache.openwhisk.core.etcd.{EtcdClient, EtcdConfig}
15+
import org.junit.runner.RunWith
16+
import org.scalatest.concurrent.ScalaFutures
17+
import org.scalatest.junit.JUnitRunner
18+
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike}
19+
import pureconfig.loadConfigOrThrow
20+
import org.apache.openwhisk.core.entity.size._
21+
22+
import scala.collection.JavaConverters._
23+
import scala.concurrent.ExecutionContextExecutor
24+
import scala.concurrent.duration._
25+
import pureconfig.generic.auto._
26+
27+
@RunWith(classOf[JUnitRunner])
28+
class InvokerBootUpTests
29+
extends TestKit(ActorSystem("SchedulerFlow"))
30+
with FlatSpecLike
31+
with BeforeAndAfterAll
32+
with WskTestHelpers
33+
with ScalaFutures {
34+
private implicit val ec: ExecutionContextExecutor = system.dispatcher
35+
36+
private val systemNamespace = "whisk.system"
37+
private val etcd = EtcdClient.apply(loadConfigOrThrow[EtcdConfig](ConfigKeys.etcd))
38+
39+
override def afterAll(): Unit = {
40+
etcd.close()
41+
super.afterAll()
42+
}
43+
44+
behavior of "Invoker Etcd Key"
45+
it should "haven't health action key" in {
46+
val healthActionPrefix = s"$namespacePrefix/namespace/$systemNamespace/$systemNamespace/$healthActionNamePrefix"
47+
awaitAssert({
48+
etcd.getPrefix(healthActionPrefix).futureValue.getKvsList.size() shouldBe 0
49+
}, 10.seconds)
50+
}
51+
52+
it should "have lease key" in {
53+
val leasePrefix = s"$namespacePrefix/instance"
54+
awaitAssert({
55+
val leases = etcd.getPrefix(leasePrefix).futureValue.getKvsList.asScala.toArray
56+
57+
// validate size
58+
leases.length > 0
59+
60+
// validate key
61+
for (i <- leases.indices) {
62+
val invokerId = InvokerInstanceId(i, userMemory = 256.MB)
63+
leases(i).getKey.toString(StandardCharsets.UTF_8) shouldBe InstanceKeys.instanceLease(invokerId)
64+
}
65+
}, 10.seconds)
66+
}
67+
68+
it should "have invoker key" in {
69+
val invokerPrefix = InvokerKeys.prefix
70+
awaitAssert(
71+
{
72+
val invokers = etcd.getPrefix(invokerPrefix).futureValue.getKvsList.asScala.toArray
73+
74+
// validate size
75+
invokers.length > 0
76+
77+
for (i <- invokers.indices) {
78+
val invokerId = InvokerInstanceId(i, uniqueName = Some(s"$i"), userMemory = 256.MB)
79+
// validate key
80+
invokers(i).getKey.toString(StandardCharsets.UTF_8) shouldBe InvokerKeys.health(invokerId)
81+
82+
// validate if all invoker is healthy
83+
InvokerResourceMessage
84+
.parse(invokers(i).getValue.toString(StandardCharsets.UTF_8))
85+
.map { resource =>
86+
resource.status shouldBe Healthy.asString
87+
}
88+
}
89+
},
90+
10.seconds)
91+
}
92+
}

0 commit comments

Comments
 (0)