Browse Source

Clean up play2-scala-activate
Squashed commit of the following:

commit 7dd0314e505ec220895fa10c9afdef62ccb0924c
Author: Brittany Mazza <[email protected]>
Date: Wed Mar 11 14:05:28 2015 -0700

Include play2 scala activate

... because I don't know why not.

commit 572f9a64aa00095c3776a6ac3a1d1425496291c7
Author: Brittany Mazza <[email protected]>
Date: Wed Mar 11 14:04:16 2015 -0700

Add set up file for play2 scala activate

commit 127855c5d30ca0e0e00e22b3d229a276a50cc26f
Author: Brittany Mazza <[email protected]>
Date: Wed Mar 11 13:45:04 2015 -0700

Use old methods for play2-scala-reactivemongo (mongodb) to pass tests

commit b77e03129861181f383f38140754118f87500e37
Author: Brittany Mazza <[email protected]>
Date: Wed Mar 11 13:11:54 2015 -0700

Remove unused python setup scripts

commit 2717813f4b2823793434b4854e663efbe010ce61
Author: Brittany Mazza <[email protected]>
Date: Wed Mar 11 13:06:31 2015 -0700

WIP Replace play2-scala-mongodb with play2-scala-reactivemongo

commit b6fef5388d10983d76cdd31d59aff4218e05bad5
Author: Brittany Mazza <[email protected]>
Date: Wed Mar 11 12:49:09 2015 -0700

Remove generage python set up script for play 2

Brittany Mazza 10 years ago
parent
commit
0617e73730

+ 0 - 179
frameworks/Java/play2-java/generate_config.py

@@ -1,179 +0,0 @@
-#!/usr/bin/env python
-
-import collections, json, os, textwrap
-
-# This script generates the benchmark_config and setup_*.py files.
-# To add new tests, modify the `configurations` and `test_urls` tables.
-
-# Each line corresponds to a test application.
-# Format is: (language, orm, (opsys, ...), (test, ...))
-# See the dir_name logic below to see the directory name for each test application.
-Config = collections.namedtuple('Config', ['lang', 'orm', 'db', 'operatingSystems', 'tests', 'shouldIncludeResults'])
-configurations = [
-
-  # Plain Java test
-
-  Config(
-    'Java', None, None,
-    operatingSystems = ['Linux'],
-    tests = ['json'],
-    shouldIncludeResults = True
-  ),
-
-  # Java database tests
-
-  Config(
-    'Java', 'Ebean', 'MySQL',
-    operatingSystems = ['Linux'],
-    tests = ['db', 'query'],
-    shouldIncludeResults = True
-  ),
-  Config(
-    'Java', 'JPA', 'MySQL',
-    operatingSystems = ['Linux'],
-    tests = ['db', 'query', 'fortune', 'update', 'plaintext'],
-    shouldIncludeResults = True
-  ),
-  Config(
-    'Java', 'JPA HikariCP', 'MySQL',
-    operatingSystems = ['Linux'],
-    tests = ['db', 'query', 'fortune', 'update', 'plaintext'],
-    shouldIncludeResults = True
-  ),
-
-  # Plain Scala test
-
-  Config(
-    'Scala', None, None,
-    operatingSystems = ['Linux'],
-    tests = ['json'],
-    shouldIncludeResults = True
-  ),
-
-  # Scala database tests
-
-  Config(
-    'Scala', 'Activate', 'MySQL',
-    operatingSystems = ['Linux'],
-    tests = ['db', 'query', 'fortune', 'update'],
-    shouldIncludeResults = False # Uses old versions of Play and Activate
-  ),
-  Config(
-    'Scala', 'Anorm', 'MySQL',
-    operatingSystems = ['Linux', 'Windows'],
-    tests = ['db', 'query', 'fortune', 'update'],
-    shouldIncludeResults = True
-  ),
-  Config(
-    'Scala', 'ReactiveMongo', 'MongoDB',
-    operatingSystems = ['Linux'],
-    tests = ['db', 'query'],
-    shouldIncludeResults = True # Updated to Play 2.3 and ReactiveMongo 0.10, but no maintainer
-  ),
-  Config(
-    'Scala', 'Slick', 'MySQL',
-    operatingSystems = ['Linux'],
-    tests = ['db', 'query', 'fortune', 'update'],
-    shouldIncludeResults = True
-  )
-]
-
-# All play2 test applications must use the same URLs.
-test_urls = {
-  'json': '/json',
-  'db': '/db',
-  'query': '/queries?queries=',
-  'fortune': '/fortunes',
-  'update': '/update?queries=',
-  'plaintext': '/plaintext',
-}
-
-langs = {
-  'Java': ['Java', 'play2-java'],
-  'Scala': ['Scala', 'play2-scala']
-}
-def pathForLang(lang):
-  return os.path.join(frameworksPath(), *langs[lang])
-def frameworksPath():
-  'Get the absolute path of ROOT/frameworks'
-  return os.path.abspath(os.path.join(__file__, '..', '..', '..'))
-
-def maybe(item):
-  'Maps None => [] and item => [item]'
-  if item is None:
-    return []
-  else:
-    return [item]
-
-def namify(bits, sep):
-  'Joins a list of bits together then replaces spaces with sep.'
-  return ' '.join(bits).replace(' ', sep).lower()
-
-lang_test_configs = {}
-for lang, _ in langs.iteritems():
-  lang_test_configs[lang] = collections.OrderedDict()
-
-for config in configurations:
-
-  core_name_bits = [config.lang] + maybe(config.orm)
-  dir_name = namify(['play2'] + core_name_bits, '-')
-  setup_name = namify(['setup'] + core_name_bits, '_')
-
-  setup_path = os.path.join(pathForLang(config.lang), setup_name+'.py')
-  print 'Generating', setup_path
-  with open(setup_path, 'w') as f:
-    f.write(textwrap.dedent("""
-      # This file was generated by frameworks/Java/play2-java/generate_config.py.
-      # Do not edit this file directly, use the script to regenerate.
-      from .setup_common import make_setup_for_dir
-
-      make_setup_for_dir(globals(), '"""+dir_name+"""')
-    """))
-
-  # We make a separate test config entry for each operating system
-  # that the test runs on.
-  for opsys in config.operatingSystems:
-
-    # Note the test name may differ from the directory name because
-    # it may have the OS name or a word to show that results shouldn't
-    # be included.
-
-    # If there is more than one OS then add the current OS to the test name
-    # so we can distinguish between the tests.
-    opsys_name_bit = [] if len(config.operatingSystems) == 1 else [opsys]
-
-    # If the test is out of date then add 'do not include' to the end of the
-    # test name to make it harder to accidentally include in final results.
-    tags_bit = [] if config.shouldIncludeResults else ['do not include']
-    test_name_bits = core_name_bits + opsys_name_bit + tags_bit
-
-    test_config_json = collections.OrderedDict([
-      ('display_name', namify(['play2'] + test_name_bits, '-')),
-      ('setup_file', setup_name),
-      ('framework', 'play2'),
-      ('language', config.lang),
-      ('orm', 'Full' if config.orm else 'Raw'),
-      ('os', opsys),
-      ('database', config.db if config.db else 'None'),
-      ('approach', 'Realistic'),
-      ('classification', 'Fullstack'),
-      ('platform', 'Netty'),
-      ('webserver', 'None'),
-      ('database_os', 'Linux'),
-      ('notes', ''),
-      ('versus', 'netty'),
-      ('port', '9000'),
-    ])
-    for test in config.tests:
-      test_config_json[test+'_url'] = test_urls[test]
-      lang_test_configs[config.lang][namify(test_name_bits, '-')] = test_config_json
-
-for lang, _ in langs.iteritems():
-  benchmark_config_path = os.path.join(pathForLang(lang), 'benchmark_config')
-  print 'Generating', benchmark_config_path
-  with open(benchmark_config_path, 'w') as f:
-    json_str = json.dumps({
-      'framework': 'play2',
-      'tests': [lang_test_configs[lang]]
-    }, indent=2)
-    f.write(json_str)

+ 0 - 13
frameworks/Scala/play-activate-mysql/setup.sh

@@ -1,13 +0,0 @@
-#!/bin/bash
-export PLAY2_HOME=${IROOT}/play-2.2.0
-
-sed -i 's|jdbc:mysql://.*:3306|jdbc:mysql://'"${DBHOST}"':3306|g' conf/application.conf
-
-${PLAY2_HOME}/play clean dist
-
-cd target/universal
-unzip play-activate-mysql-1.0-SNAPSHOT.zip
-cd play-activate-mysql-1.0-SNAPSHOT/bin
-chmod +x play-activate-mysql
-
-./play-activate-mysql &

+ 0 - 33
frameworks/Scala/play2-scala/play2-scala-mongodb/.gitignore

@@ -1,33 +0,0 @@
-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
-

+ 0 - 20
frameworks/Scala/play2-scala/play2-scala-mongodb/README.md

@@ -1,20 +0,0 @@
-#Play Benchmarking Test
-
-This is the Play portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
-
-### 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.2.0](http://http://www.playframework.com/)
-* [Reactivemongo 0.10.5.0.akka22](https://github.com/zenexity/Play-ReactiveMongo)
-
-## Test URLs
-### Single Database Query test
-http://localhost:9000/db
-### Multiple Database Query test
-http://localhost:9000/queries?queries=5

+ 0 - 77
frameworks/Scala/play2-scala/play2-scala-mongodb/app/controllers/Application.scala

@@ -1,77 +0,0 @@
-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, ExecutionContext}
-import scala.collection.convert.WrapAsScala.collectionAsScalaIterable
-import play.modules.reactivemongo.ReactiveMongoPlugin
-import play.modules.reactivemongo.json.collection.JSONCollection
-import play.api.libs.concurrent.Execution.Implicits._
-import play.api.libs.concurrent.Akka
-
-object Application extends Controller {
-
-  private val TestDatabaseRows = 10000
-
-  val DEFAULT_HOST = "localhost:27017"
-  val servers = current.configuration.getStringList("mongodb.servers") match {
-    case Some(servers) => collectionAsScalaIterable(servers).toList
-    case None => List(DEFAULT_HOST)
-  }
-
-  val DEFAULT_DB = "hello_world"
-  val db = current.configuration.getString("mongodb.db").getOrElse(DEFAULT_DB)
-
-  //private val dbExecutionContext: ExecutionContext = Akka.system.dispatchers.lookup("dbExecutionContext")
-  private val database = ReactiveMongoPlugin
-    .driver
-    .connection(servers, nbChannelsPerNode = 10)
-    .db(db)//(dbExecutionContext)
-
-  private def collection: JSONCollection = database.collection[JSONCollection]("world")
-  private val projection = Json.obj("_id" -> 0)
-  /**
-   * Returns the closest number to <code>toRestrict</code> that is within the
-   * specified bounds, inclusive on both ends.
-   */
-  private def restrictWithin(toRestrict: String, lowerBound: Int, upperBound: Int): Option[Int] = {
-    try {
-      Some(math.min(upperBound, math.max(toRestrict.toInt, lowerBound)))
-    } catch {
-      case e: Exception => None
-    }
-  }
-
-  def dbqueries(requestedQueries: String) = Action.async {
-    import scala.concurrent.ExecutionContext.Implicits.global
-
-    val random = ThreadLocalRandom.current()
-    val queries = restrictWithin(requestedQueries, 1, 500).getOrElse(1)
-    val futureWorlds = Future.sequence((for {
-      _ <- 1 to queries
-    } yield { collection
-      .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)), projection)
-      .one[JsValue]
-    }))
-    futureWorlds.map { worlds =>
-      Ok(Json.toJson(worlds.map {maybeWorld =>
-        maybeWorld.map {world =>
-          world.as[Map[String, Int]]
-        }
-      }))
-    }
-  }
-  def singledb() = Action.async {
-    import scala.concurrent.ExecutionContext.Implicits.global
-
-    val random = ThreadLocalRandom.current()
-    val futureWorld = collection
-      .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)), projection)
-      .one[JsValue]
-    futureWorld.map { world =>
-      Ok(Json.toJson(world.head.as[Map[String, Int]]))
-    }
-  }
-}

+ 0 - 68
frameworks/Scala/play2-scala/play2-scala-mongodb/conf/application.conf

@@ -1,68 +0,0 @@
-# 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
-
-#play {
-#  akka {
-#    event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
-#    loglevel = ERROR
-#    actor {
-#      dbExecutionContext = {
-#        fork-join-executor {
-#          parallelism-min = 128
-#          parallelism-max = 128
-#        }
-#      }
-#    }
-#  }
-#}

+ 0 - 1
frameworks/Scala/play2-scala/play2-scala-mongodb/conf/play.plugins

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

+ 0 - 10
frameworks/Scala/play2-scala/play2-scala-mongodb/conf/routes

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

+ 0 - 16
frameworks/Scala/play2-scala/play2-scala-mongodb/project/Build.scala

@@ -1,16 +0,0 @@
-import sbt._
-import Keys._
-
-object ApplicationBuild extends Build {
-
-  val appName         = "play2-scala-mongodb"
-  val appVersion      = "1.0-SNAPSHOT"
-
-  val appDependencies = Seq(
-    "org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka22" exclude("org.scala-stm", "scala-stm_2.10.0")
-  )
-
-  val main = play.Project(appName, appVersion, appDependencies).settings(
-  )
-
-}

+ 0 - 1
frameworks/Scala/play2-scala/play2-scala-mongodb/project/build.properties

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

+ 0 - 8
frameworks/Scala/play2-scala/play2-scala-mongodb/project/plugins.sbt

@@ -1,8 +0,0 @@
-// 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("com.typesafe.play" % "sbt-plugin" % "2.2.0")

+ 0 - 3
frameworks/Scala/play2-scala/play2-scala-mongodb/source_code

@@ -1,3 +0,0 @@
-./play-scala-mongodb/app/
-./play-scala-mongodb/app/controllers
-./play-scala-mongodb/app/controllers/Application.scala

+ 42 - 40
frameworks/Scala/play2-scala/play2-scala-reactivemongo/app/controllers/Application.scala

@@ -13,6 +13,8 @@ import play.api.libs.concurrent.Akka
 
 object Application extends Controller {
 
+  private val TestDatabaseRows = 10000
+
   val DEFAULT_HOST = "localhost:27017"
   val servers = current.configuration.getStringList("mongodb.servers") match {
     case Some(servers) => collectionAsScalaIterable(servers).toList
@@ -20,56 +22,56 @@ object Application extends Controller {
   }
 
   val DEFAULT_DB = "hello_world"
-  val dbName = current.configuration.getString("mongodb.db").getOrElse(DEFAULT_DB)
+  val db = current.configuration.getString("mongodb.db").getOrElse(DEFAULT_DB)
 
   //private val dbExecutionContext: ExecutionContext = Akka.system.dispatchers.lookup("dbExecutionContext")
-  private val database = {
-    ReactiveMongoPlugin
-      .driver
-      .connection(servers, nbChannelsPerNode = 10)
-      .db(dbName)//(dbExecutionContext)
-  }
+  private val database = ReactiveMongoPlugin
+    .driver
+    .connection(servers, nbChannelsPerNode = 10)
+    .db(db)//(dbExecutionContext)
 
+  private def collection: JSONCollection = database.collection[JSONCollection]("world")
   private val projection = Json.obj("_id" -> 0)
-
-  def getRandomWorlds(n: Int): Future[Seq[JsValue]] = {
-    val random = ThreadLocalRandom.current()
-    Future.sequence((for {
-      _ <- 1 to n
-    } yield {
-      database.collection[JSONCollection]("world")
-        .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)), projection)
-        .one[JsValue].map(_.get)
-    }))
-  }
-
-  // Common code between Scala database code
-
-  private val TestDatabaseRows = 10000
-
-  def db = Action.async {
-    getRandomWorlds(1).map { worlds =>
-      Ok(Json.toJson(worlds.head))
+  /**
+   * Returns the closest number to <code>toRestrict</code> that is within the
+   * specified bounds, inclusive on both ends.
+   */
+  private def restrictWithin(toRestrict: String, lowerBound: Int, upperBound: Int): Option[Int] = {
+    try {
+      Some(math.min(upperBound, math.max(toRestrict.toInt, lowerBound)))
+    } catch {
+      case e: Exception => None
     }
   }
 
-  def queries(countString: String) = Action.async {
-    val n = parseCount(countString)
-    getRandomWorlds(n).map { worlds =>
-      Ok(Json.toJson(worlds))
+  def dbqueries(requestedQueries: String) = Action.async {
+    import scala.concurrent.ExecutionContext.Implicits.global
+
+    val random = ThreadLocalRandom.current()
+    val queries = restrictWithin(requestedQueries, 1, 500).getOrElse(1)
+    val futureWorlds = Future.sequence((for {
+      _ <- 1 to queries
+    } yield { collection
+      .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)), projection)
+      .one[JsValue]
+    }))
+    futureWorlds.map { worlds =>
+      Ok(Json.toJson(worlds.map {maybeWorld =>
+        maybeWorld.map {world =>
+          world.as[Map[String, Int]]
+        }
+      }))
     }
   }
+  def singledb() = Action.async {
+    import scala.concurrent.ExecutionContext.Implicits.global
 
-  private def parseCount(s: String): Int = {
-    try {
-      val parsed = java.lang.Integer.parseInt(s, 10)
-      parsed match {
-        case i if i < 1 => 1
-        case i if i > 500 => 500
-        case i => i
-      }
-    } catch {
-      case _: NumberFormatException => 1
+    val random = ThreadLocalRandom.current()
+    val futureWorld = collection
+      .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)), projection)
+      .one[JsValue]
+    futureWorld.map { world =>
+      Ok(Json.toJson(world.head.as[Map[String, Int]]))
     }
   }
 }

+ 2 - 2
frameworks/Scala/play2-scala/play2-scala-reactivemongo/conf/routes

@@ -2,8 +2,8 @@
 # This file defines all application routes (Higher priority routes first)
 # ~~~~
 
-GET     /db                             controllers.Application.db
-GET     /queries                        controllers.Application.queries(queries ?= "1")
+GET     /db                             controllers.Application.singledb
+GET     /queries                        controllers.Application.dbqueries(queries: String ?= "1")
 
 # Map static resources from the /public folder to the /assets URL path
 GET     /assets/*file                   controllers.Assets.at(path="/public", file)

+ 0 - 6
frameworks/Scala/play2-scala/setup_scala_activate.py

@@ -1,6 +0,0 @@
-
-# This file was generated by frameworks/Java/play2-java/generate_config.py.
-# Do not edit this file directly, use the script to regenerate.
-from .setup_common import make_setup_for_dir
-
-make_setup_for_dir(globals(), 'play2-scala-activate')

+ 4 - 4
frameworks/Scala/play2-scala/setup_scala_mongodb.sh → frameworks/Scala/play2-scala/setup_scala_activate.sh

@@ -1,16 +1,16 @@
 #!/bin/bash
 
-cd play2-scala-mongodb
+cd play2-scala-activate
 sed -i 's|jdbc:mysql://.*:3306|jdbc:mysql://'"${DBHOST}"':3306|g' conf/application.conf
 
 # If application has an already existing process id, clear it.
-if [ -f ${TROOT}/play2-scala-mongodb/target/universal/stage/RUNNING_PID ]
+if [ -f ${TROOT}/play2-scala-activate/target/universal/stage/RUNNING_PID ]
 then
-  rm -f -r ${TROOT}/play2-scala-mongodb/target/universal/stage/RUNNING_PID
+  rm -f -r ${TROOT}/play2-scala-activate/target/universal/stage/RUNNING_PID
 fi
 
 # Stage application.
 ${IROOT}/sbt/bin/sbt stage
 
 # Execute Start script in background.
-${TROOT}/play2-scala-mongodb/target/universal/stage/bin/play2-scala-mongodb &
+${TROOT}/play2-scala-activate/target/universal/stage/bin/play2-scala-activate &

+ 0 - 6
frameworks/Scala/play2-scala/setup_scala_reactivemongo.py

@@ -1,6 +0,0 @@
-
-# This file was generated by frameworks/Java/play2-java/generate_config.py.
-# Do not edit this file directly, use the script to regenerate.
-from .setup_common import make_setup_for_dir
-
-make_setup_for_dir(globals(), 'play2-scala-reactivemongo')

+ 16 - 0
frameworks/Scala/play2-scala/setup_scala_reactivemongo.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+cd play2-scala-reactivemongo
+sed -i 's|jdbc:mysql://.*:3306|jdbc:mysql://'"${DBHOST}"':3306|g' conf/application.conf
+
+# If application has an already existing process id, clear it.
+if [ -f ${TROOT}/play2-scala-reactivemongo/target/universal/stage/RUNNING_PID ]
+then
+  rm -f -r ${TROOT}/play2-scala-reactivemongo/target/universal/stage/RUNNING_PID
+fi
+
+# Stage application.
+${IROOT}/sbt/bin/sbt stage
+
+# Execute Start script in background.
+${TROOT}/play2-scala-reactivemongo/target/universal/stage/bin/play2-scala-reactivemongo &