Browse Source

Updated configuration and reduced code

ericbn 10 years ago
parent
commit
e2bcc4c63b

+ 6 - 23
frameworks/Java/activeweb/benchmark_config

@@ -4,40 +4,23 @@
     "default": {
       "setup_file": "setup",
       "json_url": "/activeweb/json",
-      "plaintext_url": "/activeweb/plaintext",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Platform",
-      "database": "None",
-      "framework": "activeweb",
-      "language": "Java",
-      "orm": "Raw",
-      "platform": "ActiveWeb",
-      "webserver": "Resin",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "ActiveWeb",
-      "notes": "",
-      "versus": "servlet"
-    },
-    "raw": {
-      "setup_file": "setup",
       "db_url": "/activeweb/db",
       "query_url": "/activeweb/queries?queries=",
       "fortune_url": "/activeweb/fortunes",
       "update_url": "/activeweb/updates?queries=",
+      "plaintext_url": "/activeweb/plaintext",
       "port": 8080,
       "approach": "Realistic",
-      "classification": "Platform",
+      "classification": "Full-stack",
       "database": "MySQL",
-      "framework": "ActiveWeb",
+      "framework": "activeweb",
       "language": "Java",
-      "orm": "Raw",
-      "platform": "ActiveWeb",
+      "orm": "Micro",
+      "platform": "Servlet",
       "webserver": "Resin",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "activeweb",
+      "display_name": "ActiveWeb",
       "notes": "",
       "versus": "servlet"
     }

+ 5 - 0
frameworks/Java/activeweb/pom.xml

@@ -89,6 +89,11 @@
             <artifactId>activeweb</artifactId>
             <version>${activeweb.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.javalite</groupId>
+            <artifactId>activejdbc</artifactId>
+            <version>1.4.10-SNAPSHOT</version>
+        </dependency>
         <dependency>
             <groupId>org.javalite</groupId>
             <artifactId>activeweb-testing</artifactId>

+ 13 - 14
frameworks/Java/activeweb/source_code

@@ -1,14 +1,13 @@
-./src/main/java/app/config/AppControllerConfig.java
-./src/main/java/app/config/RouteConfig.java
-./src/main/java/app/config/FreeMarkerConfig.java
-./src/main/java/app/config/DbConfig.java
-./src/main/java/app/config/AppBootstrap.java
-./src/main/java/app/models/World.java
-./src/main/java/app/models/Fortune.java
-./src/main/java/app/controllers/PlaintextController.java
-./src/main/java/app/controllers/JsonController.java
-./src/main/java/app/controllers/DatabaseController.java
-./src/main/java/app/controllers/FortunesController.java
-./src/main/java/app/controllers/QueriesController.java
-./src/main/java/app/controllers/HomeController.java
-./src/main/java/app/controllers/UpdatesController.java
+./activeweb/src/main/java/app/config/AppBootstrap.java
+./activeweb/src/main/java/app/config/AppControllerConfig.java
+./activeweb/src/main/java/app/config/DbConfig.java
+./activeweb/src/main/java/app/config/RouteConfig.java
+./activeweb/src/main/java/app/controllers/DbController.java
+./activeweb/src/main/java/app/controllers/FortunesController.java
+./activeweb/src/main/java/app/controllers/HomeController.java
+./activeweb/src/main/java/app/controllers/JsonController.java
+./activeweb/src/main/java/app/controllers/PlaintextController.java
+./activeweb/src/main/java/app/controllers/QueriesController.java
+./activeweb/src/main/java/app/controllers/UpdatesController.java
+./activeweb/src/main/java/app/models/Fortune.java
+./activeweb/src/main/java/app/models/World.java

+ 0 - 3
frameworks/Java/activeweb/src/main/java/app/config/AppBootstrap.java

@@ -17,8 +17,6 @@ package app.config;
 
 import org.javalite.activeweb.AppContext;
 import org.javalite.activeweb.Bootstrap;
-
-import org.javalite.activeweb.Configuration;
 import org.javalite.templator.TemplatorConfig;
 
 /**
@@ -26,7 +24,6 @@ import org.javalite.templator.TemplatorConfig;
  */
 public class AppBootstrap extends Bootstrap {
     public void init(AppContext context) {
-        Configuration.setUseDefaultLayoutForErrors(true);
         TemplatorConfig.instance().cacheTemplates(true);
     }
 }

+ 2 - 2
frameworks/Java/activeweb/src/main/java/app/config/AppControllerConfig.java

@@ -16,7 +16,7 @@ limitations under the License.
 package app.config;
 
 
-import app.controllers.DatabaseController;
+import app.controllers.DbController;
 import app.controllers.FortunesController;
 import app.controllers.QueriesController;
 import app.controllers.UpdatesController;
@@ -33,7 +33,7 @@ public class AppControllerConfig extends AbstractControllerConfig {
     public void init(AppContext context) {
 //        addGlobalFilters(new TimingFilter()); for speed - not sure how logging is configured
 
-        add(new DBConnectionFilter()).to(DatabaseController.class, QueriesController.class,
+        add(new DBConnectionFilter()).to(DbController.class, QueriesController.class,
                 FortunesController.class, UpdatesController.class);
     }
 }

+ 1 - 4
frameworks/Java/activeweb/src/main/java/app/config/RouteConfig.java

@@ -20,13 +20,10 @@ limitations under the License.
 
 package app.config;
 
-import app.controllers.DatabaseController;
 import org.javalite.activeweb.AbstractRouteConfig;
 import org.javalite.activeweb.AppContext;
 
 public class RouteConfig extends AbstractRouteConfig {
-    @Override
-    public void init(AppContext appContext) {
-        route("/db").to(DatabaseController.class);
+    @Override public void init(AppContext appContext) {
     }
 }

+ 12 - 15
frameworks/Java/activeweb/src/main/java/app/controllers/DatabaseController.java → frameworks/Java/activeweb/src/main/java/app/controllers/DbController.java

@@ -1,17 +1,17 @@
 /*
-Copyright 2009-2010 Igor Polevoy 
+Copyright 2009-2010 Igor Polevoy
 
-Licensed under the Apache License, Version 2.0 (the "License"); 
-you may not use this file except in compliance with the License. 
-You may obtain a copy of the License at 
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
 
-http://www.apache.org/licenses/LICENSE-2.0 
+http://www.apache.org/licenses/LICENSE-2.0
 
-Unless required by applicable law or agreed to in writing, software 
-distributed under the License is distributed on an "AS IS" BASIS, 
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-See the License for the specific language governing permissions and 
-limitations under the License. 
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
 */
 
 /**
@@ -24,14 +24,11 @@ import app.models.World;
 import org.javalite.activeweb.AppController;
 
 import java.util.Date;
-import java.util.Random;
 import java.util.concurrent.ThreadLocalRandom;
 
-public class DatabaseController extends AppController {
+public class DbController extends AppController {
     public void index() {
-
-        String json = World.findById(ThreadLocalRandom.current().nextInt(10000)).toJson(false, "id", "randomNumber");
-
+        String json = World.findById(ThreadLocalRandom.current().nextInt(10000) + 1).toJson(false, "id", "randomNumber");
         respond(json).contentType("application/json")
                 .header("Content-Length", String.valueOf(json.length()))
                 .header("Date", new Date().toString());

+ 0 - 1
frameworks/Java/activeweb/src/main/java/app/controllers/FortunesController.java

@@ -25,7 +25,6 @@ import org.javalite.activeweb.AppController;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
 
 public class FortunesController extends AppController {

+ 2 - 4
frameworks/Java/activeweb/src/main/java/app/controllers/QueriesController.java

@@ -25,7 +25,6 @@ import org.javalite.activeweb.AppController;
 
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.ThreadLocalRandom;
 
@@ -46,7 +45,7 @@ public class QueriesController extends AppController {
         return worlds;
     }
 
-    public int getQueries() {
+    protected int getQueries() {
         int queries;
         try {
             queries = Integer.parseInt(param("queries"));
@@ -64,8 +63,7 @@ public class QueriesController extends AppController {
         return ThreadLocalRandom.current().nextInt(10000) + 1;
     }
 
-    @Override
-    protected String getLayout() {
+    @Override protected String getLayout() {
         return null;
     }
 }

+ 1 - 3
frameworks/Java/activeweb/src/main/java/app/controllers/UpdatesController.java

@@ -21,13 +21,11 @@ limitations under the License.
 package app.controllers;
 
 import app.models.World;
-import org.javalite.activeweb.AppController;
 
 import java.util.List;
-import java.util.concurrent.ThreadLocalRandom;
 
 public class UpdatesController extends QueriesController {
-    public void index() {
+    @Override public void index() {
         List<World> worlds = getWorlds();
         for (World world : worlds) {
             world.set("randomNumber", randomNumber()).saveIt();

+ 1 - 1
frameworks/Java/activeweb/src/main/java/app/models/Fortune.java

@@ -25,7 +25,7 @@ import org.javalite.activejdbc.annotations.Table;
 
 @Table("Fortune")
 public class Fortune extends Model implements Comparable<Fortune> {
-    public int compareTo(Fortune other) {
+    @Override public int compareTo(Fortune other) {
         return getString("message").compareTo(other.getString("message"));
     }
 }

+ 1 - 20
frameworks/Java/activeweb/src/main/webapp/WEB-INF/views/fortunes/index.html

@@ -1,20 +1 @@
-<!DOCTYPE html>
-<html>
-<head><title>Fortunes</title></head>
-<body>
-<table>
-    <tr>
-        <th>id</th>
-        <th>message</th>
-    </tr>
-
-<#list fortunes as fortune >
-    <tr>
-        <td>${fortune.id}</td>
-        <td>${fortune.message}</td>
-    </tr>
-</#list>
-
-</table>
-</body>
-</html>
+<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr><#list fortunes as fortune ><tr><td>${fortune.id}</td><td>${fortune.message}</td></tr></#list></table></body></html>

+ 1 - 5
frameworks/Java/activeweb/src/main/webapp/WEB-INF/views/queries/index.html

@@ -1,5 +1 @@
-[<#list worlds as w >
-    {"id":${w.id},"randomNumber":${w.randomNumber}}
-    <#if w_has_next >,</#if>
-</#list>]
-
+[<#list worlds as w >{"id":${w.id},"randomNumber":${w.randomNumber}}<#if w_has_next >,</#if></#list>]

+ 11 - 13
frameworks/Java/activeweb/src/test/java/app/controllers/DatabaseControllerSpec.java → frameworks/Java/activeweb/src/test/java/app/controllers/DbControllerSpec.java

@@ -1,17 +1,17 @@
 /*
-Copyright 2009-2010 Igor Polevoy 
+Copyright 2009-2010 Igor Polevoy
 
-Licensed under the Apache License, Version 2.0 (the "License"); 
-you may not use this file except in compliance with the License. 
-You may obtain a copy of the License at 
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
 
-http://www.apache.org/licenses/LICENSE-2.0 
+http://www.apache.org/licenses/LICENSE-2.0
 
-Unless required by applicable law or agreed to in writing, software 
-distributed under the License is distributed on an "AS IS" BASIS, 
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-See the License for the specific language governing permissions and 
-limitations under the License. 
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
 */
 
 /**
@@ -20,13 +20,11 @@ limitations under the License.
 
 package app.controllers;
 
-
-import org.javalite.activeweb.DBControllerSpec;
 import org.junit.Test;
 
 import java.util.Map;
 
-public class DatabaseControllerSpec extends DBControllerSpec {
+public class DbControllerSpec extends org.javalite.activeweb.DBControllerSpec {
 
     @Test
     public void shouldRenderOneRecord(){

+ 11 - 1
frameworks/Java/activeweb/src/test/java/app/controllers/JsonControllerSpec.java

@@ -20,11 +20,11 @@ limitations under the License.
 
 package app.controllers;
 
-import org.javalite.activeweb.Configuration;
 import org.javalite.activeweb.ControllerSpec;
 import org.junit.Test;
 
 import java.util.Map;
+import org.junit.Ignore;
 
 public class JsonControllerSpec extends ControllerSpec {
 
@@ -36,7 +36,17 @@ public class JsonControllerSpec extends ControllerSpec {
         Map result = JsonHelper.toMap(responseContent());
 
         //test result
+        the(result.size()).shouldBeEqual(1);
         a(result.get("message")).shouldBeEqual("Hello, World!");
         a(contentType()).shouldBeEqual("application/json");
     }
+
+    @Ignore
+    public void shouldRenderMessageOneMinute() {
+        long endMillis = System.currentTimeMillis() + 60*1000;
+        do {
+            request().integrateViews().get("index");
+            responseContent();
+        } while (System.currentTimeMillis() < endMillis);
+    }
 }