click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From med...@apache.org
Subject svn commit: r1311324 - in /click/trunk/click/framework: src/org/apache/click/service/ src/org/apache/click/util/ test/org/apache/click/service/ test/org/apache/click/util/
Date Mon, 09 Apr 2012 16:59:25 GMT
Author: medgar
Date: Mon Apr  9 16:59:25 2012
New Revision: 1311324

URL: http://svn.apache.org/viewvc?rev=1311324&view=rev
Log:
CLK-306, added performance tests

Added:
    click/trunk/click/framework/test/org/apache/click/service/PropertyServicePerformanceTest.java
Modified:
    click/trunk/click/framework/src/org/apache/click/service/OGNLPropertyService.java
    click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java
    click/trunk/click/framework/test/org/apache/click/util/ChildObject.java

Modified: click/trunk/click/framework/src/org/apache/click/service/OGNLPropertyService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/service/OGNLPropertyService.java?rev=1311324&r1=1311323&r2=1311324&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/service/OGNLPropertyService.java (original)
+++ click/trunk/click/framework/src/org/apache/click/service/OGNLPropertyService.java Mon
Apr  9 16:59:25 2012
@@ -103,7 +103,7 @@ public class OGNLPropertyService impleme
      * @return the property value for the given source object and property name
      */
     public Object getValue(Object source, String name, Map<?, ?> cache) {
-        return PropertyUtils.getValue(source, name);
+        return PropertyUtils.getValue(source, name, cache);
     }
 
     /**

Modified: click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java?rev=1311324&r1=1311323&r2=1311324&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java Mon Apr  9 16:59:25
2012
@@ -29,6 +29,7 @@ import javax.servlet.ServletContext;
 import org.apache.click.Context;
 import org.apache.click.service.ConfigService;
 import org.apache.click.service.PropertyService;
+import org.apache.commons.lang.Validate;
 
 
 /**
@@ -108,6 +109,8 @@ public class PropertyUtils {
      * @return the property value for the given source object and property name
      */
     public static Object getValue(Object source, String name, Map cache) {
+        Validate.notNull(cache, "Null cache paramenter");
+
         String basePart = name;
         String remainingPart = null;
 

Added: click/trunk/click/framework/test/org/apache/click/service/PropertyServicePerformanceTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/service/PropertyServicePerformanceTest.java?rev=1311324&view=auto
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/service/PropertyServicePerformanceTest.java
(added)
+++ click/trunk/click/framework/test/org/apache/click/service/PropertyServicePerformanceTest.java
Mon Apr  9 16:59:25 2012
@@ -0,0 +1,156 @@
+package org.apache.click.service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import junit.framework.TestCase;
+
+import org.apache.click.util.ChildObject;
+import org.apache.click.util.ParentObject;
+
+public class PropertyServicePerformanceTest extends TestCase {
+	
+	public AtomicLong readDuration = new AtomicLong();
+	public AtomicLong writeDuration = new AtomicLong();
+	
+	public void test_MVELService() throws Exception {
+		PropertyService ps = new MVELPropertyService();
+
+		for (int i = 0; i < 100; i++) {
+			Thread testThread = new Thread(new TestRunner(ps, i == 49));
+			testThread.start();
+		}
+		
+		Thread.sleep(10000);
+	}
+	
+	public void test_OGNLService() throws Exception {
+		readDuration.set(0);
+		writeDuration.set(0);
+		
+		PropertyService ps = new OGNLPropertyService();
+
+		for (int i = 0; i < 50; i++) {
+			Thread testThread = new Thread(new TestRunner(ps, i == 49));
+			testThread.start();
+		}
+		
+		Thread.sleep(10000);
+	}
+	
+	
+	public class TestRunner implements Runnable {
+		
+		PropertyService propertyService;
+		boolean print;
+		
+		public TestRunner(PropertyService propertyService, boolean print) {
+			this.propertyService = propertyService;
+			this.print = print;
+		}
+		
+		@Override
+		public void run() {
+			long read = readDuration.addAndGet(testPropertyServiceRead(propertyService));
+			long write = writeDuration.addAndGet(testPropertyServiceWrite(propertyService));
+			
+			if (print) {
+				System.err.printf("%1s cumulative  read test in %2d ms \n", propertyService.getClass().getSimpleName(),
read);
+				System.err.printf("%1s cumulative write test in %2d ms \n", propertyService.getClass().getSimpleName(),
write);
+			}
+		}
+	}
+	
+	
+	private long testPropertyServiceRead(PropertyService propertyService) {
+		
+		long start = System.currentTimeMillis();
+		
+		for (int i = 0; i < 10000; i++) {
+			performReadTest(propertyService);
+		}
+		
+		long duration = System.currentTimeMillis() - start;
+		return duration;
+	}
+
+	private long testPropertyServiceWrite(PropertyService propertyService) {
+		
+		long start = System.currentTimeMillis();
+		
+		for (int i = 0; i < 10000; i++) {
+			performWriteTest(propertyService, i);
+		}
+		
+		long duration = System.currentTimeMillis() - start;
+		return duration;
+	}
+	
+	private void performReadTest(PropertyService propertyService) {
+        ParentObject testObject = new ParentObject();
+        Map<?, ?> cache = new HashMap<Object, Object>();
+
+        assertNull(propertyService.getValue(testObject, "name", cache));
+        assertNull(propertyService.getValue(testObject, "value", cache));
+        assertNull(propertyService.getValue(testObject, "date", cache));
+        assertNull(propertyService.getValue(testObject, "child", cache));
+
+        assertNull(propertyService.getValue(testObject, "name"));
+        assertNull(propertyService.getValue(testObject, "value"));
+        assertNull(propertyService.getValue(testObject, "date"));
+        assertNull(propertyService.getValue(testObject, "child"));
+
+        ParentObject parentObject =
+            new ParentObject("malcolm", null, new Date(), Boolean.TRUE,
+            new ChildObject("edgar", "medgar@avoka.com"));
+
+        assertEquals("malcolm", propertyService.getValue(parentObject, "name", cache));
+        assertNull(propertyService.getValue(parentObject, "value", cache));
+        assertNotNull(propertyService.getValue(parentObject, "date", cache));
+        assertNotNull(propertyService.getValue(parentObject, "valid", cache));
+        assertEquals("edgar", propertyService.getValue(parentObject, "child.name", cache));
+        assertEquals("medgar@avoka.com", propertyService.getValue(parentObject, "child.email",
cache));
+
+
+        assertEquals("malcolm", propertyService.getValue(parentObject, "name"));
+        assertNull(propertyService.getValue(parentObject, "value"));
+        assertNotNull(propertyService.getValue(parentObject, "date"));
+        assertNotNull(propertyService.getValue(parentObject, "valid"));
+        assertEquals("edgar", propertyService.getValue(parentObject, "child.name"));
+        assertEquals("medgar@avoka.com", propertyService.getValue(parentObject, "child.email"));
+        
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("name", "malcolm");
+
+        assertEquals("malcolm", propertyService.getValue(map, "name"));
+	}
+	
+	private void performWriteTest(PropertyService propertyService, int index) {
+    	ParentObject parentObject = new ParentObject();
+
+    	propertyService.setValue(parentObject, "name", "malcolm" + index);
+    	assertEquals("malcolm" + index, parentObject.getName());
+    	
+    	propertyService.setValue(parentObject, "value", "value" + index);
+    	assertEquals("value" + index, parentObject.getValue());
+    	
+    	Date date = new Date();
+    	propertyService.setValue(parentObject, "date", date);
+    	assertEquals(date, parentObject.getDate());
+    	
+    	propertyService.setValue(parentObject, "valid", true);
+    	assertEquals(Boolean.TRUE, parentObject.getValid());
+    	
+        Map<String, Object> map = new HashMap<String, Object>();
+        propertyService.setValue(map, "name", "malcolm" + index);
+    	assertEquals("malcolm" + index, map.get("name"));
+    	
+    	parentObject.setChild(new ChildObject());
+    	
+        propertyService.setValue(parentObject, "child.name", "malcolm" + index);
+        assertEquals("malcolm" + index, parentObject.getChild().getName());			
+	}
+
+}

Modified: click/trunk/click/framework/test/org/apache/click/util/ChildObject.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/util/ChildObject.java?rev=1311324&r1=1311323&r2=1311324&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/util/ChildObject.java (original)
+++ click/trunk/click/framework/test/org/apache/click/util/ChildObject.java Mon Apr  9 16:59:25
2012
@@ -39,7 +39,8 @@ public class ChildObject {
 		this.name = name;
 	}
     
-    public String email() {
+    public String getEmail() {
         return email;
     }
+
 }
\ No newline at end of file



Mime
View raw message