Browse Source

Start building out redis tests, improve lang/framework integration
Conflicts:
.travis.yml
toolset/setup/linux/languages/crystal.sh

Zane Kansil 10 years ago
parent
commit
774e16d8d0

+ 1 - 0
.travis.yml

@@ -36,6 +36,7 @@ env:
     - "TESTDIR=Clojure/pedestal"
     - "TESTDIR=Clojure/aleph"
     - "TESTDIR=Crystal/crystal-raw"
+    - "TESTDIR=Crystal/moonshine"
     - "TESTDIR=Dart/dart"
     - "TESTDIR=Dart/dart-redstone"
     - "TESTDIR=Dart/dart-start"

+ 1 - 0
frameworks/Crystal/moonshine/Projectfile

@@ -1,3 +1,4 @@
 deps do
   github "dhruvrajvanshi/Moonshine", name: "moonshine"
+  github "stefanwille/crystal-redis"
 end

+ 19 - 2
frameworks/Crystal/moonshine/benchmark_config.json

@@ -4,15 +4,32 @@
     "default": {
       "setup_file": "setup",
       "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "None",
+      "framework": "moonshine",
+      "language": "Crystal",
+      "orm": "raw",
+      "platform": "Crystal",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Moonshine",
+      "notes": "",
+      "versus": "ruby"
+    },
+    "redis": {
+      "setup_file": "setup",
       "db_url": "/db",
       "query_url": "/queries?queries=",
       "fortune_url": "/fortunes",
       "update_url": "/updates?queries=",
-      "plaintext_url": "/plaintext",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",
-      "database": "MySQL",
+      "database": "Redis",
       "framework": "moonshine",
       "language": "Crystal",
       "orm": "",

+ 25 - 10
frameworks/Crystal/moonshine/server.cr

@@ -1,4 +1,6 @@
 require "moonshine"
+require "redis"
+
 include Moonshine
 include Moonshine::Shortcuts
 include Moonshine::Http
@@ -6,12 +8,14 @@ include Moonshine::Http
 # Compose Objects (like Hash) to have a to_json method
 require "json/to_json"
 
+redis = Redis.new
 app = Moonshine::App.new
 
-is = {
-  :JSON => "application/json; charset=UTF-8"
-  :PLAIN => "text/plain"
-}
+class CONTENT
+  JSON = "application/json; charset=UTF-8"
+  PLAIN = "text/plain"
+end
+
 
 app.response_middleware do |req, res|
     res.headers["Server"] = "Moonshine"
@@ -21,15 +25,26 @@ end
 
 app.define do
 
-  route "/plaintext", do |request|
-    res = ok("Hello, World!")
-    res.headers["Content-type"] = is[:PLAIN]
+  # Test 1: JSON Serialization
+  get "/json", do |request|
+    res = ok({ :message => "Hello, World!" }.to_json)
+    res.headers["Content-type"] = CONTENT::JSON
     res
   end
 
-  get "/json", do |request|
-    res = ok({ :message => "Hello, World!" }.to_json)
-    res.headers["Content-type"] = is[:JSON]
+  # Test 4: Fortunes
+  route "/fortunes", do |request|
+    res = ok({
+      :length => redis.llen("fortunes")
+    }.to_json)
+    res.headers["Content-type"] = CONTENT::JSON
+    res
+  end
+
+  # Test 6: Plaintext
+  route "/plaintext", do |request|
+    res = ok("Hello, World!")
+    res.headers["Content-type"] = CONTENT::PLAIN
     res
   end
 

+ 1 - 4
frameworks/Crystal/moonshine/setup.sh

@@ -1,8 +1,5 @@
-export CRYSTAL_HOME=${IROOT}/crystal-0.7.1-1
-crystal=${IROOT}/crystal
+source ${IROOT}/crystal.installed
 
 $crystal deps install
 
 $crystal server.cr &
-
-exit 0

+ 1 - 3
toolset/setup/linux/languages/crystal.sh

@@ -11,6 +11,4 @@ fw_get -O $SAVE_AS $URL
 
 fw_untar crystal-0.7.1-1-linux-x86_64.tar.gz
 
-ln -s ${IROOT}/crystal-0.7.1-1/bin/crystal ${IROOT}/crystal
-
-touch ${IROOT}/crystal.installed
+echo "crystal=${IROOT}/crystal-0.7.1-1/bin/crystal" >> ${IROOT}/crystal.installed