Browse Source

Add json benchmark support to dylan framework. (#6094)

Alfredo Beaumont 4 years ago
parent
commit
1ab035feb5

+ 4 - 0
frameworks/Dylan/dylan/README.md

@@ -12,3 +12,7 @@ The tests were run with:
 ### Plaintext Test
 
 http://localhost:8080/plaintext
+
+### JSON Test
+
+http://localhost:8080/json

+ 1 - 0
frameworks/Dylan/dylan/benchmark_config.json

@@ -2,6 +2,7 @@
   "framework": "dylan",
   "tests": [{
     "default": {
+      "json_url": "/json",
       "plaintext_url": "/plaintext",
       "port": 8080,
       "approach": "Realistic",

+ 14 - 3
frameworks/Dylan/dylan/dylan-server.dylan

@@ -1,17 +1,28 @@
 Module: dylan-server
 
-define class <hello-page> (<resource>)
+define class <plaintext> (<resource>)
 end;
 
-define method respond (page :: <hello-page>, #key)
+define method respond (plaintext :: <plaintext>, #key)
   let stream = current-response();
   set-header(stream, "Content-Type", "text/plain;charset=utf-8");
   set-header(stream, "Date", as-rfc1123-string(current-date()));
   write(stream, "Hello, World!");
 end;
 
+define class <json> (<resource>)
+end;
+
+define method respond (json :: <json>, #key)
+  let stream = current-response();
+  set-header(stream, "Content-Type", "application/json");
+  set-header(stream, "Date", as-rfc1123-string(current-date()));
+  print(table("message" => "Hello, World!"), stream);
+end;
+
 let server = make(<http-server>, listeners: list("0.0.0.0:8080"));
 
-add-resource(server, "/plaintext", make(<hello-page>));
+add-resource(server, "/plaintext", make(<plaintext>));
+add-resource(server, "/json", make(<json>));
 
 start-server(server);

+ 2 - 1
frameworks/Dylan/dylan/dylan.dockerfile

@@ -9,6 +9,7 @@ RUN wget -q https://opendylan.org/downloads/opendylan/2019.1/opendylan-2019.1-x8
 RUN tar xjf opendylan-2019.1-x86_64-linux.tar.bz2
 
 RUN git clone --recursive https://github.com/dylan-lang/http
+RUN git clone https://github.com/dylan-lang/json
 
 ENV PATH /opt/opendylan-2019.1/bin:$PATH
 
@@ -16,7 +17,7 @@ WORKDIR /
 
 RUN make-dylan-app dylan-server
 
-ENV OPEN_DYLAN_USER_REGISTRIES /dylan-server/registry:/opt/http/registry
+ENV OPEN_DYLAN_USER_REGISTRIES /dylan-server/registry:/opt/http/registry:/opt/json/registry
 
 COPY *.dylan dylan-server/
 

+ 5 - 1
frameworks/Dylan/dylan/library.dylan

@@ -2,9 +2,11 @@ Module: dylan-user
 
 define library dylan-server
   use common-dylan;
-  use io, import: { streams };
+  use collections;
   use http-common;
   use http-server;
+  use io, import: { streams };
+  use json;
   use system, import: { date };
 end library dylan-server;
 
@@ -13,5 +15,7 @@ define module dylan-server
   use date, import: { as-rfc1123-string, current-date };
   use http-common;
   use http-server;
+  use json;
   use streams, import: { write };
+  use table-extensions;
 end module dylan-server;