portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r348124 - in /portals/jetspeed-2/trunk/components/portal: ./ src/java/org/apache/jetspeed/administration/ src/java/org/apache/jetspeed/aggregator/impl/ src/java/org/apache/jetspeed/engine/ src/test/org/apache/jetspeed/aggregator/
Date Tue, 22 Nov 2005 07:57:46 GMT
Author: taylor
Date: Mon Nov 21 23:57:43 2005
New Revision: 348124

URL: http://svn.apache.org/viewcvs?rev=348124&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-412

Portal Adminstration impl

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/MockRenderJob.java
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
Modified:
    portals/jetspeed-2/trunk/components/portal/maven.xml
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitorImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedEngine.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java

Modified: portals/jetspeed-2/trunk/components/portal/maven.xml
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/maven.xml?rev=348124&r1=348123&r2=348124&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/maven.xml (original)
+++ portals/jetspeed-2/trunk/components/portal/maven.xml Mon Nov 21 23:57:43 2005
@@ -17,6 +17,6 @@
 <project default="java:jar" xmlns:j="jelly:core" xmlns:define="jelly:define" xmlns:maven="jelly:maven">
 
     <!-- Target of maven test:single test -->
-    <property name='testcase' value='org.apache.jetspeed.components.TestComponentManager'
/>
+    <property name='testcase' value='org.apache.jetspeed.aggregator.TestWorkerMonitor'
/>
 
 </project>

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java?rev=348124&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
Mon Nov 21 23:57:43 2005
@@ -0,0 +1,347 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.administration;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.prefs.PreferencesProvider;
+import org.apache.jetspeed.prefs.om.Node;
+import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.security.GroupManager;
+import org.apache.jetspeed.security.RoleManager;
+import org.apache.jetspeed.security.SecurityHelper;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.springframework.mail.MailException;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+
+
+/**
+ * PortalAdministrationImpl
+ * Implements aggregate portal administration functions:
+ *  - Emails
+ *  - Registration
+ *  - Password Generation
+ *  - 
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+
+public class PortalAdministrationImpl implements PortalAdministration
+{
+    /** administration services */
+    protected Configuration config;
+    protected UserManager userManager;
+    protected RoleManager roleManager;
+    protected GroupManager groupManager;
+    protected PageManager pageManager;
+    private PreferencesProvider preferences;    
+    protected Profiler profiler;
+    protected JavaMailSender mailSender;
+    protected VelocityEngine velocityEngine;
+    
+    /** list of default roles for a registered user */
+    protected List defaultRoles;
+    /** list of default groups for a registered user */
+    protected List defaultGroups;
+    /** map of default profiling rules for a registered user */
+    protected Map defaultRules;
+    /** name of PSML Folder Template to clone from when registering new user */
+    protected String folderTemplate;
+    
+    public PortalAdministrationImpl( UserManager userManager,
+                                     RoleManager roleManager,
+                                     GroupManager groupManager, 
+                                     PageManager pageManager,
+                                     PreferencesProvider preferences,
+                                     Profiler profiler,
+                                     JavaMailSender mailSender,
+                                     VelocityEngine velocityEngine)
+    {
+        this.userManager = userManager;
+        this.roleManager = roleManager;
+        this.groupManager = groupManager;
+        this.pageManager = pageManager;
+        this.preferences = preferences;
+        this.mailSender = mailSender;
+        this.velocityEngine = velocityEngine;                        
+    }
+
+    public void start()
+    {
+        this.config = (Configuration) Jetspeed.getComponentManager().getComponent("PortalConfiguration");
+        
+        this.defaultRoles = 
+            config.getList(PortalConfigurationConstants.REGISTRATION_ROLES_DEFAULT);
+        this.defaultGroups = 
+            config.getList(PortalConfigurationConstants.REGISTRATION_GROUPS_DEFAULT);
+    
+        Object[] profileRuleNames = (Object[]) 
+            config.getList(PortalConfigurationConstants.PROFILER_RULE_NAMES_DEFAULT).toArray();
+        Object[] profileRuleValues = (Object[])
+            config.getList(PortalConfigurationConstants.PROFILER_RULE_VALUES_DEFAULT).toArray();
+        defaultRules = new HashMap();
+        if (profileRuleNames != null && profileRuleValues != null)
+        {
+            for (int ix = 0; ix < ((profileRuleNames.length < profileRuleValues.length)
? profileRuleNames.length : profileRuleValues.length); ix++)
+            {
+                defaultRules.put(profileRuleNames[ix], profileRuleValues[ix]);
+            }
+        }
+        this.folderTemplate = 
+            config.getString(PortalConfigurationConstants.PSML_TEMPLATE_FOLDER);
+    }
+    
+    public void registerUser(String userName, String password)
+    throws RegistrationException
+    {
+        registerUser(userName, password, (List)null, null, null, null, null);
+    }
+        
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#registerUser(java.lang.String,
java.lang.String, java.util.Map, java.awt.List, java.awt.List, java.lang.String)
+     */    
+    public void registerUser(
+            String userName, 
+            String password, 
+            List roles, 
+            List groups, 
+            Map userInfo, 
+            Map rules, 
+            String folderTemplate)
+    throws RegistrationException    
+    {
+        try 
+        {
+            // create the user
+            userManager.addUser(userName, password);
+            User user = userManager.getUser(userName);
+                        
+            // assign roles to user
+            if (roles == null)
+            {
+                roles = this.defaultRoles;
+            }
+            if (roles != null)
+            {
+                Iterator roleList = roles.iterator();
+                while (roleList.hasNext())
+                {
+                    String role = (String)roleList.next();
+                    if (!role.startsWith(Folder.ROLE_FOLDER))
+                    {
+                        role = Folder.ROLE_FOLDER + role;
+                    }
+                    roleManager.addRoleToUser(userName, role);
+                }
+            }
+            
+            // assign groups to user
+            if (groups == null)
+            {
+                groups = this.defaultGroups;
+            }
+            if (groups != null)
+            {
+                Iterator groupsList = groups.iterator();
+                while (groupsList.hasNext())
+                {
+                    String group = (String)groupsList.next();
+                    if (!group.startsWith(Folder.GROUP_FOLDER))
+                    {
+                        group = Folder.GROUP_FOLDER + group;
+                    }                    
+                    groupManager.addUserToGroup(userName, group);
+                }
+            }
+            
+            // assign user attributes to user
+            if (userInfo != null)
+            {
+                Iterator info = userInfo.entrySet().iterator();
+                while (info.hasNext())
+                {           
+                    Map.Entry entry = (Map.Entry)info.next();
+                    user.getUserAttributes().put((String)entry.getKey(), (String)entry.getValue());
+                }
+            }
+            
+            // assign profiling rules to user
+            if (rules == null)
+            {
+                rules = this.defaultRules;
+            }
+            if (rules != null)
+            {
+                Iterator ruleEntries = rules.entrySet().iterator();
+                while (ruleEntries.hasNext())
+                {           
+                    Map.Entry entry = (Map.Entry)ruleEntries.next();
+                    ProfilingRule rule = profiler.getRule((String)entry.getKey());
+                    if (rule != null)
+                    {
+                        Principal principal = SecurityHelper.getBestPrincipal(user.getSubject(),
UserPrincipal.class);
+                        profiler.setRuleForPrincipal(principal, rule, (String)entry.getValue());
+                    }
+                }
+            }
+            
+            // create user's home folder                        
+            // deep copy from the default folder template tree, creating a deep-copy of the
template
+            // in the new user's folder tree
+            if (folderTemplate == null)
+            {
+                folderTemplate = this.folderTemplate; 
+            }
+            Folder source = pageManager.getFolder(folderTemplate);
+            pageManager.deepCopyFolder(source, Folder.USER_FOLDER + userName);
+                        
+        } 
+        catch (Exception e) 
+        {
+            throw new RegistrationException(e); 
+        }        
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#generatePassword()
+     */
+    public String generatePassword()
+    {
+        // TODO: Find a replacement for Ostermiller's utility
+        // http://ostermiller.org/utils/RandPass.html
+        // almost screwed up and checked in a GPL licensed piece of code
+        // had to remove
+        return "secret";
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.administration.PortalAdministration#sendPassword(java.lang.String)
+     */
+    public void sendEmail(String emailAddress, 
+                          String localizedSubject, 
+                          String localizedTemplatePath,
+                          Map userAttributes)                            
+    throws AdministrationEmailException    
+    {       
+        SimpleMailMessage msg = new SimpleMailMessage();
+        msg.setFrom(config.getString(PortalConfigurationConstants.EMAIL_SENDER));
+        msg.setSubject(localizedSubject);
+        msg.setTo(emailAddress);
+        msg.setText(mergeEmailTemplate(userAttributes, "map", localizedTemplatePath));
+
+        try
+        {
+            mailSender.send(msg);
+        } 
+        catch (MailException ex)
+        {
+            throw new AdministrationEmailException(
+                    "Failed to send forgotten password email to user with email address "
+                            ); //+ user.getEmail());
+        }
+    }
+    
+    public void sendEmail(String recipient,
+            String localizedSubject,
+            String message)
+    throws AdministrationEmailException
+    {
+        
+    }
+    
+    
+    public String mergeEmailTemplate(Map attributes, String attributesName, String template)
+    throws AdministrationEmailException
+    {
+        VelocityContext context = new VelocityContext();
+        context.put(attributesName, attributes);
+        
+        StringWriter writer = new StringWriter();
+        final InputStream templateResource = this.getClass()
+                .getResourceAsStream(template);
+        Reader templateReader = new InputStreamReader(templateResource);
+        try
+        {
+            velocityEngine.evaluate(context, writer, "UserEmailProcessor",
+                    templateReader);
+        } catch (Exception e)
+        {
+            throw new AdministrationEmailException(
+                    "Failed to generate email text for email template "
+                            + template, e);
+        }
+        
+        String buffer = writer.getBuffer().toString();
+        
+        return buffer;
+    }
+    
+    private static final String USER_NOT_FOUND_FROM_EMAIL = "User not found for Email address:
";
+    
+    public User lookupUserFromEmail(String email)
+        throws AdministrationEmailException    
+    {
+        Collection result = preferences.lookupPreference("userinfo", "user.email", email);
+        if (result.size() == 0)
+        {
+            throw new AdministrationEmailException(USER_NOT_FOUND_FROM_EMAIL + email);
+        }
+        Iterator nodes = result.iterator();
+        Node node = (Node)nodes.next();
+        String nodePath = node.getFullPath();
+        if (nodePath == null)
+        {
+            throw new AdministrationEmailException(USER_NOT_FOUND_FROM_EMAIL + email);
+        }
+        String[] paths = nodePath.split("/");
+        if (paths == null || paths.length != 4)
+        {
+            throw new AdministrationEmailException(USER_NOT_FOUND_FROM_EMAIL + email);
+        }
+        String userName = paths[2];
+        try
+        {
+            return userManager.getUser(userName);
+        }
+        catch (Exception e)
+        {
+            throw new AdministrationEmailException(USER_NOT_FOUND_FROM_EMAIL + email);
+        }
+    }
+
+}

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitorImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitorImpl.java?rev=348124&r1=348123&r2=348124&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitorImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerMonitorImpl.java
Mon Nov 21 23:57:43 2005
@@ -18,6 +18,8 @@
 
 import java.security.AccessControlContext;
 import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Stack;
 
 import org.apache.commons.logging.Log;
@@ -55,6 +57,9 @@
     /** Static counters for identifying workers */
     private static long sCount = 0;
 
+    /** Count of running jobs **/
+    private int runningJobs = 0;
+    
     /** Minimum number of wokers to create */
     private int minWorkers = 5;
 
@@ -166,6 +171,7 @@
                 {
                     worker.setJob(job, context);
                     worker.notify();
+                    runningJobs++;
                 }
             }
             catch (Throwable t)
@@ -192,12 +198,14 @@
                 RenderingJob job = (RenderingJob)queue.pop();
                 AccessControlContext context = (AccessControlContext)queue.pop();
                 worker.setJob(job, context);
+                runningJobs--;
                 return;
             }
             else
             {
                 worker.setJob(null);
                 worker.resetJobCount();
+                runningJobs--;
             }
         }
 
@@ -206,4 +214,24 @@
             this.workers.push(worker);
         }
     }
+
+    public int getQueuedJobsCount()
+    {
+        return queue.size();
+    }
+    
+    /**
+     * Returns a snapshot of the available jobs
+     * @return available jobs
+     */
+    public int getAvailableJobsCount()
+    {
+        return workers.size();
+    }
+    
+    public int getRunningJobsCount()
+    {
+        return this.tg.activeCount();
+    }
+    
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedEngine.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedEngine.java?rev=348124&r1=348123&r2=348124&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedEngine.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedEngine.java
Mon Nov 21 23:57:43 2005
@@ -90,7 +90,8 @@
         
         // Make these availble as beans to Spring
         componentManager.addComponent("Engine", this);
-        componentManager.addComponent("PortalContext", context);        
+        componentManager.addComponent("PortalContext", context);
+        componentManager.addComponent("PortalConfiguration", configuration);
     }  
     
     

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java?rev=348124&r1=348123&r2=348124&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
Mon Nov 21 23:57:43 2005
@@ -143,8 +143,8 @@
                 engine = new JetspeedEngine(properties, applicationRoot, config, initializeComponentManager(config,
applicationRoot, properties));
              
                 console.info("JetspeedServlet attempting to start the Jetspeed Portal Engine...");
-                engine.start();
                 Jetspeed.setEngine(engine);
+                engine.start();                
                 console.info("JetspeedServlet has successfuly started the Jetspeed Portal
Engine....");
 
             }

Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/MockRenderJob.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/MockRenderJob.java?rev=348124&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/MockRenderJob.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/MockRenderJob.java
Mon Nov 21 23:57:43 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.aggregator;
+
+import org.apache.pluto.om.window.PortletWindow;
+
+
+/**
+ * MockRenderJob
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+
+public class MockRenderJob  implements RenderingJob
+{
+    private long mockTime;
+    private String jobName;
+    private PortletWindow window;
+    
+    public MockRenderJob(String jobName, long mockTime, PortletWindow window)
+    {
+        this.mockTime = mockTime;
+        this.jobName = jobName;
+        this.window = window;
+    }
+    
+    public void run()
+    {       
+        execute();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.aggregator.RenderingJob#execute()
+     */
+    public void execute()
+    {
+        System.out.println("Running mock rendering job ..." + jobName);
+        try
+        {
+            Thread.sleep(mockTime);
+        }
+        catch (InterruptedException e)
+        {
+            System.out.println("Interrupted job..." + jobName);
+        }
+        System.out.println("mock job completed " + jobName);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.aggregator.RenderingJob#getWindow()
+     */
+    public PortletWindow getWindow()
+    {
+        // TODO Auto-generated method stub
+        return window;
+    }
+
+}

Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java?rev=348124&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
Mon Nov 21 23:57:43 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.aggregator;
+ 
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.jetspeed.aggregator.impl.ContentServerAdapterImpl;
+import org.apache.jetspeed.aggregator.impl.PageAggregatorImpl;
+import org.apache.jetspeed.aggregator.impl.PortletAggregatorImpl;
+import org.apache.jetspeed.aggregator.impl.WorkerMonitorImpl;
+import org.apache.jetspeed.headerresource.HeaderResourceFactory;
+import org.apache.jetspeed.headerresource.impl.HeaderResourceFactoryImpl;
+import org.apache.jetspeed.om.window.impl.PortletWindowImpl;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * <P>Test the aggregation service</P>
+ *
+ * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
+ * @version $Id: TestAggregator.java 279463 2005-09-07 23:45:24Z taylor $
+ * 
+ */
+public class TestWorkerMonitor extends TestCase
+{    
+    /**
+     * Start the tests.
+     *
+     * @param args the arguments. Not used
+     */
+    public static void main(String args[])
+    {
+        junit.awtui.TestRunner.main(new String[] { TestWorkerMonitor.class.getName()});
+    }
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        
+        
+    }
+    
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(TestWorkerMonitor.class);
+    }
+
+    private static final int JOB_COUNT = 2;
+    
+    public void testBasic() throws Exception
+    {
+        WorkerMonitor monitor = new WorkerMonitorImpl(1, 2, 1, 1);
+        
+        List jobs = new ArrayList(JOB_COUNT);
+        for (int ix = 0; ix < JOB_COUNT; ix++)
+        {
+            PortletWindow window = new PortletWindowImpl("w" + String.valueOf(ix));     
 
+            jobs.add(new MockRenderJob("Job-" + (ix + 1), 4000, window));
+        }
+        assertNotNull("monitor is null", monitor);
+        monitor.start();
+        for (int ix = 0; ix < JOB_COUNT; ix++)
+           monitor.process((RenderingJob)jobs.get(ix));
+        
+        Thread.sleep(2000);
+        assertTrue("available jobs expect 0", monitor.getAvailableJobsCount() == 0);
+        assertTrue("running jobs expect 2", monitor.getRunningJobsCount() == 2);
+        assertTrue("queued jobs expect 0", monitor.getQueuedJobsCount() == 0);
+        monitor.stop();
+    }
+
+}



---------------------------------------------------------------------
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