Browse Source

Merge branch 'fortune-page' of https://github.com/martin-g/FrameworkBenchmarks into PR648

Conflicts:
	wicket/benchmark_config
	wicket/source_code
	wicket/src/main/java/hellowicket/WicketApplication.java
	wicket/src/main/resources/hibernate.cfg.xml
Mike Smith 11 years ago
parent
commit
44a64bb79a

+ 1 - 0
wicket/benchmark_config

@@ -6,6 +6,7 @@
       "json_url": "/wicket/json",
       "db_url": "/wicket/db",
       "query_url": "/wicket/db?queries=",
+      "fortune_url": "/wicket/fortunes",
       "update_url": "/wicket/updates?queries=",
       "plaintext_url": "/wicket/plaintext",
       "port": 8080,

+ 21 - 11
wicket/source_code

@@ -1,23 +1,33 @@
-./wicket/src/main/java/
+./wicket/src/
+./wicket/src/main
+./wicket/src/main/resources
+./wicket/src/main/resources/log4j.properties
+./wicket/src/main/resources/hibernate.cfg.xml
+./wicket/src/main/java
 ./wicket/src/main/java/hellowicket
-./wicket/src/main/java/hellowicket/HelloDbResponse.java
-./wicket/src/main/java/hellowicket/HelloDbReference.java
+./wicket/src/main/java/hellowicket/BasePage.html
+./wicket/src/main/java/hellowicket/World.java
+./wicket/src/main/java/hellowicket/WicketApplication.java
+./wicket/src/main/java/hellowicket/HelloJsonReference.java
+./wicket/src/main/java/hellowicket/fortune
+./wicket/src/main/java/hellowicket/fortune/Fortune.java
+./wicket/src/main/java/hellowicket/fortune/FortunePage.html
+./wicket/src/main/java/hellowicket/fortune/FortunePage.java
 ./wicket/src/main/java/hellowicket/BasePage.java
+./wicket/src/main/java/hellowicket/HelloDbReference.java
+./wicket/src/main/java/hellowicket/HelloDbResponse.java
 ./wicket/src/main/java/hellowicket/HomePage.java
 ./wicket/src/main/java/hellowicket/HelloJsonResponse.java
-./wicket/src/main/java/hellowicket/WicketApplication.java
-./wicket/src/main/java/hellowicket/HelloJsonReference.java
-./wicket/src/main/java/hellowicket/HibernateUtil.java
-./wicket/src/main/java/hellowicket/BasePage.html
 ./wicket/src/main/java/hellowicket/HomePage.html
-./wicket/src/main/java/hellowicket/World.java
 ./wicket/src/main/java/hellowicket/plaintext/HelloTextReference.java
 ./wicket/src/main/java/hellowicket/plaintext/HelloTextResource.java
 ./wicket/src/main/java/hellowicket/dbupdates/HelloDbUpdatesResource.java
 ./wicket/src/main/java/hellowicket/dbupdates/HelloDbUpdatesReference.java
-./wicket/src/main/webapp/
-./wicket/src/main/webapp/logo.png
 ./wicket/src/main/webapp/style.css
+./wicket/src/main/java/hellowicket/HibernateUtil.java
+./wicket/src/main/webapp
 ./wicket/src/main/webapp/WEB-INF
-./wicket/src/main/webapp/WEB-INF/resin-web.xml
 ./wicket/src/main/webapp/WEB-INF/web.xml
+./wicket/src/main/webapp/WEB-INF/resin-web.xml
+./wicket/src/main/webapp/logo.png
+./wicket/src/main/webapp/style.css

+ 0 - 2
wicket/src/main/java/hellowicket/BasePage.java

@@ -1,7 +1,5 @@
 package hellowicket;
 
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.WebPage;
 
 public class BasePage extends WebPage

+ 15 - 2
wicket/src/main/java/hellowicket/HelloDbResponse.java

@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.util.concurrent.ThreadLocalRandom;
 
 import org.apache.wicket.request.resource.AbstractResource;
+import org.apache.wicket.util.string.StringValue;
 import org.hibernate.IdentifierLoadAccess;
 import org.hibernate.Session;
 
@@ -20,7 +21,17 @@ public class HelloDbResponse extends AbstractResource
 
   protected ResourceResponse newResourceResponse(Attributes attributes)
   {
-    final int queries = attributes.getRequest().getQueryParameters().getParameterValue("queries").toInt(1);
+    final StringValue queriesParam = attributes.getRequest().getQueryParameters().getParameterValue("queries");
+    int qs = queriesParam.toInt(1);
+    if (qs < 1)
+    {
+      qs = 1;
+    } 
+    else if (qs > 500)
+    {
+      qs = 500;
+    }
+    final int queries = qs;
     final World[] worlds = new World[queries];
     final ThreadLocalRandom random = ThreadLocalRandom.current();
 
@@ -44,12 +55,14 @@ public class HelloDbResponse extends AbstractResource
         try
         {
           String data;
-          if (queries == 1)
+          if (queriesParam.isNull())
           {
+              // request to /db should return JSON object
               data = HelloDbResponse.mapper.writeValueAsString(worlds[0]);
           }
           else
           {
+              // request to /db?queries=xyz should return JSON array (issue #648)
               data = HelloDbResponse.mapper.writeValueAsString(worlds);
           }
           attributes.getResponse().write(data);

+ 17 - 14
wicket/src/main/java/hellowicket/WicketApplication.java

@@ -1,43 +1,46 @@
 package hellowicket;
 
-import hellowicket.plaintext.HelloTextReference;
-import hellowicket.dbupdates.HelloDbUpdatesReference;
+import hellowicket.fortune.FortunePage;
+import org.apache.wicket.RuntimeConfigurationType;
 import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.settings.IRequestCycleSettings;
 
 /**
- * Application object for your web application. If you want to run this application without deploying, run the Start class.
- * 
- * @see hellowicket.Start#main(String[])
+ * Application object for your web application..
  */
 public class WicketApplication extends WebApplication
 {
-	/**
-	 * @see org.apache.wicket.Application#getHomePage()
-	 */
 	@Override
 	public Class<HomePage> getHomePage()
 	{
 		return HomePage.class;
 	}
 
-	/**
-	 * @see org.apache.wicket.Application#init()
-	 */
 	@Override
 	public void init()
 	{
 		super.init();
 
-		// add your configuration here
-
 		// mount the resources under test
 		mountResource("/json", new HelloJsonReference());
 		mountResource("/db", new HelloDbReference());
 		mountResource("/updates", new HelloDbUpdatesReference());
 		mountResource("/plaintext", new HelloTextReference());
 
+		mountPage("/fortunes", FortunePage.class);
+
 		// disable response caching to be more close to other
 		// test applications' behavior
-		getRequestCycleSettings().setBufferResponse(false);
+		IRequestCycleSettings requestCycleSettings = getRequestCycleSettings();
+		requestCycleSettings.setBufferResponse(false);
+
+		// set UTF-8 for /fortunes test
+		requestCycleSettings.setResponseRequestEncoding("UTF-8");
+	}
+
+	@Override
+	public RuntimeConfigurationType getConfigurationType()
+	{
+		return RuntimeConfigurationType.DEPLOYMENT;
 	}
 }

+ 18 - 0
wicket/src/main/java/hellowicket/fortune/Fortune.java

@@ -0,0 +1,18 @@
+package hellowicket.fortune;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ *
+ */
+@Entity
+public class Fortune
+{
+	@Id
+	@GeneratedValue(strategy = GenerationType.IDENTITY)
+	public int id;
+	public String message;
+}

+ 14 - 0
wicket/src/main/java/hellowicket/fortune/FortunePage.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+    <title>Fortunes</title>
+</head>
+<body>
+    <table>
+        <tr><th>id</th><th>message</th></tr>
+        <wicket:container wicket:id="fortunes">
+            <tr><td wicket:id="id"></td><td wicket:id="message"></td></tr>
+        </wicket:container>
+    </table>
+</body>
+</html>

+ 62 - 0
wicket/src/main/java/hellowicket/fortune/FortunePage.java

@@ -0,0 +1,62 @@
+package hellowicket.fortune;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import hellowicket.HibernateUtil;
+
+/**
+ * A page that loads all fortune cookies
+ */
+public class FortunePage extends WebPage
+{
+  public FortunePage()
+  {
+    Session session = HibernateUtil.getSessionFactory().openSession();
+
+    Query query = session.createQuery("from Fortune");
+    query.setReadOnly(true);
+    List list = query.list();
+    List<Fortune> fortunes = new ArrayList<Fortune>(list);
+    session.close();
+
+    Fortune newFortune = new Fortune();
+    newFortune.message = "Additional fortune added at request time.";
+    fortunes.add(newFortune);
+
+    sort(fortunes);
+
+    ListView<Fortune> listView = new ListView<Fortune>("fortunes", fortunes)
+    {
+      @Override
+      protected void populateItem(ListItem<Fortune> item)
+      {
+        Fortune fortune = item.getModelObject();
+        item.add(new Label("id", fortune.id));
+        item.add(new Label("message", fortune.message));
+      }
+    };
+    add(listView);
+  }
+
+  private void sort(List<Fortune> fortunes)
+  {
+    Collections.sort(fortunes, new Comparator<Fortune>()
+    {
+      @Override
+      public int compare(Fortune f1, Fortune f2)
+      {
+        return f1.message.compareTo(f2.message);
+      }
+    });
+  }
+}

+ 1 - 0
wicket/src/main/resources/hibernate.cfg.xml

@@ -19,5 +19,6 @@
         <property name="hibernate.jdbc.batch_size">500</property>
 
         <mapping class="hellowicket.World" />
+        <mapping class="hellowicket.fortune.Fortune"/>
     </session-factory>
 </hibernate-configuration>