Author: chris.laprun(a)jboss.com
Date: 2009-01-23 11:57:16 -0500 (Fri, 23 Jan 2009)
New Revision: 12621
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
Modified:
branches/JBoss_Portal_Branch_2_7/core/build.xml
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
branches/JBoss_Portal_Branch_2_7/testsuite/build.xml
Log:
- JBPORTAL-2281: More fundamental performance improvements (yields about 40% improvement
in my testing)...
- Added test cases.
- Fixed issues with testsuite build.
Modified: branches/JBoss_Portal_Branch_2_7/core/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/build.xml 2009-01-23 16:18:32 UTC (rev 12620)
+++ branches/JBoss_Portal_Branch_2_7/core/build.xml 2009-01-23 16:57:16 UTC (rev 12621)
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ JBoss, a division of Red Hat ~
- ~ Copyright 2006, Red Hat Middleware, LLC, and individual ~
- ~ contributors as indicated by the @authors tag. See the ~
- ~ copyright.txt in the distribution for a full listing of ~
- ~ individual contributors. ~
- ~ ~
- ~ This is free software; you can redistribute it and/or modify it ~
- ~ under the terms of the GNU Lesser General Public License as ~
- ~ published by the Free Software Foundation; either version 2.1 of ~
- ~ the License, or (at your option) any later version. ~
- ~ ~
- ~ This software is distributed in the hope that it will be useful, ~
- ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
- ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
- ~ Lesser General Public License for more details. ~
- ~ ~
- ~ You should have received a copy of the GNU Lesser General Public ~
- ~ License along with this software; if not, write to the Free ~
- ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ Copyright 2009, Red Hat Middleware, LLC, and individual
+ ~ contributors as indicated by the @authors tag. See the
+ ~ copyright.txt in the distribution for a full listing of
+ ~ individual contributors.
+ ~
+ ~ This is free software; you can redistribute it and/or modify it
+ ~ under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ This software is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this software; if not, write to the Free
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org. ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -568,8 +568,8 @@
outfile="TEST-PortalNodeTestCase">
<parameter name="CacheNaturalId" value="true"/>
<parameter name="Config"
value="persistent-jboss-beans.xml"/>
- </zest>
- <!--
+ </zest>
+ <!--
<zest todir="${test.reports}"
name="org.jboss.portal.test.core.model.portal.PortalNodeTestCase"
outfile="TEST-PortalObjectContainerTestCase">
<parameter name="CacheNaturalId" value="true"/>
@@ -581,6 +581,11 @@
<parameter name="CacheNaturalId" value="true"/>
<parameter name="Config"
value="persistent-jboss-beans.xml"/>
</zest>
+ <zest todir="${test.reports}"
name="org.jboss.portal.test.core.model.portal.PortalObjectTestCase"
+ outfile="TEST-PortalObjectTestCase">
+ <parameter name="CacheNaturalId" value="true"/>
+ <parameter name="Config"
value="persistent-jboss-beans.xml"/>
+ </zest>
<zest todir="${test.reports}"
name="org.jboss.portal.test.core.model.portal.coordination.CoordinationServiceTestCase"
outfile="TEST-CoordinationServiceTestCase">
<parameter name="CacheNaturalId" value="true"/>
@@ -695,10 +700,12 @@
-->
<target name="one-test" depends="init" if="test"
description="Run a single unit test">
<property name="build.testlog"
value="${module.output}/log"/>
+ <property name="test.reports"
value="${module.output}/tests"/>
<mkdir dir="${build.reports}"/>
<mkdir dir="${build.testlog}"/>
-
+ <mkdir dir="${test.reports}"/>
+
<junit printsummary="yes" showoutput="yes"
dir="${module.output}">
<!--jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006" /-->
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-01-23
16:18:32 UTC (rev 12620)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-01-23
16:57:16 UTC (rev 12621)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -20,6 +20,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
******************************************************************************/
+
package org.jboss.portal.core.impl.model.portal;
import org.apache.log4j.Logger;
@@ -40,6 +41,7 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -75,8 +77,6 @@
private ObjectNode objectNode;
// Runtime fields
-
- private Map childrenMap;
private Map properties;
private Map unmodifiableProperties;
private SortedSet accessedChildren;
@@ -92,7 +92,6 @@
this.listener = null;
//
- this.childrenMap = null;
this.properties = null;
this.unmodifiableProperties = null;
this.accessedChildren = null;
@@ -118,8 +117,6 @@
this.objectNode = objectNode;
}
- //
-
public PortalObjectId getId()
{
return objectNode.getPath();
@@ -141,13 +138,12 @@
{
return objectNode.getName();
}
-
+
public void setDisplayNames(Map displayNames)
{
this.displayNames = displayNames;
}
-
-
+
public Map getDisplayNames()
{
return displayNames;
@@ -161,7 +157,7 @@
}
displayNames = new HashMap();
-
+
Map map = displayName.getValues();
Iterator it = map.values().iterator();
while (it.hasNext())
@@ -170,7 +166,7 @@
displayNames.put(value.getLocale(), value.getString());
}
}
-
+
public LocalizedString getDisplayName()
{
if (displayNames != null)
@@ -203,13 +199,14 @@
private class ChildrenCollection implements Collection
{
-
/** . */
private final int mask;
+ private final SortedMap children;
- public ChildrenCollection(int mask)
+ public ChildrenCollection(int mask, Map children)
{
this.mask = mask;
+ this.children = new TreeMap(children);
}
public void clear()
@@ -254,30 +251,29 @@
public boolean isEmpty()
{
- return objectNode.getChildren().isEmpty();
+ return children.isEmpty();
}
public int size()
{
- if (mask == ALL_TYPES_MASK)
+ int count = 0;
+
+ for (Object object : children.values())
{
- return objectNode.getChildren().size();
- }
- else
- {
- int count = 0;
- for (Iterator i = iterator(); i.hasNext();)
+ ObjectNode childNode = (ObjectNode)object;
+ PortalObjectImpl childObject = childNode.getObject();
+ if (isMatchingMask(childObject, mask))
{
- i.next();
count++;
}
- return count;
}
+
+ return count;
}
public Object[] toArray()
{
- return toArray(new Object[0]);
+ return toArray(new Object[children.size()]);
}
public Iterator iterator()
@@ -287,7 +283,7 @@
public Object[] toArray(Object a[])
{
- ArrayList tmp = new ArrayList(objectNode.getChildren().size());
+ ArrayList tmp = new ArrayList(children.size());
//
Set accessedChildren = getAccessedChildren();
@@ -308,19 +304,14 @@
private class ChildrenIterator implements Iterator
{
-
- /** . */
private final Iterator iterator;
- /** . */
private PortalObject nextChild = null;
public ChildrenIterator()
{
// Make sure the children are sorted for consistent ordering downstream
- Map childrenMap = new TreeMap(objectNode.getChildren());
- Collection children = childrenMap.values();
- iterator = children.iterator();
+ iterator = children.values().iterator();
}
public void remove()
@@ -336,7 +327,7 @@
{
ObjectNode childNode = (ObjectNode)iterator.next();
PortalObjectImpl childObject = childNode.getObject();
- if (mask == ALL_TYPES_MASK || (childObject.getMask() & mask) != 0)
+ if (isMatchingMask(childObject, mask))
{
nextChild = childObject;
}
@@ -369,32 +360,25 @@
}
}
- public Collection getChildren(int wantedMask)
+ private boolean isMatchingMask(PortalObjectImpl object, int mask)
{
- /// Correct eventually the mask
- final int mask = wantedMask & ALL_TYPES_MASK;
+ return (mask == ALL_TYPES_MASK || (object.getMask() & mask) != 0);
+ }
- // Compute the lookup cache key
- Integer key = new Integer(mask);
-
- //
- Collection children = null;
- if (childrenMap == null)
+ public Collection getChildren(int wantedMask)
+ {
+ // if we want all the children, bypass ChildrenCollection
+ if (wantedMask == ALL_TYPES_MASK)
{
- childrenMap = new HashMap();
+ return new TreeMap(objectNode.getChildren()).values();
}
else
{
- children = (Collection)childrenMap.get(key);
- }
+ // Correct eventually the mask
+ final int mask = wantedMask & ALL_TYPES_MASK;
- //
- if (children == null)
- {
- children = new ChildrenCollection(mask);
- childrenMap.put(key, children);
+ return new ChildrenCollection(mask, objectNode.getChildren());
}
- return children;
}
public String getListener()
@@ -445,7 +429,7 @@
PortalObject child = getChild(name);
// only return the child if it matches the expected class
- if(expectedType.isInstance(child))
+ if (expectedType.isInstance(child))
{
return expectedType.cast(child);
}
@@ -512,7 +496,7 @@
public void setDeclaredProperty(String name, String value)
{
- ParameterValidation.throwIllegalArgExceptionIfNull(name, "property
name");
+ ParameterValidation.throwIllegalArgExceptionIfNull(name, "property
name");
if (value == null)
{
declaredPropertyMap.remove(name);
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java 2009-01-23
16:57:16 UTC (rev 12621)
@@ -0,0 +1,160 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.jboss.portal.test.core.model.portal;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.jboss.portal.common.junit.TransactionAssert;
+import org.jboss.portal.core.model.portal.Context;
+import org.jboss.portal.core.model.portal.Portal;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
+import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
+import org.jboss.portal.core.model.content.ContentType;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class PortalObjectTestCase extends AbstractPortalObjectContainerTestCase
+{
+ private Context root;
+ private Portal p_1;
+ private Page p_1_1;
+ private Page p_1_2;
+
+ public static TestSuite suite() throws Exception
+ {
+ return AbstractPortalObjectContainerTestCase.suite(PortalObjectTestCase.class);
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ TransactionAssert.beginTransaction();
+ root = container.getContext("");
+ p_1 = root.createPortal("1");
+ p_1_1 = p_1.createPage("1");
+ p_1_2 = p_1.createPage("2");
+ p_1_1.createPage("11");
+ p_1_1.createPage("12");
+ p_1_1.createPage("13");
+ p_1_1.createPage("14");
+ p_1_1.createWindow("w1", ContentType.PORTLET, "foo1");
+ p_1_1.createWindow("w2", ContentType.PORTLET, "foo2");
+ p_1_1.createWindow("w3", ContentType.PORTLET, "foo3");
+ p_1_2.createPage("21");
+ p_1_2.createPage("22");
+ p_1_2.createPage("23");
+ p_1_2.createPage("24");
+ TransactionAssert.commitTransaction();
+ }
+
+ public void testGetChildren() throws Exception
+ {
+ Collection<PortalObject> children = root.getChildren();
+ assertEquals(1, children.size());
+
+ children = p_1.getChildren();
+ assertEquals(2, children.size());
+
+ children = p_1_1.getChildren();
+ assertEquals(7, children.size());
+
+ children = p_1_2.getChildren();
+ assertEquals(4, children.size());
+
+ children = p_1_1.getChildren(PortalObject.PAGE_MASK);
+ assertEquals(4, children.size());
+
+ children = p_1_1.getChildren(PortalObject.WINDOW_MASK);
+ assertEquals(3, children.size());
+ }
+
+ public void testGetChild()
+ {
+ PortalObject child = p_1_1.getChild("w1");
+ assertNotNull(child);
+ assertEquals("w1", child.getName());
+ assertEquals(p_1_1, child.getParent());
+ }
+
+ /*public void testPerformanceGetChildren() throws DuplicatePortalObjectException,
NoSuchPortalObjectException
+ {
+ Portal portal;
+ Page page;
+
+ long time = System.currentTimeMillis();
+ TransactionAssert.beginTransaction();
+ root.destroyChild(p_1.getName());
+ int nbPortals = 5;
+ int nbPages = 20;
+ int nbWindows = 20;
+ for(int i = 0; i < nbPortals; i++)
+ {
+ portal = root.createPortal("p" + i);
+ for(int j = 0; j < nbPages; j++)
+ {
+ String name = "p" + i + "pa" + j;
+ page = portal.createPage(name);
+ page.createPage(name + "pa1");
+ page.createPage(name + "pa2");
+ for (int k = 0; k < nbWindows; k++)
+ {
+ page.createWindow(name + "w" + k, ContentType.PORTLET,
"foo" + k);
+ }
+ }
+ }
+ TransactionAssert.commitTransaction();
+ System.out.println("Creation time = " + (System.currentTimeMillis() -
time));
+
+
+ time = System.currentTimeMillis();
+ int portalIndex = (int) (nbPortals * Math.random());
+ assertEquals(nbPortals, root.getChildren().size());
+ assertEquals(nbPortals, root.getChildren(PortalObject.PORTAL_MASK).size());
+ assertEquals(nbPages, root.getChild("p" +
portalIndex).getChildren().size());
+ assertEquals(nbPages, root.getChild("p" +
portalIndex).getChildren(PortalObject.PAGE_MASK).size());
+
+ for (int i = 0; i < 1000000; i++)
+ {
+ portalIndex = (int) (nbPortals * Math.random());
+ String portalName = "p" + portalIndex;
+ PortalObject child = root.getChild(portalName);
+ assertNotNull(child);
+ int pageIndex = (int) (nbPages * Math.random());
+ child = child.getChild(portalName + "pa" + pageIndex);
+ assertNotNull(child);
+ assertEquals(2 + nbWindows, child.getChildren().size());
+ assertEquals(2, child.getChildren(PortalObject.PAGE_MASK).size());
+ assertEquals(nbWindows, child.getChildren(PortalObject.WINDOW_MASK).size());
+ }
+ System.out.println("Tests time = " + (System.currentTimeMillis() -
time));
+ }*/
+}
Modified: branches/JBoss_Portal_Branch_2_7/testsuite/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_7/testsuite/build.xml 2009-01-23 16:18:32 UTC (rev
12620)
+++ branches/JBoss_Portal_Branch_2_7/testsuite/build.xml 2009-01-23 16:57:16 UTC (rev
12621)
@@ -1,23 +1,23 @@
<?xml version="1.0"
encoding="UTF-8"?><!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ JBoss, a division of Red Hat ~
- ~ Copyright 2006, Red Hat Middleware, LLC, and individual ~
- ~ contributors as indicated by the @authors tag. See the ~
- ~ copyright.txt in the distribution for a full listing of ~
- ~ individual contributors. ~
- ~ ~
- ~ This is free software; you can redistribute it and/or modify it ~
- ~ under the terms of the GNU Lesser General Public License as ~
- ~ published by the Free Software Foundation; either version 2.1 of ~
- ~ the License, or (at your option) any later version. ~
- ~ ~
- ~ This software is distributed in the hope that it will be useful, ~
- ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
- ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
- ~ Lesser General Public License for more details. ~
- ~ ~
- ~ You should have received a copy of the GNU Lesser General Public ~
- ~ License along with this software; if not, write to the Free ~
- ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ Copyright 2009, Red Hat Middleware, LLC, and individual
+ ~ contributors as indicated by the @authors tag. See the
+ ~ copyright.txt in the distribution for a full listing of
+ ~ individual contributors.
+ ~
+ ~ This is free software; you can redistribute it and/or modify it
+ ~ under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ This software is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this software; if not, write to the Free
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org. ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -157,8 +157,6 @@
<target name="clean">
<!-- remove generated test xml files -->
<delete>
- <fileset dir="../cms" includes="output/tests/*.log"/>
- <fileset dir="../cms"
includes="output/tests/TEST-*.xml,output/tests/TEST-*.txt"/>
<fileset dir="../core"
includes="output/tests/*.log"/>
<fileset dir="../core"
includes="output/tests/TEST-*.xml,output/tests/TEST-*.txt"/>
<fileset dir="../faces" includes="*.log"/>