Author: chris.laprun(a)jboss.com
Date: 2009-01-26 05:50:21 -0500 (Mon, 26 Jan 2009)
New Revision: 12628
Added:
branches/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
Modified:
branches/Enterprise_Portal_Platform_4_3/core/build.xml
branches/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
Log:
- JBPORTAL-2281: Performance improvements (that correctly works now!)
Modified: branches/Enterprise_Portal_Platform_4_3/core/build.xml
===================================================================
--- branches/Enterprise_Portal_Platform_4_3/core/build.xml 2009-01-26 10:40:43 UTC (rev
12627)
+++ branches/Enterprise_Portal_Platform_4_3/core/build.xml 2009-01-26 10:50:21 UTC (rev
12628)
@@ -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. ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -378,12 +378,13 @@
</filterset>
<fileset dir="${build.resources}/jboss-portal"
includes="**/*.xml"/>
</copy>
-
- <!-- add jboss-cache-hibernate integration jar -->
- <copy todir="${build.resources}/jboss-portal-ha.sar/lib">
- <fileset
dir="${org/jboss/cluster/hibernate.jbc.cacheprovider.root}/lib"
includes="hibernate-jbc-cacheprovider.jar"/>
- </copy>
+ <!-- add jboss-cache-hibernate integration jar -->
+ <copy todir="${build.resources}/jboss-portal-ha.sar/lib">
+ <fileset
dir="${org/jboss/cluster/hibernate.jbc.cacheprovider.root}/lib"
+ includes="hibernate-jbc-cacheprovider.jar"/>
+ </copy>
+
<implode
dir="${build.resources}/jboss-portal-ha.sar"
tofile="${build.lib}/jboss-portal-ha.sar"/>
@@ -552,8 +553,8 @@
<execute-tests>
<x-sysproperty>
- <!--<jvmarg value="-Xdebug"/>-->
- <!--<jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/>-->
+ <!--<jvmarg value="-Xdebug"/>-->
+ <!--<jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/>-->
<sysproperty
key="jboss.aop.path"
@@ -581,7 +582,13 @@
<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"
+ <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"/>
<parameter name="Config"
value="persistent-jboss-beans.xml"/>
@@ -695,10 +702,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/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
branches/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-01-26
10:40:43 UTC (rev 12627)
+++
branches/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-01-26
10:50:21 UTC (rev 12628)
@@ -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,36 @@
public boolean isEmpty()
{
- return objectNode.getChildren().isEmpty();
+ return children.isEmpty();
}
public int size()
{
- if (mask == ALL_TYPES_MASK)
+ if (mask != ALL_TYPES_MASK)
{
- return objectNode.getChildren().size();
- }
- else
- {
int count = 0;
- for (Iterator i = iterator(); i.hasNext();)
+
+ for (Object object : children.values())
{
- i.next();
- count++;
+ ObjectNode childNode = (ObjectNode)object;
+ PortalObjectImpl childObject = childNode.getObject();
+ if (isMatchingMask(childObject, mask))
+ {
+ count++;
+ }
}
+
return count;
}
+ else
+ {
+ return children.size();
+ }
}
public Object[] toArray()
{
- return toArray(new Object[0]);
+ return toArray(new Object[children.size()]);
}
public Iterator iterator()
@@ -287,7 +290,7 @@
public Object[] toArray(Object a[])
{
- ArrayList tmp = new ArrayList(objectNode.getChildren().size());
+ ArrayList tmp = new ArrayList(children.size());
//
Set accessedChildren = getAccessedChildren();
@@ -308,19 +311,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 +334,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 +367,17 @@
}
}
+ private boolean isMatchingMask(PortalObjectImpl object, int mask)
+ {
+ return (mask == ALL_TYPES_MASK || (object.getMask() & mask) != 0);
+ }
+
public Collection getChildren(int wantedMask)
{
- /// Correct eventually the mask
+ // Correct eventually the mask
final int mask = wantedMask & ALL_TYPES_MASK;
- // Compute the lookup cache key
- Integer key = new Integer(mask);
-
- //
- Collection children = null;
- if (childrenMap == null)
- {
- childrenMap = new HashMap();
- }
- else
- {
- children = (Collection)childrenMap.get(key);
- }
-
- //
- if (children == null)
- {
- children = new ChildrenCollection(mask);
- childrenMap.put(key, children);
- }
- return children;
+ return new ChildrenCollection(mask, objectNode.getChildren());
}
public String getListener()
@@ -445,7 +428,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 +495,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/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
===================================================================
---
branches/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
(rev 0)
+++
branches/Enterprise_Portal_Platform_4_3/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java 2009-01-26
10:50:21 UTC (rev 12628)
@@ -0,0 +1,202 @@
+/******************************************************************************
+ * 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.TestSuite;
+import org.jboss.portal.common.junit.TransactionAssert;
+import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.core.model.portal.Context;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
+import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.Portal;
+import org.jboss.portal.core.model.portal.PortalObject;
+
+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;
+ private static final int A_INDEX = 65;
+
+ 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 testIterator() throws NoSuchPortalObjectException,
DuplicatePortalObjectException
+ {
+ Portal portal;
+ Page page;
+
+ TransactionAssert.beginTransaction();
+ root.destroyChild(p_1.getName());
+ char nbChildren = 20;
+ portal = root.createPortal("portal");
+ page = portal.createPage("page");
+
+ // create children, we need to convert the current index with Character.toString as
default ordering results in
+ // pa10 < pa2 and in test failure
+ for (char i = A_INDEX; i < nbChildren + A_INDEX; i++)
+ {
+ // convert current index into a letter
+ String letter = Character.toString(i);
+ page.createPage("pa" + letter);
+ page.createWindow("w" + letter, ContentType.PORTLET, "foo" +
letter);
+ }
+ TransactionAssert.commitTransaction();
+
+ Collection<PortalObject> children =
page.getChildren(PortalObject.PAGE_MASK);
+ assertNotNull(children);
+ char i = A_INDEX;
+ String name;
+ for (PortalObject child : children)
+ {
+ name = child.getName();
+ assertEquals("pa" + Character.toString(i++), name);
+ }
+
+ children = page.getChildren(PortalObject.WINDOW_MASK);
+ assertNotNull(children);
+ i = A_INDEX;
+ for (PortalObject child : children)
+ {
+ name = child.getName();
+ assertEquals("w" + Character.toString(i++), name);
+ }
+ }
+
+ /*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));
+ }*/
+}