Browse Source

Initial commit

It's now a standalone app to keep the environmental impact of one
separate from the other, as suggestes by @huntc
Skamander 12 years ago
parent
commit
2c883a1e4b

+ 33 - 0
play-scala-mongodb/.gitignore

@@ -0,0 +1,33 @@
+logs
+project/project
+project/target
+public
+target
+test
+tmp
+.history
+dist
+conf/evolutions
+
+# Ignore all dotfiles...
+.*
+# except for .gitignore
+!.gitignore
+
+# Ignore Play! working directory #
+db
+eclipse
+lib
+log
+logs
+modules
+precompiled
+project/project
+project/target
+target
+tmp
+test-result
+server.pid
+*.iml
+*.eml
+

+ 23 - 0
play-scala-mongodb/README.md

@@ -0,0 +1,23 @@
+#Play Benchmarking Test
+
+This is the Play portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+
+* [JSON test source](app/controllers/Application.scala)
+
+### Data-Store/Database Mapping Test
+
+* [Database test controller](app/controllers/Application.scala)
+
+## Infrastructure Software Versions
+The tests were run with:
+
+* [Java OpenJDK 1.7.0_09](http://openjdk.java.net/)
+* [Play 2.1.0](http://http://www.playframework.com/)
+* [Reactivemongo 0.9-SNAPSHOT](https://github.com/zenexity/Play-ReactiveMongo)
+
+## Test URLs
+### Data-Store/Database Mapping Test
+
+http://localhost/db?queries=5

+ 0 - 0
play-scala-mongodb/__init__.py


+ 40 - 0
play-scala-mongodb/app/controllers/Application.scala

@@ -0,0 +1,40 @@
+package controllers
+
+import play.api.Play.current
+import play.api.mvc._
+import play.api.libs.json._
+import scala.concurrent.forkjoin.ThreadLocalRandom
+import scala.concurrent.Future
+import play.modules.reactivemongo.ReactiveMongoPlugin
+import play.modules.reactivemongo.json.collection.JSONCollection
+import play.api.libs.concurrent.Execution.Implicits._
+
+object Application extends Controller {
+
+  private val TestDatabaseRows = 10000
+  private val database = ReactiveMongoPlugin.db
+  private def collection: JSONCollection = database.collection[JSONCollection]("world")
+  private val worldWithoutMongoId = (__ \ "_id").json.prune
+
+  def db(queries: Int) = Action {
+    import scala.concurrent.ExecutionContext.Implicits.global
+
+    Async {
+      val random = ThreadLocalRandom.current()
+      val futureWorlds = Future.sequence((for {
+        _ <- 1 to queries
+      } yield { collection
+        .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)))
+        .cursor[JsValue]
+        .toList map {
+          l => l.head.transform(worldWithoutMongoId).get
+        }
+      }))
+
+      futureWorlds.map { worlds =>
+        Ok(Json.toJson(worlds))
+      }
+    }
+  }
+
+}

+ 12 - 0
play-scala-mongodb/benchmark_config

@@ -0,0 +1,12 @@
+{
+  "framework": "play-scala-reactivemongo",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 9000,
+      "sort": 73
+    }
+  }]
+}

+ 53 - 0
play-scala-mongodb/conf/application.conf

@@ -0,0 +1,53 @@
+# This is the main configuration file for the application.
+# ~~~~~
+
+# Secret key
+# ~~~~~
+# The secret key is used to secure cryptographics functions.
+# If you deploy your application to several instances be sure to use the same key!
+application.secret="RItx1I:80?W@]8GAtPDuF8Ydd3mXM85p/<7og]Q;uBOdijQAauRDgu73B6`wQP59"
+
+# The application languages
+# ~~~~~
+application.langs="en"
+
+# Global object class
+# ~~~~~
+# Define the Global object class for this application.
+# Default to Global in the root package.
+# global=Global
+
+# Database configuration
+# ~~~~~ 
+# You can declare as many datasources as you want.
+# By convention, the default datasource is named `default`
+#
+#db.default.driver=org.h2.Driver
+#db.default.url="jdbc:h2:mem:play"
+#db.default.user=sa
+# db.default.password=
+#
+# You can expose this datasource via JNDI if needed (Useful for JPA)
+# db.default.jndiName=DefaultDS
+
+#mongodb.servers = ["192.168.100.101:27017"]
+mongodb.servers = ["localhost:27017"]
+mongodb.db = "hello_world"
+
+# Evolutions
+# ~~~~~
+# You can disable evolutions if needed
+# evolutionplugin=disabled
+
+# Logger
+# ~~~~~
+# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory .
+
+# Root logger:
+logger.root=ERROR
+
+# Logger used by the framework:
+logger.play=ERROR
+
+# Logger provided to your application:
+logger.application=ERROR

+ 1 - 0
play-scala-mongodb/conf/play.plugins

@@ -0,0 +1 @@
+400:play.modules.reactivemongo.ReactiveMongoPlugin

+ 9 - 0
play-scala-mongodb/conf/routes

@@ -0,0 +1,9 @@
+# Routes
+# This file defines all application routes (Higher priority routes first)
+# ~~~~
+
+# Home page
+GET     /db                             controllers.Application.db(queries: Int ?= 1)
+
+# Map static resources from the /public folder to the /assets URL path
+GET     /assets/*file                   controllers.Assets.at(path="/public", file)

+ 17 - 0
play-scala-mongodb/project/Build.scala

@@ -0,0 +1,17 @@
+import sbt._
+import Keys._
+
+object ApplicationBuild extends Build {
+
+  val appName         = "play-scala"
+  val appVersion      = "1.0-SNAPSHOT"
+
+  val appDependencies = Seq(
+    "org.reactivemongo" %% "play2-reactivemongo" % "0.9-SNAPSHOT"
+  )
+
+  val main = play.Project(appName, appVersion, appDependencies).settings(
+    resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
+  )
+
+}

+ 1 - 0
play-scala-mongodb/project/build.properties

@@ -0,0 +1 @@
+sbt.version=0.12.2

+ 8 - 0
play-scala-mongodb/project/plugins.sbt

@@ -0,0 +1,8 @@
+// Comment to get more information during initialization
+logLevel := Level.Warn
+
+// The Typesafe repository 
+resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
+
+// Use the Play sbt plugin for Play projects
+addSbtPlugin("play" % "sbt-plugin" % "2.1.1")

+ 29 - 0
play-scala-mongodb/setup.py

@@ -0,0 +1,29 @@
+
+import subprocess
+import sys
+import setup_util
+import os
+
+def start(args):
+  setup_util.replace_text("play-scala/conf/application.conf", "jdbc:mysql:\/\/.*:3306", "jdbc:mysql://" + args.database_host + ":3306")
+  setup_util.replace_text("play-scala/conf/application.conf", "[\"localhost:27017\"]", "[\"" + args.database_host + ":27017\"]")
+
+  subprocess.check_call("play dist", shell=True, cwd="play-scala")
+  subprocess.check_call("unzip play-scala-1.0-SNAPSHOT.zip", shell=True, cwd="play-scala/dist")
+  subprocess.check_call("chmod +x start", shell=True, cwd="play-scala/dist/play-scala-1.0-SNAPSHOT")
+  subprocess.Popen("./start", shell=True, cwd="play-scala/dist/play-scala-1.0-SNAPSHOT")
+
+  return 0
+def stop():
+  p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+  out, err = p.communicate()
+  for line in out.splitlines():
+    if './start' in line or ('play' in line and 'java' in line):
+      pid = int(line.split(None, 2)[1])
+      os.kill(pid, 9)
+  try:
+    os.remove("play-scala/RUNNING_PID")
+  except OSError:
+    pass
+
+  return 0