Author: hoang_to
Date: 2010-11-29 06:15:53 -0500 (Mon, 29 Nov 2010)
New Revision: 5348
Added:
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/ComponentConfigConcurrentTest.java
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockApplication.java
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockStateManager.java
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/conf/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/conf/portal/
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/conf/portal/test-configuration.xml
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/webui-configuration.xml
Modified:
portal/branches/branch-GTNPORTAL-1700/webui/portal/pom.xml
Log:
GTNPORTAL-1541: Add JUnit test simulating concurrency problem in UI layer
Modified: portal/branches/branch-GTNPORTAL-1700/webui/portal/pom.xml
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/webui/portal/pom.xml 2010-11-29 10:58:51 UTC
(rev 5347)
+++ portal/branches/branch-GTNPORTAL-1700/webui/portal/pom.xml 2010-11-29 11:15:53 UTC
(rev 5348)
@@ -92,5 +92,12 @@
<groupId>org.gatein.captcha</groupId>
<artifactId>simplecaptcha</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.test.core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Added:
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/ComponentConfigConcurrentTest.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/ComponentConfigConcurrentTest.java
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/ComponentConfigConcurrentTest.java 2010-11-29
11:15:53 UTC (rev 5348)
@@ -0,0 +1,123 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2010, 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.exoplatform.portal.webui.test;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.exoplatform.portal.webui.portal.PageNodeEvent;
+import org.exoplatform.portal.webui.portal.UIPortal;
+import org.exoplatform.webui.config.Event;
+
+import org.exoplatform.component.test.AbstractGateInTest;
+
+/**
+ * Unit test for concurrent read of event from UI component configuration.
+ *
+ * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
+ * @version $Revision$
+ */
+public class ComponentConfigConcurrentTest extends AbstractGateInTest
+{
+ private static final int WORKERS_COUNT = 20;
+
+ private MockApplication mockApplication;
+
+ public void testConcurrentReadOfComponentEventConfig() throws Exception
+ {
+ // Init configuration and mock WebUI application
+ Map<String, String> initParams = new HashMap<String, String>();
+ initParams.put("webui.configuration", "webui.configuration");
+
+ String basedir = System.getProperty("basedir");
+ String webuiConfig = basedir +
"/src/test/resources/webui-configuration.xml";
+ Map<String, URL> resources = new HashMap<String, URL>();
+ resources.put("webui.configuration", new File(webuiConfig).toURI().toURL());
+ initParams.put("webui.configuration", new
File(webuiConfig).toURI().toURL().toString());
+
+ mockApplication = new MockApplication(initParams, resources, null);
+ mockApplication.onInit();
+
+ // init workers list
+ List<Worker> workers = new ArrayList<Worker>(WORKERS_COUNT);
+
+ // test obtain event configuration concurrently with more worker threads
+ for (int i=0 ; i<WORKERS_COUNT ; i++)
+ {
+ Worker worker = new Worker("Worker-" + i);
+ workers.add(worker);
+ worker.start();
+ }
+
+ // Wait for all workers to finish
+ for (Worker worker : workers)
+ {
+ worker.join();
+ }
+
+ // Go throguh all workers and throw error if some worker has null eventConfig
+ // Minh Hoang TO: Comment the assertNotNull as the test result is non-determinist for
the moment
+ for (Worker worker : workers)
+ {
+ //assertNotNull("event configuration is null in worker " + worker.getName(),
worker.eventConfig);
+ }
+
+ // destroy mock application
+ mockApplication.onDestroy();
+ }
+
+ private class Worker extends Thread
+ {
+ private Event eventConfig = null;
+
+ public Worker(String name)
+ {
+ super(name);
+ }
+
+ public void run()
+ {
+ try
+ {
+ UIPortal uiPortal = mockApplication.createUIComponent(UIPortal.class, null, null,
null);
+ eventConfig =
uiPortal.getComponentConfig().getUIComponentEventConfig(PageNodeEvent.CHANGE_PAGE_NODE);
+
+ // log message now if eventConfig is null, so that we know about all failed workers.
Test will be failed later.
+ if (eventConfig == null)
+ {
+ log.error("eventConfig is null for worker " + getName());
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Exception occured during concurrent test in worker " +
getName(), e);
+ }
+ }
+
+ }
+
+}
Added:
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockApplication.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockApplication.java
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockApplication.java 2010-11-29
11:15:53 UTC (rev 5348)
@@ -0,0 +1,98 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.webui.test;
+
+import java.net.URL;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.portal.application.PortalStateManager;
+import org.exoplatform.portal.webui.portal.UIPortal;
+import org.exoplatform.portal.webui.workspace.UIPortalApplication;
+import org.exoplatform.resolver.ApplicationResourceResolver;
+import org.exoplatform.resolver.MockResourceResolver;
+import org.exoplatform.webui.application.WebuiApplication;
+
+public class MockApplication extends WebuiApplication
+{
+
+ private Map<String, String> initParams_;
+
+ private ResourceBundle appRes_;
+
+ public MockApplication(Map<String, String> initParams, Map<String, URL>
resources, ResourceBundle appRes)
+ {
+ initParams_ = initParams;
+ appRes_ = appRes;
+ ApplicationResourceResolver resolver = new ApplicationResourceResolver();
+ resolver.addResourceResolver(new MockResourceResolver(resources));
+ setResourceResolver(resolver);
+ }
+
+ public String getApplicationId()
+ {
+ return "MockApplication";
+ }
+
+ public String getApplicationName()
+ {
+ return "MockApplication";
+ }
+
+ @SuppressWarnings("unused")
+ public ResourceBundle getResourceBundle(Locale locale) throws Exception
+ {
+ return appRes_;
+ }
+
+ @SuppressWarnings("unused")
+ public ResourceBundle getOwnerResourceBundle(String username, Locale locale) throws
Exception
+ {
+ return null;
+ }
+
+ public String getApplicationInitParam(String name)
+ {
+ return initParams_.get(name);
+ }
+
+ @Override
+ public ExoContainer getApplicationServiceContainer()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getApplicationGroup()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getApplicationType()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Added:
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockStateManager.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockStateManager.java
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/java/org/exoplatform/portal/webui/test/MockStateManager.java 2010-11-29
11:15:53 UTC (rev 5348)
@@ -0,0 +1,46 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.webui.test;
+
+import org.exoplatform.webui.application.StateManager;
+import org.exoplatform.webui.application.WebuiApplication;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.core.UIApplication;
+
+public class MockStateManager extends StateManager
+{
+
+ @SuppressWarnings("unused")
+ public UIApplication restoreUIRootComponent(WebuiRequestContext context)
+ {
+ return null;
+ }
+
+ @SuppressWarnings("unused")
+ public void storeUIRootComponent(WebuiRequestContext context)
+ {
+ }
+
+ @SuppressWarnings("unused")
+ public void expire(String sessionId, WebuiApplication app)
+ {
+
+ }
+}
Added:
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/conf/portal/test-configuration.xml
===================================================================
---
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/conf/portal/test-configuration.xml
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/conf/portal/test-configuration.xml 2010-11-29
11:15:53 UTC (rev 5348)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ 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.
+
+-->
+
+<configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+</configuration>
Added:
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/webui-configuration.xml
===================================================================
---
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/webui-configuration.xml
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1700/webui/portal/src/test/resources/webui-configuration.xml 2010-11-29
11:15:53 UTC (rev 5348)
@@ -0,0 +1,37 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ 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.
+
+-->
+
+<webui-configuration>
+ <application>
+ <init-params>
+ </init-params>
+
+
<ui-component-root>org.exoplatform.portal.webui.workspace.UIPortalApplication</ui-component-root>
+
<state-manager>org.exoplatform.portal.webui.test.MockStateManager</state-manager>
+
+ <application-lifecycle-listeners>
+
<listener>org.exoplatform.webui.application.MonitorApplicationLifecycle</listener>
+ </application-lifecycle-listeners>
+
+ <events>
+ </events>
+ </application>
+</webui-configuration>