portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r926801 - in /portals/jetspeed-2/portal/trunk/components: jetspeed-capability/ jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/ jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/ jetspeed-rdbms/src/ma...
Date Tue, 23 Mar 2010 21:43:40 GMT
Author: taylor
Date: Tue Mar 23 21:43:39 2010
New Revision: 926801

URL: http://svn.apache.org/viewvc?rev=926801&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-964
contribution from Joachim Muller

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/LocalTestUserManagerPerformance.java
  (with props)
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-capability/pom.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/JetspeedTestJNDIComponent.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/DatabasePlatformConfigurator.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/util/DatasourceTestCase.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/test/java/org/apache/jetspeed/components/TestRDBMS.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-capability/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-capability/pom.xml?rev=926801&r1=926800&r2=926801&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-capability/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-capability/pom.xml Tue Mar 23 21:43:39
2010
@@ -81,6 +81,21 @@
       <version>${org.apache.jetspeed.test.jdbc.driver.version}</version>
       <scope>test</scope>
     </dependency>
+    <!--
+      Note: tyrex and junit is normally required only for test, but in this case, abstract
test cases are included in
+      the component build... this should probably be fixed... for now, assume that junit
will be provided if these test
+      classes are used.
+    -->
+    <dependency>
+      <groupId>tyrex</groupId>
+      <artifactId>tyrex</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java?rev=926801&r1=926800&r2=926801&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java
Tue Mar 23 21:43:39 2010
@@ -25,6 +25,7 @@ import java.util.Set;
 import junit.framework.Test;
 
 import org.apache.jetspeed.components.test.AbstractSpringTestCase;
+import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
 import org.apache.jetspeed.serializer.JetspeedSerializer;
 
 
@@ -34,22 +35,10 @@ import org.apache.jetspeed.serializer.Je
  * @author <a href="roger.ruttimann@earthlink.net">Roger Ruttimann</a>
  * @version $Id$
  */
-public class TestCapability extends AbstractSpringTestCase
+public class TestCapability extends DatasourceEnabledSpringTestCase
 {
     private Capabilities capabilities = null;
 
-    /**
-     * Start the tests.
-     * 
-     * @param args
-     *            the arguments. Not used
-     */
-    public static void main(String args[])
-    {
-        junit.awtui.TestRunner.main(new String[]
-        { TestCapability.class.getName() });
-    }
-
     protected void setUp() throws Exception
     {
         super.setUp();
@@ -63,7 +52,6 @@ public class TestCapability extends Abst
 
     public void firstTestSetup() throws Exception
     {
-        System.out.println("firstTestSetup");
         JetspeedSerializer serializer = (JetspeedSerializer)scm.getComponent("serializer");
         serializer.deleteData();
         serializer.importData(getBaseDir()+"target/test-classes/j2-seed.xml");
@@ -71,7 +59,6 @@ public class TestCapability extends Abst
 
     public void lastTestTeardown() throws Exception
     {
-        System.out.println("lastTestTeardown");
         JetspeedSerializer serializer = (JetspeedSerializer)scm.getComponent("serializer");
         serializer.deleteData();
     }
@@ -423,14 +410,7 @@ public class TestCapability extends Abst
         capabilities.deleteMediaType(mediaType);
     	existingObject = capabilities.getMediaType(name);
         assertNull("creating new mediaType delete from storage didn't work",existingObject);
- 
-        
-        
-        
-        
     }
-
-    
     
     public void testNewClient() throws Exception
     {
@@ -456,16 +436,13 @@ public class TestCapability extends Abst
     	String existingKey = (String)_it.next();
     	Client existingObject = (Client)_hash.get(existingKey);
         assertNotNull("Couldn't identify existing object to run test",existingObject);
-
     	
     	// "create" existing one
     	client = capabilities.createClient(existingKey);
         assertNotNull("creating 'existing' client returns null", client);
         assertTrue("creating 'existing' client didn't return existing object", (client.equals(existingObject)));
-
-        
-        // setting fields
         
+        // setting fields        
         String name  = "TEST CLIENT";
         int numCapabilities = 3;
         int numMimeTypes = 4;
@@ -488,7 +465,7 @@ public class TestCapability extends Abst
         String manufacturer = "Test Manufacturer";
         String model = "XYZ";
         
-// set object fields               
+        // set object fields               
         client.setUserAgentPattern(userAgentPattern);
         client.setManufacturer(manufacturer);
         client.setModel(model);
@@ -500,12 +477,8 @@ public class TestCapability extends Abst
         set = new ArrayList(someMimeTypes.values());
         client.setCapabilities(set);
         assertTrue("number of MimeTypes added (" + set.size() + ") not the same as expected
("+numCapabilities+")",(set.size()==numMimeTypes));
-
         
         // setting links:
-        
-        
-        
         capabilities.storeClient(client);
     	existingObject = capabilities.getClient(name);
         assertNotNull("creating and saving new client didn't store object",existingObject);
@@ -513,14 +486,7 @@ public class TestCapability extends Abst
         capabilities.deleteClient(client);
     	existingObject = capabilities.getClient(name);
         assertNull("creating new client delete from storage didn't work",existingObject);
- 
-        
-        
-        
-        
     }
-
-    
     
     public void testCapabilityRepeat() throws Exception
     {
@@ -535,12 +501,6 @@ public class TestCapability extends Abst
         { "capabilities.xml", "transaction.xml", "serializer.xml" };
     }
 
-    protected String[] getBootConfigurations()
-    {
-        return new String[]
-        { "boot/datasource.xml"};
-    }
-
     protected String getBeanDefinitionFilterCategories()
     {
         return "default,jdbcDS";

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java?rev=926801&r1=926800&r2=926801&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
Tue Mar 23 21:43:39 2010
@@ -21,6 +21,7 @@ import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.Driver;
 import java.sql.DriverManager;
+import java.sql.SQLException;
 import java.util.Properties;
 
 import javax.sql.DataSource;
@@ -29,10 +30,10 @@ import org.apache.commons.dbcp.Connectio
 import org.apache.commons.dbcp.DriverManagerConnectionFactory;
 import org.apache.commons.dbcp.PoolableConnectionFactory;
 import org.apache.commons.dbcp.PoolingDataSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.commons.pool.ObjectPool;
 import org.apache.commons.pool.impl.GenericObjectPool;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * <p>
@@ -180,13 +181,18 @@ public class DBCPDatasourceComponent imp
     {
         try
         {
-            log.info("Stopping DBCPCDatasourceComponent");
+        	if (log.isInfoEnabled()) {
+	        	log.info("Stopping DBCPCDatasourceComponent");
+        	}
             dsConnectionFactory.getPool().close();
 
             // Support for using an embedded Derby database multiple times from one JVM
             // by properly shutting it down after each (test) run
             if (driverName.equals("org.apache.derby.jdbc.EmbeddedDriver"))
             {
+                if (log.isInfoEnabled()) {
+                	log.info("Shutting down derby ...");
+                }
                 String shutDownURI = null;
                 int parIndex = connectURI.indexOf(";");
                 if (parIndex > -1)
@@ -207,14 +213,33 @@ public class DBCPDatasourceComponent imp
             }
 
         }
+		 catch (SQLException e)  {
+		    if ( driverName.equals("org.apache.derby.jdbc.EmbeddedDriver") && (e.getSQLState().equals("XJ015")
||  e.getSQLState().equals("08006"))) {
+		    	if (log.isDebugEnabled()) {
+		    		log.debug("Database shut down normally with sql state '" + e.getSQLState() + "'.");
+		    	}
+		    } else {
+	        	IllegalStateException ise =
+	                new IllegalStateException("Unable to safely shutdown the DBCPConnection
pool: " + e.toString());
+	            ise.initCause(e);
+	            try
+	            {
+	                log.error("Unable to safely shutdown the DBCPConnection pool", ise);
+	            }
+	            catch (Exception e1)
+	            {
+	                // ignore if logger itself is gone too
+	            }
+		    }
+		 }
         catch (Exception e)
         {
-            IllegalStateException ise =
-                new IllegalStateException("Unable to sfaely shutdown the DBCPConnection pool:
" + e.toString());
+        	IllegalStateException ise =
+                new IllegalStateException("Unable to safely shutdown the DBCPConnection pool:
" + e.toString());
             ise.initCause(e);
             try
             {
-                log.error("Unable to sfaely shutdown the DBCPConnection pool", ise);
+                log.error("Unable to safely shutdown the DBCPConnection pool", ise);
             }
             catch (Exception e1)
             {

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/JetspeedTestJNDIComponent.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/JetspeedTestJNDIComponent.java?rev=926801&r1=926800&r2=926801&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/JetspeedTestJNDIComponent.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/JetspeedTestJNDIComponent.java
Tue Mar 23 21:43:39 2010
@@ -52,4 +52,13 @@ public class JetspeedTestJNDIComponent
         datasourceComponent.stop();
         jndi.unbindFromCurrentThread();
     }
+    
+    public BoundDBCPDatasourceComponent getDatasourceComponent() {
+    	return datasourceComponent;
+    }
+
+    public JNDIComponent getJNDI() {
+    	return jndi;
+    }
+
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/DatabasePlatformConfigurator.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/DatabasePlatformConfigurator.java?rev=926801&r1=926800&r2=926801&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/DatabasePlatformConfigurator.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/DatabasePlatformConfigurator.java
Tue Mar 23 21:43:39 2010
@@ -88,7 +88,9 @@ public class DatabasePlatformConfigurato
         {
             platform = jcd.getDbms();
         }
-        System.out.println("##### platform = " + platform);
+        if (log.isInfoEnabled()) {
+        	log.info("Detected database platform: " + platform);
+        }
     }
  
     /**

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/util/DatasourceTestCase.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/util/DatasourceTestCase.java?rev=926801&r1=926800&r2=926801&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/util/DatasourceTestCase.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/util/DatasourceTestCase.java
Tue Mar 23 21:43:39 2010
@@ -18,10 +18,9 @@ package org.apache.jetspeed.components.u
 
 import junit.framework.TestCase;
 
-import org.apache.commons.pool.impl.GenericObjectPool;
 import org.apache.jetspeed.components.datasource.BoundDBCPDatasourceComponent;
 import org.apache.jetspeed.components.jndi.JNDIComponent;
-import org.apache.jetspeed.components.jndi.TyrexJNDIComponent;
+import org.apache.jetspeed.components.jndi.JetspeedTestJNDIComponent;
 
 /**
  * @author <a href="mailto:sweaver@einnovation.com">Scott T. Weaver </a>
@@ -33,6 +32,9 @@ public class DatasourceTestCase extends 
     protected BoundDBCPDatasourceComponent datasourceComponent;
 
     protected JNDIComponent jndi;
+    
+    protected JetspeedTestJNDIComponent jndiDS;
+    
 
     /**
      *  
@@ -57,16 +59,10 @@ public class DatasourceTestCase extends 
      */
     protected void setUp() throws Exception
     {
-        super.setUp();
-        jndi = new TyrexJNDIComponent();
-        String url = System.getProperty("org.apache.jetspeed.database.url");
-        String driver = System.getProperty("org.apache.jetspeed.database.driver");
-        String user = System.getProperty("org.apache.jetspeed.database.user");
-        String password = System.getProperty("org.apache.jetspeed.database.password");
-        datasourceComponent = new BoundDBCPDatasourceComponent(user, password, driver, url,
20, 5000,
-                GenericObjectPool.WHEN_EXHAUSTED_GROW, true, "jetspeed", jndi);
-        datasourceComponent.start();
-
+        jndiDS = new JetspeedTestJNDIComponent();
+        jndiDS.setup();
+        super.setUp();    
+        datasourceComponent = jndiDS.getDatasourceComponent();
     }
 
     /**
@@ -74,9 +70,7 @@ public class DatasourceTestCase extends 
      */
     protected void tearDown() throws Exception
     {
-        datasourceComponent.stop();
-        jndi.unbindFromCurrentThread();
         super.tearDown();
+        jndiDS.tearDown();
     }
-
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/test/java/org/apache/jetspeed/components/TestRDBMS.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/test/java/org/apache/jetspeed/components/TestRDBMS.java?rev=926801&r1=926800&r2=926801&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/test/java/org/apache/jetspeed/components/TestRDBMS.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/test/java/org/apache/jetspeed/components/TestRDBMS.java
Tue Mar 23 21:43:39 2010
@@ -15,9 +15,9 @@
  * limitations under the License.
  */
 package org.apache.jetspeed.components;
+
 import java.sql.Connection;
 
-import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
 
@@ -58,9 +58,6 @@ public class TestRDBMS extends Datasourc
     {
         assertTrue(DatasourceComponent.class.isAssignableFrom(DBCPDatasourceComponent.class));
 
-        InitialContext context = new InitialContext();
-        //look up from jndi
-        assertNotNull(context.lookup("java:/jdbc/jetspeed"));
         assertNotNull(datasourceComponent);
         DataSource ds = datasourceComponent.getDatasource();
         assertNotNull(ds);
@@ -68,12 +65,11 @@ public class TestRDBMS extends Datasourc
         assertNotNull(conn);
         assertFalse(conn.isClosed());
         conn.close();
-        (datasourceComponent).stop();
-        
+        jndiDS.tearDown();
         
         try
         {
-            context.lookup("java:/jdbc/jetspeed");
+        	jndiDS.getJNDI().getRootContext().lookup("java:/jdbc/jetspeed");
             assertNotNull("java:/jdbc/jetspeed was not unbound", null);
         }
         catch (NamingException e)
@@ -81,8 +77,6 @@ public class TestRDBMS extends Datasourc
        
         }
         
- 
-     
     }
     
    

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/LocalTestUserManagerPerformance.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/LocalTestUserManagerPerformance.java?rev=926801&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/LocalTestUserManagerPerformance.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/LocalTestUserManagerPerformance.java
Tue Mar 23 21:43:39 2010
@@ -0,0 +1,264 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.
+ */
+package org.apache.jetspeed.security;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * <p>
+ * Unit testing for {@link UserManager}.
+ * </p>
+ * 
+ * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
+ */
+public class LocalTestUserManagerPerformance extends AbstractSecurityTestcase
+{
+    public static Test suite()
+    {
+        return new TestSuite(LocalTestUserManagerPerformance.class);
+    }
+    
+    /**
+     * <p>
+     * performance test user retrieval with low number of users.
+     * </p>
+     */
+    public void testUserRetrievalWithLowNumberOfUsers()
+    {
+        int nUsers = 20;
+    	try
+        {
+    		
+    		System.out.println("adding " + nUsers + " users...");
+    		for (int i=0; i<nUsers; i++) {
+            	ums.addUser("anon"+i);
+            }
+    		System.out.println("done.");
+    		System.gc();
+            long startTime = System.currentTimeMillis();
+            long freeMemory = Runtime.getRuntime().freeMemory();
+            UserResultList ul = ums.getUsersExtended(new JetspeedPrincipalQueryContext(null,
0, 10));
+            System.out.println(nUsers + " user: get 10 users via getUsers(null, null, 1,
10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            ul = ums.getUsersExtended(new JetspeedPrincipalQueryContext(null, 10, 10));
+            System.out.println(nUsers + " user: get 10 users via getUsers(null, null, 10,
10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            List<User> l = ums.getUsers("");
+            System.out.println(nUsers + " user: get all users via ums.getUsers(null)...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            l = ums.getUsers("");
+            System.out.println(nUsers + " user: get all users via ums.getUsers(null)...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+        }
+        catch (SecurityException sex)
+        {
+            assertTrue("user already exists. exception caught: " + sex, false);
+        }
+
+        try
+        {
+    		System.out.println("removing " + nUsers + " users...");
+            for (int i=0; i<nUsers; i++) {
+            	ums.removeUser("anon"+i);
+            }
+        }
+        catch (SecurityException sex)
+        {
+            assertTrue("could not remove user. exception caught: " + sex, false);
+        }
+    }
+
+
+    /**
+     * <p>
+     * performance test user retrieval with medium number of users.
+     * </p>
+     */
+    public void testUserRetrievalWithMediumNumberOfUsers()
+    {
+        
+        int nUsers = 300;
+    	try
+        {
+    		
+    		System.out.println("adding " + nUsers + " users...");
+    		for (int i=0; i<nUsers; i++) {
+            	ums.addUser("anon"+i);
+            }
+    		System.out.println("done.");
+    		System.gc();
+            long startTime = System.currentTimeMillis();
+            long freeMemory = Runtime.getRuntime().freeMemory();
+            UserResultList ul = ums.getUsersExtended(new JetspeedPrincipalQueryContext(null,
0, 10));
+            System.out.println(nUsers + " user: get 10 users via getUsers(null, null, 1,
10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            ul = ums.getUsersExtended(new JetspeedPrincipalQueryContext(null, 10, 10));
+            System.out.println(nUsers + " user: get 10 users via getUsers(null, null, 10,
10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            List<User> l = ums.getUsers(null);
+            System.out.println(nUsers + " user: get all users via ums.getUsers(null)...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            l = ums.getUsers(null);
+            System.out.println(nUsers + " user: get all users via ums.getUsers(null)...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+
+        }
+        catch (SecurityException sex)
+        {
+            assertTrue("user already exists. exception caught: " + sex, false);
+        }
+
+        try
+        {
+    		System.out.println("removing " + nUsers + " users...");
+            for (int i=0; i<nUsers; i++) {
+            	ums.removeUser("anon"+i);
+            }
+        }
+        catch (SecurityException sex)
+        {
+            assertTrue("could not remove user. exception caught: " + sex, false);
+        }
+    }
+    
+    
+    /**
+     * <p>
+     * performance test user retrieval with hi number of users.
+     * </p>
+     */
+    public void testUserRetrievalWithHighNumberOfUsers()
+    {
+        
+        int nUsers = 10000;
+    	try
+        {
+    		
+    		System.out.println("adding " + nUsers + " users...");
+    		for (int i=0; i<nUsers; i++) {
+    			User user = ums.addUser("anon"+i);
+            	if (i%10 == 0) {
+	            	user.getSecurityAttributes().getAttribute("name", true).setStringValue("dude");
+	            	ums.updateUser(user);
+            	}
+            }
+    		System.out.println("done.");
+    		System.gc();
+            long startTime = System.currentTimeMillis();
+            long freeMemory = Runtime.getRuntime().freeMemory();
+            UserResultList ul = ums.getUsersExtended(new JetspeedPrincipalQueryContext(null,
0, 10));
+            System.out.println(nUsers + " user: get 10 users via getUsers(null, null, 1,
10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            ul = ums.getUsersExtended(new JetspeedPrincipalQueryContext(null, 10, 10));
+            System.out.println(nUsers + " user: get 10 users via getUsers(null, null, 10,
10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            ul = ums.getUsersExtended(new JetspeedPrincipalQueryContext(null, (int)Math.round(nUsers
* 0.9), 10));
+            System.out.println(nUsers + " user: get 10 users via getUsers(null, null, " +
Math.round(nUsers * 0.9) + ", 10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            Map<String, String> attributeMap = new HashMap<String, String>()
{
+                {
+                    put("name", "dude");
+                }
+            };
+            
+            JetspeedPrincipalQueryContext c = new JetspeedPrincipalQueryContext(null, 50,
10);
+            c.put(JetspeedPrincipalQueryContext.SECURITY_ATTRIBUTES, attributeMap);
+            ul = ums.getUsersExtended(c);
+            System.out.println(nUsers + " user: get 10 users with the attribute name=dude
via getUsers(null, attributeMap, 50, 10) ...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+            System.out.println("first retrieved principals name:" + ul.getResults().get(0).getName());
+            assertEquals(ul.getResults().size(), 10);
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            List<User> l = ums.getUsers(null);
+            System.out.println(nUsers + " user: get all users via ums.getUsers(null)...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+        	System.gc();
+            startTime = System.currentTimeMillis();
+            freeMemory = Runtime.getRuntime().freeMemory();
+            l = ums.getUsers(null);
+            System.out.println(nUsers + " user: get all users via ums.getUsers(null)...");
+            System.out.println("... took " + (System.currentTimeMillis() - startTime) + "
ms, needed " + (freeMemory - Runtime.getRuntime().freeMemory()) / 1024 + " kbytes.");
+        	System.gc();
+
+        }
+        catch (SecurityException sex)
+        {
+            assertTrue("user already exists. exception caught: " + sex, false);
+        }
+
+        try
+        {
+    		System.out.println("removing " + nUsers + " users...");
+            for (int i=0; i<nUsers; i++) {
+            	ums.removeUser("anon"+i);
+            }
+        }
+        catch (SecurityException sex)
+        {
+            assertTrue("could not remove user. exception caught: " + sex, false);
+        }
+    }
+
+}
\ No newline at end of file

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/LocalTestUserManagerPerformance.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/LocalTestUserManagerPerformance.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message