[jboss-cvs] JBoss Messaging SVN: r4575 - in trunk: src/config and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 25 08:28:42 EDT 2008
Author: timfox
Date: 2008-06-25 08:28:42 -0400 (Wed, 25 Jun 2008)
New Revision: 4575
Added:
trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java
trunk/tests/tmpfiles/
Modified:
trunk/.classpath
trunk/build-messaging.xml
trunk/src/config/jbm-beans.xml
trunk/src/config/jbm-standalone-beans.xml
trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java
Log:
Filedeploymentmanagertest
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2008-06-25 12:23:54 UTC (rev 4574)
+++ trunk/.classpath 2008-06-25 12:28:42 UTC (rev 4575)
@@ -62,5 +62,6 @@
<classpathentry kind="lib" path="tests/jms-tests/config"/>
<classpathentry kind="lib" path="thirdparty/easymock-classextension/lib/easymockclassextension.jar"/>
<classpathentry kind="lib" path="thirdparty/cglib/lib/cglib.jar"/>
+ <classpathentry kind="lib" path="tests/tmpfiles"/>
<classpathentry kind="output" path="eclipse-output"/>
</classpath>
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2008-06-25 12:23:54 UTC (rev 4574)
+++ trunk/build-messaging.xml 2008-06-25 12:28:42 UTC (rev 4575)
@@ -212,13 +212,14 @@
<path id="unit.test.execution.classpath">
<pathelement location="${test.dir}/config"/>
+ <pathelement location="${test.dir}/tmpfiles"/>
<pathelement location="${test.classes.dir}"/>
<pathelement location="${src.config.dir}"/>
<path refid="test.compilation.classpath"/>
<path refid="oswego.concurrent.classpath"/>
<path refid="slf4j.api.classpath"/>
<path refid="slf4j.log4j.classpath"/>
- <path refid="cglib.classpath" />
+ <path refid="cglib.classpath" />
</path>
<path id="jms.test.execution.classpath">
Modified: trunk/src/config/jbm-beans.xml
===================================================================
--- trunk/src/config/jbm-beans.xml 2008-06-25 12:23:54 UTC (rev 4574)
+++ trunk/src/config/jbm-beans.xml 2008-06-25 12:28:42 UTC (rev 4575)
@@ -4,7 +4,12 @@
<bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
- <bean name="DeploymentManager" class="org.jboss.messaging.core.deployers.impl.FileDeploymentManager"/>
+ <bean name="DeploymentManager" class="org.jboss.messaging.core.deployers.impl.FileDeploymentManager">
+ <constructor>
+ <!-- The scan time in milliseconds -->
+ <parameter>5000</parameter>
+ </constructor>
+ </bean>
<bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JAASSecurityManager"/>
Modified: trunk/src/config/jbm-standalone-beans.xml
===================================================================
--- trunk/src/config/jbm-standalone-beans.xml 2008-06-25 12:23:54 UTC (rev 4574)
+++ trunk/src/config/jbm-standalone-beans.xml 2008-06-25 12:28:42 UTC (rev 4575)
@@ -18,8 +18,13 @@
</property>
</bean>
- <bean name="DeploymentManager" class="org.jboss.messaging.core.deployers.impl.FileDeploymentManager"/>
-
+ <bean name="DeploymentManager" class="org.jboss.messaging.core.deployers.impl.FileDeploymentManager">
+ <constructor>
+ <!-- The scan time in milliseconds -->
+ <parameter>5000</parameter>
+ </constructor>
+ </bean>
+
<bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
<!--<bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JAASSecurityManager"/>-->
Modified: trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java 2008-06-25 12:23:54 UTC (rev 4574)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java 2008-06-25 12:28:42 UTC (rev 4575)
@@ -53,6 +53,13 @@
private boolean started;
+ private final long period;
+
+ public FileDeploymentManager(final long period)
+ {
+ this.period = period;
+ }
+
public synchronized void start() throws Exception
{
if (started)
@@ -62,7 +69,7 @@
scheduler = Executors.newSingleThreadScheduledExecutor();
- scheduler.scheduleWithFixedDelay(this, 10, 5, TimeUnit.SECONDS);
+ scheduler.scheduleWithFixedDelay(this, period, period, TimeUnit.MILLISECONDS);
started = true;
}
@@ -99,10 +106,19 @@
{
deployers.add(deployer);
- Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployer.getConfigFileName());
+ String filename = deployer.getConfigFileName();
+
+ log.info("the filename is " + filename);
+
+ log.info(System.getProperty("java.class.path"));
+
+ Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(filename);
+
while (urls.hasMoreElements())
{
URL url = urls.nextElement();
+
+ log.info("Got url " + url);
try
{
@@ -116,7 +132,9 @@
deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));
}
- }
+ }
+
+ log.info("Done register");
}
public synchronized void unregisterDeployer(final Deployer deployer) throws Exception
@@ -150,93 +168,92 @@
try
{
- scan();
- }
- catch (Exception e)
- {
- log.warn("error scanning for URL's " + e);
- }
- }
+ for (Deployer deployer : deployers)
+ {
+ Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployer.getConfigFileName());
- /**
- * scans for changes to any of the configuration files registered
- *
- * @throws Exception .
- */
- public void scan() throws Exception
- {
- if (!started)
- {
- throw new IllegalStateException("Service is not started");
- }
-
- for (Deployer deployer : deployers)
- {
- Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployer.getConfigFileName());
-
- while (urls.hasMoreElements())
- {
- URL url = urls.nextElement();
-
- DeployInfo info = deployed.get(url);
-
- if (info == null)
- {
- try
- {
- log.info("Deploying " + deployer + " with url " + url);
+ while (urls.hasMoreElements())
+ {
+ URL url = urls.nextElement();
+
+ DeployInfo info = deployed.get(url);
+
+ long newLastModified = new File(url.getFile()).lastModified();
- deployer.deploy(url);
-
- deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));
+ if (info == null)
+ {
+ try
+ {
+ log.info("Deploying " + deployer + " with url " + url);
+
+ deployer.deploy(url);
+
+ deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));
+ }
+ catch (Exception e)
+ {
+ log.error("Error deploying " + url, e);
+ }
}
- catch (Exception e)
- {
- log.error("Error deploying " + url, e);
+ else if (newLastModified > info.lastModified)
+ {
+ try
+ {
+ log.info("Redeploying " + deployer + " with url " + url);
+
+ deployer.redeploy(url);
+
+ deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));
+ }
+ catch (Exception e)
+ {
+ log.error("Error redeploying " + url, e);
+ }
}
- }
- else if (new File(url.getFile()).lastModified() > info.lastModified)
- {
+ }
+ }
+
+ for (Map.Entry<URL, DeployInfo> entry : deployed.entrySet())
+ {
+ if (!new File(entry.getKey().getFile()).exists())
+ {
try
{
- log.info("Redeploying " + deployer + " with url " + url);
+ Deployer deployer = entry.getValue().deployer;
+ log.info("Undeploying " + deployer + " with url" + entry.getKey());
+ deployer.undeploy(entry.getKey());
- deployer.redeploy(url);
-
- deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));
+ deployed.remove(entry.getKey());
}
catch (Exception e)
{
- log.error("Error redeploying " + url, e);
+ log.error("Error undeploying " + entry.getKey(), e);
}
}
- }
+ }
}
-
- for (Map.Entry<URL, DeployInfo> entry : deployed.entrySet())
+ catch (Exception e)
{
- if (!new File(entry.getKey().getFile()).exists())
- {
- try
- {
- Deployer deployer = entry.getValue().deployer;
- log.info("Undeploying " + deployer + " with url" + entry.getKey());
- deployer.undeploy(entry.getKey());
- }
- catch (Exception e)
- {
- log.error("Error undeploying " + entry.getKey(), e);
- }
- }
+ log.warn("error scanning for URL's " + e);
}
}
+
+ public synchronized List<Deployer> getDeployers()
+ {
+ return deployers;
+ }
+ public synchronized Map<URL, DeployInfo> getDeployed()
+ {
+ return deployed;
+ }
+
// Inner classes -------------------------------------------------------------------------------------------
- private static class DeployInfo
+ public static class DeployInfo
{
- Deployer deployer;
- long lastModified;
+ public Deployer deployer;
+ public long lastModified;
DeployInfo(final Deployer deployer, final long lastModified)
{
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java 2008-06-25 12:28:42 UTC (rev 4575)
@@ -0,0 +1,390 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.unit.core.deployers.impl;
+
+import java.io.File;
+import java.net.URL;
+
+import org.easymock.classextension.EasyMock;
+import org.jboss.messaging.core.deployers.Deployer;
+import org.jboss.messaging.core.deployers.impl.FileDeploymentManager;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ *
+ * A FileDeploymentManagerTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class FileDeploymentManagerTest extends UnitTestCase
+{
+ private static final Logger log = Logger.getLogger(FileDeploymentManagerTest.class);
+
+ public void testStartStop() throws Exception
+ {
+ FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE);
+
+ Deployer deployer = EasyMock.createStrictMock(Deployer.class);
+
+ try
+ {
+ fdm.registerDeployer(deployer);
+ fail("Should throw exception");
+ }
+ catch (IllegalStateException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ fdm.unregisterDeployer(deployer);
+ fail("Should throw exception");
+ }
+ catch (IllegalStateException e)
+ {
+ //Ok
+ }
+
+ fdm.start();
+
+ String filename = "fdm_test_file.xml";
+
+ log.info("Filename is " + filename);
+
+ File file = new File("tests/tmpfiles/" + filename);
+
+ log.info(file.getAbsoluteFile());
+
+ file.createNewFile();
+
+ try
+ {
+ EasyMock.expect(deployer.getConfigFileName()).andReturn(filename);
+
+ URL url = file.toURL();
+
+ deployer.deploy(url);
+
+ EasyMock.replay(deployer);
+
+ fdm.registerDeployer(deployer);
+
+ EasyMock.verify(deployer);
+
+ //Start again should do nothing
+
+ EasyMock.reset(deployer);
+
+ EasyMock.replay(deployer);
+
+ fdm.start();
+
+ EasyMock.verify(deployer);
+
+ fdm.stop();
+
+ try
+ {
+ fdm.registerDeployer(deployer);
+ fail("Should throw exception");
+ }
+ catch (IllegalStateException e)
+ {
+ //Ok
+ }
+
+ try
+ {
+ fdm.unregisterDeployer(deployer);
+ fail("Should throw exception");
+ }
+ catch (IllegalStateException e)
+ {
+ //Ok
+ }
+ }
+ finally
+ {
+ file.delete();
+ }
+ }
+
+ public void testRegisterUnregister() throws Exception
+ {
+ FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE);
+
+ Deployer deployer1 = EasyMock.createStrictMock(Deployer.class);
+ Deployer deployer2 = EasyMock.createStrictMock(Deployer.class);
+ Deployer deployer3 = EasyMock.createStrictMock(Deployer.class);
+
+ fdm.start();
+
+ String filename1 = "fdm_test_file.xml1";
+ String filename2 = "fdm_test_file.xml2";
+ String filename3 = "fdm_test_file.xml3";
+
+ File file1 = new File("tests/tmpfiles/" + filename1);
+ File file2 = new File("tests/tmpfiles/" + filename2);
+ File file3 = new File("tests/tmpfiles/" + filename3);
+
+ file1.createNewFile();
+ file2.createNewFile();
+ file3.createNewFile();
+
+ try
+ {
+ EasyMock.expect(deployer1.getConfigFileName()).andReturn(filename1);
+ URL url1 = file1.toURL();
+ deployer1.deploy(url1);
+
+ EasyMock.expect(deployer2.getConfigFileName()).andReturn(filename2);
+ URL url2 = file2.toURL();
+ deployer2.deploy(url2);
+
+ EasyMock.expect(deployer3.getConfigFileName()).andReturn(filename3);
+ URL url3 = file3.toURL();
+ deployer3.deploy(url3);
+
+ EasyMock.replay(deployer1, deployer2, deployer3);
+
+ fdm.registerDeployer(deployer1);
+ fdm.registerDeployer(deployer2);
+ fdm.registerDeployer(deployer3);
+
+ EasyMock.verify(deployer1, deployer2, deployer3);
+
+ assertEquals(3, fdm.getDeployers().size());
+ assertTrue(fdm.getDeployers().contains(deployer1));
+ assertTrue(fdm.getDeployers().contains(deployer2));
+ assertTrue(fdm.getDeployers().contains(deployer3));
+ assertEquals(3, fdm.getDeployed().size());
+
+ //Registering same again should do nothing
+
+ EasyMock.reset(deployer1, deployer2, deployer3);
+ EasyMock.replay(deployer1, deployer2, deployer3);
+
+ fdm.registerDeployer(deployer1);
+
+ EasyMock.verify(deployer1, deployer2, deployer3);
+
+ assertEquals(3, fdm.getDeployers().size());
+ assertTrue(fdm.getDeployers().contains(deployer1));
+ assertTrue(fdm.getDeployers().contains(deployer2));
+ assertTrue(fdm.getDeployers().contains(deployer3));
+ assertEquals(3, fdm.getDeployed().size());
+
+ EasyMock.reset(deployer1, deployer2, deployer3);
+
+ EasyMock.expect(deployer1.getConfigFileName()).andReturn(filename1);
+
+ EasyMock.replay(deployer1, deployer2, deployer3);
+
+ fdm.unregisterDeployer(deployer1);
+
+ EasyMock.verify(deployer1, deployer2, deployer3);
+
+ assertEquals(2, fdm.getDeployers().size());
+ assertTrue(fdm.getDeployers().contains(deployer2));
+ assertTrue(fdm.getDeployers().contains(deployer3));
+ assertEquals(2, fdm.getDeployed().size());
+
+ EasyMock.reset(deployer1, deployer2, deployer3);
+
+ EasyMock.expect(deployer2.getConfigFileName()).andReturn(filename2);
+ EasyMock.expect(deployer3.getConfigFileName()).andReturn(filename3);
+
+ EasyMock.replay(deployer1, deployer2, deployer3);
+
+ fdm.unregisterDeployer(deployer2);
+ fdm.unregisterDeployer(deployer3);
+
+ EasyMock.verify(deployer1, deployer2, deployer3);
+
+ assertEquals(0, fdm.getDeployers().size());
+ assertEquals(0, fdm.getDeployed().size());
+
+ //Now unregister again - should do nothing
+
+ EasyMock.reset(deployer1, deployer2, deployer3);
+ EasyMock.replay(deployer1, deployer2, deployer3);
+ fdm.unregisterDeployer(deployer1);
+ EasyMock.verify(deployer1, deployer2, deployer3);
+
+ assertEquals(0, fdm.getDeployers().size());
+ assertEquals(0, fdm.getDeployed().size());
+ }
+ finally
+ {
+ file1.delete();
+ file2.delete();
+ file3.delete();
+ }
+ }
+
+ public void testRedeploy() throws Exception
+ {
+ FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE);
+
+ Deployer deployer = EasyMock.createStrictMock(Deployer.class);
+
+ fdm.start();
+
+ String filename = "fdm_test_file.xml1";
+
+ File file = new File("tests/tmpfiles/" + filename);
+
+ file.createNewFile();
+ long oldLastModified = file.lastModified();
+
+ try
+ {
+ EasyMock.expect(deployer.getConfigFileName()).andReturn(filename);
+ URL url = file.toURL();
+ deployer.deploy(url);
+
+ EasyMock.replay(deployer);
+
+ fdm.registerDeployer(deployer);
+
+ EasyMock.verify(deployer);
+
+ //Touch the file
+ file.setLastModified(oldLastModified + 1000);
+
+ EasyMock.reset(deployer);
+
+ EasyMock.expect(deployer.getConfigFileName()).andReturn(filename);
+ deployer.redeploy(url);
+
+ EasyMock.replay(deployer);
+
+ fdm.run();
+
+ EasyMock.verify(deployer);
+
+ assertEquals(1, fdm.getDeployers().size());
+ assertTrue(fdm.getDeployers().contains(deployer));
+ assertEquals(1, fdm.getDeployed().size());
+
+ assertEquals(oldLastModified + 1000, fdm.getDeployed().get(url).lastModified);
+
+ //Scanning again should not redeploy
+
+ EasyMock.reset(deployer);
+
+ EasyMock.expect(deployer.getConfigFileName()).andReturn(filename);
+
+ EasyMock.replay(deployer);
+
+ fdm.run();
+
+ EasyMock.verify(deployer);
+
+ assertEquals(oldLastModified + 1000, fdm.getDeployed().get(url).lastModified);
+ }
+ finally
+ {
+ file.delete();
+ }
+ }
+
+ public void testUndeployAndDeployAgain() throws Exception
+ {
+ FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE);
+
+ Deployer deployer = EasyMock.createStrictMock(Deployer.class);
+
+ fdm.start();
+
+ String filename = "fdm_test_file.xml1";
+
+ File file = new File("tests/tmpfiles/" + filename);
+
+ file.createNewFile();
+
+ try
+ {
+ EasyMock.expect(deployer.getConfigFileName()).andReturn(filename);
+ URL url = file.toURL();
+ deployer.deploy(url);
+
+ EasyMock.replay(deployer);
+
+ fdm.registerDeployer(deployer);
+
+ EasyMock.verify(deployer);
+
+ assertEquals(1, fdm.getDeployers().size());
+ assertTrue(fdm.getDeployers().contains(deployer));
+ assertEquals(1, fdm.getDeployed().size());
+
+ file.delete();
+
+ //This should cause undeployment
+
+ EasyMock.reset(deployer);
+
+ EasyMock.expect(deployer.getConfigFileName()).andReturn(filename);
+
+ deployer.undeploy(url);
+
+ EasyMock.replay(deployer);
+
+ fdm.run();
+
+ EasyMock.verify(deployer);
+
+ assertEquals(1, fdm.getDeployers().size());
+ assertTrue(fdm.getDeployers().contains(deployer));
+ assertEquals(0, fdm.getDeployed().size());
+
+ //Recreate file and it should be redeployed
+
+ file.createNewFile();
+
+ EasyMock.reset(deployer);
+
+ EasyMock.expect(deployer.getConfigFileName()).andReturn(filename);
+
+ deployer.deploy(url);
+
+ EasyMock.replay(deployer);
+
+ fdm.run();
+
+ EasyMock.verify(deployer);
+
+ assertEquals(1, fdm.getDeployers().size());
+ assertTrue(fdm.getDeployers().contains(deployer));
+ assertEquals(1, fdm.getDeployed().size());
+ }
+ finally
+ {
+ file.delete();
+ }
+ }
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java 2008-06-25 12:23:54 UTC (rev 4574)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueImplTest.java 2008-06-25 12:28:42 UTC (rev 4575)
@@ -1004,36 +1004,6 @@
}
}
- /*
- public void testQuickSpeedTest()
- {
- Queue queue = new QueueImpl(1);
-
- final int numMessages = 1000000;
-
- FakeConsumer cons = new FakeConsumer();
-
- queue.addConsumer(cons);
-
- long start = System.currentTimeMillis();
-
- for (int i = 0; i < numMessages; i++)
- {
- MessageReference ref = this.generateReference(1);
-
- queue.addLast(ref);
- }
-
- long end = System.currentTimeMillis();
-
- double rate = 1000 * (double)numMessages / (end - start);
-
- System.out.println("Rate: " + rate);
-
- assertEquals(numMessages, cons.getReferences().size());
- }
- */
-
public void testConsumeWithFiltersAddAndRemoveConsumer() throws Exception
{
Queue queue = new QueueImpl(1, queue1, null, false, true, false, -1, scheduledExecutor);
More information about the jboss-cvs-commits
mailing list