-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffe10a9
commit 556b5bd
Showing
4 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
tests/src/test/scala/org/apache/openwhisk/operation/RuntimeConfiguration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package org.apache.openwhisk.operation | ||
|
||
import akka.http.scaladsl.Http | ||
import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials} | ||
import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpMethods, HttpRequest, StatusCodes} | ||
import akka.http.scaladsl.unmarshalling.Unmarshal | ||
import akka.stream.ActorMaterializer | ||
import common._ | ||
import common.rest.HttpConnection | ||
import org.apache.openwhisk.core.connector.PrewarmContainerDataList | ||
import org.apache.openwhisk.core.connector.PrewarmContainerDataProtocol._ | ||
import org.junit.runner.RunWith | ||
import org.scalatest.Matchers | ||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.junit.JUnitRunner | ||
import spray.json._ | ||
import system.rest.RestUtil | ||
|
||
import scala.concurrent.duration._ | ||
import scala.util.Random | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class RuntimeConfigurationTests | ||
extends TestHelpers | ||
with RestUtil | ||
with Matchers | ||
with ScalaFutures | ||
with WskActorSystem | ||
with StreamLogging { | ||
|
||
implicit val materializer = ActorMaterializer() | ||
|
||
val kind = "nodejs:10" | ||
val memory = 128 | ||
var count = new Random().nextInt(3) + 1 | ||
|
||
def getRuntimes = { | ||
s""" { | ||
"runtimes": { | ||
"nodejs": [{ | ||
"kind": "${kind}", | ||
"default": true, | ||
"image": { | ||
"prefix": "openwhisk", | ||
"name": "action-nodejs-v10", | ||
"tag": "nightly" | ||
}, | ||
"deprecated": false, | ||
"attached": { | ||
"attachmentName": "codefile", | ||
"attachmentType": "text/plain" | ||
}, | ||
"stemCells": [{ | ||
"count": ${count}, | ||
"memory": "${memory} MB" | ||
}] | ||
}] | ||
} | ||
}""" | ||
} | ||
|
||
val invokerProtocol = WhiskProperties.getInvokerProtocol | ||
val invokerAddress = WhiskProperties.getBaseInvokerAddress | ||
val invokerUsername = WhiskProperties.getInvokerUsername | ||
val invokerPassword = WhiskProperties.getInvokerPassword | ||
val invokerAuthHeader = Authorization(BasicHttpCredentials(invokerUsername, invokerPassword)) | ||
|
||
val controllerProtocol = WhiskProperties.getControllerProtocol | ||
val controllerAddress = WhiskProperties.getBaseControllerAddress | ||
val controllerUsername = WhiskProperties.getControllerUsername | ||
val controllerPassword = WhiskProperties.getControllerPassword | ||
val controllerAuthHeader = Authorization(BasicHttpCredentials(controllerUsername, controllerPassword)) | ||
|
||
val getRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/getRuntime" | ||
val invokerChangeRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/config/runtime" | ||
val controllerChangeRuntimeUrl = | ||
s"${controllerProtocol}://${controllerAddress}/config/runtime" | ||
|
||
it should "change assigned invoker node's runtime config directly" in { | ||
//Change config | ||
Http() | ||
.singleRequest( | ||
HttpRequest( | ||
method = HttpMethods.POST, | ||
uri = s"${invokerChangeRuntimeUrl}", | ||
headers = List(invokerAuthHeader), | ||
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)), | ||
connectionContext = HttpConnection.getContext(invokerProtocol)) | ||
.map { response => | ||
response.status shouldBe StatusCodes.OK | ||
} | ||
|
||
Thread.sleep(5.seconds.toMillis) | ||
|
||
//Cal the prewarm container number whether right | ||
Http() | ||
.singleRequest( | ||
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)), | ||
connectionContext = HttpConnection.getContext(invokerProtocol)) | ||
.map { response => | ||
response.status shouldBe StatusCodes.OK | ||
val prewarmContainerDataList = | ||
Unmarshal(response).to[String].futureValue.parseJson.convertTo[PrewarmContainerDataList] | ||
val nodejs10ContainerData = prewarmContainerDataList.items.filter { prewarmContainerData => | ||
prewarmContainerData.kind == kind && prewarmContainerData.memory == memory | ||
} | ||
nodejs10ContainerData.head.number shouldBe count | ||
} | ||
} | ||
|
||
it should "change all managed invokers's prewarm config via controller" in { | ||
//Change runtime config | ||
Http() | ||
.singleRequest( | ||
HttpRequest( | ||
method = HttpMethods.POST, | ||
uri = s"${controllerChangeRuntimeUrl}", | ||
headers = List(controllerAuthHeader), | ||
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)), | ||
connectionContext = HttpConnection.getContext(controllerProtocol)) | ||
.map { response => | ||
response.status shouldBe StatusCodes.OK | ||
} | ||
|
||
Thread.sleep(5.seconds.toMillis) | ||
|
||
//Cal the prewarm container number whether right | ||
Http() | ||
.singleRequest( | ||
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)), | ||
connectionContext = HttpConnection.getContext(invokerProtocol)) | ||
.map { response => | ||
response.status shouldBe StatusCodes.OK | ||
val prewarmContainerDataList = | ||
Unmarshal(response).to[String].futureValue.parseJson.convertTo[PrewarmContainerDataList] | ||
val nodejs10ContainerData = prewarmContainerDataList.items.filter { prewarmContainerData => | ||
prewarmContainerData.kind == kind && prewarmContainerData.memory == memory | ||
} | ||
nodejs10ContainerData.head.number shouldBe count | ||
} | ||
} | ||
} |