|
@@ -40,60 +40,54 @@ object Application extends Controller {
|
|
|
def isDbAvailable: Boolean = (tpe.getQueue.size() < maxConnections * MaxQueriesPerRequest)
|
|
|
|
|
|
def db(queries: Int) = PredicatedAction(isDbAvailable, ServiceUnavailable) {
|
|
|
- Action {
|
|
|
- Async {
|
|
|
- val random = ThreadLocalRandom.current()
|
|
|
-
|
|
|
- val _worlds = Future.sequence((for {
|
|
|
- _ <- 1 to queries
|
|
|
- } yield Future(worldsTable.findById(random.nextInt(TestDatabaseRows) + 1))(dbEc)
|
|
|
- ).toList)
|
|
|
-
|
|
|
- _worlds map {
|
|
|
- w => Ok(Json.toJson(w))
|
|
|
- }
|
|
|
+ Action.async {
|
|
|
+ val random = ThreadLocalRandom.current()
|
|
|
+
|
|
|
+ val _worlds = Future.sequence((for {
|
|
|
+ _ <- 1 to queries
|
|
|
+ } yield Future(worldsTable.findById(random.nextInt(TestDatabaseRows) + 1))(dbEc)
|
|
|
+ ).toList)
|
|
|
+
|
|
|
+ _worlds map {
|
|
|
+ w => Ok(Json.toJson(w))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
def fortunes() = PredicatedAction(isDbAvailable, ServiceUnavailable) {
|
|
|
- Action {
|
|
|
- Async {
|
|
|
- Future(fortunesTable.getAll())(dbEc).map { fs =>
|
|
|
- val fortunes = Fortune(-1, "Additional fortune added at request time.") +: fs
|
|
|
- Ok(views.html.fortune(fortunes))
|
|
|
- }
|
|
|
+ Action.async {
|
|
|
+ Future(fortunesTable.getAll())(dbEc).map { fs =>
|
|
|
+ val fortunes = Fortune(-1, "Additional fortune added at request time.") +: fs
|
|
|
+ Ok(views.html.fortune(fortunes))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
def update(queries: Int) = PredicatedAction(isDbAvailable, ServiceUnavailable) {
|
|
|
- Action {
|
|
|
- Async {
|
|
|
- val random = ThreadLocalRandom.current()
|
|
|
-
|
|
|
- val boundsCheckedQueries = queries match {
|
|
|
- case q if q > 500 => 500
|
|
|
- case q if q < 1 => 1
|
|
|
- case _ => queries
|
|
|
- }
|
|
|
-
|
|
|
- val worlds = Future.sequence((for {
|
|
|
- _ <- 1 to boundsCheckedQueries
|
|
|
- } yield Future {
|
|
|
- for {
|
|
|
- world <- worldsTable.findById(random.nextInt(TestDatabaseRows) + 1)
|
|
|
- } yield {
|
|
|
- val updatedWorld = world.copy(randomNumber = random.nextInt(TestDatabaseRows) + 1)
|
|
|
- worldsTable.updateRandom(updatedWorld)
|
|
|
- updatedWorld
|
|
|
- }
|
|
|
- }(dbEc)
|
|
|
- ).toList)
|
|
|
+ Action.async {
|
|
|
+ val random = ThreadLocalRandom.current()
|
|
|
+
|
|
|
+ val boundsCheckedQueries = queries match {
|
|
|
+ case q if q > 500 => 500
|
|
|
+ case q if q < 1 => 1
|
|
|
+ case _ => queries
|
|
|
+ }
|
|
|
|
|
|
- worlds.map {
|
|
|
- w => Ok(Json.toJson(w)).withHeaders("Server" -> "Netty")
|
|
|
- }
|
|
|
+ val worlds = Future.sequence((for {
|
|
|
+ _ <- 1 to boundsCheckedQueries
|
|
|
+ } yield Future {
|
|
|
+ for {
|
|
|
+ world <- worldsTable.findById(random.nextInt(TestDatabaseRows) + 1)
|
|
|
+ } yield {
|
|
|
+ val updatedWorld = world.copy(randomNumber = random.nextInt(TestDatabaseRows) + 1)
|
|
|
+ worldsTable.updateRandom(updatedWorld)
|
|
|
+ updatedWorld
|
|
|
+ }
|
|
|
+ }(dbEc)
|
|
|
+ ).toList)
|
|
|
+
|
|
|
+ worlds.map {
|
|
|
+ w => Ok(Json.toJson(w)).withHeaders("Server" -> "Netty")
|
|
|
}
|
|
|
}
|
|
|
}
|