[jboss-cvs] JBoss Messaging SVN: r5417 - trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 21 10:24:58 EST 2008


Author: timfox
Date: 2008-11-21 10:24:58 -0500 (Fri, 21 Nov 2008)
New Revision: 5417

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowBatchTimeTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTransformerTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleTransformer.java
Log:
Missing files


Added: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowBatchTimeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowBatchTimeTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowBatchTimeTest.java	2008-11-21 15:24:58 UTC (rev 5417)
@@ -0,0 +1,193 @@
+/*
+ * 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.integration.cluster.distribution;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.cluster.MessageFlowConfiguration;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * 
+ * A MessageFlowBatchTimeTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * Created 15 Nov 2008 09:06:55
+ *
+ *
+ */
+public class MessageFlowBatchTimeTest extends MessageFlowTestBase
+{
+   private static final Logger log = Logger.getLogger(MessageFlowBatchTimeTest.class);
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testBatchTime() throws Exception
+   {
+      Map<String, Object> service0Params = new HashMap<String, Object>();      
+      MessagingService service0 = createMessagingService(0, service0Params);
+      
+      Map<String, Object> service1Params = new HashMap<String, Object>();      
+      MessagingService service1 = createMessagingService(1, service1Params);      
+      service1.start();
+
+      List<TransportConfiguration> connectors = new ArrayList<TransportConfiguration>();
+      TransportConfiguration server1tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                    service1Params);
+      connectors.add(server1tc);
+      
+      final SimpleString address1 = new SimpleString("testaddress");
+                       
+      final int batchSize = 10;
+      final long batchTime = 250;
+ 
+      MessageFlowConfiguration ofconfig = new MessageFlowConfiguration("outflow1", address1.toString(), null, true, batchSize, batchTime, null, connectors);
+      Set<MessageFlowConfiguration> ofconfigs = new HashSet<MessageFlowConfiguration>();
+      ofconfigs.add(ofconfig);
+      service0.getServer().getConfiguration().setMessageFlowConfigurations(ofconfigs);
+
+      service0.start();
+      
+      TransportConfiguration server0tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                    service0Params);
+      
+      ClientSessionFactory csf0 = new ClientSessionFactoryImpl(server0tc);
+      
+      ClientSession session0 = csf0.createSession(false, true, true);
+      
+      ClientSessionFactory csf1 = new ClientSessionFactoryImpl(server1tc);
+      
+      ClientSession session1 = csf1.createSession(false, true, true);
+      
+      session0.createQueue(address1, address1, null, false, false, true);
+
+      session1.createQueue(address1, address1, null, false, false, true);  
+      
+      ClientProducer prod0_1 = session0.createProducer(address1);
+         
+      ClientConsumer cons0_1 = session0.createConsumer(address1);
+      
+      ClientConsumer cons1_1 = session1.createConsumer(address1);
+
+      session0.start();
+      
+      session1.start();
+      
+      final SimpleString propKey = new SimpleString("testkey");
+      
+      for (int j = 0; j < 5; j++)
+      {
+         
+         for (int i = 0; i < batchSize - 1; i++)
+         {      
+            ClientMessage message = session0.createClientMessage(false);
+            message.putIntProperty(propKey, i);        
+            message.getBody().flip();
+                 
+            prod0_1.send(message);
+         }
+              
+         for (int i = 0; i < batchSize - 1; i++)
+         {
+            ClientMessage rmessage1 = cons0_1.receive(1000);
+            
+            assertNotNull(rmessage1);
+            
+            assertEquals(i, rmessage1.getProperty(propKey));         
+         }
+         
+         ClientMessage rmessage1 = cons1_1.receiveImmediate();
+         
+         assertNull(rmessage1);
+         
+         //Now wait until max batch time is exceeded - this should prompt delivery
+         
+         Thread.sleep(batchTime * 2);
+         
+         for (int i = 0; i < batchSize - 1; i++)
+         {
+            rmessage1 = cons1_1.receive(1000);
+            
+            assertNotNull(rmessage1);
+            
+            assertEquals(i, rmessage1.getProperty(propKey));         
+         }
+      }
+      
+            
+      session0.close();
+      
+      session1.close();
+      
+      service0.stop();      
+      service1.stop();
+      
+      assertEquals(0, service0.getServer().getRemotingService().getConnections().size());
+      assertEquals(0, service1.getServer().getRemotingService().getConnections().size());
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      assertEquals(0, InVMRegistry.instance.size());
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}
+
+

Added: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTestBase.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTestBase.java	2008-11-21 15:24:58 UTC (rev 5417)
@@ -0,0 +1,66 @@
+/*
+ * 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.integration.cluster.distribution;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+
+import junit.framework.TestCase;
+
+/**
+ * A MessageFlowTestBase
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * Created 21 Nov 2008 10:32:23
+ *
+ *
+ */
+public abstract class MessageFlowTestBase extends TestCase
+{
+   protected MessagingService createMessagingService(final int id, Map<String, Object> params)
+   {
+      Configuration serviceConf = new ConfigurationImpl();
+      serviceConf.setClustered(true);
+      serviceConf.setSecurityEnabled(false);     
+      params.put(TransportConstants.SERVER_ID_PROP_NAME, id);
+      serviceConf.getAcceptorConfigurations()
+                  .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+                                                  params));
+      MessagingService service = MessagingServiceImpl.newNullStorageMessagingServer(serviceConf);
+      return service;
+   }
+   
+   protected MessagingService createMessagingService(final int id)
+   {
+      return this.createMessagingService(id, new HashMap<String, Object>());
+   }
+}

Added: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTransformerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTransformerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/MessageFlowTransformerTest.java	2008-11-21 15:24:58 UTC (rev 5417)
@@ -0,0 +1,174 @@
+/*
+ * 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.integration.cluster.distribution;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.cluster.MessageFlowConfiguration;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * 
+ * A MessageFlowWildcardTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * Created 15 Nov 2008 08:19:07
+ *
+ *
+ */
+public class MessageFlowTransformerTest extends MessageFlowTestBase
+{
+   private static final Logger log = Logger.getLogger(MessageFlowTransformerTest.class);
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testWithTransformer() throws Exception
+   {
+      Map<String, Object> service0Params = new HashMap<String, Object>();
+      MessagingService service0 = createMessagingService(0, service0Params);
+
+      Map<String, Object> service1Params = new HashMap<String, Object>();
+      MessagingService service1 = createMessagingService(1, service1Params);
+      service1.start();
+
+      List<TransportConfiguration> connectors = new ArrayList<TransportConfiguration>();
+      TransportConfiguration server1tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                    service1Params);
+      connectors.add(server1tc);
+
+      final SimpleString address1 = new SimpleString("address1");
+      
+      MessageFlowConfiguration ofconfig = new MessageFlowConfiguration("outflow1",
+                                                                       "address1",
+                                                                       null,
+                                                                       true,
+                                                                       1,
+                                                                       -1,
+                                                                       "org.jboss.messaging.tests.integration.cluster.distribution.SimpleTransformer",
+                                                                       connectors);
+      Set<MessageFlowConfiguration> ofconfigs = new HashSet<MessageFlowConfiguration>();
+      ofconfigs.add(ofconfig);
+      service0.getServer().getConfiguration().setMessageFlowConfigurations(ofconfigs);
+
+      service0.start();
+
+      TransportConfiguration server0tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                    service0Params);
+
+      ClientSessionFactory csf0 = new ClientSessionFactoryImpl(server0tc);
+
+      ClientSession session0 = csf0.createSession(false, true, true);
+
+      ClientSessionFactory csf1 = new ClientSessionFactoryImpl(server1tc);
+
+      ClientSession session1 = csf1.createSession(false, true, true);
+      
+      
+
+      session0.createQueue(address1, address1, null, false, false, true);
+    
+      session1.createQueue(address1, address1, null, false, false, true);
+
+      ClientProducer prod0 = session0.createProducer(address1);
+
+      ClientConsumer cons1 = session1.createConsumer(address1);
+     
+      session1.start();
+
+      final int numMessages = 100;
+
+      final SimpleString propKey = new SimpleString("wibble");
+
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage message = session0.createClientMessage(false);
+         message.putStringProperty(propKey, new SimpleString("bing"));
+         message.getBody().putString("doo be doo be doo be doo");
+         message.getBody().flip();
+
+         prod0.send(message);
+      }
+      
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage rmessage = cons1.receive(1000);
+
+         assertNotNull(rmessage);
+         
+         SimpleString val = (SimpleString)rmessage.getProperty(propKey);
+         assertEquals(new SimpleString("bong"), val);
+         
+         String sval = rmessage.getBody().getString();
+         assertEquals("dee be dee be dee be dee", sval);
+      }
+
+      service0.stop();
+      service1.stop();
+
+      assertEquals(0, service0.getServer().getRemotingService().getConnections().size());
+      assertEquals(0, service1.getServer().getRemotingService().getConnections().size());
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      assertEquals(0, InVMRegistry.instance.size());
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleTransformer.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleTransformer.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SimpleTransformer.java	2008-11-21 15:24:58 UTC (rev 5417)
@@ -0,0 +1,74 @@
+/*
+ * 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.integration.cluster.distribution;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.server.cluster.Transformer;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * A SimpleTransformer
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * Created 21 Nov 2008 11:44:37
+ *
+ *
+ */
+public class SimpleTransformer implements Transformer
+{
+   private static final Logger log = Logger.getLogger(SimpleTransformer.class);
+   
+   public ServerMessage transform(final ServerMessage message)
+   {
+      SimpleString oldProp = (SimpleString)message.getProperty(new SimpleString("wibble"));
+      
+      if (!oldProp.equals(new SimpleString("bing")))
+      {
+         throw new IllegalStateException("Wrong property value!!");
+      }
+      
+      //Change a property
+      message.putStringProperty(new SimpleString("wibble"), new SimpleString("bong"));
+      
+      //Change the body
+      MessagingBuffer buffer = message.getBody();
+      
+      String str = buffer.getString();
+      
+      if (!str.equals("doo be doo be doo be doo"))
+      {
+         throw new IllegalStateException("Wrong body!!");
+      }
+        
+      buffer.flip();
+      
+      buffer.putString("dee be dee be dee be dee");
+      
+      return message;
+   }
+
+}




More information about the jboss-cvs-commits mailing list