Skip to content

Commit

Permalink
Port Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dubee committed Jun 13, 2017
1 parent ef13730 commit 4021c82
Show file tree
Hide file tree
Showing 21 changed files with 551 additions and 696 deletions.
34 changes: 26 additions & 8 deletions common/scala/src/main/scala/whisk/http/BasicHttpService.scala
Expand Up @@ -43,7 +43,8 @@ import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.model.HttpRequest
//import akka.http.scaladsl.server.RejectionHandler

import akka.http.scaladsl.model._
import akka.http.scaladsl.server.RejectionHandler
/*import spray.can.Http
import spray.http.ContentType
import spray.http.HttpEntity
Expand Down Expand Up @@ -87,6 +88,22 @@ trait BasicHttpService extends Directives with Actor with TransactionCounter {
*/
implicit def logging: Logging

implicit def myRejectionHandler =
RejectionHandler.default
.mapRejectionResponse {
case res @ HttpResponse(_, _, ent: HttpEntity.Strict, _) =>
// since all Akka default rejection responses are Strict this will handle all rejections
val message = ent.data.utf8String.replaceAll("\"", """\"""")

// we copy the response in order to keep all headers and status code, wrapping the message as hand rolled JSON
// you could the entity using your favourite marshalling library (e.g. spray json or anything else)
res.copy(entity = HttpEntity(ContentTypes.`application/json`, s"""{"rejection": "$message"}"""))

//case CustomRejection(status, cause) :: _ => complete(status, ErrorResponse(cause, transid))

case x => x // pass through all other types of responses
}

/**
* Gets the routes implemented by the HTTP service.
*
Expand All @@ -109,13 +126,14 @@ trait BasicHttpService extends Directives with Actor with TransactionCounter {
def receive = {
case _ =>

/*assignId { implicit transid =>
//DebuggingDirectives.logRequest(logRequestInfo _) {
// DebuggingDirectives.logRequestResponse(logResponseInfo _) {
routes
// }
//}*/
}
assignId { implicit transid =>
//DebuggingDirectives.logRequest(logRequestInfo _) {
// DebuggingDirectives.logRequestResponse(logResponseInfo _) {
Route.seal(routes)
// }
//}
}
}

/** Assigns transaction id to every request. */
protected val assignId = extract(_ => transid())
Expand Down
65 changes: 34 additions & 31 deletions core/controller/src/main/resources/application.conf
@@ -1,40 +1,43 @@
# common logging configuration see common scala
include "logging"
include "akka-http-version"

# see http://spray.io/documentation/spray-can/configuration/
# descriptions inlined below for convenience
spray.can.server {
# Description:
# If a request hasn't been responded to after the time period set here
# a `spray.http.Timedout` message will be sent to the timeout handler.
# Set to `infinite` to completely disable request timeouts.
#
# Explaining the set value:
# The controller holds connections up to 60s for blocking invokes, and
# all other operations are expected to complete quickly. We allow a grace
# period in addition to the blocking invoke timeout.
request-timeout = 90s
// # http://doc.akka.io/docs/akka-http/current/scala/http/configuration.html
// # descriptions inlined below for convenience
akka.http {
server {
# Description:
# If a request hasn't been responded to after the time period set here
# a `spray.http.Timedout` message will be sent to the timeout handler.
# Set to `infinite` to completely disable request timeouts.
#
# Explaining the set value:
# The controller holds connections up to 60s for blocking invokes, and
# all other operations are expected to complete quickly. We allow a grace
# period in addition to the blocking invoke timeout.
request-timeout = 90s

# Description:
# Enables/disables support for statistics collection and querying.
# Even though stats keeping overhead is small,
# for maximum performance switch off when not needed.
stats-support = off
# Description:
# Enables/disables support for statistics collection and querying.
# Even though stats keeping overhead is small,
# for maximum performance switch off when not needed.
stats-support = off

# Description:
# The time after which an idle connection will be automatically closed.
# Set to `infinite` to completely disable idle connection timeouts.
#
# Explaining the set value:
# This must be greater than the request timeout.
idle-timeout = 120s
# Description:
# The time after which an idle connection will be automatically closed.
# Set to `infinite` to completely disable idle connection timeouts.
#
# Explaining the set value:
# This must be greater than the request timeout.
idle-timeout = 120s

parsing {
# This indirectly puts a bound on the name of entities
# 8k matches nginx default
max-uri-length = 8k
parsing {
# This indirectly puts a bound on the name of entities
# 8k matches nginx default
max-uri-length = 8k

# This is 50MB to allow action attachments
max-content-length = 50m
# This is 50MB to allow action attachments
max-content-length = 50m
}
}
}
Expand Up @@ -254,7 +254,8 @@ class API(config: WhiskConfig, apiPath: String, apiVersion: String)(
override val consulServer: String,
override val executionContext: ExecutionContext,
override val logging: Logging,
override val whiskConfig: WhiskConfig)
override val whiskConfig: WhiskConfig,
override val materializer: ActorMaterializer)
extends WhiskTriggersApi with WhiskServices

protected[controller] class WebActionsApi(
Expand Down
Expand Up @@ -109,7 +109,7 @@ trait WhiskTriggersApi extends WhiskCollectionAPI {
/** Path to Triggers REST API. */
protected val triggersPath = "triggers"

implicit val materializer = ActorMaterializer()
protected implicit val materializer: ActorMaterializer

/**
* Creates or updates trigger if it already exists. The PUT content is deserialized into a WhiskTriggerPut
Expand Down
2 changes: 2 additions & 0 deletions tests/build.gradle
Expand Up @@ -53,6 +53,8 @@ dependencies {
compile project(':common:scala')
compile project(':core:controller')
compile project(':core:invoker')

testCompile 'com.typesafe.akka:akka-http-testkit_2.11:10.0.2'
}

tasks.withType(ScalaCompile) {
Expand Down

0 comments on commit 4021c82

Please sign in to comment.