Skip to content

Commit 556b5bd

Browse files
committed
Add test case
1 parent ffe10a9 commit 556b5bd

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed

ansible/templates/whisk.properties.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ kafka.hosts={{ kafka_connect_string }}
4646
redis.host={{ groups["redis"]|default([""])|first }}
4747
router.host={{ groups["edge"]|first }}
4848
zookeeper.hosts={{ zookeeper_connect_string }}
49+
invoker.protocol={{ invoker.protocol }}
4950
invoker.hosts={{ groups["invokers"] | map('extract', hostvars, 'ansible_host') | list | join(",") }}
51+
invoker.username={{ invoker.username }}
52+
invoker.password={{ invoker.password }}
5053

5154
edge.host.apiport=443
5255
kafkaras.host.port={{ kafka.ras.port }}
@@ -57,6 +60,8 @@ controller.hosts={{ groups["controllers"] | map('extract', hostvars, 'ansible_ho
5760
controller.host.basePort={{ controller.basePort }}
5861
controller.instances={{ controller.instances }}
5962
controller.protocol={{ controller.protocol }}
63+
controller.username={{ controller.username }}
64+
controller.password={{ controller.password }}
6065

6166
invoker.container.network=bridge
6267
invoker.container.policy={{ invoker_container_policy_name | default()}}

tests/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def systemIncludes = [
5252
"org/apache/openwhisk/core/apigw/actions/test/**",
5353
"org/apache/openwhisk/core/database/test/*CacheConcurrencyTests*",
5454
"org/apache/openwhisk/core/controller/test/*ControllerApiTests*",
55+
"org/apache/openwhisk/operation/**",
5556
"apigw/healthtests/**",
5657
"ha/**",
5758
"services/**",
@@ -70,6 +71,7 @@ ext.testSets = [
7071
"org/apache/openwhisk/standalone/**",
7172
"org/apache/openwhisk/core/cli/test/**",
7273
"org/apache/openwhisk/core/limits/**",
74+
"org/apache/openwhisk/operation/**",
7375
"**/*CacheConcurrencyTests*",
7476
"**/*ControllerApiTests*",
7577
"org/apache/openwhisk/testEntities/**",

tests/src/test/scala/common/WhiskProperties.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,40 @@ public static int getControllerBasePort() {
258258
return Integer.parseInt(whiskProperties.getProperty("controller.host.basePort"));
259259
}
260260

261+
public static String getControllerProtocol() {
262+
return whiskProperties.getProperty("controller.protocol");
263+
}
264+
261265
public static String getBaseControllerHost() {
262266
return getControllerHosts().split(",")[0];
263267
}
264268

269+
public static String getInvokerProtocol() {
270+
return whiskProperties.getProperty("invoker.protocol");
271+
}
272+
273+
274+
public static String getBaseInvokerAddress(){
275+
return getInvokerHosts()[0] + ":" + whiskProperties.getProperty("invoker.hosts.basePort");
276+
}
277+
278+
public static String getControllerUsername() {
279+
return whiskProperties.getProperty("controller.username");
280+
}
281+
282+
public static String getControllerPassword() {
283+
return whiskProperties.getProperty("controller.password");
284+
}
285+
286+
287+
public static String getInvokerUsername() {
288+
return whiskProperties.getProperty("invoker.username");
289+
}
290+
291+
public static String getInvokerPassword() {
292+
return whiskProperties.getProperty("invoker.password");
293+
}
294+
265295
public static String getBaseDBHost() {
266296
return getDBHosts().split(",")[0];
267297
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package org.apache.openwhisk.operation
2+
3+
import akka.http.scaladsl.Http
4+
import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials}
5+
import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpMethods, HttpRequest, StatusCodes}
6+
import akka.http.scaladsl.unmarshalling.Unmarshal
7+
import akka.stream.ActorMaterializer
8+
import common._
9+
import common.rest.HttpConnection
10+
import org.apache.openwhisk.core.connector.PrewarmContainerDataList
11+
import org.apache.openwhisk.core.connector.PrewarmContainerDataProtocol._
12+
import org.junit.runner.RunWith
13+
import org.scalatest.Matchers
14+
import org.scalatest.concurrent.ScalaFutures
15+
import org.scalatest.junit.JUnitRunner
16+
import spray.json._
17+
import system.rest.RestUtil
18+
19+
import scala.concurrent.duration._
20+
import scala.util.Random
21+
22+
@RunWith(classOf[JUnitRunner])
23+
class RuntimeConfigurationTests
24+
extends TestHelpers
25+
with RestUtil
26+
with Matchers
27+
with ScalaFutures
28+
with WskActorSystem
29+
with StreamLogging {
30+
31+
implicit val materializer = ActorMaterializer()
32+
33+
val kind = "nodejs:10"
34+
val memory = 128
35+
var count = new Random().nextInt(3) + 1
36+
37+
def getRuntimes = {
38+
s""" {
39+
"runtimes": {
40+
"nodejs": [{
41+
"kind": "${kind}",
42+
"default": true,
43+
"image": {
44+
"prefix": "openwhisk",
45+
"name": "action-nodejs-v10",
46+
"tag": "nightly"
47+
},
48+
"deprecated": false,
49+
"attached": {
50+
"attachmentName": "codefile",
51+
"attachmentType": "text/plain"
52+
},
53+
"stemCells": [{
54+
"count": ${count},
55+
"memory": "${memory} MB"
56+
}]
57+
}]
58+
}
59+
}"""
60+
}
61+
62+
val invokerProtocol = WhiskProperties.getInvokerProtocol
63+
val invokerAddress = WhiskProperties.getBaseInvokerAddress
64+
val invokerUsername = WhiskProperties.getInvokerUsername
65+
val invokerPassword = WhiskProperties.getInvokerPassword
66+
val invokerAuthHeader = Authorization(BasicHttpCredentials(invokerUsername, invokerPassword))
67+
68+
val controllerProtocol = WhiskProperties.getControllerProtocol
69+
val controllerAddress = WhiskProperties.getBaseControllerAddress
70+
val controllerUsername = WhiskProperties.getControllerUsername
71+
val controllerPassword = WhiskProperties.getControllerPassword
72+
val controllerAuthHeader = Authorization(BasicHttpCredentials(controllerUsername, controllerPassword))
73+
74+
val getRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/getRuntime"
75+
val invokerChangeRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/config/runtime"
76+
val controllerChangeRuntimeUrl =
77+
s"${controllerProtocol}://${controllerAddress}/config/runtime"
78+
79+
it should "change assigned invoker node's runtime config directly" in {
80+
//Change config
81+
Http()
82+
.singleRequest(
83+
HttpRequest(
84+
method = HttpMethods.POST,
85+
uri = s"${invokerChangeRuntimeUrl}",
86+
headers = List(invokerAuthHeader),
87+
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
88+
connectionContext = HttpConnection.getContext(invokerProtocol))
89+
.map { response =>
90+
response.status shouldBe StatusCodes.OK
91+
}
92+
93+
Thread.sleep(5.seconds.toMillis)
94+
95+
//Cal the prewarm container number whether right
96+
Http()
97+
.singleRequest(
98+
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)),
99+
connectionContext = HttpConnection.getContext(invokerProtocol))
100+
.map { response =>
101+
response.status shouldBe StatusCodes.OK
102+
val prewarmContainerDataList =
103+
Unmarshal(response).to[String].futureValue.parseJson.convertTo[PrewarmContainerDataList]
104+
val nodejs10ContainerData = prewarmContainerDataList.items.filter { prewarmContainerData =>
105+
prewarmContainerData.kind == kind && prewarmContainerData.memory == memory
106+
}
107+
nodejs10ContainerData.head.number shouldBe count
108+
}
109+
}
110+
111+
it should "change all managed invokers's prewarm config via controller" in {
112+
//Change runtime config
113+
Http()
114+
.singleRequest(
115+
HttpRequest(
116+
method = HttpMethods.POST,
117+
uri = s"${controllerChangeRuntimeUrl}",
118+
headers = List(controllerAuthHeader),
119+
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
120+
connectionContext = HttpConnection.getContext(controllerProtocol))
121+
.map { response =>
122+
response.status shouldBe StatusCodes.OK
123+
}
124+
125+
Thread.sleep(5.seconds.toMillis)
126+
127+
//Cal the prewarm container number whether right
128+
Http()
129+
.singleRequest(
130+
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)),
131+
connectionContext = HttpConnection.getContext(invokerProtocol))
132+
.map { response =>
133+
response.status shouldBe StatusCodes.OK
134+
val prewarmContainerDataList =
135+
Unmarshal(response).to[String].futureValue.parseJson.convertTo[PrewarmContainerDataList]
136+
val nodejs10ContainerData = prewarmContainerDataList.items.filter { prewarmContainerData =>
137+
prewarmContainerData.kind == kind && prewarmContainerData.memory == memory
138+
}
139+
nodejs10ContainerData.head.number shouldBe count
140+
}
141+
}
142+
}

0 commit comments

Comments
 (0)