[jboss-cvs] JBoss Messaging SVN: r5170 - in branches/Branch_Chunk_Clebert: src/main/org/jboss/messaging/core/remoting/impl/invm and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 22 16:18:52 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-10-22 16:18:51 -0400 (Wed, 22 Oct 2008)
New Revision: 5170

Added:
   branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/
   branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnector.java
   branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnectorFactory.java
Modified:
   branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
   branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java
   branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java
   branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/remoting/DestroyConsumerTest.java
   branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java
   branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
Log:
Test on failures (deleting files in case of failure)

Modified: branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
===================================================================
--- branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java	2008-10-22 15:43:15 UTC (rev 5169)
+++ branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -733,7 +733,6 @@
          {
             try
             {
-               System.out.println("Deleting file " + file);
                file.delete();
             }
             catch (Exception e)

Modified: branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java
===================================================================
--- branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java	2008-10-22 15:43:15 UTC (rev 5169)
+++ branches/Branch_Chunk_Clebert/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -94,13 +94,12 @@
 
    public Connection createConnection()
    {
-      Connection conn = new InVMConnection(acceptor.getHandler(), new Listener());
+      Connection conn = internalCreateConnection(acceptor.getHandler(), new Listener());
       
       acceptor.connect((String)conn.getID(), handler, this);
            
       return conn;
    }
-
    public synchronized void start()
    {          
       started = true;
@@ -125,7 +124,16 @@
          conn.close();
       }
    }
+
+
+   // This may be an injection point for mocks on tests
+   protected Connection internalCreateConnection(final BufferHandler handler, final ConnectionLifeCycleListener listener)
+   {
+      return new InVMConnection(handler, listener);
+   }
+
    
+   
    private class Listener implements ConnectionLifeCycleListener
    {
       public void connectionCreated(final Connection connection)

Modified: branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java
===================================================================
--- branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java	2008-10-22 15:43:15 UTC (rev 5169)
+++ branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -29,6 +29,7 @@
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import junit.framework.AssertionFailedError;
 
@@ -38,15 +39,21 @@
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.ClientSessionFactory;
 import org.jboss.messaging.core.client.FileClientMessage;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionImpl;
 import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
-import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
+import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
+import org.jboss.messaging.core.remoting.impl.RemotingServiceImpl;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.core.server.ServerMessage;
 import org.jboss.messaging.core.server.impl.ServerMessageImpl;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.tests.integration.chunkmessage.mock.MockConnector;
+import org.jboss.messaging.tests.integration.chunkmessage.mock.MockConnectorFactory;
 import org.jboss.messaging.tests.util.ServiceTestBase;
 import org.jboss.messaging.util.DataConstants;
 import org.jboss.messaging.util.SimpleString;
@@ -76,6 +83,112 @@
 
    // Public --------------------------------------------------------
 
+   public void testFailureOnSendingFile() throws Exception
+   {
+      clearData();
+
+      Configuration config = createDefaultConfig();
+
+      config.setPagingMaxGlobalSizeBytes(20 * 1024);
+      config.setPagingDefaultSize(10 * 1024);
+
+      messagingService = createService(true, config, new HashMap<String, QueueSettings>());
+
+      messagingService.start();
+
+      final int numberOfIntegersBigMessage = 15000;
+      
+      ClientSession session = null;
+      
+      class LocalCallback implements MockConnector.MockCallback
+      {
+         
+         AtomicInteger counter = new AtomicInteger(0);
+         
+         ClientSession session;
+
+         public void onWrite(MessagingBuffer buffer)
+         {
+            System.out.println("onWrite");
+            if (counter.incrementAndGet() == 10)
+            {
+               RemotingConnectionImpl conn = (RemotingConnectionImpl)((ClientSessionImpl)session).getConnection();
+               RemotingServiceImpl remotingServiceImpl = (RemotingServiceImpl)messagingService.getServer().getRemotingService();
+               remotingServiceImpl.connectionException(conn.getID(), new MessagingException(MessagingException.NOT_CONNECTED, "blah!"));
+               conn.fail(new MessagingException (MessagingException.NOT_CONNECTED, "blah"));
+               throw new IllegalStateException ("blah");
+            }
+         }
+         
+      }
+      
+      LocalCallback callback = new LocalCallback();
+      
+      try
+      {
+         HashMap<String, Object> parameters = new HashMap<String, Object>();
+         parameters.put("callback", callback);
+         
+         TransportConfiguration transport = new TransportConfiguration(MockConnectorFactory.class.getCanonicalName(), parameters);
+         
+         ClientSessionFactory mockFactory = new ClientSessionFactoryImpl(transport);
+         
+         mockFactory.setBlockOnNonPersistentSend(false);
+         mockFactory.setBlockOnPersistentSend(false);
+         mockFactory.setBlockOnAcknowledge(false);
+
+         session = mockFactory.createSession(false, true, true, true);
+         
+         callback.session = session;
+
+         session.createQueue(ADDRESS, ADDRESS, null, true, false);
+         
+         ClientProducer producer = session.createProducer(ADDRESS);
+         
+         FileClientMessage clientLarge = createLargeClientMessage(session, numberOfIntegersBigMessage);
+         
+         try
+         {
+            producer.send(clientLarge);
+            fail ("Exception was expected!");
+         }
+         catch (Exception e)
+         {
+         }
+         
+         File largeMessagesFileDir = new File(largeMessagesDir);
+
+         // Deleting the file is async... we keep looking for a period of the time until the file is really gone
+         for (int i = 0; i < 100; i++)
+         {
+            if (largeMessagesFileDir.listFiles().length > 0)
+            {
+               Thread.sleep(1);
+            }
+            else
+            {
+               break;
+            }
+         }
+         
+         assertEquals(0, largeMessagesFileDir.listFiles().length);
+         
+       }
+      finally
+      {
+         try
+         {
+             messagingService.stop();
+         }
+         catch (Exception ignored)
+         {
+            ignored.printStackTrace();
+         }
+      }
+
+
+   }
+
    public void testMessageChunkNullPersistence() throws Exception
    {
       testInternal(false, false, 5000, false);
@@ -207,7 +320,7 @@
       config.setPagingMaxGlobalSizeBytes(20 * 1024);
       config.setPagingDefaultSize(10 * 1024);
 
-      messagingService = createService(realFiles, false, config, new HashMap<String, QueueSettings>());
+      messagingService = createService(realFiles, config, new HashMap<String, QueueSettings>());
 
       messagingService.start();
 
@@ -271,14 +384,7 @@
          {
             messagingService.stop();
 
-            InVMRegistry.instance.clear();
-
-            config = createDefaultConfig();
-
-            config.setPagingMaxGlobalSizeBytes(20 * 1024);
-            config.setPagingDefaultSize(10 * 1024);
-
-            messagingService = createService(true, false, config, new HashMap<String, QueueSettings>());
+            messagingService = createService(true, config, new HashMap<String, QueueSettings>());
             messagingService.start();
 
             sf = createInVMFactory();
@@ -344,7 +450,7 @@
       }
 
    }
-
+   
    private FileClientMessage createLargeClientMessage(ClientSession session, int numberOfIntegers) throws Exception
    {
 

Added: branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnector.java
===================================================================
--- branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnector.java	                        (rev 0)
+++ branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnector.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -0,0 +1,113 @@
+/*
+ * 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.chunkmessage.mock;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnector;
+import org.jboss.messaging.core.remoting.spi.BufferHandler;
+import org.jboss.messaging.core.remoting.spi.Connection;
+import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+
+/**
+ * A MockConnector
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * 
+ * Created Oct 22, 2008 11:23:18 AM
+ *
+ *
+ */
+public class MockConnector extends InVMConnector
+{
+   private final MockCallback callback;
+
+   /**
+    * @param configuration
+    * @param handler
+    * @param listener
+    */
+   public MockConnector(final Map<String, Object> configuration,
+                        final BufferHandler handler,
+                        final ConnectionLifeCycleListener listener)
+   {
+      super(configuration, handler, listener);
+      callback = (MockCallback)configuration.get("callback");
+   }
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected Connection internalCreateConnection(final BufferHandler handler, final ConnectionLifeCycleListener listener)
+   {
+      return new MockConnection(handler, listener);
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+   public static interface MockCallback
+   {
+      void onWrite(final MessagingBuffer buffer);
+   }
+   
+   class MockConnection extends InVMConnection
+   {
+      
+      /**
+       * @param handler
+       * @param listener
+       */
+      public MockConnection(BufferHandler handler, ConnectionLifeCycleListener listener)
+      {
+         super(handler, listener);
+      }
+      
+      public void write(final MessagingBuffer buffer)
+      {
+         System.out.println("Writing");
+         if (callback != null)
+         {
+            callback.onWrite(buffer);
+         }
+         
+         super.write(buffer);
+      }
+   }
+}

Added: branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnectorFactory.java
===================================================================
--- branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnectorFactory.java	                        (rev 0)
+++ branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/chunkmessage/mock/MockConnectorFactory.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -0,0 +1,71 @@
+/*
+ * 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.chunkmessage.mock;
+
+import java.util.Map;
+
+import org.jboss.messaging.core.remoting.spi.BufferHandler;
+import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
+import org.jboss.messaging.core.remoting.spi.Connector;
+import org.jboss.messaging.core.remoting.spi.ConnectorFactory;
+
+/**
+ * A MockConnectorFactory
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * 
+ * Created Oct 22, 2008 12:04:11 PM
+ *
+ *
+ */
+public class MockConnectorFactory implements ConnectorFactory
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.ConnectorFactory#createConnector(java.util.Map, org.jboss.messaging.core.remoting.spi.BufferHandler, org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener)
+    */
+   public Connector createConnector(Map<String, Object> configuration,
+                                    BufferHandler handler,
+                                    ConnectionLifeCycleListener listener)
+   {
+      return new MockConnector(configuration, handler, listener);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/remoting/DestroyConsumerTest.java
===================================================================
--- branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/remoting/DestroyConsumerTest.java	2008-10-22 15:43:15 UTC (rev 5169)
+++ branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/integration/remoting/DestroyConsumerTest.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -30,6 +30,7 @@
 import org.jboss.messaging.core.client.ClientSessionFactory;
 import org.jboss.messaging.core.client.impl.ClientSessionImpl;
 import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
 import org.jboss.messaging.core.server.MessagingService;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.jboss.messaging.tests.util.ServiceTestBase;
@@ -50,7 +51,7 @@
    
    public void testDestroyConsumer() throws Exception
    {
-      MessagingService service = createService(false, false, createDefaultConfig(), new HashMap<String, QueueSettings>());
+      MessagingService service = createService(false, createDefaultConfig(), new HashMap<String, QueueSettings>());
       service.start();
       
       try
@@ -83,6 +84,7 @@
       }
       finally
       {
+         InVMRegistry.instance.clear();
          try
          {
             service.stop();

Modified: branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java
===================================================================
--- branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java	2008-10-22 15:43:15 UTC (rev 5169)
+++ branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/stress/paging/MultipleDestinationPagingTest.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -77,7 +77,7 @@
          settings.put("page-adr", setting);
       }
 
-      service = createService(true, false, config, settings);
+      service = createService(true, config, settings);
       service.start();
 
       ClientSessionFactory factory = createInVMFactory();

Modified: branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
===================================================================
--- branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java	2008-10-22 15:43:15 UTC (rev 5169)
+++ branches/Branch_Chunk_Clebert/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java	2008-10-22 20:18:51 UTC (rev 5170)
@@ -72,9 +72,9 @@
    protected String pageDir = System.getProperty("java.io.tmpdir", "/tmp") + "/unit-test/page";
 
    protected String largeMessagesDir = System.getProperty("java.io.tmpdir", "/tmp") + "/unit-test/large-msg";
-   
+
    protected String clientLargeMessagesDir = System.getProperty("java.io.tmpdir", "/tmp") + "/unit-test/client-large-msg";
-   
+
    protected String temporaryDir = System.getProperty("java.io.tmpdir", "/tmp") + "/unit-test/temporary";
 
    protected MessagingService messagingService;
@@ -89,7 +89,6 @@
 
    // Protected -----------------------------------------------------
 
-
    protected void clearData()
    {
       deleteAndCreateDir(journalDir);
@@ -99,28 +98,19 @@
       deleteAndCreateDir(clientLargeMessagesDir);
       deleteAndCreateDir(temporaryDir);
    }
-   
+
    protected void deleteAndCreateDir(String directory)
    {
       File file = new File(directory);
       deleteDirectory(file);
       file.mkdirs();
    }
-   
 
    protected MessagingService createService(final boolean realFiles,
-                                            final boolean netty,
                                             final Configuration configuration,
                                             final Map<String, QueueSettings> settings)
    {
-      TransportConfiguration transportConfig = new TransportConfiguration(INVM_ACCEPTOR_FACTORY);
-      configuration.getAcceptorConfigurations().add(transportConfig);
 
-      if (netty)
-      {
-         configuration.getAcceptorConfigurations().add(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY));
-      }
-
       MessagingService service;
 
       if (realFiles)
@@ -145,30 +135,62 @@
 
    protected MessagingService createService(final boolean realFiles)
    {
-      return createService(realFiles, false, createDefaultConfig(), new HashMap<String, QueueSettings>());
+      return createService(realFiles, createDefaultConfig(), new HashMap<String, QueueSettings>());
    }
 
    protected Configuration createDefaultConfig()
    {
+      return createDefaultConfig(false);
+   }
+
+   
+   protected Configuration createDefaultConfig(final boolean netty)
+   {
+      if (netty)
+      {
+         return createDefaultConfig(INVM_ACCEPTOR_FACTORY, NETTY_ACCEPTOR_FACTORY);
+      }
+      else
+      {
+         return createDefaultConfig(INVM_ACCEPTOR_FACTORY);
+      }
+      
+   }
+
+   protected Configuration createDefaultConfig(final String... acceptors)
+   {
       Configuration configuration = new ConfigurationImpl();
       configuration.setSecurityEnabled(false);
       configuration.setJournalMinFiles(2);
-      configuration.setJournalFileSize(100*1024);
+      configuration.setJournalFileSize(100 * 1024);
       configuration.setPagingDirectory(pageDir);
 
+      configuration.getAcceptorConfigurations().clear();
+
+      for (String acceptor : acceptors)
+      {
+         TransportConfiguration transportConfig = new TransportConfiguration(acceptor);
+         configuration.getAcceptorConfigurations().add(transportConfig);
+      }
+
       return configuration;
    }
 
    protected ClientSessionFactory createInVMFactory()
    {
-      return new ClientSessionFactoryImpl(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
+      return createFactory(INVM_CONNECTOR_FACTORY);
    }
 
    protected ClientSessionFactory createNettyFactory()
    {
-      return new ClientSessionFactoryImpl(new TransportConfiguration(NETTY_CONNECTOR_FACTORY));
+      return createFactory(NETTY_CONNECTOR_FACTORY);
    }
 
+   protected ClientSessionFactory createFactory(final String connectorClass)
+   {
+      return new ClientSessionFactoryImpl(new TransportConfiguration(connectorClass));
+   }
+
    protected ClientMessage createTextMessage(final ClientSession session, final String s)
    {
       return createTextMessage(session, s, true);




More information about the jboss-cvs-commits mailing list