[jboss-cvs] JBoss Messaging SVN: r4778 - in branches/Branch_JBMESSAGING-1314: src/main/org/jboss/messaging/core/paging/impl and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 6 19:08:57 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-08-06 19:08:57 -0400 (Wed, 06 Aug 2008)
New Revision: 4778

Added:
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/AbstractPage.java
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/MessagePageImpl.java
   branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/
   branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java
   branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java
Removed:
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java
Modified:
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Page.java
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java
   branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java
   branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
   branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java
Log:
Backup point

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Page.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Page.java	2008-08-06 01:03:49 UTC (rev 4777)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/Page.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -23,18 +23,18 @@
 
 package org.jboss.messaging.core.paging;
 
-import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.journal.EncodingSupport;
 
 /**
  * 
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  */
-public interface Page
+public interface Page<T extends EncodingSupport>
 {
-   void queueMessage(ServerMessage message) throws Exception;
+   void queue(T message) throws Exception;
    
-   ServerMessage[] dequeueMessages() throws Exception;
+   T[] dequeue() throws Exception;
    
    void sync() throws Exception;
    

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java	2008-08-06 01:03:49 UTC (rev 4777)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -22,6 +22,7 @@
 
 package org.jboss.messaging.core.paging;
 
+import org.jboss.messaging.core.journal.EncodingSupport;
 import org.jboss.messaging.core.server.MessagingComponent;
 import org.jboss.messaging.util.SimpleString;
 
@@ -32,7 +33,7 @@
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  *
  */
-public interface PagingManager extends MessagingComponent
+public interface PagingManager<T extends EncodingSupport> extends MessagingComponent
 {
-   public PagingStore getPaging(SimpleString address);
+   public PagingStore<T> getPaging(SimpleString address);
 }

Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java	2008-08-06 01:03:49 UTC (rev 4777)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -23,7 +23,9 @@
 
 package org.jboss.messaging.core.paging;
 
-public interface PagingStore extends Page
+import org.jboss.messaging.core.journal.EncodingSupport;
+
+public interface PagingStore<T extends EncodingSupport> extends Page<T>
 {
    
 }

Copied: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/AbstractPage.java (from rev 4777, branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java)
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/AbstractPage.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/AbstractPage.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -0,0 +1,226 @@
+/*
+ * 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.core.paging.impl;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
+import org.jboss.messaging.core.journal.EncodingSupport;
+import org.jboss.messaging.core.journal.IOCallback;
+import org.jboss.messaging.core.journal.SequentialFile;
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.paging.Page;
+import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.server.impl.ServerMessageImpl;
+import org.jboss.messaging.util.VariableLatch;
+
+/**
+ * 
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public abstract class AbstractPage<T extends EncodingSupport> implements Page<T>
+{
+   
+   // Constants -----------------------------------------------------
+   
+   private static final int SIZE_INTEGER = 4;
+   
+   public static final byte START_BYTE= (byte)'{';
+   public static final byte END_BYTE= (byte)'}';
+   
+   // Attributes ----------------------------------------------------
+   
+   private final SequentialFile file;
+   private final SequentialFileFactory fileFactory;
+   private final PagingCallback callback;
+   private volatile long size;
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   public AbstractPage(final SequentialFileFactory factory, final SequentialFile file) throws Exception
+   {
+      this.file = file;
+      this.size = file.size();
+      this.fileFactory = factory;
+      if (factory.isSupportsCallbacks())
+      {
+         callback = new PagingCallback();
+      }
+      else
+      {
+         callback = null;
+      }
+   }
+   
+   
+   // Public --------------------------------------------------------
+
+   
+   // PagingFile implementation
+   
+   public T[] dequeue() throws Exception
+   {
+      
+      ArrayList<T> messages = new ArrayList<T>();
+
+      ByteBuffer buffer = fileFactory.newBuffer((int)file.size());
+      file.position(0);
+      file.read(buffer);
+      
+      ByteBufferWrapper messageBuffer = new ByteBufferWrapper(buffer);
+      
+      while (buffer.hasRemaining())
+      {
+         final int position = buffer.position();
+         
+         byte byteRead = buffer.get();
+         
+         if (byteRead == START_BYTE)
+         {
+            if (buffer.position() + SIZE_INTEGER < buffer.limit())
+            {
+               int messageSize = buffer.getInt();
+               int oldPos = buffer.position();
+               if (buffer.position() + messageSize < buffer.limit() && buffer.get(oldPos + messageSize) == END_BYTE)
+               {
+                  T msg = instantiateObject();
+                  msg.decode(messageBuffer);
+                  messages.add(msg);
+               }
+               else
+               {
+                  buffer.position(position + 1); 
+               }
+            }
+         }
+         else
+         {
+            buffer.position(position + 1); 
+         }
+      }
+      
+      return messages.toArray(instantiateArray(messages.size()));
+   }
+   
+   public void queue(final T message) throws Exception
+   {
+      ByteBuffer buffer = fileFactory.newBuffer(message.getEncodeSize() + 6);
+      buffer.put(START_BYTE);
+      buffer.putInt(message.getEncodeSize());
+      message.encode(new ByteBufferWrapper(buffer));
+      buffer.put(END_BYTE);
+      buffer.rewind();
+      if (callback != null)
+      {
+         callback.countUp();
+         expandIfNeeded(buffer.limit());
+         file.write(buffer, callback);
+      }
+      else
+      {
+         file.write(buffer, false);
+      }
+      
+   }
+   
+   public void sync() throws Exception
+   {
+      if (callback != null)
+      {
+         callback.waitCompletion();
+      }
+      else
+      {
+         file.sync();
+      }
+   }
+   
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   protected abstract T instantiateObject();
+   
+   protected abstract T[] instantiateArray(int size);
+   
+   // Private -------------------------------------------------------
+   
+   private synchronized void expandIfNeeded(final int bytesToWrite) throws Exception
+   {
+      while (file.position() + bytesToWrite > size)
+      {
+         final int position = file.position();
+         
+         file.fill((int)size, 1024*1024, (byte)0);
+         
+         size = file.size();
+         
+         file.position(position);
+      }
+   }
+   
+   // Inner classes -------------------------------------------------
+
+   private static class PagingCallback implements IOCallback
+   {      
+      private final VariableLatch countLatch = new VariableLatch();
+      
+      private volatile String errorMessage = null;
+      
+      private volatile int errorCode = 0;
+      
+      public void countUp()
+      {
+         countLatch.up();
+      }
+      
+      public void done()
+      {
+         countLatch.down();
+      }
+      
+      public void waitCompletion() throws InterruptedException
+      {
+         countLatch.waitCompletion();
+         
+         if (errorMessage != null)
+         {
+            throw new IllegalStateException("Error on Callback: " + errorCode + " - " + errorMessage);
+         }
+      }
+      
+      public void onError(final int errorCode, final String errorMessage)
+      {
+         this.errorMessage = errorMessage;
+         this.errorCode = errorCode;
+         countLatch.down();
+      }
+      
+   }
+   
+}

Added: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/MessagePageImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/MessagePageImpl.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/MessagePageImpl.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -0,0 +1,121 @@
+/*
+ * 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.core.paging.impl;
+
+import org.jboss.messaging.core.journal.EncodingSupport;
+import org.jboss.messaging.core.journal.SequentialFile;
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.remoting.MessagingBuffer;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.server.impl.ServerMessageImpl;
+
+/**
+ * 
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public class MessagePageImpl extends AbstractPage<MessagePageImpl.MessageContainer>
+{
+
+   
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+
+   public MessagePageImpl(final SequentialFileFactory factory, final SequentialFile file) throws Exception
+   {
+      super(factory, file);
+   }
+
+   
+   // Public --------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+   
+   @Override
+   protected MessagePageImpl.MessageContainer[] instantiateArray(final int size)
+   {
+      return new MessagePageImpl.MessageContainer[size];
+   }
+
+   @Override
+   protected MessageContainer instantiateObject()
+   {
+      return new MessagePageImpl.MessageContainer();
+   }
+   // Protected -----------------------------------------------------
+   
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+   
+   /**
+    * ServerMessageImpl doesn't store the ID by itself (as the RecordID is used on the Journal).
+    * So, when paging we need to store the ID somehow.
+    */
+   public static class MessageContainer implements EncodingSupport
+   {
+
+      final ServerMessage containerMsg;
+      
+      public MessageContainer(ServerMessage containerMsg)
+      {
+         super();
+         this.containerMsg = containerMsg;
+      }
+
+      public MessageContainer()
+      {
+         super();
+         this.containerMsg = new ServerMessageImpl();
+      }
+
+      public void decode(final MessagingBuffer buffer)
+      {
+         containerMsg.setMessageID(buffer.getLong());
+         containerMsg.decode(buffer);
+      }
+
+      public void encode(MessagingBuffer buffer)
+      {
+         buffer.putLong(containerMsg.getMessageID());
+         containerMsg.encode(buffer);
+      }
+
+      public int getEncodeSize()
+      {
+         return 8 + containerMsg.getEncodeSize();
+      }
+      
+      public ServerMessage getMessage()
+      {
+         return containerMsg;
+      }
+   }
+   
+}

Deleted: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java	2008-08-06 01:03:49 UTC (rev 4777)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -1,199 +0,0 @@
-/*
- * 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.core.paging.impl;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-
-import org.jboss.messaging.core.journal.IOCallback;
-import org.jboss.messaging.core.journal.SequentialFile;
-import org.jboss.messaging.core.journal.SequentialFileFactory;
-import org.jboss.messaging.core.paging.Page;
-import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
-import org.jboss.messaging.core.server.ServerMessage;
-import org.jboss.messaging.core.server.impl.ServerMessageImpl;
-import org.jboss.messaging.util.VariableLatch;
-
-/**
- * 
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public class PageImpl implements Page
-{
-   
-   // Constants -----------------------------------------------------
-   
-   private static final int SIZE_INTEGER = 4;
-   
-   public static final byte START_BYTE= (byte)'{';
-   public static final byte END_BYTE= (byte)'}';
-   
-   // Attributes ----------------------------------------------------
-   
-   private final SequentialFile file;
-   private final SequentialFileFactory fileFactory;
-   private final PagingCallback callback;
-   
-   // Static --------------------------------------------------------
-   
-   // Constructors --------------------------------------------------
-   
-   public PageImpl(SequentialFileFactory factory, SequentialFile file)
-   {
-      this.file = file;
-      this.fileFactory = factory;
-      if (factory.isSupportsCallbacks())
-      {
-         callback = new PagingCallback();
-      }
-      else
-      {
-         callback = null;
-      }
-   }
-   
-   
-   // Public --------------------------------------------------------
-
-   
-   // PagingFile implementation
-   
-   public ServerMessage[] dequeueMessages() throws Exception
-   {
-      
-      ArrayList<ServerMessage> messages = new ArrayList<ServerMessage>();
-
-      ByteBuffer buffer = fileFactory.newBuffer((int)file.size());
-      
-      while (buffer.hasRemaining())
-      {
-         final int position = buffer.position();
-         
-         ByteBufferWrapper messageBuffer = new ByteBufferWrapper(buffer);
-         
-         if (buffer.get() == START_BYTE)
-         {
-            if (buffer.position() + SIZE_INTEGER < buffer.limit())
-            {
-               int messageSize = buffer.getInt();
-               int oldPos = buffer.position();
-               if (buffer.position() + messageSize < buffer.limit() && buffer.get(oldPos + messageSize) == END_BYTE)
-               {
-                  ServerMessage msg = new ServerMessageImpl();
-                  msg.decode(messageBuffer);
-                  messages.add(msg);
-               }
-               else
-               {
-                  buffer.position(position + 1); 
-               }
-            }
-         }
-         else
-         {
-            buffer.position(position + 1); 
-         }
-      }
-      
-      return messages.toArray(new ServerMessage[messages.size()]);
-   }
-   
-   public void queueMessage(ServerMessage message) throws Exception
-   {
-      ByteBuffer buffer = fileFactory.newBuffer(message.getEncodeSize() + 6);
-      buffer.put(START_BYTE);
-      buffer.putInt(message.getEncodeSize());
-      message.encode(new ByteBufferWrapper(buffer));
-      buffer.put(END_BYTE);
-      if (callback != null)
-      {
-         callback.countUp();
-         file.write(buffer, callback);
-      }
-      else
-      {
-         file.write(buffer, false);
-      }
-      
-   }
-   
-   public void sync() throws Exception
-   {
-      if (callback != null)
-      {
-         callback.waitCompletion();
-      }
-      else
-      {
-         file.sync();
-      }
-   }
-   
-   // Package protected ---------------------------------------------
-   
-   // Protected -----------------------------------------------------
-   
-   // Private -------------------------------------------------------
-   
-   // Inner classes -------------------------------------------------
-
-   private static class PagingCallback implements IOCallback
-   {      
-      private final VariableLatch countLatch = new VariableLatch();
-      
-      private volatile String errorMessage = null;
-      
-      private volatile int errorCode = 0;
-      
-      public void countUp()
-      {
-         countLatch.up();
-      }
-      
-      public void done()
-      {
-         countLatch.down();
-      }
-      
-      public void waitCompletion() throws InterruptedException
-      {
-         countLatch.waitCompletion();
-         
-         if (errorMessage != null)
-         {
-            throw new IllegalStateException("Error on Callback: " + errorCode + " - " + errorMessage);
-         }
-      }
-      
-      public void onError(final int errorCode, final String errorMessage)
-      {
-         this.errorMessage = errorMessage;
-         this.errorCode = errorCode;
-         countLatch.down();
-      }
-      
-   }
-   
-}

Added: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -0,0 +1,88 @@
+/*
+ * 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.paging;
+
+import java.io.File;
+
+import org.jboss.messaging.core.asyncio.impl.AsynchronousFileImpl;
+import org.jboss.messaging.core.journal.impl.AIOSequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
+import org.jboss.messaging.tests.unit.core.paging.impl.PageImplTestBase;
+
+public class PagingIntegrationTest extends PageImplTestBase
+{
+   
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+
+   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") +  "/journal-test";
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   // Public --------------------------------------------------------
+   
+   public void testPageWithAIO() throws Exception
+   {
+      if (!AsynchronousFileImpl.isLoaded())
+      {
+         fail(String.format("libAIO is not loaded on %s %s %s", 
+               System.getProperty("os.name"), 
+               System.getProperty("os.arch"), 
+               System.getProperty("os.version")));
+      }
+      testAdd(new AIOSequentialFileFactory(journalDir));
+   }
+   
+   public void testPageWithNIO() throws Exception
+   {
+      testAdd(new NIOSequentialFileFactory(journalDir));
+   }
+   
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      File fileJournalDir = new File(journalDir);
+      deleteDirectory(fileJournalDir);
+      fileJournalDir.mkdirs();
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      deleteDirectory(new File(journalDir));
+   }
+
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+   
+}

Modified: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java	2008-08-06 01:03:49 UTC (rev 4777)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -311,6 +311,7 @@
       public synchronized void open(int currentMaxIO) throws Exception
       {
          open = true;
+         checkAndResize(0);
       }
 
       public void fill(final int pos, final int size, final byte fillCharacter) throws Exception

Modified: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java	2008-08-06 01:03:49 UTC (rev 4777)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -23,25 +23,15 @@
 
 package org.jboss.messaging.tests.unit.core.paging.impl;
 
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-
-import org.jboss.messaging.core.journal.SequentialFile;
-import org.jboss.messaging.core.paging.impl.PageImpl;
-import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
-import org.jboss.messaging.core.server.ServerMessage;
-import org.jboss.messaging.core.server.impl.ServerMessageImpl;
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
-import org.jboss.messaging.tests.util.RandomUtil;
-import org.jboss.messaging.tests.util.UnitTestCase;
-import org.jboss.messaging.util.SimpleString;
 
+
 /**
  * 
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  */
-public class PageImplTest extends UnitTestCase
+public class PageImplTest extends PageImplTestBase
 {
    
    // Constants -----------------------------------------------------
@@ -54,49 +44,21 @@
    
    // Public --------------------------------------------------------
    
+   public void testPageFakeWithCallbacks() throws Exception
+   {
+      testAdd(new FakeSequentialFileFactory(512, true));
+   }
    
-   /** Validate if everything we add is recovered */
-   public void testSimpleAdd() throws Exception
+   public void testPageFakeWithoutCallbacks() throws Exception
    {
-      FakeSequentialFileFactory fakeFactory = new FakeSequentialFileFactory(512, true);
-      
-      SequentialFile file = fakeFactory.createSequentialFile("testPage.page", 1);
-      file.open();
-      PageImpl impl = new PageImpl(fakeFactory, file);
-
-      ArrayList<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
-      
-      SimpleString simpleDestination = new SimpleString("Test");
-      
-      for (int i = 0; i < 100; i++)
-      {
-         ByteBuffer buffer = ByteBuffer.allocate(10);
-         
-         for (int j = 0; j < buffer.limit(); j++)
-         {
-            buffer.put(RandomUtil.randomByte());
-         }
-         
-         buffers.add(buffer);
-
-         ServerMessage msg = new ServerMessageImpl((byte)1, true, 0,
-               System.currentTimeMillis(), (byte)0, new ByteBufferWrapper(buffer));
-         
-         msg.setMessageID((long)i);
-         
-         msg.setDestination(simpleDestination);
-         
-         impl.queueMessage(msg);
-      }
-      
-      
-
+      testAdd(new FakeSequentialFileFactory(512, false));
    }
    
    // Package protected ---------------------------------------------
    
    // Protected -----------------------------------------------------
    
+   
    // Private -------------------------------------------------------
    
    // Inner classes -------------------------------------------------

Added: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java	2008-08-06 23:08:57 UTC (rev 4778)
@@ -0,0 +1,114 @@
+/*
+ * 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.paging.impl;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
+import org.jboss.messaging.core.journal.SequentialFile;
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.paging.impl.MessagePageImpl;
+import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.server.impl.ServerMessageImpl;
+import org.jboss.messaging.tests.util.RandomUtil;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.util.SimpleString;
+
+public abstract class PageImplTestBase extends UnitTestCase
+{
+   
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   // Public --------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   /** Validate if everything we add is recovered */
+   protected void testAdd(SequentialFileFactory fakeFactory) throws Exception
+   {
+      
+      SequentialFile file = fakeFactory.createSequentialFile("testPage.page", 1);
+      file.open();
+      MessagePageImpl impl = new MessagePageImpl(fakeFactory, file);
+
+      ArrayList<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
+      
+      SimpleString simpleDestination = new SimpleString("Test");
+      
+      for (int i = 0; i < 100; i++)
+      {
+         ByteBuffer buffer = ByteBuffer.allocate(10);
+         
+         for (int j = 0; j < buffer.limit(); j++)
+         {
+            buffer.put(RandomUtil.randomByte());
+         }
+         
+         buffers.add(buffer);
+
+         ServerMessage msg = new ServerMessageImpl((byte)1, true, 0,
+               System.currentTimeMillis(), (byte)0, new ByteBufferWrapper(buffer));
+         
+         msg.setMessageID((long)i);
+         
+         msg.setDestination(simpleDestination);
+         
+         impl.queue(new MessagePageImpl.MessageContainer(msg));
+      }
+      
+      impl.sync();
+      file.close();
+      
+      file = fakeFactory.createSequentialFile("testPage.page", 1);
+      file.open();
+      impl = new MessagePageImpl(fakeFactory, file);
+      
+      MessagePageImpl.MessageContainer msgs[] = impl.dequeue();
+      
+      for (int i = 0; i < msgs.length; i++)
+      {
+         assertEquals((long)i, msgs[i].getMessage().getMessageID());
+         
+         assertEqualsByteArrays(buffers.get(i).array(), msgs[i].getMessage().getBody().array());
+      }
+      
+      assertEquals(100, msgs.length);
+      
+   }
+
+ 
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+   
+}




More information about the jboss-cvs-commits mailing list