Skip to content

Commit 1ec0720

Browse files
committed
Add test case
1 parent ffe10a9 commit 1ec0720

File tree

4 files changed

+196
-0
lines changed

4 files changed

+196
-0
lines changed

ansible/templates/whisk.properties.j2

+5
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

+2
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

+30
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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.openwhisk.operation
19+
20+
import akka.http.scaladsl.Http
21+
import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials}
22+
import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpMethods, HttpRequest, StatusCodes}
23+
import akka.http.scaladsl.unmarshalling.Unmarshal
24+
import akka.stream.ActorMaterializer
25+
import common._
26+
import common.rest.HttpConnection
27+
import org.apache.openwhisk.core.connector.PrewarmContainerDataList
28+
import org.apache.openwhisk.core.connector.PrewarmContainerDataProtocol._
29+
import org.junit.runner.RunWith
30+
import org.scalatest.Matchers
31+
import org.scalatest.concurrent.ScalaFutures
32+
import org.scalatest.junit.JUnitRunner
33+
import spray.json._
34+
import system.rest.RestUtil
35+
36+
import scala.concurrent.duration._
37+
import scala.util.Random
38+
39+
@RunWith(classOf[JUnitRunner])
40+
class RuntimeConfigurationTests
41+
extends TestHelpers
42+
with RestUtil
43+
with Matchers
44+
with ScalaFutures
45+
with WskActorSystem
46+
with StreamLogging {
47+
48+
implicit val materializer = ActorMaterializer()
49+
50+
val kind = "nodejs:10"
51+
val memory = 128
52+
var count = new Random().nextInt(3) + 1
53+
54+
def getRuntimes = {
55+
s""" {
56+
"runtimes": {
57+
"nodejs": [{
58+
"kind": "${kind}",
59+
"default": true,
60+
"image": {
61+
"prefix": "openwhisk",
62+
"name": "action-nodejs-v10",
63+
"tag": "nightly"
64+
},
65+
"deprecated": false,
66+
"attached": {
67+
"attachmentName": "codefile",
68+
"attachmentType": "text/plain"
69+
},
70+
"stemCells": [{
71+
"count": ${count},
72+
"memory": "${memory} MB"
73+
}]
74+
}]
75+
}
76+
}"""
77+
}
78+
79+
val invokerProtocol = WhiskProperties.getInvokerProtocol
80+
val invokerAddress = WhiskProperties.getBaseInvokerAddress
81+
val invokerUsername = WhiskProperties.getInvokerUsername
82+
val invokerPassword = WhiskProperties.getInvokerPassword
83+
val invokerAuthHeader = Authorization(BasicHttpCredentials(invokerUsername, invokerPassword))
84+
85+
val controllerProtocol = WhiskProperties.getControllerProtocol
86+
val controllerAddress = WhiskProperties.getBaseControllerAddress
87+
val controllerUsername = WhiskProperties.getControllerUsername
88+
val controllerPassword = WhiskProperties.getControllerPassword
89+
val controllerAuthHeader = Authorization(BasicHttpCredentials(controllerUsername, controllerPassword))
90+
91+
val getRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/getRuntime"
92+
val invokerChangeRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/config/runtime"
93+
val controllerChangeRuntimeUrl =
94+
s"${controllerProtocol}://${controllerAddress}/config/runtime"
95+
96+
it should "change assigned invoker node's runtime config directly" in {
97+
//Change config
98+
Http()
99+
.singleRequest(
100+
HttpRequest(
101+
method = HttpMethods.POST,
102+
uri = s"${invokerChangeRuntimeUrl}",
103+
headers = List(invokerAuthHeader),
104+
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
105+
connectionContext = HttpConnection.getContext(invokerProtocol))
106+
.map { response =>
107+
response.status shouldBe StatusCodes.OK
108+
}
109+
110+
Thread.sleep(5.seconds.toMillis)
111+
112+
//Cal the prewarm container number whether right
113+
Http()
114+
.singleRequest(
115+
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)),
116+
connectionContext = HttpConnection.getContext(invokerProtocol))
117+
.map { response =>
118+
response.status shouldBe StatusCodes.OK
119+
val prewarmContainerDataList =
120+
Unmarshal(response).to[String].futureValue.parseJson.convertTo[PrewarmContainerDataList]
121+
val nodejs10ContainerData = prewarmContainerDataList.items.filter { prewarmContainerData =>
122+
prewarmContainerData.kind == kind && prewarmContainerData.memory == memory
123+
}
124+
nodejs10ContainerData.head.number shouldBe count
125+
}
126+
}
127+
128+
it should "change all managed invokers's prewarm config via controller" in {
129+
//Change runtime config
130+
Http()
131+
.singleRequest(
132+
HttpRequest(
133+
method = HttpMethods.POST,
134+
uri = s"${controllerChangeRuntimeUrl}",
135+
headers = List(controllerAuthHeader),
136+
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
137+
connectionContext = HttpConnection.getContext(controllerProtocol))
138+
.map { response =>
139+
response.status shouldBe StatusCodes.OK
140+
}
141+
142+
Thread.sleep(5.seconds.toMillis)
143+
144+
//Cal the prewarm container number whether right
145+
Http()
146+
.singleRequest(
147+
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)),
148+
connectionContext = HttpConnection.getContext(invokerProtocol))
149+
.map { response =>
150+
response.status shouldBe StatusCodes.OK
151+
val prewarmContainerDataList =
152+
Unmarshal(response).to[String].futureValue.parseJson.convertTo[PrewarmContainerDataList]
153+
val nodejs10ContainerData = prewarmContainerDataList.items.filter { prewarmContainerData =>
154+
prewarmContainerData.kind == kind && prewarmContainerData.memory == memory
155+
}
156+
nodejs10ContainerData.head.number shouldBe count
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)