[jboss-cvs] JBossAS SVN: r102629 - projects/test/trunk/src/main/java/org/jboss/test/jms.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 19 12:01:10 EDT 2010


Author: clebert.suconic at jboss.com
Date: 2010-03-19 12:01:09 -0400 (Fri, 19 Mar 2010)
New Revision: 102629

Added:
   projects/test/trunk/src/main/java/org/jboss/test/jms/LegacyJMSTestAdmin.java
Modified:
   projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java
   projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java
Log:
https://jira.jboss.org/jira/browse/JBTEST-17 - adding Legacy JMS Admin

Modified: projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java	2010-03-19 16:00:47 UTC (rev 102628)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java	2010-03-19 16:01:09 UTC (rev 102629)
@@ -57,7 +57,25 @@
       jmx = (MBeanServerConnection) ctx.lookup(adaptorName);
       ctx.close();
    }
+   
+   @Override
+   public boolean isSupported()
+   {
+      try
+      {
+           createQueue("deleteMe");
+           destroyCreatedDestinations();
+           for (int i = 0 ; i < 100; i++) staticLog.info("HornetQ is supported!!!");
+           return true;
+      }
+      catch (Exception e)
+      {
+         staticLog.debug("HornetQTestAdmin is not support because an exception happened", e);
+         return false;
+      }
+   }
 
+   
    public void createQueue(String name, TestRole... securityConfig) throws Exception
    {
       createQueue(name, new String[]

Modified: projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java	2010-03-19 16:00:47 UTC (rev 102628)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java	2010-03-19 16:01:09 UTC (rev 102629)
@@ -1,24 +1,24 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2010, JBoss Inc., 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.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., 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.test.jms;
 
@@ -32,7 +32,7 @@
 /**
  * 
  * @author <mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- *
+ * 
  */
 public abstract class JMSTestAdmin
 {
@@ -41,51 +41,72 @@
    protected Map<String, TestRole[]> deployedQueues = new HashMap<String, TestRole[]>();
 
    public static JMSTestAdmin admin;
-   
-   public static JMSTestAdmin getAdmin()
+
+   public synchronized static JMSTestAdmin getAdmin()
    {
       if (admin == null)
       {
          try
          {
-            // TODO: make this configurable
-            admin = new HornetQTestAdmin();
-         }
-         catch (Exception e)
+            JMSTestAdmin tmpadmin = new HornetQTestAdmin();
+            if (tmpadmin.isSupported())
+            {
+               admin = tmpadmin;
+            }
+            else
+            {
+               tmpadmin = new LegacyJMSTestAdmin();
+               if (tmpadmin.isSupported())
+               {
+                  admin = tmpadmin;
+               }
+            }
+         } catch (Exception e)
          {
             e.printStackTrace(); // >> junit report
             throw new NestedRuntimeException(e.getMessage(), e);
          }
       }
+
+      if (admin == null)
+      {
+         throw new RuntimeException("There is no supported TestAdmin for this JMS implementation");
+      }
       
       return admin;
    }
-   
-   
-	/**
-	 * 
-	 * @param name
-	 * @param securityConfig
-	 * @return information about the deployment required to undeploy/remove the topic
-	 * @throws Exception 
-	 */
-   public abstract void createTopic(String name, TestRole ... securityConfig) throws Exception;
 
-   public abstract void createTopic(String name, String[] jndi, TestRole ... securityConfig) throws Exception;
+   public abstract boolean isSupported();
 
-	public abstract void deleteTopic(String topic) throws Exception;
+   /**
+    * 
+    * @param name
+    * @param securityConfig
+    * @return information about the deployment required to undeploy/remove the
+    *         topic
+    * @throws Exception
+    */
+   public abstract void createTopic(String name, TestRole... securityConfig)
+         throws Exception;
 
-	public abstract void createQueue(String name, TestRole ... securityConfig) throws Exception;
+   public abstract void createTopic(String name, String[] jndi,
+         TestRole... securityConfig) throws Exception;
 
-   public abstract void createQueue(String name, String[] jndi, TestRole ... securityConfig) throws Exception;
+   public abstract void deleteTopic(String topic) throws Exception;
 
+   public abstract void createQueue(String name, TestRole... securityConfig)
+         throws Exception;
+
+   public abstract void createQueue(String name, String[] jndi,
+         TestRole... securityConfig) throws Exception;
+
    public abstract void deleteQueue(String queue) throws Exception;
-	
-	public abstract void destroyCreatedDestinations() throws Exception;
-	
-	public abstract void destroyEveryDestination() throws Exception;
-	
-	public abstract ObjectName createQueueJMXName(String queueName);
-	
-	public abstract ObjectName createTopicJMXName(String queueName);
+
+   public abstract void destroyCreatedDestinations() throws Exception;
+
+   public abstract void destroyEveryDestination() throws Exception;
+
+   public abstract ObjectName createQueueJMXName(String queueName);
+
+   public abstract ObjectName createTopicJMXName(String queueName);
 }

Added: projects/test/trunk/src/main/java/org/jboss/test/jms/LegacyJMSTestAdmin.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/LegacyJMSTestAdmin.java	                        (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/LegacyJMSTestAdmin.java	2010-03-19 16:01:09 UTC (rev 102629)
@@ -0,0 +1,255 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., 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.test.jms;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.util.Map;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * 
+ * @author <mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * 
+ */
+public class LegacyJMSTestAdmin extends JMSTestAdmin
+{
+   private final MBeanServerConnection jmx;
+
+   protected final ObjectName mainDeployer = new ObjectName("jboss.system:service=MainDeployer");
+
+   /** The static log */
+   private static final Logger staticLog = Logger.getLogger(LegacyJMSTestAdmin.class);
+
+   public LegacyJMSTestAdmin() throws Exception
+   {
+      InitialContext ctx = new InitialContext();
+      String adaptorName = System.getProperty("jbosstest.server.name", "jmx/invoker/RMIAdaptor");
+      jmx = (MBeanServerConnection) ctx.lookup(adaptorName);
+      ctx.close();
+   }
+
+   @Override
+   public boolean isSupported()
+   {
+      try
+      {
+         createQueue("deleteMeTest");
+         destroyCreatedDestinations();
+         
+         for (int i = 0 ; i < 100; i++) staticLog.info("Legacy is supported!!!");
+
+         return true;
+      } catch (Throwable e)
+      {
+         staticLog.debug("LegacyJMSTestAdmin is not support because an exception happened", e);
+         return false;
+      }
+   }
+
+   public void createQueue(String name, TestRole... securityConfig) throws Exception
+   {
+
+      createQueue(name, new String[]
+      { "/queue/" + name, name }, securityConfig);
+   }
+
+   public void createQueue(String name, String[] jndiArray, TestRole... securityConfig) throws Exception
+   {
+
+      createDestination(false, name, securityConfig);
+
+      deployedQueues.put(name, securityConfig);
+   }
+
+   public void createTopic(String name, TestRole... securityConfig) throws Exception
+   {
+      createTopic(name, new String[]
+      { "/topic/" + name, name }, securityConfig);
+   }
+
+   public void createTopic(String name, String[] jndiArray, TestRole... securityConfig) throws Exception
+   {
+
+      createDestination(true, name, securityConfig);
+
+      deployedTopics.put(name, securityConfig);
+   }
+
+   public void deleteQueue(String name) throws Exception
+   {
+      try
+      {
+         deployedQueues.remove(name);
+         undeploy(false, name);
+      } catch (Exception e)
+      {
+         staticLog.warn(e.getMessage(), e);
+         throw e;
+      }
+   }
+
+   public void deleteTopic(String name) throws Exception
+   {
+      try
+      {
+         deployedTopics.remove(name);
+         undeploy(true, name);
+      } catch (Exception e)
+      {
+         staticLog.warn(e.getMessage(), e);
+         throw e;
+      }
+   }
+
+   /**
+    * This method only exists because hornetQ doesn't actually delete the
+    * destination on undeploy. On HornetQ we need to remove every destination
+    * from the storage while on Legacy versions a simple undeploy is fine
+    */
+   public void destroyEveryDestination() throws Exception
+   {
+      destroyCreatedDestinations();
+   }
+
+   @Override
+   public void destroyCreatedDestinations() throws Exception
+   {
+      for (Map.Entry<String, TestRole[]> queue : deployedQueues.entrySet())
+      {
+         undeploy(false, queue.getKey());
+      }
+
+      for (Map.Entry<String, TestRole[]> topic : deployedTopics.entrySet())
+      {
+         undeploy(true, topic.getKey());
+      }
+
+      deployedQueues.clear();
+      deployedTopics.clear();
+   }
+
+   @Override
+   public ObjectName createQueueJMXName(String queueName)
+   {
+      try
+      {
+         return new ObjectName("org.jboss.mq.server.jmx.Queue\" name=\"jboss.mq.destination:service=Queue,name=\"" + queueName + "\"");
+      } catch (Exception e)
+      {
+         staticLog.warn(e.getMessage(), e);
+         e.printStackTrace(); // >> junit reports
+         return null;
+      }
+   }
+
+   @Override
+   public ObjectName createTopicJMXName(String queueName)
+   {
+      try
+      {
+         return new ObjectName("org.jboss.mq.server.jmx.Topic\" name=\"jboss.mq.destination:service=Topic,name=\"" + queueName + "\"");
+      } catch (Exception e)
+      {
+         staticLog.warn(e.getMessage(), e);
+         e.printStackTrace(); // >> junit reports
+         return null;
+      }
+   }
+
+   private void undeploy(boolean isTopic, String destinationName) throws Exception
+   {
+      File destFile = createFile(isTopic, destinationName);
+
+      jmx.invoke(mainDeployer, "undeploy", new Object[]
+      { destFile.toURI().toURL() }, new String[]
+      { "java.net.URL" });
+
+      destFile.delete();
+   }
+
+   private void createDestination(boolean isTopic, String name, TestRole... securityConfig) throws Exception
+   {
+      // OK, lets see if we can figure out what it might be.
+      File fileout = createFile(isTopic, name);
+
+      if (fileout.exists())
+      {
+         fileout.delete();
+      }
+
+      FileOutputStream out = new FileOutputStream(fileout);
+
+      PrintStream str = new PrintStream(out);
+      str.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+      str.println("<server>");
+      if (isTopic)
+      {
+         str.println("  <mbean code=\"org.jboss.mq.server.jmx.Topic\" name=\"jboss.mq.destination:service=Topic,name=" + name + "\">");
+      } else
+      {
+         str.println("  <mbean code=\"org.jboss.mq.server.jmx.Queue\" name=\"jboss.mq.destination:service=Queue,name=" + name + "\">");
+      }
+      str.println("    <depends optional-attribute-name=\"DestinationManager\">jboss.mq:service=DestinationManager</depends>");
+      str.println("    <depends optional-attribute-name=\"SecurityManager\">jboss.mq:service=SecurityManager</depends>");
+
+      if (securityConfig != null && securityConfig.length > 0)
+      {
+         str.println("    <attribute name=\"SecurityConf\">");
+         str.println("       <security>");
+         for (TestRole role : securityConfig)
+         {
+            str.println("       <role name=\"" + role.getName() + "\" read=" + role.isConsume() + " write=" + role.isSend() + " create=" + (role.isCreateDurableQueue() || role.isCreateNonDurableQueue()) + "/>");
+         }
+         str.println("   </security>");
+         str.println("</attribute>");
+      }
+      
+      str.println("   </mbean>");
+
+      str.println("</server>");
+
+      jmx.invoke(mainDeployer, "deploy", new Object[]
+      { fileout.toURI().toURL() }, new String[]
+      { "java.net.URL" });
+
+   }
+
+   private File createFile(boolean isTopic, String destinationName)
+   {
+      String deployDir = System.getProperty("jbosstest.deploy.dir");
+      if (deployDir == null)
+      {
+         deployDir = "output/lib";
+      }
+      File fileout = new File(deployDir + "/" + "tmpdest_" + (isTopic ? "topic_" : "queue_") + destinationName + "-destination-service.xml");
+      return fileout;
+   }
+
+}




More information about the jboss-cvs-commits mailing list