[jboss-cvs] JBoss Messaging SVN: r4972 - in trunk: src/main/org/jboss/messaging/core/asyncio/impl and 11 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 17 15:49:58 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-09-17 15:49:57 -0400 (Wed, 17 Sep 2008)
New Revision: 4972

Modified:
   trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java
   trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java
   trunk/src/main/org/jboss/messaging/core/asyncio/BufferCallback.java
   trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java
   trunk/src/main/org/jboss/messaging/core/journal/BufferCallback.java
   trunk/src/main/org/jboss/messaging/core/journal/EncodingSupport.java
   trunk/src/main/org/jboss/messaging/core/journal/IOCallback.java
   trunk/src/main/org/jboss/messaging/core/journal/Journal.java
   trunk/src/main/org/jboss/messaging/core/journal/LoadManager.java
   trunk/src/main/org/jboss/messaging/core/journal/PreparedTransactionInfo.java
   trunk/src/main/org/jboss/messaging/core/journal/RecordInfo.java
   trunk/src/main/org/jboss/messaging/core/journal/SequentialFile.java
   trunk/src/main/org/jboss/messaging/core/journal/SequentialFileFactory.java
   trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFileFactory.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/AbstractSequentialFactory.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFile.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFileImpl.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFileFactory.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/Reclaimer.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/TransactionHolder.java
   trunk/src/main/org/jboss/messaging/core/paging/LastPageRecord.java
   trunk/src/main/org/jboss/messaging/core/paging/Page.java
   trunk/src/main/org/jboss/messaging/core/paging/PageMessage.java
   trunk/src/main/org/jboss/messaging/core/paging/PageTransactionInfo.java
   trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java
   trunk/src/main/org/jboss/messaging/core/paging/PagingStore.java
   trunk/src/main/org/jboss/messaging/core/paging/PagingStoreFactory.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/LastPageRecordImpl.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/PageMessageImpl.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/PageTransactionInfoImpl.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerFactoryNIO.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
   trunk/src/main/org/jboss/messaging/core/paging/impl/TestSupportPageStore.java
   trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/AIOTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/journal/AIOSequentialFileFactoryTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/journal/NIOSequentialFileFactoryTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealAIOJournalImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealNIOJournalImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AIOSequentialFileTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/CleanBufferTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/EasyMockJournalTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeJournalImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeSequentialFileFactoryTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FileFactoryTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalAsyncTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/ReclaimerTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeCallback.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/SimpleEncoding.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java
Log:
Some auto-cleanup on the classes I know (or think) nobody else is working on now

Modified: trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.asyncio;
 
@@ -29,9 +29,9 @@
  */
 public interface AIOCallback
 {
-    /** Leave this method as soon as possible, or you would be blocking the whole notification thread */
-    void done();
+   /** Leave this method as soon as possible, or you would be blocking the whole notification thread */
+   void done();
 
-    /** Observation: The whole file will be probably failing if this happens. Like, if you delete the file, you will start to get errors for these operations*/
-    void onError(int errorCode, String errorMessage);
+   /** Observation: The whole file will be probably failing if this happens. Like, if you delete the file, you will start to get errors for these operations*/
+   void onError(int errorCode, String errorMessage);
 }

Modified: trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.asyncio;
 
@@ -30,34 +30,34 @@
  *
  */
 public interface AsynchronousFile
-{	
-	void close() throws Exception;
-	
-	/**
-	 * 
-	 * Note: If you are using a native Linux implementation, maxIO can't be higher than what's defined on /proc/sys/fs/aio-max-nr, or you would get an error 
-	 * @param fileName
-	 * @param maxIO The number of max concurrent asynchrnous IO operations. It has to be balanced between the size of your writes and the capacity of your disk.
-	 */
-	void open(String fileName, int maxIO);
-	
-	/** 
-	 * Warning: This function will perform a synchronous IO, probably translating to a fstat call
-	 * */
-	long size();
-	
-	void write(long position, long size, ByteBuffer directByteBuffer, AIOCallback aioPackage);
-	
-	void read(long position, long size, ByteBuffer directByteBuffer,  AIOCallback aioPackage);
-	
-	void fill(long position, int blocks, long size, byte fillChar);
-	
-	ByteBuffer newBuffer(int size);
-	
-	void setBufferCallback(BufferCallback callback);
-	
-	int getBlockSize();
-	
-	String getFileName();
-	
+{
+   void close() throws Exception;
+
+   /**
+    * 
+    * Note: If you are using a native Linux implementation, maxIO can't be higher than what's defined on /proc/sys/fs/aio-max-nr, or you would get an error 
+    * @param fileName
+    * @param maxIO The number of max concurrent asynchrnous IO operations. It has to be balanced between the size of your writes and the capacity of your disk.
+    */
+   void open(String fileName, int maxIO);
+
+   /** 
+    * Warning: This function will perform a synchronous IO, probably translating to a fstat call
+    * */
+   long size();
+
+   void write(long position, long size, ByteBuffer directByteBuffer, AIOCallback aioPackage);
+
+   void read(long position, long size, ByteBuffer directByteBuffer, AIOCallback aioPackage);
+
+   void fill(long position, int blocks, long size, byte fillChar);
+
+   ByteBuffer newBuffer(int size);
+
+   void setBufferCallback(BufferCallback callback);
+
+   int getBlockSize();
+
+   String getFileName();
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/asyncio/BufferCallback.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/BufferCallback.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/BufferCallback.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.asyncio;
 
 import java.nio.ByteBuffer;

Modified: trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.asyncio.impl;
 
@@ -34,7 +34,6 @@
 import org.jboss.messaging.core.asyncio.BufferCallback;
 import org.jboss.messaging.core.logging.Logger;
 
-
 /**
  * 
  * AsynchronousFile implementation
@@ -45,29 +44,29 @@
  */
 public class AsynchronousFileImpl implements AsynchronousFile
 {
-   // Static 
+   // Static
    // -------------------------------------------------------------------------------
-   
+
    private static final Logger log = Logger.getLogger(AsynchronousFileImpl.class);
-   
+
    private static final AtomicInteger totalMaxIO = new AtomicInteger(0);
-   
+
    private static boolean loaded = false;
-   
+
    private static int EXPECTED_NATIVE_VERSION = 14;
-      
-   static void addMax(int io)
+
+   static void addMax(final int io)
    {
       totalMaxIO.addAndGet(io);
    }
-   
+
    /** For test purposes */
    public static int getTotalMaxIO()
    {
       return totalMaxIO.get();
    }
-   
-   private static boolean loadLibrary(final String name) 
+
+   private static boolean loadLibrary(final String name)
    {
       try
       {
@@ -88,14 +87,14 @@
          log.trace(name + " -> error loading the native library", e);
          return false;
       }
-      
+
    }
-   
+
    static
    {
-      String libraries[] = new String[] {"JBMLibAIO", "JBMLibAIO32", "JBMLibAIO64"};
-            
-      for (String library: libraries)
+      String libraries[] = new String[] { "JBMLibAIO", "JBMLibAIO32", "JBMLibAIO64" };
+
+      for (String library : libraries)
       {
          if (loadLibrary(library))
          {
@@ -107,275 +106,292 @@
             log.debug("Library " + library + " not found!");
          }
       }
-      
+
       if (!loaded)
       {
          log.debug("Couldn't locate LibAIO Wrapper");
       }
    }
-   
+
    public static boolean isLoaded()
    {
       return loaded;
    }
-   
+
    // Attributes
    // ---------------------------------------------------------------------------------
-		
-	private boolean opened = false;
-	private String fileName;
-	private volatile Thread poller;	
-	private int maxIO;	
-	private Lock writeLock = new ReentrantReadWriteLock().writeLock();
-   private Semaphore writeSemaphore;   
+
+   private boolean opened = false;
+
+   private String fileName;
+
+   private volatile Thread poller;
+
+   private int maxIO;
+
+   private final Lock writeLock = new ReentrantReadWriteLock().writeLock();
+
+   private Semaphore writeSemaphore;
+
    private BufferCallback bufferCallback;
-	
-	/**
-	 *  Warning: Beware of the C++ pointer! It will bite you! :-)
-	 */ 
-	private long handler;
-	
-	
-	
-	// AsynchronousFile implementation
-	// ------------------------------------------------------------------------------------
-			
-	public void open(final String fileName, final int maxIO)
-	{
+
+   /**
+    *  Warning: Beware of the C++ pointer! It will bite you! :-)
+    */
+   private long handler;
+
+   // AsynchronousFile implementation
+   // ------------------------------------------------------------------------------------
+
+   public void open(final String fileName, final int maxIO)
+   {
       writeLock.lock();
 
-		try
-		{
+      try
+      {
          if (opened)
          {
             throw new IllegalStateException("AsynchronousFile is already opened");
          }
 
          this.maxIO = maxIO;
- 			writeSemaphore = new Semaphore(this.maxIO);
-			
-			opened = true;
-			this.fileName=fileName;
-			handler = init (fileName, this.maxIO, log);
-			addMax(this.maxIO);
-		}
-		finally
-		{
-			writeLock.unlock();
-		}
-	}
-			
-	public void close() throws Exception
-	{
-		checkOpened();
-		
+         writeSemaphore = new Semaphore(this.maxIO);
+
+         opened = true;
+         this.fileName = fileName;
+         handler = init(fileName, this.maxIO, log);
+         addMax(this.maxIO);
+      }
+      finally
+      {
+         writeLock.unlock();
+      }
+   }
+
+   public void close() throws Exception
+   {
+      checkOpened();
+
       writeLock.lock();
 
       try
-		{
-	      
-	      while (!writeSemaphore.tryAcquire(maxIO, 60, TimeUnit.SECONDS))
-	      {
-	         log.warn("Couldn't acquire lock after 60 seconds on AIO", new Exception ("Warning: Couldn't acquire lock after 60 seconds on AIO"));
-	      }
-	      writeSemaphore = null;
-	      if (poller != null)
-	      {
-	         Thread currentPoller = poller;
-   	      stopPoller(handler);
-   	      // We need to make sure we won't call close until Poller is completely done, or we might get beautiful GPFs
-   	      currentPoller.join();
-	      }
+      {
 
-	      closeInternal(handler);
-			addMax(maxIO * -1);
-			opened = false;
-			handler = 0;
-		}
-		finally
-		{
-			writeLock.unlock();
-		}
-	}
-		
-	public void write(final long position, final long size, final ByteBuffer directByteBuffer, final AIOCallback aioPackage)
-	{
-		checkOpened();
-		if (poller == null)
-		{
-		   startPoller();
-		}
+         while (!writeSemaphore.tryAcquire(maxIO, 60, TimeUnit.SECONDS))
+         {
+            log.warn("Couldn't acquire lock after 60 seconds on AIO",
+                     new Exception("Warning: Couldn't acquire lock after 60 seconds on AIO"));
+         }
+         writeSemaphore = null;
+         if (poller != null)
+         {
+            Thread currentPoller = poller;
+            stopPoller(handler);
+            // We need to make sure we won't call close until Poller is
+            // completely done, or we might get beautiful GPFs
+            currentPoller.join();
+         }
+
+         closeInternal(handler);
+         addMax(maxIO * -1);
+         opened = false;
+         handler = 0;
+      }
+      finally
+      {
+         writeLock.unlock();
+      }
+   }
+
+   public void write(final long position,
+                     final long size,
+                     final ByteBuffer directByteBuffer,
+                     final AIOCallback aioPackage)
+   {
+      checkOpened();
+      if (poller == null)
+      {
+         startPoller();
+      }
       writeSemaphore.acquireUninterruptibly();
-		try
-		{
-			write (handler, position, size, directByteBuffer, aioPackage);
-		}
-		catch (RuntimeException e)
-		{
+      try
+      {
+         write(handler, position, size, directByteBuffer, aioPackage);
+      }
+      catch (RuntimeException e)
+      {
          writeSemaphore.release();
-			throw e;
-		}
-		
-	}
-	
-	public void read(final long position, final long size, final ByteBuffer directByteBuffer, final AIOCallback aioPackage)
-	{
-		checkOpened();
+         throw e;
+      }
+
+   }
+
+   public void read(final long position,
+                    final long size,
+                    final ByteBuffer directByteBuffer,
+                    final AIOCallback aioPackage)
+   {
+      checkOpened();
       if (poller == null)
       {
          startPoller();
       }
       writeSemaphore.acquireUninterruptibly();
-		try
-		{
-			read (handler, position, size, directByteBuffer, aioPackage);
-		}
-		catch (RuntimeException e)
-		{
+      try
+      {
+         read(handler, position, size, directByteBuffer, aioPackage);
+      }
+      catch (RuntimeException e)
+      {
          writeSemaphore.release();
-			throw e;
-		}		
-	}
-	
-	public long size()
-	{
-		checkOpened();
-		return size0(handler);
-	}
-	
-	public void fill(final long position, final int blocks, final long size, final byte fillChar)
-	{
-		checkOpened();
-		fill(handler, position, blocks, size, fillChar);
-	}
-	
-	public int getBlockSize()
-	{
-		return 512;
-	}
-	
-	public String getFileName()
-	{
-	   return fileName;
-	}
-	
+         throw e;
+      }
+   }
+
+   public long size()
+   {
+      checkOpened();
+      return size0(handler);
+   }
+
+   public void fill(final long position, final int blocks, final long size, final byte fillChar)
+   {
+      checkOpened();
+      fill(handler, position, blocks, size, fillChar);
+   }
+
+   public int getBlockSize()
+   {
+      return 512;
+   }
+
+   public String getFileName()
+   {
+      return fileName;
+   }
+
    // Should we make this method static?
-   public ByteBuffer newBuffer(int size)
+   public ByteBuffer newBuffer(final int size)
    {
       if (size % getBlockSize() != 0)
       {
          throw new RuntimeException("Buffer size needs to be aligned to 512");
       }
-      
-      return ByteBuffer.allocateDirect((int)size);
+
+      return ByteBuffer.allocateDirect(size);
    }
-   
-   public void setBufferCallback(BufferCallback callback)
+
+   public void setBufferCallback(final BufferCallback callback)
    {
-      this.bufferCallback = callback;
+      bufferCallback = callback;
    }
 
-      
-	// Private
-	// ---------------------------------------------------------------------------------
-	
+   // Private
+   // ---------------------------------------------------------------------------------
+
    /** The JNI layer will call this method, so we could use it to unlock readWriteLocks held in the java layer */
-	@SuppressWarnings("unused") // Called by the JNI layer.. just ignore the warning
-	private void callbackDone(final AIOCallback callback, final ByteBuffer buffer)
-	{
+   @SuppressWarnings("unused")
+   // Called by the JNI layer.. just ignore the
+                                 // warning
+   private void callbackDone(final AIOCallback callback, final ByteBuffer buffer)
+   {
       writeSemaphore.release();
-		callback.done();
-		if (this.bufferCallback != null)
-		{
-		   this.bufferCallback.bufferDone(buffer);
-		}
-	}
-	
-	@SuppressWarnings("unused") // Called by the JNI layer.. just ignore the warning
-	private void callbackError(final AIOCallback callback, final int errorCode, final String errorMessage)
-	{
-	   log.warn("CallbackError: " + errorMessage);
+      callback.done();
+      if (bufferCallback != null)
+      {
+         bufferCallback.bufferDone(buffer);
+      }
+   }
+
+   @SuppressWarnings("unused")
+   // Called by the JNI layer.. just ignore the
+                                 // warning
+   private void callbackError(final AIOCallback callback, final int errorCode, final String errorMessage)
+   {
+      log.warn("CallbackError: " + errorMessage);
       writeSemaphore.release();
-		callback.onError(errorCode, errorMessage);
-	}
-	
-	private void pollEvents()
-	{
-		if (!opened)
-		{
-			return;
-		}
-		internalPollEvents(handler);
-	}
-	
-	private void startPoller()
-	{
-		writeLock.lock();
-		
-		try
-		{
-   		
-   		if (poller == null)
-   		{
-      		poller = new PollerThread(); 
-      		try
-      		{
-      			poller.start();
-      		}
-      		catch (Exception ex)
-      		{
-      			log.error(ex.getMessage(), ex);
-      		}
-   		}
-		}
-		finally
-		{
-		   writeLock.unlock();
-		}
-	}
-	
-	private void checkOpened() 
-	{
-		if (!opened)
-		{
-			throw new RuntimeException("File is not opened");
-		}
-	}
-	
-	// Native
-	// ------------------------------------------------------------------------------------------
-	
-	public static native void resetBuffer(ByteBuffer directByteBuffer, int size);
-	
-	private static native long init(String fileName, int maxIO, Logger logger);
-	
-	private native long size0(long handle);
-	
-	private native void write(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
-	
-	private native void read(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
-	
-	private static native void fill(long handle, long position, int blocks, long size, byte fillChar);
-	
-	private static native void closeInternal(long handler);
-	
-	private static native void stopPoller(long handler);
-	
-	/** A native method that does nothing, and just validate if the ELF dependencies are loaded and on the correct platform as this binary format */
-	private static native int getNativeVersion();
-	
-	/** Poll asynchrounous events from internal queues */
-	private static native void internalPollEvents(long handler);
-	
-	// Inner classes
-	// -----------------------------------------------------------------------------------------
-	
-	private class PollerThread extends Thread
+      callback.onError(errorCode, errorMessage);
+   }
+
+   private void pollEvents()
    {
-      PollerThread ()
+      if (!opened)
       {
+         return;
+      }
+      internalPollEvents(handler);
+   }
+
+   private void startPoller()
+   {
+      writeLock.lock();
+
+      try
+      {
+
+         if (poller == null)
+         {
+            poller = new PollerThread();
+            try
+            {
+               poller.start();
+            }
+            catch (Exception ex)
+            {
+               log.error(ex.getMessage(), ex);
+            }
+         }
+      }
+      finally
+      {
+         writeLock.unlock();
+      }
+   }
+
+   private void checkOpened()
+   {
+      if (!opened)
+      {
+         throw new RuntimeException("File is not opened");
+      }
+   }
+
+   // Native
+   // ------------------------------------------------------------------------------------------
+
+   public static native void resetBuffer(ByteBuffer directByteBuffer, int size);
+
+   private static native long init(String fileName, int maxIO, Logger logger);
+
+   private native long size0(long handle);
+
+   private native void write(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
+
+   private native void read(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
+
+   private static native void fill(long handle, long position, int blocks, long size, byte fillChar);
+
+   private static native void closeInternal(long handler);
+
+   private static native void stopPoller(long handler);
+
+   /** A native method that does nothing, and just validate if the ELF dependencies are loaded and on the correct platform as this binary format */
+   private static native int getNativeVersion();
+
+   /** Poll asynchrounous events from internal queues */
+   private static native void internalPollEvents(long handler);
+
+   // Inner classes
+   // -----------------------------------------------------------------------------------------
+
+   private class PollerThread extends Thread
+   {
+      PollerThread()
+      {
          super("NativePoller for " + fileName);
       }
+
+      @Override
       public void run()
       {
          try
@@ -385,9 +401,10 @@
          finally
          {
             // This gives us extra protection in cases of interruption
-            // Case the poller thread is interrupted, this will allow us to restart the thread when required
-            AsynchronousFileImpl.this.poller = null;
+            // Case the poller thread is interrupted, this will allow us to
+            // restart the thread when required
+            poller = null;
          }
       }
-   }	
+   }
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/BufferCallback.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/BufferCallback.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/BufferCallback.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.journal;
 
 /**
@@ -32,5 +31,5 @@
  */
 public interface BufferCallback extends org.jboss.messaging.core.asyncio.BufferCallback
 {
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/EncodingSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/EncodingSupport.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/EncodingSupport.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -36,8 +36,8 @@
 public interface EncodingSupport
 {
    int getEncodeSize();
-   
+
    void encode(MessagingBuffer buffer);
-   
+
    void decode(MessagingBuffer buffer);
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/IOCallback.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/IOCallback.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/IOCallback.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -34,5 +34,5 @@
  */
 public interface IOCallback extends AIOCallback
 {
-	
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/Journal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/Journal.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/Journal.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,13 +18,14 @@
  * 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.journal;
 
 import java.util.List;
 
 import org.jboss.messaging.core.server.MessagingComponent;
+
 /**
  * 
  * A Journal
@@ -36,25 +37,25 @@
 public interface Journal extends MessagingComponent
 {
    // Non transactional operations
-   
+
    void appendAddRecord(long id, byte recordType, EncodingSupport record) throws Exception;
-   
+
    void appendUpdateRecord(long id, byte recordType, EncodingSupport record) throws Exception;
-   
+
    void appendDeleteRecord(long id) throws Exception;
-   
+
    // Transactional operations
-   
+
    long getTransactionID();
-   
+
    void appendAddRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws Exception;
-   
+
    void appendUpdateRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws Exception;
-   
+
    void appendDeleteRecordTransactional(long txID, long id, EncodingSupport record) throws Exception;
-   
+
    void appendCommitRecord(long txID) throws Exception;
-   
+
    /** 
     * 
     * <p>If the system crashed after a prepare was called, it should store information that is required to bring the transaction 
@@ -67,14 +68,13 @@
     * @throws Exception
     */
    void appendPrepareRecord(long txID, EncodingSupport transactionData) throws Exception;
-   
+
    void appendRollbackRecord(long txID) throws Exception;
-   
+
    // Load
-   
-   long load(List<RecordInfo> committedRecords,
-         List<PreparedTransactionInfo> preparedTransactions) throws Exception;
-   
+
+   long load(List<RecordInfo> committedRecords, List<PreparedTransactionInfo> preparedTransactions) throws Exception;
+
    int getAlignment() throws Exception;
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/LoadManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/LoadManager.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/LoadManager.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -30,10 +30,10 @@
 public interface LoadManager
 {
    void addRecord(RecordInfo info);
-   
+
    void deleteRecord(long id);
-   
+
    void updateRecord(RecordInfo info);
-   
+
    void addPreparedTransaction(PreparedTransactionInfo preparedTransaction);
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/PreparedTransactionInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/PreparedTransactionInfo.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/PreparedTransactionInfo.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,9 +18,8 @@
  * 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.journal;
 
 import java.util.ArrayList;
@@ -36,17 +35,17 @@
 public class PreparedTransactionInfo
 {
    public final long id;
-   
+
    public final byte[] extraData;
-   
+
    public final List<RecordInfo> records = new ArrayList<RecordInfo>();
-   
+
    public final List<RecordInfo> recordsToDelete = new ArrayList<RecordInfo>();
 
    public PreparedTransactionInfo(final long id, final byte[] extraData)
    {
       this.id = id;
-      
+
       this.extraData = extraData;
    }
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/RecordInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/RecordInfo.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/RecordInfo.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,11 +18,10 @@
  * 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.journal;
 
-
 /**
  * 
  * A RecordInfo
@@ -33,40 +32,42 @@
  */
 public class RecordInfo
 {
-   public RecordInfo(final long id, byte userRecordType, final byte[] data, final boolean isUpdate)
+   public RecordInfo(final long id, final byte userRecordType, final byte[] data, final boolean isUpdate)
    {
       this.id = id;
-      
+
       this.userRecordType = userRecordType;
-      
+
       this.data = data;
-      
+
       this.isUpdate = isUpdate;
    }
-   
+
    public final long id;
-   
+
    public final byte userRecordType;
-   
+
    public final byte[] data;
-   
+
    public boolean isUpdate;
-   
+
    public byte getUserRecordType()
    {
       return userRecordType;
    }
-   
+
+   @Override
    public int hashCode()
    {
-      return (int)((id >>> 32) ^ id);
+      return (int)(id >>> 32 ^ id);
    }
-   
-   public boolean equals(Object other)
+
+   @Override
+   public boolean equals(final Object other)
    {
       RecordInfo r = (RecordInfo)other;
-      
-      return r.id == this.id;		
+
+      return r.id == id;
    }
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/SequentialFile.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/SequentialFile.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/SequentialFile.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -38,42 +38,42 @@
     * Creates the file if it doesn't already exist, then opens it
     */
    void open() throws Exception;
-   
+
    /**
     * For certain operations (like loading) we don't need open the file with full maxIO
     * @param maxIO
     * @throws Exception
     */
    void open(int maxIO) throws Exception;
-   
-   void setBufferCallback(BufferCallback callback);   
-   
+
+   void setBufferCallback(BufferCallback callback);
+
    int getAlignment() throws Exception;
-   
+
    int calculateBlockStart(int position) throws Exception;
-   
+
    String getFileName();
-   
+
    void fill(int position, int size, byte fillCharacter) throws Exception;
-   
+
    void delete() throws Exception;
-   
+
    int write(ByteBuffer bytes, IOCallback callback) throws Exception;
-   
+
    int write(ByteBuffer bytes, boolean sync) throws Exception;
-   
+
    int read(ByteBuffer bytes, IOCallback callback) throws Exception;
-   
+
    int read(ByteBuffer bytes) throws Exception;
-   
+
    void position(int pos) throws Exception;
-   
+
    int position() throws Exception;
-   
+
    void close() throws Exception;
-   
+
    void sync() throws Exception;
-   
+
    long size() throws Exception;
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/SequentialFileFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/SequentialFileFactory.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/SequentialFileFactory.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -36,23 +36,23 @@
 public interface SequentialFileFactory
 {
    SequentialFile createSequentialFile(String fileName, int maxIO) throws Exception;
-   
+
    List<String> listFiles(String extension) throws Exception;
-   
+
    boolean isSupportsCallbacks();
-   
+
    ByteBuffer newBuffer(int size);
-   
-   // Avoid using this method in production as it creates an unecessary copy 
+
+   // Avoid using this method in production as it creates an unecessary copy
    ByteBuffer wrapBuffer(byte[] bytes);
-   
+
    int getAlignment();
-   
+
    int calculateBlockSize(int bytes);
-   
+
    /** This method is not being used currently. 
     *  The journal will complete the buffer when reusing the buffer.
     *  Look at JournalImpl#newBuffer for more information about this */
    void clearBuffer(ByteBuffer buffer);
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -33,43 +33,42 @@
 public interface TestableJournal extends Journal
 {
    void checkAndReclaimFiles() throws Exception;
-   
+
    int getDataFilesCount();
-   
+
    int getFreeFilesCount();
-   
+
    int getOpenedFilesCount();
-   
+
    int getIDMapSize();
-   
+
    String debug() throws Exception;
-   
+
    void debugWait() throws Exception;
-   
+
    int getFileSize();
-   
+
    int getMinFiles();
-   
+
    boolean isSyncTransactional();
-   
+
    boolean isSyncNonTransactional();
-   
+
    String getFilePrefix();
-   
+
    String getFileExtension();
-   
+
    int getMaxAIO();
-   
+
    /** This method could be promoted to {@link Journal} interface when we decide to use the loadManager 
     *  instead of load(List,List)
     */
    long load(LoadManager reloadManager) throws Exception;
-   
-   
+
    void forceMoveNextFile() throws Exception;
-   
+
    void setAutoReclaim(boolean autoReclaim);
-   
+
    boolean isAutoReclaim();
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -48,62 +48,64 @@
 public class AIOSequentialFile implements SequentialFile
 {
    private static final Logger log = Logger.getLogger(AIOSequentialFile.class);
-   
+
    private final String journalDir;
-   
+
    private final String fileName;
-   
+
    private boolean opened = false;
-   
+
    private final int maxIO;
-   
+
    private AsynchronousFile aioFile;
-   
-   private AtomicLong position = new AtomicLong(0);
-   
-   // A context switch on AIO would make it to synchronize the disk before switching to the new thread, what would cause
-   // serious performance problems. Because of that we make all the writes on AIO using a single thread.
+
+   private final AtomicLong position = new AtomicLong(0);
+
+   // A context switch on AIO would make it to synchronize the disk before
+   // switching to the new thread, what would cause
+   // serious performance problems. Because of that we make all the writes on
+   // AIO using a single thread.
    private ExecutorService executor;
-   
+
    public AIOSequentialFile(final String journalDir, final String fileName, final int maxIO) throws Exception
    {
-      this.journalDir = journalDir;		
+      this.journalDir = journalDir;
       this.fileName = fileName;
       this.maxIO = maxIO;
    }
-   
+
    public int getAlignment() throws Exception
    {
       checkOpened();
-      
+
       return aioFile.getBlockSize();
    }
-   
-   public int calculateBlockStart(int position) throws Exception
+
+   public int calculateBlockStart(final int position) throws Exception
    {
       int alignment = getAlignment();
-      
-      int pos = ((position / alignment) + (position % alignment != 0 ? 1 : 0)) * alignment;
-      
+
+      int pos = (position / alignment + (position % alignment != 0 ? 1 : 0)) * alignment;
+
       return pos;
    }
-   
+
    public synchronized void close() throws Exception
    {
       checkOpened();
       opened = false;
       executor.shutdown();
-      
+
       while (!executor.awaitTermination(60, TimeUnit.SECONDS))
       {
-         log.warn("Executor on file " + this.fileName + " couldn't complete its tasks in 60 seconds.",
-               new Exception ("Warning: Executor on file " + this.fileName + " couldn't complete its tasks in 60 seconds.") );
+         log.warn("Executor on file " + fileName + " couldn't complete its tasks in 60 seconds.",
+                  new Exception("Warning: Executor on file " + fileName + " couldn't complete its tasks in 60 seconds."));
       }
-      
+
       aioFile.close();
-      aioFile = null;		
+      aioFile = null;
    }
-   
+
    public void delete() throws Exception
    {
       if (aioFile != null)
@@ -111,146 +113,145 @@
          aioFile.close();
          aioFile = null;
       }
-      
-      File file = new File(journalDir + "/" +  fileName);
+
+      File file = new File(journalDir + "/" + fileName);
       file.delete();
    }
-   
+
    public void fill(final int position, final int size, final byte fillCharacter) throws Exception
    {
       checkOpened();
-      
+
       int fileblockSize = aioFile.getBlockSize();
-      
+
       int blockSize = fileblockSize;
-      
-      if (size % (100*1024*1024) == 0)
+
+      if (size % (100 * 1024 * 1024) == 0)
       {
-         blockSize = 100*1024*1024;
+         blockSize = 100 * 1024 * 1024;
       }
-      else if (size % (10*1024*1024) == 0)
+      else if (size % (10 * 1024 * 1024) == 0)
       {
-         blockSize = 10*1024*1024;
+         blockSize = 10 * 1024 * 1024;
       }
-      else if (size % (1024*1024) == 0)
+      else if (size % (1024 * 1024) == 0)
       {
-         blockSize = 1024*1024;
+         blockSize = 1024 * 1024;
       }
-      else if (size % (10*1024) == 0)
+      else if (size % (10 * 1024) == 0)
       {
-         blockSize = 10*1024;
+         blockSize = 10 * 1024;
       }
       else
       {
          blockSize = fileblockSize;
       }
-      
+
       int blocks = size / blockSize;
-      
+
       if (size % blockSize != 0)
       {
          blocks++;
       }
-      
+
       int filePosition = position;
-      
+
       if (position % fileblockSize != 0)
       {
-         filePosition = ((position / fileblockSize) + 1) * fileblockSize;
+         filePosition = (position / fileblockSize + 1) * fileblockSize;
       }
-      
-      aioFile.fill((long)filePosition, blocks, blockSize, (byte)fillCharacter);		
+
+      aioFile.fill(filePosition, blocks, blockSize, fillCharacter);
    }
-   
+
    public String getFileName()
    {
       return fileName;
    }
-   
+
    public void open() throws Exception
    {
-     open(maxIO);
+      open(maxIO);
    }
-   
-   public synchronized void open(int currentMaxIO) throws Exception
+
+   public synchronized void open(final int currentMaxIO) throws Exception
    {
       opened = true;
       executor = Executors.newSingleThreadExecutor();
       aioFile = newFile();
       aioFile.open(journalDir + "/" + fileName, currentMaxIO);
       position.set(0);
-      
+
    }
-   
-   public void setBufferCallback(BufferCallback callback)
+
+   public void setBufferCallback(final BufferCallback callback)
    {
       aioFile.setBufferCallback(callback);
    }
-   
+
    public void position(final int pos) throws Exception
    {
-      position.set(pos);		
+      position.set(pos);
    }
-   
+
    public int position() throws Exception
    {
       return (int)position.get();
    }
-   
+
    public int read(final ByteBuffer bytes, final IOCallback callback) throws Exception
    {
       int bytesToRead = bytes.limit();
-      
+
       long positionToRead = position.getAndAdd(bytesToRead);
-      
+
       bytes.rewind();
-      
+
       aioFile.read(positionToRead, bytesToRead, bytes, callback);
-      
+
       return bytesToRead;
    }
-   
+
    public int read(final ByteBuffer bytes) throws Exception
    {
       WaitCompletion waitCompletion = new WaitCompletion();
-      
-      int bytesRead = read (bytes, waitCompletion);
-      
+
+      int bytesRead = read(bytes, waitCompletion);
+
       waitCompletion.waitLatch();
-      
+
       return bytesRead;
    }
-   
-   
+
    public int write(final ByteBuffer bytes, final IOCallback callback) throws Exception
    {
       final int bytesToWrite = bytes.limit();
-      
+
       final long positionToWrite = position.getAndAdd(bytesToWrite);
-      
+
       execWrite(bytes, callback, bytesToWrite, positionToWrite);
-      
+
       return bytesToWrite;
    }
-   
+
    public int write(final ByteBuffer bytes, final boolean sync) throws Exception
    {
       if (sync)
       {
          WaitCompletion completion = new WaitCompletion();
-         
+
          int bytesWritten = write(bytes, completion);
-         
+
          completion.waitLatch();
-         
+
          return bytesWritten;
       }
       else
       {
-         return write (bytes, DummyCallback.instance);
-      }		
+         return write(bytes, DummyCallback.instance);
+      }
    }
-   
+
    public void sync() throws Exception
    {
       throw new IllegalArgumentException("This method is not supported on AIO");
@@ -261,9 +262,10 @@
       return aioFile.size();
    }
 
+   @Override
    public String toString()
    {
-      return "AIOSequentialFile:" + this.journalDir + "/" + this.fileName;
+      return "AIOSequentialFile:" + journalDir + "/" + fileName;
    }
 
    // Protected methods
@@ -276,12 +278,14 @@
    {
       return new AsynchronousFileImpl();
    }
-   
+
    // Private methods
    // -----------------------------------------------------------------------------------------------------
-   
-   private void execWrite(final ByteBuffer bytes, final IOCallback callback,
-         final int bytesToWrite, final long positionToWrite)
+
+   private void execWrite(final ByteBuffer bytes,
+                          final IOCallback callback,
+                          final int bytesToWrite,
+                          final long positionToWrite)
    {
       executor.execute(new Runnable()
       {
@@ -290,7 +294,8 @@
             try
             {
                aioFile.write(positionToWrite, bytesToWrite, bytes, callback);
-            } catch (Exception e)
+            }
+            catch (Exception e)
             {
                log.warn(e.getMessage(), e);
                if (callback != null)
@@ -301,54 +306,53 @@
          }
       });
    }
-   
-   
+
    private void checkOpened() throws Exception
    {
       if (aioFile == null || !opened)
       {
-         throw new IllegalStateException ("File not opened");
+         throw new IllegalStateException("File not opened");
       }
    }
-   
+
    private static class DummyCallback implements IOCallback
-   {	   
+   {
       static DummyCallback instance = new DummyCallback();
-      
+
       public void done()
       {
       }
-      
-      public void onError(int errorCode, String errorMessage)
+
+      public void onError(final int errorCode, final String errorMessage)
       {
-         log.warn("Error on writing data!" + errorMessage + " code - " + errorCode, new Exception (errorMessage));
-      }	   
+         log.warn("Error on writing data!" + errorMessage + " code - " + errorCode, new Exception(errorMessage));
+      }
    }
-   
+
    private static class WaitCompletion implements IOCallback
-   {		
+   {
       private final CountDownLatch latch = new CountDownLatch(1);
-      
+
       private volatile String errorMessage;
-      
+
       private volatile int errorCode = 0;
-      
+
       public void done()
       {
          latch.countDown();
       }
-      
+
       public void onError(final int errorCode, final String errorMessage)
       {
          this.errorCode = errorCode;
-         
+
          this.errorMessage = errorMessage;
-         
+
          log.warn("Error Message " + errorMessage);
-         
-         latch.countDown();			
+
+         latch.countDown();
       }
-      
+
       public void waitLatch() throws Exception
       {
          latch.await();
@@ -357,6 +361,6 @@
             throw new MessagingException(errorCode, errorMessage);
          }
          return;
-      }		
-   }	
+      }
+   }
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFileFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFileFactory.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFileFactory.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -35,27 +35,27 @@
  *
  */
 public class AIOSequentialFileFactory extends AbstractSequentialFactory
-{	
+{
    public AIOSequentialFileFactory(final String journalDir)
    {
       super(journalDir);
    }
-   
+
    public SequentialFile createSequentialFile(final String fileName, final int maxIO) throws Exception
    {
       return new AIOSequentialFile(journalDir, fileName, maxIO);
    }
-   
+
    public boolean isSupportsCallbacks()
    {
       return true;
    }
-   
+
    public static boolean isSupported()
    {
       return AsynchronousFileImpl.isLoaded();
    }
-   
+
    public ByteBuffer newBuffer(int size)
    {
       if (size % 512 != 0)
@@ -64,17 +64,17 @@
       }
       return ByteBuffer.allocateDirect(size);
    }
-   
-   public void clearBuffer(ByteBuffer directByteBuffer)
+
+   public void clearBuffer(final ByteBuffer directByteBuffer)
    {
       AsynchronousFileImpl.resetBuffer(directByteBuffer, directByteBuffer.limit());
    }
-   
+
    public int getAlignment()
    {
       return 512;
    }
-   
+
    // For tests only
    public ByteBuffer wrapBuffer(final byte[] bytes)
    {
@@ -83,12 +83,12 @@
       return newbuffer;
    }
 
-   public int calculateBlockSize(int position)
+   public int calculateBlockSize(final int position)
    {
       int alignment = getAlignment();
-      
-      int pos = ((position / alignment) + (position % alignment != 0 ? 1 : 0)) * alignment;
-      
+
+      int pos = (position / alignment + (position % alignment != 0 ? 1 : 0)) * alignment;
+
       return pos;
    }
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/AbstractSequentialFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/AbstractSequentialFactory.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/AbstractSequentialFactory.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -41,16 +41,16 @@
 public abstract class AbstractSequentialFactory implements SequentialFileFactory
 {
    protected final String journalDir;
-   
+
    public AbstractSequentialFactory(final String journalDir)
    {
       this.journalDir = journalDir;
    }
-   
+
    public List<String> listFiles(final String extension) throws Exception
    {
       File dir = new File(journalDir);
-      
+
       FilenameFilter fnf = new FilenameFilter()
       {
          public boolean accept(File file, String name)
@@ -58,15 +58,15 @@
             return name.endsWith("." + extension);
          }
       };
-      
+
       String[] fileNames = dir.list(fnf);
-      
+
       if (fileNames == null)
       {
          throw new IOException("Failed to list: " + journalDir);
       }
-      
+
       return Arrays.asList(fileNames);
    }
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFile.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFile.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFile.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -36,26 +36,26 @@
 public interface JournalFile
 {
    int getNegCount(JournalFile file);
-   
+
    void incNegCount(JournalFile file);
-   
+
    int getPosCount();
-   
+
    void incPosCount();
-   
+
    void decPosCount();
-   
+
    void setCanReclaim(boolean canDelete);
-   
+
    boolean isCanReclaim();
-   
+
    void extendOffset(final int delta);
-   
+
    int getOffset();
-   
+
    int getOrderingID();
-   
+
    void setOffset(final int offset);
-   
+
    SequentialFile getFile();
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFileImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFileImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalFileImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -39,52 +39,52 @@
  *
  */
 public class JournalFileImpl implements JournalFile
-{			
+{
    private static final Logger log = Logger.getLogger(JournalFileImpl.class);
-   
+
    private final SequentialFile file;
-   
+
    private final int orderingID;
-   
+
    private int offset;
-   
+
    private final AtomicInteger posCount = new AtomicInteger(0);
-   
+
    private boolean canReclaim;
-   
-   private Map<JournalFile, AtomicInteger> negCounts = new ConcurrentHashMap<JournalFile, AtomicInteger>();
-   
+
+   private final Map<JournalFile, AtomicInteger> negCounts = new ConcurrentHashMap<JournalFile, AtomicInteger>();
+
    public JournalFileImpl(final SequentialFile file, final int orderingID)
    {
       this.file = file;
-      
+
       this.orderingID = orderingID;
    }
-   
+
    public int getPosCount()
    {
       return posCount.intValue();
    }
-   
+
    public boolean isCanReclaim()
    {
       return canReclaim;
    }
-   
+
    public void setCanReclaim(final boolean canReclaim)
    {
       this.canReclaim = canReclaim;
    }
-   
+
    public void incNegCount(final JournalFile file)
    {
       getOrCreateNegCount(file).incrementAndGet();
    }
-   
+
    public int getNegCount(final JournalFile file)
-   {		
-      AtomicInteger count =  negCounts.get(file);
-      
+   {
+      AtomicInteger count = negCounts.get(file);
+
       if (count == null)
       {
          return 0;
@@ -94,42 +94,43 @@
          return count.intValue();
       }
    }
-   
+
    public void incPosCount()
    {
       posCount.incrementAndGet();
    }
-   
+
    public void decPosCount()
    {
       posCount.decrementAndGet();
    }
-   
+
    public void extendOffset(final int delta)
    {
       offset += delta;
    }
-   
+
    public int getOffset()
    {
       return offset;
    }
-   
+
    public int getOrderingID()
    {
       return orderingID;
    }
-   
+
    public void setOffset(final int offset)
    {
       this.offset = offset;
    }
-   
+
    public SequentialFile getFile()
    {
       return file;
-   }	
-   
+   }
+
+   @Override
    public String toString()
    {
       try
@@ -142,33 +143,31 @@
          return "Error:" + e.toString();
       }
    }
-   
+
    /** Receive debug information about the journal */
    public String debug()
    {
       StringBuilder builder = new StringBuilder();
-      
-      for (Entry<JournalFile, AtomicInteger> entry: negCounts.entrySet())
+
+      for (Entry<JournalFile, AtomicInteger> entry : negCounts.entrySet())
       {
          builder.append(" file = " + entry.getKey() + " negcount value = " + entry.getValue() + "\n");
       }
-      
+
       return builder.toString();
    }
 
-   
    private synchronized AtomicInteger getOrCreateNegCount(final JournalFile file)
    {
       AtomicInteger count = negCounts.get(file);
-      
+
       if (count == null)
       {
          count = new AtomicInteger();
          negCounts.put(file, count);
       }
-      
+
       return count;
    }
-   
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -96,7 +96,7 @@
    // This method exists just to make debug easier.
    // I could replace log.trace by log.info temporarily while I was debugging
    // Journal
-   private static final void trace(String message)
+   private static final void trace(final String message)
    {
       log.trace(message);
    }
@@ -118,28 +118,33 @@
    public static final int BASIC_SIZE = SIZE_BYTE + SIZE_INT + SIZE_INT;
 
    public static final int SIZE_ADD_RECORD = BASIC_SIZE + SIZE_LONG + SIZE_BYTE + SIZE_INT; // +
-                                                                                             // record.length
 
+   // record.length
+
    public static final byte ADD_RECORD = 11;
 
    public static final byte SIZE_UPDATE_RECORD = BASIC_SIZE + SIZE_LONG + SIZE_BYTE + SIZE_INT; // +
-                                                                                                // record.length;
 
+   // record.length;
+
    public static final byte UPDATE_RECORD = 12;
 
    public static final int SIZE_ADD_RECORD_TX = BASIC_SIZE + SIZE_LONG + SIZE_BYTE + SIZE_LONG + SIZE_INT; // +
-                                                                                                            // record.length
 
+   // record.length
+
    public static final byte ADD_RECORD_TX = 13;
 
    public static final int SIZE_UPDATE_RECORD_TX = BASIC_SIZE + SIZE_LONG + SIZE_BYTE + SIZE_LONG + SIZE_INT; // +
-                                                                                                               // record.length
 
+   // record.length
+
    public static final byte UPDATE_RECORD_TX = 14;
 
    public static final int SIZE_DELETE_RECORD_TX = BASIC_SIZE + SIZE_LONG + SIZE_LONG + SIZE_INT; // +
-                                                                                                   // record.length
 
+   // record.length
+
    public static final byte DELETE_RECORD_TX = 15;
 
    public static final int SIZE_DELETE_RECORD = BASIC_SIZE + SIZE_LONG;
@@ -147,8 +152,9 @@
    public static final byte DELETE_RECORD = 16;
 
    public static final int SIZE_COMPLETE_TRANSACTION_RECORD = BASIC_SIZE + SIZE_INT + SIZE_LONG; // +
-                                                                                                   // NumerOfElements*SIZE_INT*2
 
+   // NumerOfElements*SIZE_INT*2
+
    public static final int SIZE_PREPARE_RECORD = SIZE_COMPLETE_TRANSACTION_RECORD + SIZE_INT;
 
    public static final byte PREPARE_RECORD = 17;
@@ -447,7 +453,7 @@
 
    public void appendUpdateRecordTransactional(final long txID,
                                                final long id,
-                                               byte recordType,
+                                               final byte recordType,
                                                final EncodingSupport record) throws Exception
    {
       if (state != STATE_LOADED)
@@ -549,7 +555,7 @@
       lock.acquire();
 
       TransactionCallback callback = getTransactionCallback(txID);
-      
+
       try
       {
          JournalFile usedFile = appendRecord(bb, syncTransactional, callback);
@@ -560,7 +566,7 @@
       {
          lock.release();
       }
-      
+
       // We should wait this outside of the lock, to increase throuput
       if (callback != null)
       {
@@ -604,7 +610,7 @@
       lock.acquire();
 
       TransactionCallback callback = getTransactionCallback(txID);
-      
+
       try
       {
          JournalFile usedFile = appendRecord(bb, syncTransactional, callback);
@@ -617,13 +623,13 @@
       {
          lock.release();
       }
-      
+
       // We should wait this outside of the lock, to increase throuput
       if (callback != null)
       {
          callback.waitCompletion();
       }
-      
+
    }
 
    public void appendRollbackRecord(final long txID) throws Exception
@@ -652,7 +658,6 @@
       lock.acquire();
 
       TransactionCallback callback = getTransactionCallback(txID);
-      
 
       try
       {
@@ -666,14 +671,13 @@
       {
          lock.release();
       }
-      
+
       // We should wait this outside of the lock, to increase throuput
       if (callback != null)
       {
          callback.waitCompletion();
       }
-      
-      
+
    }
 
    /**
@@ -1055,7 +1059,7 @@
                      transactions.put(transactionID, tx);
                   }
 
-                  tx.recordsToDelete.add(new RecordInfo(recordID, (byte) 0, record, true));
+                  tx.recordsToDelete.add(new RecordInfo(recordID, (byte)0, record, true));
 
                   JournalTransaction tnp = transactionInfos.get(transactionID);
 
@@ -1275,7 +1279,7 @@
       {
          currentFile.getFile().open();
 
-         if (this.reuseBufferSize > 0)
+         if (reuseBufferSize > 0)
          {
             currentFile.getFile().setBufferCallback(buffersControl.callback);
          }
@@ -1333,7 +1337,7 @@
 
    public int getAlignment() throws Exception
    {
-      return this.fileFactory.getAlignment();
+      return fileFactory.getAlignment();
    }
 
    // TestableJournal implementation
@@ -1346,12 +1350,12 @@
 
    public boolean isAutoReclaim()
    {
-      return this.autoReclaim;
+      return autoReclaim;
    }
 
    public String debug() throws Exception
    {
-      this.checkReclaimStatus();
+      checkReclaimStatus();
 
       StringBuilder builder = new StringBuilder();
 
@@ -1365,7 +1369,7 @@
                         "\n");
          if (file instanceof JournalFileImpl)
          {
-            builder.append(((JournalFileImpl) file).debug());
+            builder.append(((JournalFileImpl)file).debug());
 
          }
       }
@@ -1381,7 +1385,7 @@
 
          if (currentFile instanceof JournalFileImpl)
          {
-            builder.append(((JournalFileImpl) currentFile).debug());
+            builder.append(((JournalFileImpl)currentFile).debug());
          }
       }
       else
@@ -1389,7 +1393,7 @@
          builder.append("CurrentFile: No current file at this point!");
       }
 
-      builder.append("#Opened Files:" + this.openedFiles.size());
+      builder.append("#Opened Files:" + openedFiles.size());
 
       return builder.toString();
    }
@@ -1409,7 +1413,7 @@
          // until its end
          final CountDownLatch latch = new CountDownLatch(1);
 
-         this.filesExecutor.execute(new Runnable()
+         filesExecutor.execute(new Runnable()
          {
             public void run()
             {
@@ -1433,7 +1437,9 @@
             // File can be reclaimed or deleted
 
             if (trace)
+            {
                trace("Reclaiming file " + file);
+            }
 
             dataFiles.remove(file);
 
@@ -1632,7 +1638,7 @@
 
       // This line aways show an annoying compilation-warning, the
       // SupressWarning is to avoid a warning about this cast
-      Pair<Integer, Integer> values[] = (Pair<Integer, Integer>[]) new Pair[numberOfFiles];
+      Pair<Integer, Integer> values[] = new Pair[numberOfFiles];
 
       for (int i = 0; i < numberOfFiles; i++)
       {
@@ -1740,7 +1746,7 @@
    private ByteBuffer writeTransaction(final byte recordType,
                                        final long txID,
                                        final JournalTransaction tx,
-                                       EncodingSupport transactionData) throws Exception
+                                       final EncodingSupport transactionData) throws Exception
    {
       int size = SIZE_COMPLETE_TRANSACTION_RECORD + tx.getElementsSummary().size() *
                  SIZE_INT *
@@ -1868,12 +1874,12 @@
 
       class JournalFileComparator implements Comparator<JournalFile>
       {
-         public int compare(JournalFile f1, JournalFile f2)
+         public int compare(final JournalFile f1, final JournalFile f2)
          {
             int id1 = f1.getOrderingID();
             int id2 = f2.getOrderingID();
 
-            return (id1 < id2 ? -1 : (id1 == id2 ? 0 : 1));
+            return id1 < id2 ? -1 : id1 == id2 ? 0 : 1;
          }
       }
 
@@ -1967,7 +1973,7 @@
 
       file.setOffset(file.getFile().calculateBlockStart(SIZE_HEADER));
 
-      if (this.reuseBufferSize > 0)
+      if (reuseBufferSize > 0)
       {
          file.getFile().setBufferCallback(buffersControl.callback);
       }
@@ -2018,7 +2024,9 @@
    private JournalFile enqueueOpenFile() throws InterruptedException
    {
       if (trace)
+      {
          trace("enqueueOpenFile with openedFiles.size=" + openedFiles.size());
+      }
 
       filesExecutor.execute(new Runnable()
       {
@@ -2136,7 +2144,7 @@
    {
       if (fileFactory.isSupportsCallbacks() && syncTransactional)
       {
-         TransactionCallback callback = this.transactionCallbacks.get(transactionId);
+         TransactionCallback callback = transactionCallbacks.get(transactionId);
 
          if (callback == null)
          {
@@ -2293,7 +2301,7 @@
             int alignedSize = fileFactory.calculateBlockSize(size);
 
             // Try getting a buffer from the queue...
-            ByteBuffer buffer = this.reuseBuffers.poll();
+            ByteBuffer buffer = reuseBuffers.poll();
 
             if (buffer == null)
             {
@@ -2318,7 +2326,7 @@
 
       private class LocalBufferCallback implements BufferCallback
       {
-         public void bufferDone(ByteBuffer buffer)
+         public void bufferDone(final ByteBuffer buffer)
          {
             bufferReuseLastTime = System.currentTimeMillis();
 

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -43,36 +43,36 @@
 public class NIOSequentialFile implements SequentialFile
 {
    private static final Logger log = Logger.getLogger(NIOSequentialFile.class);
-   
-   private String journalDir;
-   
-   private String fileName;
-   
+
+   private final String journalDir;
+
+   private final String fileName;
+
    private File file;
-   
+
    private FileChannel channel;
-   
+
    private RandomAccessFile rfile;
-   
+
    BufferCallback bufferCallback;
-   
+
    public NIOSequentialFile(final String journalDir, final String fileName)
    {
       this.journalDir = journalDir;
-      
-      this.fileName = fileName;   
+
+      this.fileName = fileName;
    }
-   
+
    public int getAlignment()
    {
       return 1;
    }
-   
+
    public int calculateBlockStart(final int position) throws Exception
    {
       return position;
-   }	
-   
+   }
+
    public String getFileName()
    {
       return fileName;
@@ -81,69 +81,67 @@
    public synchronized void open() throws Exception
    {
       file = new File(journalDir + "/" + fileName);
-      
+
       rfile = new RandomAccessFile(file, "rw");
-      
-      channel = rfile.getChannel();    
+
+      channel = rfile.getChannel();
    }
-   
-   public void open(int currentMaxIO) throws Exception
+
+   public void open(final int currentMaxIO) throws Exception
    {
       open();
    }
-   
-   
-   
-   public void setBufferCallback(BufferCallback callback)
+
+   public void setBufferCallback(final BufferCallback callback)
    {
-      this.bufferCallback = callback;
+      bufferCallback = callback;
    }
 
    public void fill(final int position, final int size, final byte fillCharacter) throws Exception
    {
       ByteBuffer bb = ByteBuffer.allocateDirect(size);
-      
+
       for (int i = 0; i < size; i++)
       {
-         bb.put(fillCharacter);        
+         bb.put(fillCharacter);
       }
-      
+
       bb.flip();
-      
+
       channel.position(position);
-      
+
       channel.write(bb);
-      
-      channel.force(false);   
-      
+
+      channel.force(false);
+
       channel.position(0);
    }
-   
+
    public void close() throws Exception
    {
       channel.close();
-      
+
       rfile.close();
-      
+
       channel = null;
-      
+
       rfile = null;
-      
+
       file = null;
    }
-   
+
    public void delete() throws Exception
-   {     
+   {
       file.delete();
-      
-      close();    
+
+      close();
    }
-   
+
    public int read(final ByteBuffer bytes) throws Exception
    {
       return read(bytes, null);
    }
-   
+
    public int read(final ByteBuffer bytes, final IOCallback callback) throws Exception
    {
       try
@@ -162,35 +160,35 @@
          {
             callback.onError(-1, e.getLocalizedMessage());
          }
-         
+
          throw e;
       }
-      
+
    }
-   
+
    public int write(final ByteBuffer bytes, final boolean sync) throws Exception
    {
       int bytesRead = channel.write(bytes);
-      
+
       if (sync)
       {
          sync();
       }
-      
+
       if (bufferCallback != null)
       {
          bufferCallback.bufferDone(bytes);
       }
-      
+
       return bytesRead;
    }
-   
+
    public int write(final ByteBuffer bytes, final IOCallback callback) throws Exception
    {
       try
       {
          int bytesRead = channel.write(bytes);
-         
+
          if (callback != null)
          {
             callback.done();
@@ -200,8 +198,7 @@
          {
             bufferCallback.bufferDone(bytes);
          }
-         
-         
+
          return bytesRead;
       }
       catch (Exception e)
@@ -210,26 +207,25 @@
          throw e;
       }
    }
-      
+
    public void sync() throws Exception
    {
       channel.force(false);
    }
-   
+
    public long size() throws Exception
    {
       return channel.size();
    }
 
-   
    public void position(final int pos) throws Exception
    {
       channel.position(pos);
    }
-   
+
    public int position() throws Exception
    {
-      return (int) channel.position();
+      return (int)channel.position();
    }
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFileFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFileFactory.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFileFactory.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -35,34 +35,34 @@
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  */
-public class NIOSequentialFileFactory extends AbstractSequentialFactory implements SequentialFileFactory 
+public class NIOSequentialFileFactory extends AbstractSequentialFactory implements SequentialFileFactory
 {
    public NIOSequentialFileFactory(final String journalDir)
    {
       super(journalDir);
-   }	
-   
+   }
+
    // maxIO is ignored on NIO
    public SequentialFile createSequentialFile(final String fileName, final int maxIO)
    {
       return new NIOSequentialFile(journalDir, fileName);
    }
-   
+
    public boolean isSupportsCallbacks()
    {
       return false;
    }
-   
+
    public ByteBuffer newBuffer(final int size)
    {
       return ByteBuffer.allocate(size);
    }
-   
+
    public void clearBuffer(final ByteBuffer buffer)
    {
       final int limit = buffer.limit();
       buffer.rewind();
-      
+
       for (int i = 0; i < limit; i++)
       {
          buffer.put((byte)0);
@@ -70,21 +70,20 @@
 
       buffer.rewind();
    }
-   
+
    public ByteBuffer wrapBuffer(final byte[] bytes)
    {
       return ByteBuffer.wrap(bytes);
    }
-   
+
    public int getAlignment()
    {
       return 1;
    }
 
-   public int calculateBlockSize(int bytes)
+   public int calculateBlockSize(final int bytes)
    {
       return bytes;
    }
-   
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/Reclaimer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/Reclaimer.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/Reclaimer.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,13 +18,12 @@
  * 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.journal.impl;
 
 import org.jboss.messaging.core.logging.Logger;
 
-
 /**
  * 
  * <p>A ReclaimerTest</p>
@@ -50,24 +49,24 @@
 public class Reclaimer
 {
    private static final Logger log = Logger.getLogger(Reclaimer.class);
-   
+
    private static boolean trace = log.isTraceEnabled();
-   
-   private static void trace(String message)
+
+   private static void trace(final String message)
    {
       log.trace(message);
    }
-   
+
    public void scan(final JournalFile[] files)
    {
       for (int i = 0; i < files.length; i++)
       {
-         //First we evaluate criterion 1)
-         
+         // First we evaluate criterion 1)
+
          JournalFile currentFile = files[i];
-         
+
          int posCount = currentFile.getPosCount();
-         
+
          int totNeg = 0;
 
          if (trace)
@@ -84,27 +83,27 @@
                   trace("Negative from " + files[j] + " = " + files[j].getNegCount(currentFile));
                }
             }
-            
+
             totNeg += files[j].getNegCount(currentFile);
          }
-         
+
          currentFile.setCanReclaim(true);
-         
+
          if (posCount <= totNeg)
-         {   		
-            //Now we evaluate criterion 2)
-            
+         {
+            // Now we evaluate criterion 2)
+
             for (int j = 0; j <= i; j++)
             {
                JournalFile file = files[j];
-               
+
                int negCount = currentFile.getNegCount(file);
-               
+
                if (negCount != 0)
                {
                   if (file.isCanReclaim())
                   {
-                     //Ok
+                     // Ok
                   }
                   else
                   {
@@ -112,18 +111,18 @@
                      {
                         trace(currentFile + " Can't be reclaimed because " + file + " has negative values");
                      }
-                     
+
                      currentFile.setCanReclaim(false);
-                     
+
                      break;
                   }
                }
-            }   		
+            }
          }
          else
          {
             currentFile.setCanReclaim(false);
-         }			
-      }			
+         }
+      }
    }
 }

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/TransactionHolder.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/TransactionHolder.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/TransactionHolder.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl;
 
@@ -40,19 +40,19 @@
 {
    public TransactionHolder(final long id)
    {
-      this.transactionID = id;
+      transactionID = id;
    }
-   
+
    public final long transactionID;
-   
+
    public final List<RecordInfo> recordInfos = new ArrayList<RecordInfo>();
-   
+
    public final List<RecordInfo> recordsToDelete = new ArrayList<RecordInfo>();
-   
+
    public boolean prepared;
-   
+
    public boolean invalid;
 
    public byte[] extraData;
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/LastPageRecord.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/LastPageRecord.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/LastPageRecord.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging;
 
 import org.jboss.messaging.core.journal.EncodingSupport;
@@ -35,17 +34,17 @@
  */
 public interface LastPageRecord extends EncodingSupport
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    /** Internal field with the primary key, used on the journal/database */
    long getRecordId();
 
@@ -61,13 +60,13 @@
 
    /** Last Page ID*/
    void setLastId(long lastId);
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/Page.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/Page.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/Page.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,10 +20,8 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging;
 
-
 /**
  * 
  * <p>Look at the <a href="http://wiki.jboss.org/auth/wiki/JBossMessaging2Paging">WIKI</a> for more information.</p>
@@ -33,23 +31,23 @@
  */
 public interface Page
 {
-   
+
    int getPageId();
-   
+
    void write(PageMessage message) throws Exception;
-   
+
    PageMessage[] read() throws Exception;
-   
+
    int getSize();
-   
+
    int getNumberOfMessages();
-   
+
    void sync() throws Exception;
-   
+
    void open() throws Exception;
-   
+
    void close() throws Exception;
-   
+
    void delete() throws Exception;
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/PageMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/PageMessage.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/PageMessage.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,13 +20,11 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging;
 
 import org.jboss.messaging.core.journal.EncodingSupport;
 import org.jboss.messaging.core.server.ServerMessage;
 
-
 /**
  * 
  * The record taken by Page.

Modified: trunk/src/main/org/jboss/messaging/core/paging/PageTransactionInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/PageTransactionInfo.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/PageTransactionInfo.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging;
 
 import org.jboss.messaging.core.journal.EncodingSupport;
@@ -36,9 +35,9 @@
 {
 
    boolean waitCompletion() throws Exception;
-   
+
    void complete();
-   
+
    void forget();
 
    long getRecordID();
@@ -46,13 +45,13 @@
    void setRecordID(long id);
 
    long getTransactionID();
-   
+
    int increment();
-   
+
    int decrement();
-   
+
    int getNumberOfMessages();
-   
+
    void markIncomplete();
 
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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;
 
@@ -40,21 +40,20 @@
 public interface PagingManager extends MessagingComponent
 {
 
-   
    boolean isGlobalPageMode();
-   
+
    /** To return the PageStore associated with the address */
    PagingStore getPageStore(SimpleString address) throws Exception;
-   
+
    /** An injection point for the PostOffice to inject itself */
    void setPostOffice(PostOffice postOffice);
-   
+
    /**
     * @param pagingStoreImpl 
     * @return false if the listener can't handle more pages
     */
    boolean onDepage(int pageId, SimpleString destination, PagingStore pagingStoreImpl, PageMessage[] data) throws Exception;
-   
+
    /**
     * To be used by transactions only.
     * If you're sure you will page if isPaging, just call the method page and look at its return. 
@@ -62,47 +61,45 @@
     * @return
     */
    boolean isPaging(SimpleString destination) throws Exception;
-   
+
    /**
     * Page, only if destination is in page mode.
     * @param message
     * @return false if destination is not on page mode
     */
    boolean page(ServerMessage message) throws Exception;
-   
+
    /**
     * Page, only if destination is in page mode.
     * @param message
     * @return false if destination is not on page mode
     */
    boolean page(ServerMessage message, long transactionId) throws Exception;
-   
+
    /**
     * Point to inform/restoring Transactions used when the messages were added into paging
     * */
    void addTransaction(PageTransactionInfo pageTransaction);
-   
-   
+
    /**
     * Use this method to inform when a transaction was completed.
     * @param transactionId
     */
    void completeTransaction(long transactionId);
-   
-   
+
    /**
     * 
     * Duplication detection for paging processing
     *  */
    void setLastPage(LastPageRecord lastPage) throws Exception;
-   
+
    /** 
     * 
     * To be called when there are no more references to the message
     * @param message
     */
    void messageDone(ServerMessage message) throws Exception;
-   
+
    /** To be called when an message is being added to the address.
     *  @return the current size of the queue, or -1 if the queue is full and it should drop the message */
    long addSize(ServerMessage message) throws Exception;
@@ -116,7 +113,5 @@
     * @throws Exception 
     * */
    void clearLastPageRecord(LastPageRecord lastRecord) throws Exception;
-   
-   
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/PagingStore.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/PagingStore.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/PagingStore.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging;
 
 import org.jboss.messaging.core.server.MessagingComponent;
@@ -39,37 +38,37 @@
  */
 public interface PagingStore extends MessagingComponent
 {
-   
+
    int getNumberOfPages();
-   
+
    SimpleString getStoreName();
-   
-   /** Maximum number of bytes allowed in memory */ 
+
+   /** Maximum number of bytes allowed in memory */
    long getMaxSizeBytes();
-   
+
    boolean isDroppedMessage();
-   
+
    void setDroppedMessage(boolean droppedMessages);
-   
+
    boolean isDropWhenMaxSize();
-   
+
    long getPageSizeBytes();
-   
+
    long getAddressSize();
-   
+
    long addAddressSize(long add);
-   
+
    /** @return true if paging was started, or false if paging was already started before this call */
    boolean startPaging() throws Exception;
-   
+
    boolean isPaging();
-   
+
    void sync() throws Exception;
-   
+
    public boolean readPage() throws Exception;
-   
+
    boolean page(PageMessage message) throws Exception;
-   
+
    /** 
     * Remove the first page from the Writing Queue.
     * The file will still exist until Page.delete is called, 
@@ -78,7 +77,7 @@
     * @throws Exception 
     */
    Page depage() throws Exception;
-   
+
    /**
     * 
     * @return false if a thread was already started, or if not in page mode

Modified: trunk/src/main/org/jboss/messaging/core/paging/PagingStoreFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/PagingStoreFactory.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/PagingStoreFactory.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,15 +20,12 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging;
 
 import java.util.concurrent.Executor;
 
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 
-
-
 /**
  * The integration point between the PagingManger and the File System (aka SequentialFiles)
  * 
@@ -39,9 +36,9 @@
 {
 
    PagingStore newStore(org.jboss.messaging.util.SimpleString destinationName, QueueSettings queueSettings);
-   
+
    Executor getPagingExecutor();
-   
+
    void setPagingManager(PagingManager manager);
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/LastPageRecordImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/LastPageRecordImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/LastPageRecordImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import org.jboss.messaging.core.paging.LastPageRecord;
@@ -34,22 +33,21 @@
  */
 public class LastPageRecordImpl implements LastPageRecord
 {
-   
-    // Constants -----------------------------------------------------
-   
+
+   // Constants -----------------------------------------------------
+
    // Attributes ----------------------------------------------------
-   
-   
+
    private long recordId = 0;
+
    private SimpleString destination;
+
    private long lastId;
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
-   
-   
+
    // Public --------------------------------------------------------
 
    public LastPageRecordImpl(final long lastId, final SimpleString destination)
@@ -93,32 +91,30 @@
    {
       this.lastId = lastId;
    }
-   
-   
+
    public void decode(final MessagingBuffer buffer)
    {
       lastId = buffer.getLong();
       destination = buffer.getSimpleString();
    }
-   
+
    public void encode(final MessagingBuffer buffer)
    {
       buffer.putLong(lastId);
       buffer.putSimpleString(destination);
    }
-   
+
    public int getEncodeSize()
    {
-      return 8  + SimpleString.sizeofString(destination);
+      return 8 + SimpleString.sizeofString(destination);
    }
 
-
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PageImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import java.nio.ByteBuffer;
@@ -42,36 +41,42 @@
  */
 public class PageImpl implements Page
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    private static final int SIZE_INTEGER = 4;
-   
+
    private static final int SIZE_BYTE = 1;
-   
-   public static final int SIZE_RECORD = SIZE_BYTE + SIZE_INTEGER + SIZE_BYTE; 
-   
-   public static final byte START_BYTE= (byte)'{';
-   public static final byte END_BYTE= (byte)'}';
-   
+
+   public static final int SIZE_RECORD = SIZE_BYTE + SIZE_INTEGER + SIZE_BYTE;
+
+   public static final byte START_BYTE = (byte)'{';
+
+   public static final byte END_BYTE = (byte)'}';
+
    // Attributes ----------------------------------------------------
-   
+
    private final int pageId;
+
    private final AtomicInteger numberOfMessages = new AtomicInteger(0);
+
    private final SequentialFile file;
+
    private final SequentialFileFactory fileFactory;
+
    private final PagingCallback callback;
+
    private final AtomicInteger size = new AtomicInteger(0);
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
-   public PageImpl(final SequentialFileFactory factory, final SequentialFile file,final int pageId) throws Exception
+
+   public PageImpl(final SequentialFileFactory factory, final SequentialFile file, final int pageId) throws Exception
    {
       this.pageId = pageId;
       this.file = file;
-      this.fileFactory = factory;
+      fileFactory = factory;
       if (factory.isSupportsCallbacks())
       {
          callback = new PagingCallback();
@@ -81,36 +86,33 @@
          callback = null;
       }
    }
-   
-   
+
    // Public --------------------------------------------------------
 
-   
    // PagingFile implementation
-   
-   
+
    public int getPageId()
    {
       return pageId;
    }
-   
+
    public PageMessage[] read() throws Exception
    {
-      
+
       ArrayList<PageMessage> messages = new ArrayList<PageMessage>();
 
       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())
@@ -125,21 +127,21 @@
                }
                else
                {
-                  buffer.position(position + 1); 
+                  buffer.position(position + 1);
                }
             }
          }
          else
          {
-            buffer.position(position + 1); 
+            buffer.position(position + 1);
          }
       }
-      
+
       numberOfMessages.set(messages.size());
-      
+
       return messages.toArray(instantiateArray(messages.size()));
    }
-   
+
    public void write(final PageMessage message) throws Exception
    {
       ByteBuffer buffer = fileFactory.newBuffer(message.getEncodeSize() + SIZE_RECORD);
@@ -158,12 +160,12 @@
       {
          file.write(buffer, false);
       }
-      
+
       numberOfMessages.incrementAndGet();
       size.addAndGet(buffer.limit());
-      
+
    }
-   
+
    public void sync() throws Exception
    {
       if (callback != null)
@@ -175,89 +177,87 @@
          file.sync();
       }
    }
-   
+
    public void open() throws Exception
    {
       file.open();
-      this.size.set((int)file.size());
+      size.set((int)file.size());
       file.position(0);
    }
-   
+
    public void close() throws Exception
    {
       file.close();
    }
-   
+
    public void delete() throws Exception
    {
       file.delete();
    }
-   
+
    public int getNumberOfMessages()
    {
       return numberOfMessages.intValue();
    }
-   
+
    public int getSize()
    {
-      return this.size.intValue();
+      return size.intValue();
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
-   protected  PageMessage instantiateObject()
+
+   protected PageMessage instantiateObject()
    {
       return new PageMessageImpl();
    }
 
-   
    protected PageMessage[] instantiateArray(final int size)
    {
       return new PageMessage[size];
    }
-   
+
    // 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();
       }
-      
+
    }
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PageMessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PageMessageImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PageMessageImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import org.jboss.messaging.core.paging.PageMessage;
@@ -37,36 +36,37 @@
  */
 public class PageMessageImpl implements PageMessage
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
 
    private final ServerMessage message;
+
    private long transactionID = -1;
-   
+
    public PageMessageImpl(final ServerMessage message, final long transactionID)
    {
       this.message = message;
       this.transactionID = transactionID;
    }
-   
+
    public PageMessageImpl(final ServerMessage message)
    {
       this.message = message;
    }
-   
+
    public PageMessageImpl()
    {
       this(new ServerMessageImpl());
    }
-   
+
    public ServerMessage getMessage()
    {
       return message;
@@ -76,8 +76,7 @@
    {
       return transactionID;
    }
-   
-   
+
    // EncodingSupport implementation --------------------------------
 
    public void decode(final MessagingBuffer buffer)
@@ -94,16 +93,16 @@
 
    public int getEncodeSize()
    {
-      
+
       return 8 + message.getEncodeSize();
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PageTransactionInfoImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PageTransactionInfoImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PageTransactionInfoImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import java.util.concurrent.CountDownLatch;
@@ -39,25 +38,27 @@
 {
 
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    private long transactionID;
+
    private long recordID;
+
    private CountDownLatch countDownCompleted;
+
    private volatile boolean complete;
-   
+
    final AtomicInteger numberOfMessages = new AtomicInteger(0);
-   
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    public PageTransactionInfoImpl(final long transactionID)
    {
       this.transactionID = transactionID;
-      this.countDownCompleted = new CountDownLatch(1);
+      countDownCompleted = new CountDownLatch(1);
    }
 
    public PageTransactionInfoImpl()
@@ -66,27 +67,26 @@
 
    // Public --------------------------------------------------------
 
-   
    public long getRecordID()
    {
       return recordID;
    }
-   
-   public void setRecordID(long recordID)
+
+   public void setRecordID(final long recordID)
    {
       this.recordID = recordID;
    }
-   
+
    public long getTransactionID()
    {
       return transactionID;
    }
-   
+
    public int increment()
    {
       return numberOfMessages.incrementAndGet();
    }
-   
+
    public int decrement()
    {
       final int value = numberOfMessages.decrementAndGet();
@@ -94,34 +94,36 @@
       {
          throw new IllegalStateException("Internal error Negative value on Paging transactions!");
       }
-      
+
       return value;
    }
-   
+
    public int getNumberOfMessages()
    {
       return numberOfMessages.get();
    }
-   
-   // EncodingSupport implementation 
-   
+
+   // EncodingSupport implementation
+
    public synchronized void decode(final MessagingBuffer buffer)
    {
-      this.transactionID = buffer.getLong();
-      this.numberOfMessages.set(buffer.getInt());
-      this.countDownCompleted = null; // if it is being readed, probably it was committed
-      this.complete = true;           // Unless it is a incomplete prepare, which is marked by markIcomplete
+      transactionID = buffer.getLong();
+      numberOfMessages.set(buffer.getInt());
+      countDownCompleted = null; // if it is being readed, probably it was
+                                 // committed
+      complete = true; // Unless it is a incomplete prepare, which is marked by
+                        // markIcomplete
    }
-   
+
    public synchronized void encode(final MessagingBuffer buffer)
    {
-      buffer.putLong(this.transactionID);
-      buffer.putInt(this.numberOfMessages.get());
+      buffer.putLong(transactionID);
+      buffer.putInt(numberOfMessages.get());
    }
 
    public synchronized int getEncodeSize()
    {
-      return 8 /* long */ + 4 /* int */;
+      return 8 /* long */+ 4 /* int */;
    }
 
    public void complete()
@@ -132,7 +134,7 @@
        */
       countDownCompleted.countDown();
    }
-   
+
    /** 
     * this is to avoid a race condition where the transaction still being committed another thread is depaging messages
     */
@@ -142,29 +144,29 @@
       {
          countDownCompleted.await();
       }
-      
+
       return complete;
    }
-   
+
    public void forget()
    {
       complete = false;
 
       countDownCompleted.countDown();
    }
-   
+
    public void markIncomplete()
    {
       complete = false;
       countDownCompleted = new CountDownLatch(1);
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerFactoryNIO.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerFactoryNIO.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerFactoryNIO.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import java.io.File;
@@ -44,65 +43,69 @@
  */
 public class PagingManagerFactoryNIO implements PagingStoreFactory
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    private final String directory;
-   
+
    private final Executor executor;
-   
+
    private PagingManager pagingManager;
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    public PagingManagerFactoryNIO(final String directory)
    {
       this.directory = directory;
-      this.executor = Executors.newCachedThreadPool(new JBMThreadFactory("JBM-depaging-threads"));
+      executor = Executors.newCachedThreadPool(new JBMThreadFactory("JBM-depaging-threads"));
    }
-   
+
    public PagingManagerFactoryNIO(final String directory, final Executor executor)
    {
       this.directory = directory;
       this.executor = executor;
    }
-   
+
    // Public --------------------------------------------------------
 
    public Executor getPagingExecutor()
    {
-      return this.executor;
+      return executor;
    }
-   
-   public PagingStore newStore(final SimpleString destinationName, QueueSettings settings)
+
+   public PagingStore newStore(final SimpleString destinationName, final QueueSettings settings)
    {
       final String destinationDirectory = directory + "/" + destinationName.toString();
       File destinationFile = new File(destinationDirectory);
       destinationFile.mkdirs();
-      
-      return new PagingStoreImpl(pagingManager, newFileFactory(destinationDirectory), destinationName, settings, executor);
+
+      return new PagingStoreImpl(pagingManager,
+                                 newFileFactory(destinationDirectory),
+                                 destinationName,
+                                 settings,
+                                 executor);
    }
-   
-   public void setPagingManager(PagingManager manager)
+
+   public void setPagingManager(final PagingManager manager)
    {
-      this.pagingManager = manager;
+      pagingManager = manager;
    }
 
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    protected SequentialFileFactory newFileFactory(final String destinationDirectory)
    {
       return new NIOSequentialFileFactory(destinationDirectory);
    }
 
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import java.util.ArrayList;
@@ -57,56 +56,55 @@
 public class PagingManagerImpl implements PagingManager
 {
 
-   
    // Constants -----------------------------------------------------
    private static final long WATERMARK_GLOBAL_PAGE = QueueSettings.DEFAULT_PAGE_SIZE_BYTES;
-   
+
    // Attributes ----------------------------------------------------
-   
-   
+
    private volatile boolean started = false;
-   
+
    private final long maxGlobalSize;
-   
+
    private final AtomicLong globalSize = new AtomicLong(0);
-   
+
    private final AtomicBoolean globalMode = new AtomicBoolean(false);
-   
+
    private final AtomicBoolean globalDepageRunning = new AtomicBoolean(false);
-   
+
    private final ConcurrentMap<SimpleString, PagingStore> stores = new ConcurrentHashMap<SimpleString, PagingStore>();
-   
+
    private final HierarchicalRepository<QueueSettings> queueSettingsRepository;
-   
+
    private final PagingStoreFactory pagingSPI;
-   
+
    private final StorageManager storageManager;
 
    private PostOffice postOffice;
-   
-   private final ConcurrentMap</*TransactionID*/ Long , PageTransactionInfo> transactions = new ConcurrentHashMap<Long, PageTransactionInfo>();
-   
 
-   
-   // Static --------------------------------------------------------------------------------------------------------------------------
+   private final ConcurrentMap</*TransactionID*/Long, PageTransactionInfo> transactions = new ConcurrentHashMap<Long, PageTransactionInfo>();
 
+   // Static
+   // --------------------------------------------------------------------------------------------------------------------------
+
    private static final Logger log = Logger.getLogger(PagingManagerImpl.class);
-   
-   //private static final boolean isTrace = log.isTraceEnabled();
+
+   // private static final boolean isTrace = log.isTraceEnabled();
    private static final boolean isTrace = true;
-   
+
    // This is just a debug tool method.
-   // During debugs you could make log.trace as log.info, and change the variable isTrace above
-   private static void trace(String message)
+   // During debugs you could make log.trace as log.info, and change the
+   // variable isTrace above
+   private static void trace(final String message)
    {
-      //log.trace(message);
+      // log.trace(message);
       log.info(message);
    }
-   
-   
-   // Constructors --------------------------------------------------------------------------------------------------------------------
-   
-   public PagingManagerImpl(final PagingStoreFactory pagingSPI, StorageManager storageManager, 
+
+   // Constructors
+   // --------------------------------------------------------------------------------------------------------------------
+
+   public PagingManagerImpl(final PagingStoreFactory pagingSPI,
+                            final StorageManager storageManager,
                             final HierarchicalRepository<QueueSettings> queueSettingsRepository,
                             final long maxGlobalSize)
    {
@@ -115,70 +113,75 @@
       this.storageManager = storageManager;
       this.maxGlobalSize = maxGlobalSize;
    }
-   
-   // Public ---------------------------------------------------------------------------------------------------------------------------
-   
-   // PagingManager implementation -----------------------------------------------------------------------------------------------------
-   
-   
+
+   // Public
+   // ---------------------------------------------------------------------------------------------------------------------------
+
+   // PagingManager implementation
+   // -----------------------------------------------------------------------------------------------------
+
    public boolean isGlobalPageMode()
    {
       return globalMode.get();
    }
-   
+
    public PagingStore getPageStore(final SimpleString storeName) throws Exception
    {
       validateStarted();
-      
+
       PagingStore store = stores.get(storeName);
       if (store == null)
       {
-         
+
          store = newStore(storeName);
-         
+
          PagingStore oldStore = stores.putIfAbsent(storeName, store);
-         
+
          if (oldStore != null)
          {
             store = oldStore;
          }
-         
+
          store.start();
       }
 
       return store;
-      
+
    }
-   
+
    /** this will be set by the postOffice itself.
     *  There is no way to set this on the constructor as the PagingManager is constructed before the postOffice.
     *  (There is a one-to-one relationship here) */
-   public void setPostOffice(PostOffice postOffice)
+   public void setPostOffice(final PostOffice postOffice)
    {
       this.postOffice = postOffice;
    }
 
-   public void clearLastPageRecord(LastPageRecord lastRecord) throws Exception
+   public void clearLastPageRecord(final LastPageRecord lastRecord) throws Exception
    {
       trace("Clearing lastRecord information " + lastRecord.getLastId());
       storageManager.storeDelete(lastRecord.getRecordId());
    }
-   
+
    /**
     * This method will remove files from the page system and add them into the journal, doing it transactionally
     * 
     * A Transaction will be opened only if persistent messages are used.
     * If persistent messages are also used, it will update eventual PageTransactions
     */
-   public boolean onDepage(int pageId, final SimpleString destination, PagingStore pagingStore, final PageMessage[] data) throws Exception
+   public boolean onDepage(final int pageId,
+                           final SimpleString destination,
+                           final PagingStore pagingStore,
+                           final PageMessage[] data) throws Exception
    {
       trace("Depaging....");
-      
-      /// Depage has to be done atomically, in case of failure it should be back to where it was
+
+      // / Depage has to be done atomically, in case of failure it should be
+      // back to where it was
       final long depageTransactionID = storageManager.generateTransactionID();
-      
-      LastPageRecord lastPage = pagingStore.getLastRecord(); 
-      
+
+      LastPageRecord lastPage = pagingStore.getLastRecord();
+
       if (lastPage == null)
       {
          lastPage = new LastPageRecordImpl(pageId, destination);
@@ -195,20 +198,21 @@
 
       lastPage.setLastId(pageId);
       storageManager.storeLastPage(depageTransactionID, lastPage);
-      
+
       HashSet<PageTransactionInfo> pageTransactionsToUpdate = new HashSet<PageTransactionInfo>();
 
       final List<MessageReference> refsToAdd = new ArrayList<MessageReference>();
-      
-      for (PageMessage msg: data)
+
+      for (PageMessage msg : data)
       {
          final long transactionIdDuringPaging = msg.getTransactionID();
          if (transactionIdDuringPaging >= 0)
          {
             final PageTransactionInfo pageTransactionInfo = transactions.get(transactionIdDuringPaging);
-            
+
             // http://wiki.jboss.org/auth/wiki/JBossMessaging2Paging
-            // This is the Step D described on the "Transactions on Paging" section
+            // This is the Step D described on the "Transactions on Paging"
+            // section
             if (pageTransactionInfo == null)
             {
                if (isTrace)
@@ -217,161 +221,159 @@
                }
                continue;
             }
-            
-            // This is to avoid a race condition where messages are depaged before the commit arrived
+
+            // This is to avoid a race condition where messages are depaged
+            // before the commit arrived
             if (!pageTransactionInfo.waitCompletion())
             {
                trace("Rollback was called after prepare, ignoring message " + msg.getMessage());
                continue;
             }
 
-            /// Update information about transactions
+            // / Update information about transactions
             if (msg.getMessage().isDurable())
             {
                pageTransactionInfo.decrement();
                pageTransactionsToUpdate.add(pageTransactionInfo);
             }
          }
-         
+
          msg.getMessage().setMessageID(storageManager.generateID());
 
          refsToAdd.addAll(postOffice.route(msg.getMessage()));
-         
+
          if (msg.getMessage().getDurableRefCount() != 0)
          {
             storageManager.storeMessageTransactional(depageTransactionID, msg.getMessage());
          }
       }
-      
-      
-      for (PageTransactionInfo pageWithTransaction: pageTransactionsToUpdate)
+
+      for (PageTransactionInfo pageWithTransaction : pageTransactionsToUpdate)
       {
          if (pageWithTransaction.getNumberOfMessages() == 0)
-         { 
+         {
             // http://wiki.jboss.org/auth/wiki/JBossMessaging2Paging
             // numberOfReads==numberOfWrites -> We delete the record
             storageManager.storeDeleteTransactional(depageTransactionID, pageWithTransaction.getRecordID());
-            this.transactions.remove(pageWithTransaction.getTransactionID());
+            transactions.remove(pageWithTransaction.getTransactionID());
          }
          else
          {
             storageManager.storePageTransaction(depageTransactionID, pageWithTransaction);
          }
       }
-      
+
       storageManager.commit(depageTransactionID);
 
       for (MessageReference ref : refsToAdd)
       {
          ref.getQueue().addLast(ref);
       }
-      
-      
+
       if (globalMode.get())
       {
-         return globalSize.get() < maxGlobalSize -  WATERMARK_GLOBAL_PAGE &&
-                pagingStore.getMaxSizeBytes() <= 0 || pagingStore.getAddressSize() < pagingStore.getMaxSizeBytes();
+         return globalSize.get() < maxGlobalSize - WATERMARK_GLOBAL_PAGE && pagingStore.getMaxSizeBytes() <= 0 ||
+                pagingStore.getAddressSize() < pagingStore.getMaxSizeBytes();
       }
       else
       {
-         // If Max-size is not configured (-1) it will aways return true, as this method was probably called by global-depage
+         // If Max-size is not configured (-1) it will aways return true, as
+         // this method was probably called by global-depage
          return pagingStore.getMaxSizeBytes() <= 0 || pagingStore.getAddressSize() < pagingStore.getMaxSizeBytes();
       }
 
    }
-   
-   public void setLastPage(LastPageRecord lastPage) throws Exception
+
+   public void setLastPage(final LastPageRecord lastPage) throws Exception
    {
       trace("LastPage loaded was " + lastPage.getLastId() + " recordID = " + lastPage.getRecordId());
-      this.getPageStore(lastPage.getDestination()).setLastRecord(lastPage);
+      getPageStore(lastPage.getDestination()).setLastRecord(lastPage);
    }
 
-   public boolean isPaging(SimpleString destination) throws Exception
+   public boolean isPaging(final SimpleString destination) throws Exception
    {
-      return this.getPageStore(destination).isPaging();
+      return getPageStore(destination).isPaging();
    }
-   
-   public void messageDone(ServerMessage message) throws Exception
+
+   public void messageDone(final ServerMessage message) throws Exception
    {
       addSize(message.getDestination(), message.getMemoryEstimate() * -1);
    }
-   
+
    public long addSize(final ServerMessage message) throws Exception
    {
-      return addSize(message.getDestination(), message.getMemoryEstimate());      
+      return addSize(message.getDestination(), message.getMemoryEstimate());
    }
-   
-   public boolean page(ServerMessage message, long transactionId)
-         throws Exception
+
+   public boolean page(final ServerMessage message, final long transactionId) throws Exception
    {
-      return this.getPageStore(message.getDestination()).page(new PageMessageImpl(message, transactionId));
+      return getPageStore(message.getDestination()).page(new PageMessageImpl(message, transactionId));
    }
 
-
-   public boolean page(ServerMessage message) throws Exception
+   public boolean page(final ServerMessage message) throws Exception
    {
-      return this.getPageStore(message.getDestination()).page(new PageMessageImpl(message));
+      return getPageStore(message.getDestination()).page(new PageMessageImpl(message));
    }
 
-   
-   public void addTransaction(PageTransactionInfo pageTransaction)
+   public void addTransaction(final PageTransactionInfo pageTransaction)
    {
-      this.transactions.put(pageTransaction.getTransactionID(), pageTransaction);
+      transactions.put(pageTransaction.getTransactionID(), pageTransaction);
    }
 
-   public void completeTransaction(long transactionId)
+   public void completeTransaction(final long transactionId)
    {
-      PageTransactionInfo pageTrans = this.transactions.get(transactionId);
-      
-      // If nothing was paged.. we just remove the information to avoid memory leaks
+      PageTransactionInfo pageTrans = transactions.get(transactionId);
+
+      // If nothing was paged.. we just remove the information to avoid memory
+      // leaks
       if (pageTrans.getNumberOfMessages() == 0)
       {
-         this.transactions.remove(pageTrans);
+         transactions.remove(pageTrans);
       }
    }
-   
-   public void sync(Collection<SimpleString> destinationsToSync) throws Exception
+
+   public void sync(final Collection<SimpleString> destinationsToSync) throws Exception
    {
-      for (SimpleString destination: destinationsToSync)
+      for (SimpleString destination : destinationsToSync)
       {
-         this.getPageStore(destination).sync();
+         getPageStore(destination).sync();
       }
    }
-   
-   // MessagingComponent implementation ------------------------------------------------------------------------------------------------
-   
+
+   // MessagingComponent implementation
+   // ------------------------------------------------------------------------------------------------
+
    public boolean isStarted()
    {
       return started;
    }
-   
+
    public void start() throws Exception
    {
-      this.started = true;      
+      started = true;
    }
-   
+
    public void stop() throws Exception
    {
-      this.started = false;
-      
-      for (PagingStore store: stores.values())
+      started = false;
+
+      for (PagingStore store : stores.values())
       {
          store.stop();
       }
    }
-   
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    private PagingStore newStore(final SimpleString destinationName)
    {
-      return pagingSPI.newStore(destinationName, this.queueSettingsRepository.getMatch(destinationName.toString()));
+      return pagingSPI.newStore(destinationName, queueSettingsRepository.getMatch(destinationName.toString()));
    }
-   
+
    private void validateStarted()
    {
       if (!started)
@@ -380,27 +382,26 @@
       }
    }
 
-   
    private long addSize(final SimpleString destination, final long size) throws Exception
    {
-      final PagingStore store = this.getPageStore(destination);
-      
+      final PagingStore store = getPageStore(destination);
+
       final long maxSize = store.getMaxSizeBytes();
-      
+
       final long pageSize = store.getPageSizeBytes();
 
-      
       if (store.isDropWhenMaxSize() && size > 0)
       {
-         // if destination configured to drop messages && size is over the limit, we return -1 what means drop the message
-         if ((store.getAddressSize() + size > maxSize) || (maxGlobalSize > 0 && (globalSize.get() + size > maxGlobalSize)))
+         // if destination configured to drop messages && size is over the
+         // limit, we return -1 what means drop the message
+         if (store.getAddressSize() + size > maxSize || maxGlobalSize > 0 && globalSize.get() + size > maxGlobalSize)
          {
             if (!store.isDroppedMessage())
             {
                store.setDroppedMessage(true);
                log.warn("Messages are being dropped on adress " + store.getStoreName());
             }
-            
+
             return -1l;
          }
          else
@@ -410,14 +411,14 @@
       }
       else
       {
-         
+
          long currentGlobalSize = globalSize.addAndGet(size);
-         
+
          final long addressSize = store.addAddressSize(size);
 
          if (size > 0)
          {
-            if ((maxGlobalSize > 0 && (currentGlobalSize > maxGlobalSize)))
+            if (maxGlobalSize > 0 && currentGlobalSize > maxGlobalSize)
             {
                globalMode.set(true);
                if (store.startPaging())
@@ -428,8 +429,7 @@
                   }
                }
             }
-            else
-            if ((maxSize > 0 && (addressSize > maxSize)))
+            else if (maxSize > 0 && addressSize > maxSize)
             {
                if (store.startPaging())
                {
@@ -442,13 +442,13 @@
          }
          else
          {
-            // When in Global mode, we use the default page size as the minimal watermark to start depage
+            // When in Global mode, we use the default page size as the minimal
+            // watermark to start depage
             if (globalMode.get() && currentGlobalSize < maxGlobalSize - QueueSettings.DEFAULT_PAGE_SIZE_BYTES)
             {
                startGlobalDepage();
             }
-            else
-            if ( maxSize > 0 && addressSize < (maxSize - pageSize))
+            else if (maxSize > 0 && addressSize < maxSize - pageSize)
             {
                if (store.startDepaging())
                {
@@ -456,12 +456,11 @@
                }
             }
          }
-         
+
          return addressSize;
       }
    }
 
-
    private void startGlobalDepage()
    {
       if (globalDepageRunning.compareAndSet(false, true))
@@ -471,10 +470,8 @@
       }
    }
 
-   
    // Inner classes -------------------------------------------------
-   
-   
+
    class GlobalDepager implements Runnable
    {
       public void run()
@@ -484,7 +481,8 @@
             while (globalSize.get() < maxGlobalSize)
             {
                boolean depaged = false;
-               // Round robin depaging one page at the time from each destination
+               // Round robin depaging one page at the time from each
+               // destination
                for (PagingStore store : stores.values())
                {
                   if (globalSize.get() < maxGlobalSize)
@@ -508,10 +506,10 @@
                   break;
                }
             }
-            
+
             if (globalSize.get() < maxGlobalSize)
             {
-               
+
                globalMode.set(false);
                // Clearing possible messages still in page-mode
                for (PagingStore store : stores.values())
@@ -522,10 +520,10 @@
          }
          finally
          {
-            PagingManagerImpl.this.globalDepageRunning.set(false);
+            globalDepageRunning.set(false);
          }
       }
-      
+
    }
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import java.text.DecimalFormat;
@@ -39,6 +38,7 @@
 import org.jboss.messaging.core.paging.Page;
 import org.jboss.messaging.core.paging.PageMessage;
 import org.jboss.messaging.core.paging.PagingManager;
+import org.jboss.messaging.core.paging.PagingStore;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.jboss.messaging.util.SimpleString;
 
@@ -54,96 +54,101 @@
 
    // Constants -----------------------------------------------------
    private static final Logger log = Logger.getLogger(PagingStoreImpl.class);
-   
+
    // Attributes ----------------------------------------------------
-   
+
    private final DecimalFormat format = new DecimalFormat("000000000");
-   
+
    private final AtomicInteger pageUsedSize = new AtomicInteger(0);
-   
+
    private final SimpleString storeName;
-   
+
    private final SequentialFileFactory fileFactory;
-   
+
    private final long maxSize;
-   
+
    private final long pageSize;
-   
+
    private final boolean dropMessagesOnSize;
-   
+
    private boolean droppedMessages;
-   
+
    private final PagingManager pagingManager;
-   
+
    private final Executor executor;
-   
+
    // Bytes consumed by the queue on the memory
    private final AtomicLong sizeInBytes = new AtomicLong();
-   
+
    private volatile Runnable dequeueThread;
+
    private volatile int numberOfPages;
+
    private volatile int firstPageId = Integer.MAX_VALUE;
+
    private volatile int currentPageId;
+
    private volatile Page currentPage;
 
-   // positioningGlobalLock protects opening/closing and messing up with positions (currentPage and IDs)
-   private final Semaphore positioningGlobalLock = new Semaphore(1); 
+   // positioningGlobalLock protects opening/closing and messing up with
+   // positions (currentPage and IDs)
+   private final Semaphore positioningGlobalLock = new Semaphore(1);
 
    private final ReadWriteLock lock = new ReentrantReadWriteLock();
+
    private volatile boolean initialized = false;
 
    private volatile LastPageRecord lastPageRecord;
-   
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
-   
-   public PagingStoreImpl(final PagingManager pagingManager, final SequentialFileFactory fileFactory, final SimpleString storeName, QueueSettings queueSettings, Executor executor) 
+
+   public PagingStoreImpl(final PagingManager pagingManager,
+                          final SequentialFileFactory fileFactory,
+                          final SimpleString storeName,
+                          final QueueSettings queueSettings,
+                          final Executor executor)
    {
       this.fileFactory = fileFactory;
       this.storeName = storeName;
-      this.maxSize = queueSettings.getMaxSizeBytes();
-      this.pageSize = queueSettings.getPageSizeBytes();
-      this.dropMessagesOnSize = queueSettings.isDropMessagesWhenFull();
+      maxSize = queueSettings.getMaxSizeBytes();
+      pageSize = queueSettings.getPageSizeBytes();
+      dropMessagesOnSize = queueSettings.isDropMessagesWhenFull();
       this.executor = executor;
       this.pagingManager = pagingManager;
    }
-   
-   
+
    // Public --------------------------------------------------------
 
    // PagingStore implementation ------------------------------------
-   
-   
+
    public boolean isDroppedMessage()
    {
       return droppedMessages;
    }
-   
-   public void setDroppedMessage(boolean droppedMessages)
+
+   public void setDroppedMessage(final boolean droppedMessages)
    {
       this.droppedMessages = droppedMessages;
    }
 
-   
    public long getAddressSize()
    {
       return sizeInBytes.get();
    }
-   
-   public long addAddressSize(long delta)
+
+   public long addAddressSize(final long delta)
    {
       return sizeInBytes.addAndGet(delta);
    }
 
-   /** Maximum number of bytes allowed in memory */ 
+   /** Maximum number of bytes allowed in memory */
    public long getMaxSizeBytes()
    {
       return maxSize;
    }
-   
+
    public boolean isDropWhenMaxSize()
    {
       return dropMessagesOnSize;
@@ -154,7 +159,6 @@
       return pageSize;
    }
 
-   
    public boolean isPaging()
    {
       lock.readLock().lock();
@@ -167,18 +171,16 @@
          lock.readLock().unlock();
       }
    }
-   
+
    public int getNumberOfPages()
    {
       return numberOfPages;
    }
-   
+
    public SimpleString getStoreName()
    {
       return storeName;
    }
-   
-   
 
    /**
     * Depage one page-file, read it and send it to the pagingManager / postoffice
@@ -199,14 +201,13 @@
       }
       page.open();
       PageMessage messages[] = page.read();
-      boolean addressNotFull = pagingManager.onDepage(page.getPageId(), PagingStoreImpl.this.storeName, PagingStoreImpl.this, messages);
+      boolean addressNotFull = pagingManager.onDepage(page.getPageId(), storeName, PagingStoreImpl.this, messages);
       page.delete();
-      
+
       return addressNotFull;
 
    }
-   
-   
+
    /** 
     *  It returns a Page out of the Page System without reading it. 
     *  The method calling this method will remove the page and will start reading it outside of any locks. 
@@ -215,13 +216,15 @@
    public Page depage() throws Exception
    {
       validateInit();
-      
-      positioningGlobalLock.acquire(); // Can't change currentPage or any of ids without a global lock
-      lock.writeLock().lock();  // Wait pending writes to finish before entering the block
-      
+
+      positioningGlobalLock.acquire(); // Can't change currentPage or any of ids
+                                       // without a global lock
+      lock.writeLock().lock(); // Wait pending writes to finish before
+                                 // entering the block
+
       try
       {
-         
+
          if (numberOfPages == 0)
          {
             return null;
@@ -230,7 +233,7 @@
          {
 
             numberOfPages--;
-            
+
             final Page returnPage;
             if (currentPageId == firstPageId)
             {
@@ -247,7 +250,7 @@
                   // sanity check... it shouldn't happen!
                   throw new IllegalStateException("CurrentPage is null");
                }
-               
+
                if (returnPage.getNumberOfMessages() == 0)
                {
                   returnPage.open();
@@ -259,15 +262,13 @@
                   openNewPage();
                }
 
-               
-               
                return returnPage;
             }
             else
             {
-               returnPage =  createPage(firstPageId++);
+               returnPage = createPage(firstPageId++);
             }
-            
+
             return returnPage;
          }
       }
@@ -276,36 +277,40 @@
          lock.writeLock().unlock();
          positioningGlobalLock.release();
       }
-      
+
    }
 
    public boolean page(final PageMessage message) throws Exception
    {
       validateInit();
-      
-      // Max-size is set, but reject is activated, what means.. never page on this address
+
+      // Max-size is set, but reject is activated, what means.. never page on
+      // this address
       if (dropMessagesOnSize)
       {
          return false;
       }
-      
+
       int bytesToWrite = fileFactory.calculateBlockSize(message.getEncodeSize() + PageImpl.SIZE_RECORD);
-      
-      
-      // The only thing single-threaded done on paging is positioning and check-files (verifying if we need to open a new page file)
+
+      // The only thing single-threaded done on paging is positioning and
+      // check-files (verifying if we need to open a new page file)
       positioningGlobalLock.acquire();
 
-      // After we have it locked we keep all the threads working until we need to move to a new file (in which case we demand a writeLock, to wait for the writes to finish)
+      // After we have it locked we keep all the threads working until we need
+      // to move to a new file (in which case we demand a writeLock, to wait for
+      // the writes to finish)
       try
       {
          if (currentPage == null)
          {
             return false;
          }
-         
-         if ((pageUsedSize.addAndGet(bytesToWrite) > this.pageSize && currentPage.getNumberOfMessages() > 0))
+
+         if (pageUsedSize.addAndGet(bytesToWrite) > pageSize && currentPage.getNumberOfMessages() > 0)
          {
-            // Wait any pending write on the current page to finish before we can open another page.
+            // Wait any pending write on the current page to finish before we
+            // can open another page.
             lock.writeLock().lock();
             try
             {
@@ -318,9 +323,12 @@
             }
          }
          // we must get the readLock before we release the synchronizedBlockLock
-         // or else we could end up with files records being added to the currentPage even if the max size was already achieved.
-         // (Condition tested by PagingStoreTestPage::testConcurrentPaging, The test would eventually fail, 1 in 100)
-         // This is because the checkSize and positioning has to be done protected. We only allow writing the file in multi-thread.
+         // or else we could end up with files records being added to the
+         // currentPage even if the max size was already achieved.
+         // (Condition tested by PagingStoreTestPage::testConcurrentPaging, The
+         // test would eventually fail, 1 in 100)
+         // This is because the checkSize and positioning has to be done
+         // protected. We only allow writing the file in multi-thread.
          lock.readLock().lock();
 
       }
@@ -328,9 +336,9 @@
       {
          positioningGlobalLock.release();
       }
-      
+
       // End of a synchronized block..
-      
+
       try
       {
          if (currentPage != null)
@@ -348,13 +356,13 @@
          lock.readLock().unlock();
       }
    }
-   
+
    public void sync() throws Exception
    {
       validateInit();
-      
+
       lock.readLock().lock();
-      
+
       try
       {
          currentPage.sync();
@@ -364,7 +372,7 @@
          lock.readLock().unlock();
       }
    }
-   
+
    public boolean startDepaging()
    {
       lock.readLock().lock();
@@ -378,10 +386,10 @@
          {
             synchronized (this)
             {
-               if (this.dequeueThread == null)
+               if (dequeueThread == null)
                {
-                  this.dequeueThread = new DepageRunnable();
-                  executor.execute(this.dequeueThread);
+                  dequeueThread = new DepageRunnable();
+                  executor.execute(dequeueThread);
                   return true;
                }
                else
@@ -396,39 +404,36 @@
          lock.readLock().unlock();
       }
    }
-   
-   
+
    public LastPageRecord getLastRecord()
    {
       return lastPageRecord;
    }
 
-   public void setLastRecord(LastPageRecord record)
+   public void setLastRecord(final LastPageRecord record)
    {
-      this.lastPageRecord = record;
+      lastPageRecord = record;
    }
 
-   
-   
    // MessagingComponent implementation
-   
+
    public synchronized boolean isStarted()
    {
       return initialized;
    }
-   
+
    public synchronized void stop() throws Exception
    {
       if (initialized)
       {
          lock.writeLock().lock();
-         
+
          try
          {
             initialized = false;
             if (currentPage != null)
             {
-               currentPage.close();            
+               currentPage.close();
             }
          }
          finally
@@ -438,46 +443,47 @@
       }
    }
 
-   
    public synchronized void start() throws Exception
    {
 
       if (initialized)
       {
          // don't throw an exception.
-         // You could have two threads adding PagingStore to a ConcurrentHashMap,
-         // and having both threads calling init. One of the calls should just need to be ignored
+         // You could have two threads adding PagingStore to a
+         // ConcurrentHashMap,
+         // and having both threads calling init. One of the calls should just
+         // need to be ignored
          return;
-       }
-      
+      }
+
       lock.writeLock().lock();
-      
+
       firstPageId = Integer.MAX_VALUE;
       currentPageId = 0;
       currentPage = null;
-      
+
       try
       {
-         
+
          List<String> files = fileFactory.listFiles("page");
-         
+
          numberOfPages = files.size();
-         
-         for (String fileName: files)
+
+         for (String fileName : files)
          {
             final int fileId = getPageIdFromFileName(fileName);
-            
+
             if (fileId > currentPageId)
             {
                currentPageId = fileId;
             }
-            
+
             if (fileId < firstPageId)
             {
                firstPageId = fileId;
             }
          }
-         
+
          initialized = true;
 
          if (numberOfPages != 0)
@@ -490,12 +496,11 @@
          lock.writeLock().unlock();
       }
    }
-   
+
    public boolean startPaging() throws Exception
    {
       validateInit();
 
-      
       // First check without any global locks.
       // (Faster)
       lock.readLock().lock();
@@ -510,11 +515,11 @@
       {
          lock.readLock().unlock();
       }
-      
-      
-      // if the first check failed, we do it again under a global lock (positioningGlobalLock) this time
+
+      // if the first check failed, we do it again under a global lock
+      // (positioningGlobalLock) this time
       positioningGlobalLock.acquire();
-      
+
       try
       {
          if (currentPage == null)
@@ -532,57 +537,51 @@
          positioningGlobalLock.release();
       }
    }
-   
-   
-   
+
    // TestSupportPageStore ------------------------------------------
-   
+
    public void forceAnotherPage() throws Exception
    {
       validateInit();
       openNewPage();
    }
-   
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
-   
+
    // Private -------------------------------------------------------
 
-   
    private synchronized void clearDequeueThread()
    {
-      this.dequeueThread = null;
+      dequeueThread = null;
    }
-   
 
    private void openNewPage() throws Exception
    {
       lock.writeLock().lock();
-      
+
       try
       {
          numberOfPages++;
          currentPageId++;
-         
+
          if (currentPageId < firstPageId)
          {
             firstPageId = currentPageId;
          }
-         
+
          if (currentPage != null)
          {
             currentPage.close();
          }
-         
+
          currentPage = createPage(currentPageId);
-         
+
          pageUsedSize.set(0);
-         
+
          currentPage.open();
-         
+
       }
       finally
       {
@@ -590,28 +589,27 @@
       }
    }
 
-
    private Page createPage(final int page) throws Exception
    {
       String fileName = createFileName(page);
       SequentialFile file = fileFactory.createSequentialFile(fileName, 1000);
-      
+
       file.open();
-      
+
       long size = file.size();
-      
-      if (fileFactory.isSupportsCallbacks() && size < this.pageSize)
+
+      if (fileFactory.isSupportsCallbacks() && size < pageSize)
       {
          file.fill((int)size, (int)(pageSize - size), (byte)0);
       }
-      
+
       file.position(0);
-      
+
       file.close();
-      
+
       return new PageImpl(fileFactory, file, page);
    }
-   
+
    /**
     * 
     * Note: Decimalformat is not thread safe, Use synchronization before calling this method
@@ -619,33 +617,32 @@
     * @param pageID
     * @return
     */
-   private String createFileName(int pageID)
+   private String createFileName(final int pageID)
    {
       return format.format(pageID) + ".page";
    }
-   
-   private static int getPageIdFromFileName(String fileName)
+
+   private static int getPageIdFromFileName(final String fileName)
    {
       return Integer.parseInt(fileName.substring(0, fileName.indexOf('.')));
    }
-   
+
    private void validateInit()
    {
       if (!initialized)
       {
-         throw new IllegalStateException("PagingStore " + this.storeName + " not initialized!");
+         throw new IllegalStateException("PagingStore " + storeName + " not initialized!");
       }
    }
-   
+
    // Inner classes -------------------------------------------------
-   
+
    class DepageRunnable implements Runnable
    {
       public DepageRunnable()
       {
       }
-      
-      
+
       public void run()
       {
          try
@@ -663,9 +660,9 @@
          }
          finally
          {
-            PagingStoreImpl.this.clearDequeueThread();
+            clearDequeueThread();
          }
       }
    }
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/paging/impl/TestSupportPageStore.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/impl/TestSupportPageStore.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/src/main/org/jboss/messaging/core/paging/impl/TestSupportPageStore.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.core.paging.impl;
 
 import org.jboss.messaging.core.paging.PagingStore;

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/AIOTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/AIOTestBase.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/AIOTestBase.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.asyncio;
 
@@ -38,86 +38,93 @@
  */
 public abstract class AIOTestBase extends UnitTestCase
 {
-   // The AIO Test must use a local filesystem. Sometimes $HOME is on a NFS on most enterprise systems
-   protected String fileDir = System.getProperty("java.io.tmpdir", "/tmp") +  "/journal-test";
+   // The AIO Test must use a local filesystem. Sometimes $HOME is on a NFS on
+   // most enterprise systems
+   protected String fileDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test";
+
    protected String FILE_NAME = fileDir + "/fileUsedOnNativeTests.log";
-   
+
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
-      
+
       File file = new File(fileDir);
-      
+
       deleteDirectory(file);
-      
+
       file.mkdir();
-      
+
       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")));
+         fail(String.format("libAIO is not loaded on %s %s %s",
+                            System.getProperty("os.name"),
+                            System.getProperty("os.arch"),
+                            System.getProperty("os.version")));
       }
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
       assertEquals(0, AsynchronousFileImpl.getTotalMaxIO());
-      //deleteDirectory(new File(fileDir));
+      // deleteDirectory(new File(fileDir));
    }
-   
+
    protected void encodeBufer(final ByteBuffer buffer)
    {
       buffer.clear();
       int size = buffer.limit();
       for (int i = 0; i < size - 1; i++)
       {
-         buffer.put((byte) ('a' + (i % 20)));
+         buffer.put((byte)('a' + i % 20));
       }
-      
-      buffer.put((byte) '\n');
-      
+
+      buffer.put((byte)'\n');
+
    }
-   
-   protected void preAlloc(AsynchronousFileImpl controller, long size)
+
+   protected void preAlloc(final AsynchronousFileImpl controller, final long size)
    {
-      controller.fill(0l, 1, size, (byte) 0);
+      controller.fill(0l, 1, size, (byte)0);
    }
 
    protected static class CountDownCallback implements AIOCallback
    {
-       private final CountDownLatch latch;
-       
-       public CountDownCallback(final CountDownLatch latch)
-       {
-           this.latch = latch;
-       }
-       
-       volatile boolean doneCalled = false;
-       volatile boolean errorCalled = false;
-       final AtomicInteger timesDoneCalled = new AtomicInteger(0);
+      private final CountDownLatch latch;
 
-       public void done()
-       {
-           doneCalled = true;
-           timesDoneCalled.incrementAndGet();
-           if (latch != null) 
-           {
-               latch.countDown();
-           }
-       }
+      public CountDownCallback(final CountDownLatch latch)
+      {
+         this.latch = latch;
+      }
 
-       public void onError(final int errorCode, final String errorMessage)
-       {
-           errorCalled = true;
-           if (latch != null)
-           {
-               // even thought an error happened, we need to inform the latch, or the test won't finish
-               latch.countDown();
-           }
-       }
+      volatile boolean doneCalled = false;
+
+      volatile boolean errorCalled = false;
+
+      final AtomicInteger timesDoneCalled = new AtomicInteger(0);
+
+      public void done()
+      {
+         doneCalled = true;
+         timesDoneCalled.incrementAndGet();
+         if (latch != null)
+         {
+            latch.countDown();
+         }
+      }
+
+      public void onError(final int errorCode, final String errorMessage)
+      {
+         errorCalled = true;
+         if (latch != null)
+         {
+            // even thought an error happened, we need to inform the latch,
+               // or the test won't finish
+            latch.countDown();
+         }
+      }
    }
 
-   
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.asyncio;
 
@@ -48,222 +48,255 @@
 {
 
    static Logger log = Logger.getLogger(MultiThreadWriteNativeTest.class);
-   
+
    AtomicInteger position = new AtomicInteger(0);
-   
+
    static final int SIZE = 1024;
+
    static final int NUMBER_OF_THREADS = 10;
+
    static final int NUMBER_OF_LINES = 1000;
-   
-   //   Executor exec
-   
+
+   // Executor exec
+
    Executor executor = Executors.newSingleThreadExecutor();
-   
+
+   @Override
    protected void setUp() throws Exception
    {
-       super.setUp();
-       position.set(0);
+      super.setUp();
+      position.set(0);
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
    }
-   
+
    public void testMultipleASynchronousWrites() throws Throwable
    {
-       executeTest(false);
+      executeTest(false);
    }
-   
+
    public void testMultipleSynchronousWrites() throws Throwable
    {
-       executeTest(true);
+      executeTest(true);
    }
-   
-   private void executeTest(boolean sync) throws Throwable
+
+   private void executeTest(final boolean sync) throws Throwable
    {
-       log.debug(sync?"Sync test:":"Async test");
-       AsynchronousFileImpl jlibAIO = new AsynchronousFileImpl();
-       jlibAIO.open(FILE_NAME, 21000);
-       try
-       {
-          log.debug("Preallocating file");
-         
-          jlibAIO.fill(0l, NUMBER_OF_THREADS,  SIZE * NUMBER_OF_LINES, (byte)0);
-          log.debug("Done Preallocating file");
-          
-          CountDownLatch latchStart = new CountDownLatch (NUMBER_OF_THREADS + 1);
-          
-          ArrayList<ThreadProducer> list = new ArrayList<ThreadProducer>(NUMBER_OF_THREADS);
-          for(int i=0;i<NUMBER_OF_THREADS;i++)
-          {
-              ThreadProducer producer = new ThreadProducer("Thread " + i, latchStart, jlibAIO, sync);
-              list.add(producer);
-              producer.start();
-          }
-          
-          latchStart.countDown();
-          latchStart.await();
-          
-          
-          long startTime = System.currentTimeMillis();
-          
-   
-          
-          for (ThreadProducer producer: list)
-          {
-              producer.join();
-              if (producer.failed != null)
-              {
-                  throw producer.failed;
-              }
-          }
-          long endTime = System.currentTimeMillis();
-          
-          log.debug((sync?"Sync result:":"Async result:") + " Records/Second = " + (NUMBER_OF_THREADS * NUMBER_OF_LINES * 1000 / (endTime - startTime)) + " total time = " + (endTime - startTime) + " total number of records = " + (NUMBER_OF_THREADS * NUMBER_OF_LINES));
-       }
-       finally
-       {
-          jlibAIO.close();
-       }
-       
+      log.debug(sync ? "Sync test:" : "Async test");
+      AsynchronousFileImpl jlibAIO = new AsynchronousFileImpl();
+      jlibAIO.open(FILE_NAME, 21000);
+      try
+      {
+         log.debug("Preallocating file");
+
+         jlibAIO.fill(0l, NUMBER_OF_THREADS, SIZE * NUMBER_OF_LINES, (byte)0);
+         log.debug("Done Preallocating file");
+
+         CountDownLatch latchStart = new CountDownLatch(NUMBER_OF_THREADS + 1);
+
+         ArrayList<ThreadProducer> list = new ArrayList<ThreadProducer>(NUMBER_OF_THREADS);
+         for (int i = 0; i < NUMBER_OF_THREADS; i++)
+         {
+            ThreadProducer producer = new ThreadProducer("Thread " + i, latchStart, jlibAIO, sync);
+            list.add(producer);
+            producer.start();
+         }
+
+         latchStart.countDown();
+         latchStart.await();
+
+         long startTime = System.currentTimeMillis();
+
+         for (ThreadProducer producer : list)
+         {
+            producer.join();
+            if (producer.failed != null)
+            {
+               throw producer.failed;
+            }
+         }
+         long endTime = System.currentTimeMillis();
+
+         log.debug((sync ? "Sync result:" : "Async result:") + " Records/Second = " +
+                   NUMBER_OF_THREADS *
+                   NUMBER_OF_LINES *
+                   1000 /
+                   (endTime - startTime) +
+                   " total time = " +
+                   (endTime - startTime) +
+                   " total number of records = " +
+                   NUMBER_OF_THREADS *
+                   NUMBER_OF_LINES);
+      }
+      finally
+      {
+         jlibAIO.close();
+      }
+
    }
-   
+
    private int getNewPosition()
    {
-       return position.addAndGet(1);
+      return position.addAndGet(1);
    }
-   
+
    class ThreadProducer extends Thread
    {
-       Throwable failed = null;
-       CountDownLatch latchStart;
-       boolean sync;
-       AsynchronousFileImpl libaio;
+      Throwable failed = null;
 
-       public ThreadProducer(String name, CountDownLatch latchStart, AsynchronousFileImpl libaio, boolean sync)
-       {
-           super(name);
-           this.latchStart = latchStart;
-           this.libaio = libaio;
-           this.sync = sync;
-       }
-       
-       public void run()
-       {
-           super.run();
-           
-           
-           try
-           {
-               
-               ByteBuffer buffer = libaio.newBuffer(SIZE);
+      CountDownLatch latchStart;
 
-               // I'm aways reusing the same buffer, as I don't want any noise from malloc on the measurement
-               // Encoding buffer
-               addString ("Thread name=" + Thread.currentThread().getName() + ";" + "\n", buffer);
-               for (int local = buffer.position(); local < buffer.capacity() - 1; local++)
-               {
-                   buffer.put((byte)' ');
-               }
-               buffer.put((byte)'\n');
+      boolean sync;
 
+      AsynchronousFileImpl libaio;
 
-               latchStart.countDown();
-               latchStart.await();
-               
-               long startTime = System.currentTimeMillis();
-               
-               
-               CountDownLatch latchFinishThread = null;
-               
-               if (!sync) latchFinishThread = new CountDownLatch(NUMBER_OF_LINES);
+      public ThreadProducer(final String name,
+                            final CountDownLatch latchStart,
+                            final AsynchronousFileImpl libaio,
+                            final boolean sync)
+      {
+         super(name);
+         this.latchStart = latchStart;
+         this.libaio = libaio;
+         this.sync = sync;
+      }
 
-               LinkedList<CountDownCallback> list = new LinkedList<CountDownCallback>();
-               
-               for (int i=0;i<NUMBER_OF_LINES;i++)
+      @Override
+      public void run()
+      {
+         super.run();
+
+         try
+         {
+
+            ByteBuffer buffer = libaio.newBuffer(SIZE);
+
+            // I'm aways reusing the same buffer, as I don't want any noise from
+            // malloc on the measurement
+            // Encoding buffer
+            addString("Thread name=" + Thread.currentThread().getName() + ";" + "\n", buffer);
+            for (int local = buffer.position(); local < buffer.capacity() - 1; local++)
+            {
+               buffer.put((byte)' ');
+            }
+            buffer.put((byte)'\n');
+
+            latchStart.countDown();
+            latchStart.await();
+
+            long startTime = System.currentTimeMillis();
+
+            CountDownLatch latchFinishThread = null;
+
+            if (!sync)
+            {
+               latchFinishThread = new CountDownLatch(NUMBER_OF_LINES);
+            }
+
+            LinkedList<CountDownCallback> list = new LinkedList<CountDownCallback>();
+
+            for (int i = 0; i < NUMBER_OF_LINES; i++)
+            {
+
+               if (sync)
                {
-                
-                   if (sync) latchFinishThread = new CountDownLatch(1);
-                   CountDownCallback callback = new CountDownCallback(latchFinishThread);
-                   if (!sync) list.add(callback);
-                   addData(libaio, buffer,callback);
-                   if (sync)
-                   {
-                       latchFinishThread.await();
-                       assertTrue(callback.doneCalled);
-                       assertFalse(callback.errorCalled);
-                   }
+                  latchFinishThread = new CountDownLatch(1);
                }
-               if (!sync) latchFinishThread.await();
-               for (CountDownCallback callback: list)
+               CountDownCallback callback = new CountDownCallback(latchFinishThread);
+               if (!sync)
                {
-                   assertTrue (callback.doneCalled);
-                   assertFalse (callback.errorCalled);
+                  list.add(callback);
                }
-               
-               long endtime = System.currentTimeMillis();
-               
-               log.debug(Thread.currentThread().getName() + " Rec/Sec= " + (NUMBER_OF_LINES * 1000 / (endtime-startTime)) + " total time = " + (endtime-startTime) + " number of lines=" + NUMBER_OF_LINES);
-               
-               for (CountDownCallback callback: list)
+               addData(libaio, buffer, callback);
+               if (sync)
                {
-                   assertTrue (callback.doneCalled);
-                   assertFalse (callback.errorCalled);
+                  latchFinishThread.await();
+                  assertTrue(callback.doneCalled);
+                  assertFalse(callback.errorCalled);
                }
-               
-           }
-           catch (Throwable e)
-           {
-               e.printStackTrace();
-               failed = e;
-           }
-           
-       }
+            }
+            if (!sync)
+            {
+               latchFinishThread.await();
+            }
+            for (CountDownCallback callback : list)
+            {
+               assertTrue(callback.doneCalled);
+               assertFalse(callback.errorCalled);
+            }
+
+            long endtime = System.currentTimeMillis();
+
+            log.debug(Thread.currentThread().getName() + " Rec/Sec= " +
+                      NUMBER_OF_LINES *
+                      1000 /
+                      (endtime - startTime) +
+                      " total time = " +
+                      (endtime - startTime) +
+                      " number of lines=" +
+                      NUMBER_OF_LINES);
+
+            for (CountDownCallback callback : list)
+            {
+               assertTrue(callback.doneCalled);
+               assertFalse(callback.errorCalled);
+            }
+
+         }
+         catch (Throwable e)
+         {
+            e.printStackTrace();
+            failed = e;
+         }
+
+      }
    }
-   
-   private static void addString(String str, ByteBuffer buffer)
+
+   private static void addString(final String str, final ByteBuffer buffer)
    {
-       byte bytes[] = str.getBytes();
-       buffer.put(bytes);
+      byte bytes[] = str.getBytes();
+      buffer.put(bytes);
    }
-   
-   private void addData(AsynchronousFileImpl aio, ByteBuffer buffer, AIOCallback callback) throws Exception
+
+   private void addData(final AsynchronousFileImpl aio, final ByteBuffer buffer, final AIOCallback callback) throws Exception
    {
-       executor.execute(new WriteRunnable(aio, buffer, callback));
+      executor.execute(new WriteRunnable(aio, buffer, callback));
    }
-   
+
    private class WriteRunnable implements Runnable
    {
-       
-       AsynchronousFileImpl aio;
-       ByteBuffer buffer;
-       AIOCallback callback;
-       
-       
-       public WriteRunnable(AsynchronousFileImpl aio, ByteBuffer buffer, AIOCallback callback)
-       {
-           this.aio = aio;
-           this.buffer = buffer;
-           this.callback = callback;
-       }
 
-       public void run()
-       {
-           try
-           {
-               aio.write(getNewPosition()*SIZE, SIZE, buffer, callback);
-               
-           }
-           catch (Exception e)
-           {
-               callback.onError(-1, e.toString());
-               e.printStackTrace();
-           }
-       }
-       
+      AsynchronousFileImpl aio;
+
+      ByteBuffer buffer;
+
+      AIOCallback callback;
+
+      public WriteRunnable(final AsynchronousFileImpl aio, final ByteBuffer buffer, final AIOCallback callback)
+      {
+         this.aio = aio;
+         this.buffer = buffer;
+         this.callback = callback;
+      }
+
+      public void run()
+      {
+         try
+         {
+            aio.write(getNewPosition() * SIZE, SIZE, buffer, callback);
+
+         }
+         catch (Exception e)
+         {
+            callback.onError(-1, e.toString());
+            e.printStackTrace();
+         }
+      }
+
    }
 
-   
-   
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.asyncio;
 
@@ -46,31 +46,30 @@
  *   */
 public class SingleThreadWriteNativeTest extends AIOTestBase
 {
-   
-   private static final Logger log = Logger
-         .getLogger(SingleThreadWriteNativeTest.class);
-   
-   private static CharsetEncoder UTF_8_ENCODER = Charset.forName("UTF-8")
-         .newEncoder();
-   
+
+   private static final Logger log = Logger.getLogger(SingleThreadWriteNativeTest.class);
+
+   private static CharsetEncoder UTF_8_ENCODER = Charset.forName("UTF-8").newEncoder();
+
    byte commonBuffer[] = null;
-   
-   private static void debug(String msg)
+
+   private static void debug(final String msg)
    {
       log.debug(msg);
    }
-   
+
    @Override
    protected void setUp() throws Exception
    {
       super.setUp();
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
    }
-   
+
    /** 
     * Opening and closing a file immediately can lead to races on the native layer,
     * creating crash conditions.
@@ -82,10 +81,10 @@
       {
          controller.open(FILE_NAME, 10000);
          controller.close();
-         
+
       }
    }
-   
+
    /**
     * This test is validating if the AIO layer can open two different
     * simultaneous files without loose any callbacks. This test made the native
@@ -97,213 +96,233 @@
       final AsynchronousFileImpl controller2 = new AsynchronousFileImpl();
       controller.open(FILE_NAME + ".1", 10000);
       controller2.open(FILE_NAME + ".2", 10000);
-      
+
       int numberOfLines = 1000;
       int size = 1024;
-      
+
       try
       {
          CountDownLatch latchDone = new CountDownLatch(numberOfLines);
          CountDownLatch latchDone2 = new CountDownLatch(numberOfLines);
-         
+
          ByteBuffer block = controller.newBuffer(size);
          encodeBufer(block);
-         
+
          preAlloc(controller, numberOfLines * size);
          preAlloc(controller2, numberOfLines * size);
-         
+
          ArrayList<CountDownCallback> list = new ArrayList<CountDownCallback>();
          ArrayList<CountDownCallback> list2 = new ArrayList<CountDownCallback>();
-         
+
          for (int i = 0; i < numberOfLines; i++)
          {
             list.add(new CountDownCallback(latchDone));
             list2.add(new CountDownCallback(latchDone2));
          }
-         
+
          long valueInitial = System.currentTimeMillis();
-         
+
          long lastTime = System.currentTimeMillis();
          int counter = 0;
          Iterator<CountDownCallback> iter2 = list2.iterator();
-         
+
          for (CountDownCallback tmp : list)
          {
             CountDownCallback tmp2 = iter2.next();
-            
+
             controller.write(counter * size, size, block, tmp);
             controller.write(counter * size, size, block, tmp2);
             if (++counter % 5000 == 0)
             {
-               debug(5000 * 1000 / (System.currentTimeMillis() - lastTime)
-                     + " rec/sec (Async)");
+               debug(5000 * 1000 / (System.currentTimeMillis() - lastTime) + " rec/sec (Async)");
                lastTime = System.currentTimeMillis();
             }
-            
+
          }
-         
+
          long timeTotal = System.currentTimeMillis() - valueInitial;
-         
-         debug("Asynchronous time = " + timeTotal + " for " + numberOfLines
-               + " registers " + " size each line = " + size + " Records/Sec="
-               + (numberOfLines * 1000 / timeTotal) + " (Assynchronous)");
-         
+
+         debug("Asynchronous time = " + timeTotal +
+               " for " +
+               numberOfLines +
+               " registers " +
+               " size each line = " +
+               size +
+               " Records/Sec=" +
+               numberOfLines *
+               1000 /
+               timeTotal +
+               " (Assynchronous)");
+
          latchDone.await();
          latchDone2.await();
-         
+
          timeTotal = System.currentTimeMillis() - valueInitial;
-         debug("After completions time = " + timeTotal + " for "
-               + numberOfLines + " registers " + " size each line = " + size
-               + " Records/Sec=" + (numberOfLines * 1000 / timeTotal)
-               + " (Assynchronous)");
-         
+         debug("After completions time = " + timeTotal +
+               " for " +
+               numberOfLines +
+               " registers " +
+               " size each line = " +
+               size +
+               " Records/Sec=" +
+               numberOfLines *
+               1000 /
+               timeTotal +
+               " (Assynchronous)");
+
          for (CountDownCallback callback : list)
          {
             assertEquals(1, callback.timesDoneCalled.get());
             assertTrue(callback.doneCalled);
             assertFalse(callback.errorCalled);
          }
-         
+
          for (CountDownCallback callback : list2)
          {
             assertEquals(1, callback.timesDoneCalled.get());
             assertTrue(callback.doneCalled);
             assertFalse(callback.errorCalled);
          }
-         
+
          controller.close();
-      } finally
+      }
+      finally
       {
          try
          {
             controller.close();
-         } catch (Exception ignored)
+         }
+         catch (Exception ignored)
          {
          }
          try
          {
             controller2.close();
-         } catch (Exception ignored)
+         }
+         catch (Exception ignored)
          {
          }
       }
    }
-   
+
    public void testAddBeyongSimultaneousLimit() throws Exception
    {
       asyncData(3000, 1024, 10);
    }
-   
+
    public void testAddAsyncData() throws Exception
    {
       asyncData(10000, 1024, 30000);
    }
-   
+
    public void testInvalidReads() throws Exception
    {
       class LocalCallback implements AIOCallback
-      {         
-         private CountDownLatch latch = new CountDownLatch(1);
-         
+      {
+         private final CountDownLatch latch = new CountDownLatch(1);
+
          volatile boolean error;
-         
+
          public void done()
          {
             latch.countDown();
          }
-         
+
          public void onError(final int errorCode, final String errorMessage)
          {
-            this.error = true;
+            error = true;
             latch.countDown();
          }
       }
-      
+
       AsynchronousFileImpl controller = new AsynchronousFileImpl();
       try
       {
-         
+
          final int SIZE = 512;
-         
+
          controller.open(FILE_NAME, 10);
          controller.close();
-         
+
          controller = new AsynchronousFileImpl();
-         
+
          controller.open(FILE_NAME, 10);
-         
-         controller.fill(0, 1, 512, (byte) 'j');
-         
+
+         controller.fill(0, 1, 512, (byte)'j');
+
          ByteBuffer buffer = controller.newBuffer(SIZE);
-         
+
          buffer.clear();
-         
+
          for (int i = 0; i < SIZE; i++)
          {
-            buffer.put((byte) (i % 100));
+            buffer.put((byte)(i % 100));
          }
-         
+
          LocalCallback callbackLocal = new LocalCallback();
-         
+
          controller.write(0, 512, buffer, callbackLocal);
-         
+
          callbackLocal.latch.await();
-         
+
          ByteBuffer newBuffer = ByteBuffer.allocateDirect(50);
-         
+
          callbackLocal = new LocalCallback();
-         
+
          controller.read(0, 50, newBuffer, callbackLocal);
-         
+
          callbackLocal.latch.await();
-         
-         //assertTrue(callbackLocal.error);
-         
+
+         // assertTrue(callbackLocal.error);
+
          callbackLocal = new LocalCallback();
-         
+
          byte bytes[] = new byte[512];
-         
+
          try
          {
             newBuffer = ByteBuffer.wrap(bytes);
-            
+
             controller.read(0, 512, newBuffer, callbackLocal);
-            
+
             fail("An exception was supposed to be thrown");
-         } catch (Exception ignored)
+         }
+         catch (Exception ignored)
          {
          }
-         
-         //newBuffer = ByteBuffer.allocateDirect(512);
+
+         // newBuffer = ByteBuffer.allocateDirect(512);
          newBuffer = controller.newBuffer(512);
          callbackLocal = new LocalCallback();
          controller.read(0, 512, newBuffer, callbackLocal);
          callbackLocal.latch.await();
          assertFalse(callbackLocal.error);
-         
+
          newBuffer.rewind();
-         
+
          byte[] bytesRead = new byte[SIZE];
-         
+
          newBuffer.get(bytesRead);
-         
+
          for (int i = 0; i < SIZE; i++)
          {
-            assertEquals((byte) (i % 100), bytesRead[i]);
+            assertEquals((byte)(i % 100), bytesRead[i]);
          }
-      } finally
+      }
+      finally
       {
          try
          {
             controller.close();
-         } catch (Throwable ignored)
+         }
+         catch (Throwable ignored)
          {
          }
-         
+
       }
-      
+
    }
-   
+
    public void testBufferCallbackUniqueBuffers() throws Exception
    {
       boolean closed = false;
@@ -312,14 +331,13 @@
       {
          final int NUMBER_LINES = 1000;
          final int SIZE = 512;
-         
-         
+
          controller.open(FILE_NAME, 1000);
-         
-         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte) 'j');
-         
+
+         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte)'j');
+
          final ArrayList<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
-         
+
          BufferCallback bufferCallback = new BufferCallback()
          {
             public void bufferDone(ByteBuffer buffer)
@@ -327,8 +345,7 @@
                buffers.add(buffer);
             }
          };
-         
-         
+
          controller.setBufferCallback(bufferCallback);
 
          CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
@@ -343,18 +360,21 @@
             }
             controller.write(i * SIZE, SIZE, buffer, aio);
          }
-         
-         // The buffer callback is only called after the complete callback was called.
-         // Because of that a race could happen on the assertions to buffers.size what would invalidate the test
-         // We close the file and that would guarantee the buffer callback was called for all the elements
+
+         // The buffer callback is only called after the complete callback was
+         // called.
+         // Because of that a race could happen on the assertions to
+         // buffers.size what would invalidate the test
+         // We close the file and that would guarantee the buffer callback was
+         // called for all the elements
          controller.close();
          closed = true;
-         
+
          assertEquals(NUMBER_LINES, buffers.size());
-         
+
          // Make sure all the buffers are unique
          ByteBuffer lineOne = null;
-         for (ByteBuffer bufferTmp: buffers)
+         for (ByteBuffer bufferTmp : buffers)
          {
             if (lineOne == null)
             {
@@ -362,10 +382,10 @@
             }
             else
             {
-               assertTrue (lineOne != bufferTmp);
+               assertTrue(lineOne != bufferTmp);
             }
          }
-         
+
          buffers.clear();
 
       }
@@ -377,7 +397,7 @@
          }
       }
    }
-   
+
    public void testBufferCallbackAwaysSameBuffer() throws Exception
    {
       boolean closed = false;
@@ -386,14 +406,13 @@
       {
          final int NUMBER_LINES = 1000;
          final int SIZE = 512;
-         
-         
+
          controller.open(FILE_NAME, 1000);
-         
-         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte) 'j');
-         
+
+         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte)'j');
+
          final ArrayList<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
-         
+
          BufferCallback bufferCallback = new BufferCallback()
          {
             public void bufferDone(ByteBuffer buffer)
@@ -401,13 +420,12 @@
                buffers.add(buffer);
             }
          };
-         
-         
+
          controller.setBufferCallback(bufferCallback);
 
          CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
          CountDownCallback aio = new CountDownCallback(latch);
-         
+
          ByteBuffer buffer = controller.newBuffer(SIZE);
          buffer.rewind();
          for (int j = 0; j < SIZE; j++)
@@ -419,18 +437,21 @@
          {
             controller.write(i * SIZE, SIZE, buffer, aio);
          }
-         
-         // The buffer callback is only called after the complete callback was called.
-         // Because of that a race could happen on the assertions to buffers.size what would invalidate the test
-         // We close the file and that would guarantee the buffer callback was called for all the elements
+
+         // The buffer callback is only called after the complete callback was
+         // called.
+         // Because of that a race could happen on the assertions to
+         // buffers.size what would invalidate the test
+         // We close the file and that would guarantee the buffer callback was
+         // called for all the elements
          controller.close();
          closed = true;
-         
+
          assertEquals(NUMBER_LINES, buffers.size());
-         
+
          // Make sure all the buffers are unique
          ByteBuffer lineOne = null;
-         for (ByteBuffer bufferTmp: buffers)
+         for (ByteBuffer bufferTmp : buffers)
          {
             if (lineOne == null)
             {
@@ -438,10 +459,10 @@
             }
             else
             {
-               assertTrue (lineOne == bufferTmp);
+               assertTrue(lineOne == bufferTmp);
             }
          }
-         
+
          buffers.clear();
 
       }
@@ -453,97 +474,99 @@
          }
       }
    }
-   
+
    public void testRead() throws Exception
    {
       final AsynchronousFileImpl controller = new AsynchronousFileImpl();
       try
       {
-         
+
          final int NUMBER_LINES = 5000;
          final int SIZE = 1024;
-         
+
          controller.open(FILE_NAME, 1000);
-         
-         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte) 'j');
-         
+
+         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte)'j');
+
          {
-         CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
-         CountDownCallback aio = new CountDownCallback(latch);
+            CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
+            CountDownCallback aio = new CountDownCallback(latch);
 
-         for (int i = 0; i < NUMBER_LINES; i++)
-         {
-            ByteBuffer buffer = ByteBuffer.allocateDirect(SIZE);
-            addString("Str value " + i + "\n", buffer);
-            for (int j = buffer.position(); j < buffer.capacity() - 1; j++)
+            for (int i = 0; i < NUMBER_LINES; i++)
             {
-               buffer.put((byte) ' ');
+               ByteBuffer buffer = ByteBuffer.allocateDirect(SIZE);
+               addString("Str value " + i + "\n", buffer);
+               for (int j = buffer.position(); j < buffer.capacity() - 1; j++)
+               {
+                  buffer.put((byte)' ');
+               }
+               buffer.put((byte)'\n');
+
+               controller.write(i * SIZE, SIZE, buffer, aio);
             }
-            buffer.put((byte) '\n');
-            
-            controller.write(i * SIZE, SIZE, buffer, aio);
+
+            latch.await();
+            assertFalse(aio.errorCalled);
+            assertEquals(NUMBER_LINES, aio.timesDoneCalled.get());
          }
-         
-         latch.await();
-         assertFalse(aio.errorCalled);
-         assertEquals(NUMBER_LINES, aio.timesDoneCalled.get());
-         }
- 
-         // If you call close you're supposed to wait events to finish before closing it
+
+         // If you call close you're supposed to wait events to finish before
+         // closing it
          controller.close();
          controller.open(FILE_NAME, 10);
-         
+
          ByteBuffer newBuffer = ByteBuffer.allocateDirect(SIZE);
-         
+
          for (int i = 0; i < NUMBER_LINES; i++)
          {
             newBuffer.clear();
             addString("Str value " + i + "\n", newBuffer);
             for (int j = newBuffer.position(); j < newBuffer.capacity() - 1; j++)
             {
-               newBuffer.put((byte) ' ');
+               newBuffer.put((byte)' ');
             }
-            newBuffer.put((byte) '\n');
-            
+            newBuffer.put((byte)'\n');
+
             CountDownLatch latch = new CountDownLatch(1);
             CountDownCallback aio = new CountDownCallback(latch);
-            
+
             ByteBuffer buffer = ByteBuffer.allocateDirect(SIZE);
-            
+
             controller.read(i * SIZE, SIZE, buffer, aio);
             latch.await();
             assertFalse(aio.errorCalled);
             assertTrue(aio.doneCalled);
-            
+
             byte bytesRead[] = new byte[SIZE];
             byte bytesCompare[] = new byte[SIZE];
-            
+
             newBuffer.rewind();
             newBuffer.get(bytesCompare);
             buffer.rewind();
             buffer.get(bytesRead);
-            
+
             for (int count = 0; count < SIZE; count++)
             {
-               assertEquals("byte position " + count + " differs on line " + i,
-                     bytesCompare[count], bytesRead[count]);
+               assertEquals("byte position " + count + " differs on line " + i, bytesCompare[count], bytesRead[count]);
             }
-            
+
             assertTrue(buffer.equals(newBuffer));
          }
-      } finally
+      }
+      finally
       {
          try
          {
             controller.close();
-         } catch (Throwable ignored)
+         }
+         catch (Throwable ignored)
          {
          }
-         
+
       }
-      
+
    }
-   
+
    /** 
     *  This test will call file.close() when there are still callbacks being processed. 
     *  This could cause a crash or callbacks missing and this test is validating both situations.
@@ -553,27 +576,27 @@
       final AsynchronousFileImpl controller = new AsynchronousFileImpl();
       try
       {
-         
+
          final int NUMBER_LINES = 1000;
          CountDownLatch readLatch = new CountDownLatch(NUMBER_LINES);
          final int SIZE = 1024;
-         
+
          controller.open(FILE_NAME, 10000);
-         
-         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte) 'j');
-         
+
+         controller.fill(0, 1, NUMBER_LINES * SIZE, (byte)'j');
+
          for (int i = 0; i < NUMBER_LINES; i++)
          {
             ByteBuffer buffer = ByteBuffer.allocateDirect(SIZE);
-            
+
             buffer.clear();
             addString("Str value " + i + "\n", buffer);
             for (int j = buffer.position(); j < buffer.capacity() - 1; j++)
             {
-               buffer.put((byte) ' ');
+               buffer.put((byte)' ');
             }
-            buffer.put((byte) '\n');
-            
+            buffer.put((byte)'\n');
+
             CountDownCallback aio = new CountDownCallback(readLatch);
             controller.write(i * SIZE, SIZE, buffer, aio);
          }
@@ -581,85 +604,85 @@
          // If you call close you're supposed to wait events to finish before
          // closing it
          controller.close();
-         
+
          assertEquals(0, readLatch.getCount());
          readLatch.await();
          controller.open(FILE_NAME, 10);
-         
+
          ByteBuffer newBuffer = ByteBuffer.allocateDirect(SIZE);
-         
+
          ByteBuffer buffer = ByteBuffer.allocateDirect(SIZE);
-         
+
          for (int i = 0; i < NUMBER_LINES; i++)
          {
             newBuffer.clear();
             addString("Str value " + i + "\n", newBuffer);
             for (int j = newBuffer.position(); j < newBuffer.capacity() - 1; j++)
             {
-               newBuffer.put((byte) ' ');
+               newBuffer.put((byte)' ');
             }
-            newBuffer.put((byte) '\n');
-            
+            newBuffer.put((byte)'\n');
+
             CountDownLatch latch = new CountDownLatch(1);
             CountDownCallback aio = new CountDownCallback(latch);
             controller.read(i * SIZE, SIZE, buffer, aio);
             latch.await();
             assertFalse(aio.errorCalled);
             assertTrue(aio.doneCalled);
-            
+
             byte bytesRead[] = new byte[SIZE];
             byte bytesCompare[] = new byte[SIZE];
-            
+
             newBuffer.rewind();
             newBuffer.get(bytesCompare);
             buffer.rewind();
             buffer.get(bytesRead);
-            
+
             for (int count = 0; count < SIZE; count++)
             {
-               assertEquals("byte position " + count + " differs on line " + i,
-                     bytesCompare[count], bytesRead[count]);
+               assertEquals("byte position " + count + " differs on line " + i, bytesCompare[count], bytesRead[count]);
             }
-            
+
             assertTrue(buffer.equals(newBuffer));
          }
-         
-      } finally
+
+      }
+      finally
       {
          try
          {
             controller.close();
-         } catch (Throwable ignored)
+         }
+         catch (Throwable ignored)
          {
          }
-         
+
       }
    }
-   
-   private void asyncData(int numberOfLines, int size, int aioLimit)
-         throws Exception
+
+   private void asyncData(final int numberOfLines, final int size, final int aioLimit) throws Exception
    {
       final AsynchronousFileImpl controller = new AsynchronousFileImpl();
       controller.open(FILE_NAME, aioLimit);
-      
+
       try
       {
          CountDownLatch latchDone = new CountDownLatch(numberOfLines);
-         
+
          ByteBuffer block = controller.newBuffer(size);
          encodeBufer(block);
-         
+
          preAlloc(controller, numberOfLines * size);
-         
+
          ArrayList<CountDownCallback> list = new ArrayList<CountDownCallback>();
-         
+
          for (int i = 0; i < numberOfLines; i++)
          {
             list.add(new CountDownCallback(latchDone));
          }
-         
+
          long valueInitial = System.currentTimeMillis();
-         
+
          long lastTime = System.currentTimeMillis();
          int counter = 0;
          for (CountDownCallback tmp : list)
@@ -667,58 +690,66 @@
             controller.write(counter * size, size, block, tmp);
             if (++counter % 20000 == 0)
             {
-               debug(20000 * 1000 / (System.currentTimeMillis() - lastTime)
-                     + " rec/sec (Async)");
+               debug(20000 * 1000 / (System.currentTimeMillis() - lastTime) + " rec/sec (Async)");
                lastTime = System.currentTimeMillis();
             }
-            
+
          }
-         
+
          latchDone.await();
-         
+
          long timeTotal = System.currentTimeMillis() - valueInitial;
-         debug("After completions time = " + timeTotal + " for "
-               + numberOfLines + " registers " + " size each line = " + size
-               + ", Records/Sec=" + (numberOfLines * 1000 / timeTotal)
-               + " (Assynchronous)");
-         
+         debug("After completions time = " + timeTotal +
+               " for " +
+               numberOfLines +
+               " registers " +
+               " size each line = " +
+               size +
+               ", Records/Sec=" +
+               numberOfLines *
+               1000 /
+               timeTotal +
+               " (Assynchronous)");
+
          for (CountDownCallback tmp : list)
          {
             assertEquals(1, tmp.timesDoneCalled.get());
             assertTrue(tmp.doneCalled);
             assertFalse(tmp.errorCalled);
          }
-         
+
          controller.close();
-      } finally
+      }
+      finally
       {
          try
          {
             controller.close();
-         } catch (Exception ignored)
+         }
+         catch (Exception ignored)
          {
          }
       }
-      
+
    }
-   
+
    public void testDirectSynchronous() throws Exception
    {
       try
       {
          final int NUMBER_LINES = 3000;
          final int SIZE = 1024;
-         
+
          final AsynchronousFileImpl controller = new AsynchronousFileImpl();
          controller.open(FILE_NAME, 2000);
-         
+
          ByteBuffer block = ByteBuffer.allocateDirect(SIZE);
          encodeBufer(block);
-         
+
          preAlloc(controller, NUMBER_LINES * SIZE);
-         
+
          long startTime = System.currentTimeMillis();
-         
+
          for (int i = 0; i < NUMBER_LINES; i++)
          {
             CountDownLatch latchDone = new CountDownLatch(1);
@@ -728,54 +759,65 @@
             assertTrue(aioBlock.doneCalled);
             assertFalse(aioBlock.errorCalled);
          }
-         
+
          long timeTotal = System.currentTimeMillis() - startTime;
-         debug("time = " + timeTotal + " for " + NUMBER_LINES
-               + " registers " + " size each line = " + SIZE + " Records/Sec="
-               + (NUMBER_LINES * 1000 / timeTotal) + " Synchronous");
-         
+         debug("time = " + timeTotal +
+               " for " +
+               NUMBER_LINES +
+               " registers " +
+               " size each line = " +
+               SIZE +
+               " Records/Sec=" +
+               NUMBER_LINES *
+               1000 /
+               timeTotal +
+               " Synchronous");
+
          controller.close();
-      } catch (Exception e)
+      }
+      catch (Exception e)
       {
          throw e;
       }
-      
+
    }
- 
+
    public void testInvalidWrite() throws Exception
    {
       final AsynchronousFileImpl controller = new AsynchronousFileImpl();
       controller.open(FILE_NAME, 2000);
-      
+
       try
-      {         
+      {
          final int SIZE = 512;
-         
+
          ByteBuffer block = controller.newBuffer(SIZE);
          encodeBufer(block);
-         
+
          preAlloc(controller, 10 * 512);
-         
+
          CountDownLatch latchDone = new CountDownLatch(1);
-         
+
          CountDownCallback aioBlock = new CountDownCallback(latchDone);
          controller.write(11, 512, block, aioBlock);
-         
+
          latchDone.await();
-         
+
          assertTrue(aioBlock.errorCalled);
          assertFalse(aioBlock.doneCalled);
 
-      } catch (Exception e)
+      }
+      catch (Exception e)
       {
          throw e;
-      } finally
+      }
+      finally
       {
          controller.close();
       }
-      
+
    }
-   
+
    public void testInvalidAlloc() throws Exception
    {
       AsynchronousFileImpl controller = new AsynchronousFileImpl();
@@ -783,35 +825,35 @@
       {
          ByteBuffer buffer = controller.newBuffer(300);
          fail("Exception expected");
-      } catch (Exception ignored)
+      }
+      catch (Exception ignored)
       {
       }
-      
+
    }
-   
+
    public void testSize() throws Exception
    {
       final AsynchronousFileImpl controller = new AsynchronousFileImpl();
-      
+
       final int NUMBER_LINES = 10;
       final int SIZE = 1024;
-      
+
       controller.open(FILE_NAME, 1);
-      
-      controller.fill(0, 1, NUMBER_LINES * SIZE, (byte) 'j');
-      
-      assertEquals (NUMBER_LINES * SIZE, controller.size());
-      
+
+      controller.fill(0, 1, NUMBER_LINES * SIZE, (byte)'j');
+
+      assertEquals(NUMBER_LINES * SIZE, controller.size());
+
       controller.close();
-      
+
    }
-   
-   
-   private void addString(String str, ByteBuffer buffer)
+
+   private void addString(final String str, final ByteBuffer buffer)
    {
       CharBuffer charBuffer = CharBuffer.wrap(str);
       UTF_8_ENCODER.encode(charBuffer, buffer, true);
-      
+
    }
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/journal/AIOSequentialFileFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/journal/AIOSequentialFileFactoryTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/journal/AIOSequentialFileFactoryTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -45,26 +45,28 @@
 {
 
    protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test";
-   
+
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
 
       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")));
+         fail(String.format("libAIO is not loaded on %s %s %s",
+                            System.getProperty("os.name"),
+                            System.getProperty("os.arch"),
+                            System.getProperty("os.version")));
       }
-      
+
       File file = new File(journalDir);
-      
+
       deleteDirectory(file);
-      
-      file.mkdir();     
+
+      file.mkdir();
    }
 
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
@@ -72,11 +74,12 @@
       deleteDirectory(new File(journalDir));
    }
 
+   @Override
    protected SequentialFileFactory createFactory()
    {
       return new AIOSequentialFileFactory(journalDir);
    }
-   
+
    public void testBuffer() throws Exception
    {
       SequentialFile file = factory.createSequentialFile("filtetmp.log", 10);
@@ -85,27 +88,29 @@
       assertEquals(512, buff.limit());
       file.close();
    }
-   
+
    public void testBlockCallback() throws Exception
    {
       class BlockCallback implements IOCallback
-      {         
+      {
          AtomicInteger countDone = new AtomicInteger(0);
+
          AtomicInteger countError = new AtomicInteger(0);
+
          CountDownLatch blockLatch;
 
          BlockCallback()
          {
-            this.blockLatch = new CountDownLatch(1);
+            blockLatch = new CountDownLatch(1);
          }
-         
+
          public void release()
          {
             blockLatch.countDown();
          }
-         
+
          public void done()
-         {            
+         {
             try
             {
                blockLatch.await();
@@ -118,7 +123,7 @@
             countDone.incrementAndGet();
          }
 
-         public void onError(int errorCode, String errorMessage)
+         public void onError(final int errorCode, final String errorMessage)
          {
             try
             {
@@ -128,64 +133,60 @@
             {
                e.printStackTrace();
             }
-            
+
             countError.incrementAndGet();
          }
       }
-      
+
       BlockCallback callback = new BlockCallback();
-      
+
       final int NUMBER_OF_RECORDS = 10000;
-      
+
       SequentialFile file = factory.createSequentialFile("callbackBlock.log", 1000);
       file.open();
       file.fill(0, 512 * NUMBER_OF_RECORDS, (byte)'a');
 
-      
-      for (int i=0; i<NUMBER_OF_RECORDS; i++)
+      for (int i = 0; i < NUMBER_OF_RECORDS; i++)
       {
          ByteBuffer buffer = factory.newBuffer(512);
-         
+
          buffer.putInt(i + 10);
-         
-         for (int j=buffer.position(); j<buffer.limit(); j++)
+
+         for (int j = buffer.position(); j < buffer.limit(); j++)
          {
             buffer.put((byte)'b');
          }
-         
+
          file.write(buffer, callback);
       }
-      
-      
+
       callback.release();
       file.close();
       assertEquals(NUMBER_OF_RECORDS, callback.countDone.get());
       assertEquals(0, callback.countError.get());
-      
+
       file.open();
-      
+
       ByteBuffer buffer = factory.newBuffer(512);
 
-      for (int i=0; i<NUMBER_OF_RECORDS; i++)
+      for (int i = 0; i < NUMBER_OF_RECORDS; i++)
       {
-         
+
          file.read(buffer);
          buffer.rewind();
-         
+
          int recordRead = buffer.getInt();
-         
+
          assertEquals(i + 10, recordRead);
-         
-         for (int j=buffer.position(); j<buffer.limit(); j++)
+
+         for (int j = buffer.position(); j < buffer.limit(); j++)
          {
             assertEquals((byte)'b', buffer.get());
          }
-         
-       }
-      
-      
+
+      }
+
       file.close();
    }
-   
 
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/journal/NIOSequentialFileFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/journal/NIOSequentialFileFactoryTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/journal/NIOSequentialFileFactoryTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -36,23 +36,25 @@
  *
  */
 public class NIOSequentialFileFactoryTest extends SequentialFileFactoryTestBase
-{		
-	protected String journalDir = System.getProperty("user.home") + "/journal-test";
-		
-	protected void setUp() throws Exception
-	{
-		super.setUp();
-		
-		File file = new File(journalDir);
-		
-		deleteDirectory(file);
-		
-		file.mkdir();		
-	}
+{
+   protected String journalDir = System.getProperty("user.home") + "/journal-test";
 
-	protected SequentialFileFactory createFactory()
-	{
-		return new NIOSequentialFileFactory(journalDir);
-	}
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
 
+      File file = new File(journalDir);
+
+      deleteDirectory(file);
+
+      file.mkdir();
+   }
+
+   @Override
+   protected SequentialFileFactory createFactory()
+   {
+      return new NIOSequentialFileFactory(journalDir);
+   }
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealAIOJournalImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealAIOJournalImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealAIOJournalImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -46,43 +46,46 @@
 public class RealAIOJournalImplTest extends JournalImplTestUnit
 {
    private static final Logger log = Logger.getLogger(RealAIOJournalImplTest.class);
-   
+
    // Need to run the test over a local disk (no NFS)
-   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") +  "/journal-test";
-     
+   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test";
+
    @Override
    protected void setUp() throws Exception
    {
       super.setUp();
       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")));
+         fail(String.format("libAIO is not loaded on %s %s %s",
+                            System.getProperty("os.name"),
+                            System.getProperty("os.arch"),
+                            System.getProperty("os.version")));
       }
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
       deleteDirectory(new File(journalDir));
    }
-   
+
+   @Override
    protected SequentialFileFactory getFileFactory() throws Exception
    {
       File file = new File(journalDir);
-      
+
       deleteDirectory(file);
-      
-      file.mkdir();     
-      
+
+      file.mkdir();
+
       return new AIOSequentialFileFactory(journalDir);
-   }  
+   }
 
+   @Override
    protected int getAlignment()
    {
       return 512;
    }
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealNIOJournalImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealNIOJournalImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/journal/RealNIOJournalImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal;
 
@@ -29,7 +29,6 @@
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.tests.unit.core.journal.impl.JournalImplTestUnit;
 
-
 /**
  * 
  * A RealJournalImplTest
@@ -40,26 +39,27 @@
 public class RealNIOJournalImplTest extends JournalImplTestUnit
 {
    private static final Logger log = Logger.getLogger(RealNIOJournalImplTest.class);
-   
+
    protected String journalDir = System.getProperty("user.home") + "/journal-test";
-      
+
+   @Override
    protected SequentialFileFactory getFileFactory() throws Exception
    {
       File file = new File(journalDir);
-      
+
       log.debug("deleting directory " + journalDir);
-      
+
       deleteDirectory(file);
-      
-      file.mkdir();     
-      
+
+      file.mkdir();
+
       return new NIOSequentialFileFactory(journalDir);
    }
-   
+
+   @Override
    protected int getAlignment()
    {
       return 1;
    }
-   
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.tests.integration.paging;
 
 import java.io.File;
@@ -32,40 +31,40 @@
 
 public class PagingIntegrationTest extends PageImplTestBase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
-   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") +  "/journal-test";
-   
+   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")));
+         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), 1000);
    }
-   
+
    public void testPageWithNIO() throws Exception
    {
       testAdd(new NIOSequentialFileFactory(journalDir), 1000);
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    @Override
    protected void setUp() throws Exception
    {
@@ -74,7 +73,8 @@
       deleteDirectory(fileJournalDir);
       fileJournalDir.mkdirs();
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
@@ -82,7 +82,7 @@
    }
 
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingManagerIntegrationTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.tests.integration.paging;
 
 import java.io.File;
@@ -49,97 +48,100 @@
  */
 public class PagingManagerIntegrationTest extends UnitTestCase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
-   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") +  "/journal-test";
-  
+   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test";
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    public void testPagingManagerNIO() throws Exception
    {
       HierarchicalRepository<QueueSettings> queueSettings = new HierarchicalObjectRepository<QueueSettings>();
       queueSettings.setDefault(new QueueSettings());
-      
-      
-      PagingManagerImpl managerImpl = 
-         new PagingManagerImpl(new PagingManagerFactoryNIO(journalDir), null, queueSettings, -1);
+
+      PagingManagerImpl managerImpl = new PagingManagerImpl(new PagingManagerFactoryNIO(journalDir),
+                                                            null,
+                                                            queueSettings,
+                                                            -1);
       managerImpl.start();
-      
+
       PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
-      
+
       ServerMessage msg = createMessage(1l, new SimpleString("simple-test"), createRandomBuffer(10));
-      
+
       assertFalse(store.page(new PageMessageImpl(msg)));
-      
+
       store.startPaging();
-      
+
       assertTrue(store.page(new PageMessageImpl(msg)));
-      
+
       Page page = store.depage();
-      
+
       page.open();
-      
+
       PageMessage msgs[] = page.read();
-      
+
       page.close();
-      
+
       assertEquals(1, msgs.length);
-      
+
       assertEqualsByteArrays(msg.getBody().array(), msgs[0].getMessage().getBody().array());
-      
+
       assertTrue(store.isPaging());
-      
+
       assertNull(store.depage());
-      
+
       assertFalse(store.page(new PageMessageImpl(msg)));
    }
-   
+
    public void testPagingManagerAddressFull() throws Exception
    {
       HierarchicalRepository<QueueSettings> queueSettings = new HierarchicalObjectRepository<QueueSettings>();
       queueSettings.setDefault(new QueueSettings());
-      
+
       QueueSettings simpleTestSettings = new QueueSettings();
       simpleTestSettings.setDropMessagesWhenFull(true);
       simpleTestSettings.setMaxSizeBytes(200);
-      
+
       queueSettings.addMatch("simple-test", simpleTestSettings);
-      
-      PagingManagerImpl managerImpl = 
-         new PagingManagerImpl(new PagingManagerFactoryNIO(journalDir), null, queueSettings, -1);
+
+      PagingManagerImpl managerImpl = new PagingManagerImpl(new PagingManagerFactoryNIO(journalDir),
+                                                            null,
+                                                            queueSettings,
+                                                            -1);
       managerImpl.start();
-      
+
       ServerMessage msg = createMessage(1l, new SimpleString("simple-test"), createRandomBuffer(100));
-      
+
       long currentSize = managerImpl.addSize(msg);
-      
+
       assertTrue(currentSize > 0);
-      
+
       assertEquals(currentSize, managerImpl.getPageStore(new SimpleString("simple-test")).getAddressSize());
-      
+
       for (int i = 0; i < 10; i++)
       {
          assertTrue(managerImpl.addSize(msg) < 0);
-         
+
          assertEquals(currentSize, managerImpl.getPageStore(new SimpleString("simple-test")).getAddressSize());
       }
-      
+
       managerImpl.messageDone(msg);
-      
+
       assertTrue(managerImpl.addSize(msg) > 0);
-      
+
       managerImpl.stop();
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
    @Override
    protected void setUp() throws Exception
@@ -148,34 +150,39 @@
       recreateDirectory();
    }
 
-   protected ServerMessage createMessage(long messageId, SimpleString destination, ByteBuffer buffer)
+   protected ServerMessage createMessage(final long messageId, final SimpleString destination, final ByteBuffer buffer)
    {
-      ServerMessage msg = new ServerMessageImpl((byte)1, true, 0,
-            System.currentTimeMillis(), (byte)0, new ByteBufferWrapper(buffer));
-      
-      msg.setMessageID((long)messageId);
-      
+      ServerMessage msg = new ServerMessageImpl((byte)1,
+                                                true,
+                                                0,
+                                                System.currentTimeMillis(),
+                                                (byte)0,
+                                                new ByteBufferWrapper(buffer));
+
+      msg.setMessageID(messageId);
+
       msg.setDestination(destination);
       return msg;
    }
 
-   protected ByteBuffer createRandomBuffer(int size)
+   protected ByteBuffer createRandomBuffer(final int size)
    {
       ByteBuffer buffer = ByteBuffer.allocate(size);
-      
+
       for (int j = 0; j < buffer.limit(); j++)
       {
          buffer.put(RandomUtil.randomByte());
       }
       return buffer;
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
-      //deleteDirectory(new File(journalDir));
+      // deleteDirectory(new File(journalDir));
    }
-   
+
    // Private -------------------------------------------------------
 
    private void recreateDirectory()
@@ -185,7 +192,6 @@
       fileJournalDir.mkdirs();
    }
 
-   
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.tests.integration.paging;
 
 import java.io.File;
@@ -33,29 +32,29 @@
 public class PagingStoreIntegrationTest extends PagingStoreTestBase
 {
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
-   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") +  "/journal-test";
-   
+   protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test";
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    public void testPageStoreWithAIO() 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")));
+         fail(String.format("libAIO is not loaded on %s %s %s",
+                            System.getProperty("os.name"),
+                            System.getProperty("os.arch"),
+                            System.getProperty("os.version")));
       }
       testConcurrentPaging(new AIOSequentialFileFactory(journalDir), 10);
    }
-   
+
    public void testPageWithNIO() throws Exception
    {
       // This integration test could fail 1 in 100 due to race conditions.
@@ -66,11 +65,11 @@
          testConcurrentPaging(new NIOSequentialFileFactory(journalDir), 1);
       }
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    @Override
    protected void setUp() throws Exception
    {
@@ -78,11 +77,11 @@
       recreateDirectory();
    }
 
-   
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
-      //deleteDirectory(new File(journalDir));
+      // deleteDirectory(new File(journalDir));
    }
 
    // Private -------------------------------------------------------
@@ -95,6 +94,5 @@
    }
 
    // Inner classes -------------------------------------------------
-   
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AIOSequentialFileTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AIOSequentialFileTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AIOSequentialFileTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,26 +1,25 @@
 /*
- * 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.
+ * 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.journal.impl;
 
 import java.io.File;
@@ -35,7 +34,6 @@
 import org.jboss.messaging.core.journal.impl.AIOSequentialFile;
 import org.jboss.messaging.tests.util.UnitTestCase;
 
-
 /**
  * Test AIOSEquentialFile using an EasyMock
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
@@ -43,19 +41,19 @@
  */
 public class AIOSequentialFileTest extends UnitTestCase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
    AsynchronousFile mockFile;
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    public void testOpen() throws Exception
    {
       openFile();
@@ -64,7 +62,7 @@
    public void testAlignment() throws Exception
    {
       SequentialFile file = new MockAIOSequentialFileImpl("/tmp", "nothing", 1);
-      
+
       try
       {
          file.getAlignment();
@@ -73,22 +71,22 @@
       catch (Exception ignored)
       {
       }
-      
+
       file = openFile();
-      
+
       EasyMock.expect(mockFile.getBlockSize()).andReturn(512);
-      
+
       EasyMock.replay(mockFile);
-      
+
       assertEquals(512, file.getAlignment());
-      
+
       EasyMock.verify(mockFile);
    }
-   
+
    public void testCalculateblockStart() throws Exception
    {
       SequentialFile file = new MockAIOSequentialFileImpl("/tmp", "nothing", 1);
-      
+
       try
       {
          file.calculateBlockStart(10);
@@ -97,22 +95,22 @@
       catch (Exception ignored)
       {
       }
-      
+
       file = openFile();
-      
+
       EasyMock.expect(mockFile.getBlockSize()).andReturn(512);
-      
+
       EasyMock.replay(mockFile);
-      
+
       assertEquals(1024, file.calculateBlockStart(900));
-      
+
       EasyMock.verify(mockFile);
    }
-   
+
    public void testClose() throws Exception
    {
       SequentialFile file = new MockAIOSequentialFileImpl("/tmp", "nothing", 1);
-      
+
       try
       {
          file.close();
@@ -121,71 +119,71 @@
       catch (Exception ignored)
       {
       }
-      
+
       file = openFile();
-      
+
       mockFile.close();
-      
+
       EasyMock.replay(mockFile);
-      
+
       file.close();
-      
+
       EasyMock.verify(mockFile);
    }
-   
+
    public void testDelete() throws Exception
    {
       File tmpFile = File.createTempFile("temporaryTestFile", ".tmp");
-      
+
       assertTrue(tmpFile.exists());
-      
+
       SequentialFile fileImpl = new MockAIOSequentialFileImpl(tmpFile.getParent(), tmpFile.getName(), 1);
-      
+
       fileImpl.delete();
 
       // delete on a closed file
       assertFalse(tmpFile.exists());
-      
+
       tmpFile = File.createTempFile("temporaryTestFile", ".tmp");
-      
+
       assertTrue(tmpFile.exists());
-      
+
       fileImpl = openFile(tmpFile.getParent(), tmpFile.getName());
-      
+
       mockFile.close();
-      
+
       EasyMock.replay(mockFile);
-      
+
       fileImpl.delete();
-      
+
       assertFalse(tmpFile.exists());
-      
+
       EasyMock.verify(mockFile);
    }
-   
+
    public void testFill() throws Exception
    {
       SequentialFile fileImpl = openFile();
-      
-      validateFill(fileImpl, 3*100*1024*1024, 3, 100*1024*1024);
-      
-      validateFill(fileImpl, 3*10*1024*1024, 3, 10*1024*1024);
-      
-      validateFill(fileImpl, 7*1024*1024, 7, 1024*1024);
-      
-      validateFill(fileImpl, 7*10*1024, 7, 10*1024);
-      
-      validateFill(fileImpl, 7*512, 7, 512);
-      
+
+      validateFill(fileImpl, 3 * 100 * 1024 * 1024, 3, 100 * 1024 * 1024);
+
+      validateFill(fileImpl, 3 * 10 * 1024 * 1024, 3, 10 * 1024 * 1024);
+
+      validateFill(fileImpl, 7 * 1024 * 1024, 7, 1024 * 1024);
+
+      validateFill(fileImpl, 7 * 10 * 1024, 7, 10 * 1024);
+
+      validateFill(fileImpl, 7 * 512, 7, 512);
+
       validateFill(fileImpl, 300, 1, 512);
    }
-   
+
    public void testWriteWithCallback() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
-      
+
       IOCallback callback = new IOCallback()
       {
 
@@ -200,109 +198,112 @@
 
       mockFile.write(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.same(callback));
 
-      mockFile.close();      
+      mockFile.close();
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       fileImpl.write(buffer, callback);
-      
+
       // We need that to make sure the executor is cleared before the verify
       fileImpl.close();
-      
+
       EasyMock.verify(mockFile);
    }
 
    public void testWriteWithSyncOnCallback() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
 
       mockFile.write(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.isA(IOCallback.class));
-      
-      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>(){
 
+      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+      {
+
          public Object answer() throws Throwable
          {
-            IOCallback callback = (IOCallback) EasyMock.getCurrentArguments()[3];
-            
+            IOCallback callback = (IOCallback)EasyMock.getCurrentArguments()[3];
+
             callback.done();
-            
+
             return null;
          }
-         
+
       });
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       fileImpl.write(buffer, true);
-      
+
       EasyMock.verify(mockFile);
    }
 
    public void testWriteWithNoSyncOnCallback() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
 
       mockFile.write(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.isA(IOCallback.class));
 
-      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>(){
+      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+      {
 
          public Object answer() throws Throwable
          {
-            IOCallback callback = (IOCallback) EasyMock.getCurrentArguments()[3];
-            
+            IOCallback callback = (IOCallback)EasyMock.getCurrentArguments()[3];
+
             callback.done();
-            
+
             return null;
          }
-         
+
       });
 
       mockFile.close();
-      
+
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       fileImpl.write(buffer, false);
-      
+
       fileImpl.close();
-      
+
       EasyMock.verify(mockFile);
    }
 
    public void testWriteWithSyncAndCallbackError() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
 
       mockFile.write(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.isA(IOCallback.class));
-      
-      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>(){
 
+      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+      {
+
          public Object answer() throws Throwable
          {
-            IOCallback callback = (IOCallback) EasyMock.getCurrentArguments()[3];
-            
+            IOCallback callback = (IOCallback)EasyMock.getCurrentArguments()[3];
+
             callback.onError(100, "Fake Message");
-            
+
             return null;
          }
-         
+
       });
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       try
       {
          fileImpl.write(buffer, true);
@@ -313,31 +314,32 @@
          assertEquals(100, e.getCode());
          assertEquals("Fake Message", e.getMessage());
       }
-      
+
       EasyMock.verify(mockFile);
    }
 
    public void testWriteWithSyncAndException() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
 
       mockFile.write(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.isA(IOCallback.class));
-      
-      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>(){
 
+      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+      {
+
          public Object answer() throws Throwable
          {
             throw new IllegalArgumentException("Fake Message");
          }
-         
+
       });
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       try
       {
          fileImpl.write(buffer, true);
@@ -348,16 +350,16 @@
          assertEquals(-1, e.getCode());
          assertEquals("Fake Message", e.getMessage());
       }
-      
+
       EasyMock.verify(mockFile);
    }
 
    public void testReadWithCallback() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
-      
+
       IOCallback callback = new IOCallback()
       {
 
@@ -369,75 +371,75 @@
          {
          }
       };
-      
+
       mockFile.read(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.same(callback));
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       fileImpl.read(buffer, callback);
-      
+
       EasyMock.verify(mockFile);
    }
 
    public void testReadWithoutCallback() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
-      
+
       mockFile.read(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.isA(IOCallback.class));
-      
-      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>(){
 
+      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+      {
+
          public Object answer() throws Throwable
          {
-            IOCallback callback = (IOCallback) EasyMock.getCurrentArguments()[3];
-            
+            IOCallback callback = (IOCallback)EasyMock.getCurrentArguments()[3];
+
             callback.done();
-            
+
             return null;
          }
-         
+
       });
-      
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       fileImpl.read(buffer);
-      
+
       EasyMock.verify(mockFile);
    }
 
    public void testReadWithoutCallbackOnError() throws Exception
    {
-      SequentialFile fileImpl = openFile();      
-      
+      SequentialFile fileImpl = openFile();
+
       ByteBuffer buffer = ByteBuffer.allocate(512);
-      
+
       mockFile.read(EasyMock.eq(512l * 3l), EasyMock.eq(512l), EasyMock.same(buffer), EasyMock.isA(IOCallback.class));
-      
-      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>(){
 
+      EasyMock.expectLastCall().andAnswer(new IAnswer<Object>()
+      {
+
          public Object answer() throws Throwable
          {
-            IOCallback callback = (IOCallback) EasyMock.getCurrentArguments()[3];
-            
+            IOCallback callback = (IOCallback)EasyMock.getCurrentArguments()[3];
+
             callback.onError(100, "Fake Message");
-            
+
             return null;
          }
-         
+
       });
-      
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.position(512 * 3);
-      
+
       try
       {
          fileImpl.read(buffer);
@@ -448,79 +450,80 @@
          assertEquals(100, e.getCode());
          assertEquals("Fake Message", "Fake Message");
       }
-      
+
       EasyMock.verify(mockFile);
    }
 
-   
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
+   @Override
    protected void setUp()
    {
-      this.mockFile = null;
+      mockFile = null;
    }
-   
+
    // Private -------------------------------------------------------
 
-   private void validateFill(SequentialFile fileImpl, int totalSize, int numberOfBlocksExpected, long blockSizeExpected) throws Exception
+   private void validateFill(final SequentialFile fileImpl,
+                             final int totalSize,
+                             final int numberOfBlocksExpected,
+                             final long blockSizeExpected) throws Exception
    {
       EasyMock.expect(mockFile.getBlockSize()).andReturn(512);
 
       mockFile.fill(512, numberOfBlocksExpected, blockSizeExpected, (byte)'b');
 
       EasyMock.replay(mockFile);
-      
+
       fileImpl.fill(5, totalSize, (byte)'b');
-      
+
       EasyMock.verify(mockFile);
-      
+
       EasyMock.reset(mockFile);
    }
 
    private SequentialFile openFile() throws Exception
    {
-      return openFile ("/tmp", "nothing");
+      return openFile("/tmp", "nothing");
    }
 
-   private SequentialFile openFile(String directory, String fileName) throws Exception
+   private SequentialFile openFile(final String directory, final String fileName) throws Exception
    {
       mockFile = EasyMock.createStrictMock(AsynchronousFile.class);
-      
+
       mockFile.open(directory + "/" + fileName, 1);
-      
+
       EasyMock.replay(mockFile);
-      
+
       SequentialFile file = new MockAIOSequentialFileImpl(directory, fileName, 1);
-      
+
       file.open();
-      
+
       EasyMock.verify(mockFile);
-      
+
       EasyMock.reset(mockFile);
 
       return file;
    }
-   
 
    // Inner classes -------------------------------------------------
-   
+
    class MockAIOSequentialFileImpl extends AIOSequentialFile
    {
 
-      public MockAIOSequentialFileImpl(String journalDir, String fileName, int maxIO)
-            throws Exception
+      public MockAIOSequentialFileImpl(final String journalDir, final String fileName, final int maxIO) throws Exception
       {
          super(journalDir, fileName, maxIO);
       }
-      
-      
+
+      @Override
       protected AsynchronousFile newFile()
       {
          return mockFile;
       }
-      
+
    }
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,26 +1,25 @@
 /*
- * 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.
+ * 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.journal.impl;
 
 import java.nio.ByteBuffer;
@@ -54,10 +53,10 @@
 
    // Constants -----------------------------------------------------
 
-   private static final LoadManager dummyLoader = new LoadManager(){
+   private static final LoadManager dummyLoader = new LoadManager()
+   {
 
-      public void addPreparedTransaction(
-            PreparedTransactionInfo preparedTransaction)
+      public void addPreparedTransaction(PreparedTransactionInfo preparedTransaction)
       {
       }
 
@@ -71,39 +70,37 @@
 
       public void updateRecord(RecordInfo info)
       {
-      }};
-   
+      }
+   };
 
-   
    // Attributes ----------------------------------------------------
-   
+
    private SequentialFileFactory factory;
 
    JournalImpl journalImpl = null;
-   
+
    private ArrayList<RecordInfo> records = null;
 
    private ArrayList<PreparedTransactionInfo> transactions = null;
-   
-   
+
    // Static --------------------------------------------------------
-   
+
    private static final Logger log = Logger.getLogger(AlignedJournalImplTest.class);
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    // This test just validates basic alignment on the FakeSequentialFile itself
    public void testBasicAlignment() throws Exception
    {
-      
+
       FakeSequentialFileFactory factory = new FakeSequentialFileFactory(200, true);
-      
+
       SequentialFile file = factory.createSequentialFile("test1", 1);
 
       file.open();
-      
+
       try
       {
          ByteBuffer buffer = ByteBuffer.allocateDirect(57);
@@ -113,135 +110,132 @@
       catch (Exception ignored)
       {
       }
-      
+
       try
       {
          ByteBuffer buffer = ByteBuffer.allocateDirect(200);
          for (int i = 0; i < 200; i++)
          {
-            buffer.put(i, (byte) 1);
+            buffer.put(i, (byte)1);
          }
-         
+
          file.write(buffer, true);
-         
+
          buffer = ByteBuffer.allocate(400);
          for (int i = 0; i < 400; i++)
          {
-            buffer.put(i, (byte) 2);
+            buffer.put(i, (byte)2);
          }
-         
+
          file.write(buffer, true);
-         
+
          buffer = ByteBuffer.allocate(600);
 
          file.position(0);
-         
+
          file.read(buffer);
-         
+
          for (int i = 0; i < 200; i++)
          {
             assertEquals((byte)1, buffer.get(i));
          }
-         
+
          for (int i = 201; i < 600; i++)
          {
             assertEquals("Position " + i, (byte)2, buffer.get(i));
          }
-         
+
       }
       catch (Exception ignored)
       {
       }
    }
-   
+
    public void testInconsistentAlignment() throws Exception
    {
       factory = new FakeSequentialFileFactory(512, true);
 
       try
       {
-         journalImpl = new JournalImpl(2000, 2,
-            true, true,
-            factory, 
-            "tt", "tt", 1000, 0);
-         fail ("Supposed to throw an exception");
+         journalImpl = new JournalImpl(2000, 2, true, true, factory, "tt", "tt", 1000, 0);
+         fail("Supposed to throw an exception");
       }
       catch (Exception ignored)
       {
       }
 
    }
-      
+
    public void testSimpleAdd() throws Exception
    {
       final int JOURNAL_SIZE = 1060;
-      
+
       setupJournal(JOURNAL_SIZE, 10);
-      
+
       journalImpl.appendAddRecord(13, (byte)14, new SimpleEncoding(1, (byte)15));
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       setupJournal(JOURNAL_SIZE, 10);
-      
+
       assertEquals(1, records.size());
-      
+
       assertEquals(13, records.get(0).id);
-      
+
       assertEquals(14, records.get(0).userRecordType);
-      
+
       assertEquals(1, records.get(0).data.length);
-      
+
       assertEquals(15, records.get(0).data[0]);
-      
+
    }
-   
+
    public void testAppendAndUpdateRecords() throws Exception
    {
-      
+
       final int JOURNAL_SIZE = 1060;
-      
+
       setupJournal(JOURNAL_SIZE, 10);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
 
       for (int i = 0; i < 25; i++)
       {
          byte[] bytes = new byte[5];
-         for (int j=0; j<bytes.length; j++)
+         for (int j = 0; j < bytes.length; j++)
          {
             bytes[j] = (byte)i;
          }
          journalImpl.appendAddRecord(i * 100l, (byte)i, new ByteArrayEncoding(bytes));
       }
-      
+
       for (int i = 25; i < 50; i++)
       {
-         EncodingSupport support = new SimpleEncoding(5, (byte) i);
+         EncodingSupport support = new SimpleEncoding(5, (byte)i);
          journalImpl.appendAddRecord(i * 100l, (byte)i, support);
       }
-      
+
       setupJournal(JOURNAL_SIZE, 1024);
-      
+
       assertEquals(50, records.size());
-      
-      int i=0;
-      for (RecordInfo recordItem: records)
+
+      int i = 0;
+      for (RecordInfo recordItem : records)
       {
          assertEquals(i * 100l, recordItem.id);
          assertEquals(i, recordItem.getUserRecordType());
          assertEquals(5, recordItem.data.length);
-         for (int j=0;j<5;j++)
+         for (int j = 0; j < 5; j++)
          {
             assertEquals((byte)i, recordItem.data[j]);
          }
-         
+
          i++;
       }
-      
+
       for (i = 40; i < 50; i++)
       {
          byte[] bytes = new byte[10];
@@ -249,22 +243,22 @@
          {
             bytes[j] = (byte)'x';
          }
-         
+
          journalImpl.appendUpdateRecord(i * 100l, (byte)i, new ByteArrayEncoding(bytes));
       }
-      
+
       setupJournal(JOURNAL_SIZE, 1024);
-      
-      i=0;
-      for (RecordInfo recordItem: records)
+
+      i = 0;
+      for (RecordInfo recordItem : records)
       {
-         
+
          if (i < 50)
          {
             assertEquals(i * 100l, recordItem.id);
             assertEquals(i, recordItem.getUserRecordType());
             assertEquals(5, recordItem.data.length);
-            for (int j=0;j<5;j++)
+            for (int j = 0; j < 5; j++)
             {
                assertEquals((byte)i, recordItem.data[j]);
             }
@@ -275,60 +269,61 @@
             assertEquals(i - 10, recordItem.getUserRecordType());
             assertTrue(recordItem.isUpdate);
             assertEquals(10, recordItem.data.length);
-            for (int j=0;j<10;j++)
+            for (int j = 0; j < 10; j++)
             {
                assertEquals((byte)'x', recordItem.data[j]);
             }
          }
-         
+
          i++;
       }
-      
+
       journalImpl.stop();
-      
+
    }
-   
+
    public void testPartialDelete() throws Exception
    {
       final int JOURNAL_SIZE = 10000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       journalImpl.setAutoReclaim(false);
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       journalImpl.debugWait();
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
+
       log.debug("Initial:--> " + journalImpl.debug());
-      
+
       log.debug("_______________________________");
-      
+
       for (int i = 0; i < 50; i++)
       {
-         journalImpl.appendAddRecord((long)i, (byte)1, new SimpleEncoding(1, (byte) 'x'));
+         journalImpl.appendAddRecord(i, (byte)1, new SimpleEncoding(1, (byte)'x'));
       }
-      
+
       journalImpl.forceMoveNextFile();
-   
-      // as the request to a new file is asynchronous, we need to make sure the async requests are done
+
+      // as the request to a new file is asynchronous, we need to make sure the
+      // async requests are done
       journalImpl.debugWait();
-      
+
       assertEquals(3, factory.listFiles("tt").size());
-      
+
       for (int i = 10; i < 50; i++)
       {
-         journalImpl.appendDeleteRecord((long)i);
+         journalImpl.appendDeleteRecord(i);
       }
-      
+
       journalImpl.debugWait();
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
-      assertEquals(10, this.records.size());
-      
+
+      assertEquals(10, records.size());
+
       assertEquals(3, factory.listFiles("tt").size());
 
    }
@@ -336,63 +331,63 @@
    public void testAddAndDeleteReclaimWithoutTransactions() throws Exception
    {
       final int JOURNAL_SIZE = 10000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       journalImpl.setAutoReclaim(false);
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       journalImpl.debugWait();
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
+
       log.debug("Initial:--> " + journalImpl.debug());
-      
+
       log.debug("_______________________________");
-      
+
       for (int i = 0; i < 50; i++)
       {
-         journalImpl.appendAddRecord((long)i, (byte)1, new SimpleEncoding(1, (byte) 'x'));
+         journalImpl.appendAddRecord(i, (byte)1, new SimpleEncoding(1, (byte)'x'));
       }
-   
-      // as the request to a new file is asynchronous, we need to make sure the async requests are done
+
+      // as the request to a new file is asynchronous, we need to make sure the
+      // async requests are done
       journalImpl.debugWait();
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
+
       for (int i = 0; i < 50; i++)
       {
-         journalImpl.appendDeleteRecord((long)i);
+         journalImpl.appendDeleteRecord(i);
       }
-      
+
       journalImpl.forceMoveNextFile();
-      
-      journalImpl.appendAddRecord((long)1000, (byte)1, new SimpleEncoding(1, (byte) 'x'));
-      
+
+      journalImpl.appendAddRecord(1000, (byte)1, new SimpleEncoding(1, (byte)'x'));
+
       journalImpl.debugWait();
-      
+
       assertEquals(4, factory.listFiles("tt").size());
 
-
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(1, records.size());
-      
+
       assertEquals(1000, records.get(0).id);
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       log.debug(journalImpl.debug());
-      
+
       journalImpl.debugWait();
-      
+
       log.debug("Final:--> " + journalImpl.debug());
-      
+
       log.debug("_______________________________");
 
       log.debug("Files size:" + factory.listFiles("tt").size());
-      
+
       assertEquals(2, factory.listFiles("tt").size());
 
    }
@@ -400,23 +395,24 @@
    public void testReloadWithTransaction() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
-      journalImpl.appendAddRecordTransactional(1, 1, (byte) 1, new SimpleEncoding(1,(byte) 1));
-      
+
+      journalImpl.appendAddRecordTransactional(1, 1, (byte)1, new SimpleEncoding(1, (byte)1));
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
 
       try
       {
          journalImpl.appendCommitRecord(1l);
-         // This was supposed to throw an exception, as the transaction was forgotten (interrupted by a reload).
+         // This was supposed to throw an exception, as the transaction was
+         // forgotten (interrupted by a reload).
          fail("Supposed to throw exception");
       }
       catch (Exception e)
@@ -425,46 +421,47 @@
       }
 
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
+
    }
-   
+
    public void testReloadWithInterruptedTransaction() throws Exception
    {
       final int JOURNAL_SIZE = 1100;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       journalImpl.setAutoReclaim(false);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(77l, 1, (byte) 1, new SimpleEncoding(1,(byte) 1));
+         journalImpl.appendAddRecordTransactional(77l, 1, (byte)1, new SimpleEncoding(1, (byte)1));
          journalImpl.forceMoveNextFile();
       }
-      
+
       journalImpl.debugWait();
-      
+
       assertEquals(12, factory.listFiles("tt").size());
-      
-      journalImpl.appendAddRecordTransactional(78l, 1, (byte) 1, new SimpleEncoding(1,(byte) 1));
 
+      journalImpl.appendAddRecordTransactional(78l, 1, (byte)1, new SimpleEncoding(1, (byte)1));
+
       assertEquals(12, factory.listFiles("tt").size());
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
 
       try
       {
          journalImpl.appendCommitRecord(77l);
-         // This was supposed to throw an exception, as the transaction was forgotten (interrupted by a reload).
+         // This was supposed to throw an exception, as the transaction was
+         // forgotten (interrupted by a reload).
          fail("Supposed to throw exception");
       }
       catch (Exception e)
@@ -473,29 +470,29 @@
       }
 
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
+
    }
-   
+
    public void testReloadWithCompletedTransaction() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1, i, (byte) 1, new SimpleEncoding(1,(byte) 1));
+         journalImpl.appendAddRecordTransactional(1, i, (byte)1, new SimpleEncoding(1, (byte)1));
          journalImpl.forceMoveNextFile();
       }
-      
+
       journalImpl.appendCommitRecord(1l);
 
       journalImpl.debugWait();
@@ -506,447 +503,447 @@
 
       assertEquals(10, records.size());
       assertEquals(0, transactions.size());
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(10, journalImpl.getDataFilesCount());
-      
+
       assertEquals(12, factory.listFiles("tt").size());
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendDeleteRecordTransactional(2l, (long)i, null);
+         journalImpl.appendDeleteRecordTransactional(2l, i, null);
          journalImpl.forceMoveNextFile();
       }
-      
+
       journalImpl.appendCommitRecord(2l);
-      
+
       journalImpl.appendAddRecord(100, (byte)1, new SimpleEncoding(5, (byte)1));
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.appendAddRecord(101, (byte)1, new SimpleEncoding(5, (byte)1));
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(1, journalImpl.getDataFilesCount());
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(1, journalImpl.getDataFilesCount());
-      
+
       assertEquals(3, factory.listFiles("tt").size());
    }
-   
-   
+
    public void testTotalSize() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
-      journalImpl.appendAddRecordTransactional(1l, 2l, (byte)3, new SimpleEncoding(1900 - JournalImpl.SIZE_ADD_RECORD_TX, (byte)4));
-      
+
+      journalImpl.appendAddRecordTransactional(1l,
+                                               2l,
+                                               (byte)3,
+                                               new SimpleEncoding(1900 - JournalImpl.SIZE_ADD_RECORD_TX, (byte)4));
+
       journalImpl.appendCommitRecord(1l);
-      
+
       journalImpl.debugWait();
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(1, records.size());
-      
+
    }
-   
-   
+
    public void testReloadInvalidCheckSizeOnTransaction() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
-      for (int i = 0; i < 20 ; i++)
+
+      for (int i = 0; i < 20; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, (long)i, (byte)0, new SimpleEncoding(1, (byte)15));
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)15));
          journalImpl.forceMoveNextFile();
       }
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.appendCommitRecord(1l);
-      
+
       SequentialFile file = factory.createSequentialFile("tt-1.tt", 1);
-      
+
       file.open();
-      
+
       ByteBuffer buffer = ByteBuffer.allocate(100);
-      
+
       // Messing up with the first record (removing the position)
       file.position(100);
-      
+
       file.read(buffer);
 
-      // jumping RecordType, FileId, TransactionID, RecordID, VariableSize, RecordType, RecordBody (that we know it is 1 )
-      buffer.position(1 + 4 + 8 + 8 + 4 + 1 + 1); 
-      
+      // jumping RecordType, FileId, TransactionID, RecordID, VariableSize,
+      // RecordType, RecordBody (that we know it is 1 )
+      buffer.position(1 + 4 + 8 + 8 + 4 + 1 + 1);
+
       int posCheckSize = buffer.position();
-      
+
       assertEquals(JournalImpl.SIZE_ADD_RECORD_TX + 1, buffer.getInt());
-      
+
       buffer.position(posCheckSize);
-      
+
       buffer.putInt(-1);
-      
+
       buffer.rewind();
-      
+
       // Changing the check size, so reload will ignore this record
       file.position(100);
 
       file.write(buffer, true);
-      
+
       file.close();
 
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(0, journalImpl.getDataFilesCount());
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
+
    }
 
    public void testPartiallyBrokenFile() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
-      for (int i = 0; i < 20 ; i++)
+
+      for (int i = 0; i < 20; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, (long)i, (byte)0, new SimpleEncoding(1, (byte)15));
-         journalImpl.appendAddRecordTransactional(2l, (long)i + 20l, (byte)0, new SimpleEncoding(1, (byte)15));
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)15));
+         journalImpl.appendAddRecordTransactional(2l, i + 20l, (byte)0, new SimpleEncoding(1, (byte)15));
          journalImpl.forceMoveNextFile();
       }
-      
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.appendCommitRecord(1l);
-      
+
       journalImpl.appendCommitRecord(2l);
-      
+
       SequentialFile file = factory.createSequentialFile("tt-1.tt", 1);
-      
+
       file.open();
-      
+
       ByteBuffer buffer = ByteBuffer.allocate(100);
-      
+
       // Messing up with the first record (removing the position)
       file.position(100);
-      
+
       file.read(buffer);
 
-      // jumping RecordType, FileId, TransactionID, RecordID, VariableSize, RecordType, RecordBody (that we know it is 1 )
-      buffer.position(1 + 4 + 8 + 8 + 4 + 1 + 1); 
-      
+      // jumping RecordType, FileId, TransactionID, RecordID, VariableSize,
+      // RecordType, RecordBody (that we know it is 1 )
+      buffer.position(1 + 4 + 8 + 8 + 4 + 1 + 1);
+
       int posCheckSize = buffer.position();
-      
+
       assertEquals(JournalImpl.SIZE_ADD_RECORD_TX + 1, buffer.getInt());
-      
+
       buffer.position(posCheckSize);
-      
+
       buffer.putInt(-1);
-      
+
       buffer.rewind();
-      
+
       // Changing the check size, so reload will ignore this record
       file.position(100);
 
       file.write(buffer, true);
-      
+
       file.close();
 
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(20, records.size());
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(20, journalImpl.getDataFilesCount());
-      
+
       assertEquals(22, factory.listFiles("tt").size());
-      
+
    }
 
    public void testReduceFreeFiles() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 100, 10);
-      
+
       assertEquals(10, factory.listFiles("tt").size());
-      
+
       setupJournal(JOURNAL_SIZE, 100, 2);
-      
+
       assertEquals(10, factory.listFiles("tt").size());
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecord(i, (byte)0, new SimpleEncoding(1,(byte)0));
+         journalImpl.appendAddRecord(i, (byte)0, new SimpleEncoding(1, (byte)0));
          journalImpl.forceMoveNextFile();
       }
-      
+
       setupJournal(JOURNAL_SIZE, 100, 2);
-      
+
       assertEquals(10, records.size());
-      
+
       assertEquals(12, factory.listFiles("tt").size());
-      
+
       for (int i = 0; i < 10; i++)
       {
          journalImpl.appendDeleteRecord(i);
       }
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       setupJournal(JOURNAL_SIZE, 100, 2);
 
       assertEquals(0, records.size());
-      
+
       assertEquals(2, factory.listFiles("tt").size());
    }
 
-   
    public void testReloadIncompleteTransaction() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
-      for (int i = 0; i < 10 ; i++)
+
+      for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, (long)i, (byte)0, new SimpleEncoding(1, (byte)15));
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)15));
          journalImpl.forceMoveNextFile();
       }
-      
-      
-      for (int i = 10; i < 20 ; i++)
+
+      for (int i = 10; i < 20; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, (long)i, (byte)0, new SimpleEncoding(1, (byte)15));
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)15));
          journalImpl.forceMoveNextFile();
       }
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.appendCommitRecord(1l);
-      
+
       SequentialFile file = factory.createSequentialFile("tt-1.tt", 1);
-      
+
       file.open();
-      
+
       ByteBuffer buffer = ByteBuffer.allocate(100);
-      
+
       // Messing up with the first record (removing the position)
       file.position(100);
-      
+
       file.read(buffer);
 
       buffer.position(1);
-      
+
       buffer.putInt(-1);
-      
+
       buffer.rewind();
-      
-      // Messing up with the first record (changing the fileID, so Journal reload will think the record came from a different journal usage)
+
+      // Messing up with the first record (changing the fileID, so Journal
+      // reload will think the record came from a different journal usage)
       file.position(100);
 
       file.write(buffer, true);
-      
+
       file.close();
 
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(0, journalImpl.getDataFilesCount());
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
+
    }
-   
+
    public void testPrepareAloneOnSeparatedFile() throws Exception
    {
       final int JOURNAL_SIZE = 20000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
-      for (int i=0;i<10;i++)
+
+      for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, (long)i, (byte)0, new SimpleEncoding(1, (byte)15));
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)15));
       }
-      
+
       journalImpl.forceMoveNextFile();
-		SimpleEncoding xidEncoding = new SimpleEncoding(10, (byte)'a');
-		
+      SimpleEncoding xidEncoding = new SimpleEncoding(10, (byte)'a');
+
       journalImpl.appendPrepareRecord(1l, xidEncoding);
       journalImpl.appendCommitRecord(1l);
-      
-      for (int i=0;i<10;i++)
+
+      for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendDeleteRecordTransactional(2l, (long)i, null);
+         journalImpl.appendDeleteRecordTransactional(2l, i, null);
       }
-      
+
       journalImpl.appendCommitRecord(2l);
-      journalImpl.appendAddRecord(100l, (byte)0, new SimpleEncoding(1, (byte)10)); // Add anything to keep holding the file
+      journalImpl.appendAddRecord(100l, (byte)0, new SimpleEncoding(1, (byte)10)); // Add
+      // anything
+      // to
+      // keep
+      // holding
+      // the
+      // file
       journalImpl.forceMoveNextFile();
       journalImpl.checkAndReclaimFiles();
 
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(1, records.size());
    }
-   
+
    public void testCommitWithMultipleFiles() throws Exception
    {
       final int JOURNAL_SIZE = 20000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
-      for (int i=0;i<50;i++)
+
+      for (int i = 0; i < 50; i++)
       {
-         if (i==10)
+         if (i == 10)
          {
             journalImpl.forceMoveNextFile();
          }
-         journalImpl.appendAddRecordTransactional(1l, (long)i, (byte)0, new SimpleEncoding(1, (byte)15));
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)15));
       }
-      
+
       journalImpl.appendCommitRecord(1l);
-      
-      for (int i=0;i<10;i++)
+
+      for (int i = 0; i < 10; i++)
       {
-         if (i==5)
+         if (i == 5)
          {
             journalImpl.forceMoveNextFile();
          }
-         journalImpl.appendDeleteRecordTransactional(2l, (long)i, null);
+         journalImpl.appendDeleteRecordTransactional(2l, i, null);
       }
-      
+
       journalImpl.appendCommitRecord(2l);
       journalImpl.forceMoveNextFile();
       journalImpl.checkAndReclaimFiles();
 
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(40, records.size());
-      
+
    }
-   
-   
+
    public void testSimplePrepare() throws Exception
    {
       final int JOURNAL_SIZE = 3 * 1024;
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
 
       SimpleEncoding xid = new SimpleEncoding(10, (byte)1);
-      
+
       journalImpl.appendAddRecord(10l, (byte)0, new SimpleEncoding(10, (byte)0));
-      
+
       journalImpl.appendDeleteRecordTransactional(1l, 10l, new SimpleEncoding(100, (byte)'j'));
 
       journalImpl.appendPrepareRecord(1, xid);
-      
+
       journalImpl.debugWait();
 
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(1, transactions.size());
       assertEquals(1, transactions.get(0).recordsToDelete.size());
       assertEquals(1, records.size());
 
-      for (RecordInfo record: transactions.get(0).recordsToDelete)
+      for (RecordInfo record : transactions.get(0).recordsToDelete)
       {
          byte[] data = record.data;
          assertEquals(100, data.length);
-         for (int i = 0; i < data.length; i++)
+         for (byte element : data)
          {
-            assertEquals((byte)'j', data[i]);
+            assertEquals((byte)'j', element);
          }
       }
-      
-      
+
       assertEquals(10, transactions.get(0).extraData.length);
-      
+
       for (int i = 0; i < 10; i++)
       {
          assertEquals((byte)1, transactions.get(0).extraData[i]);
       }
-      
+
       journalImpl.appendCommitRecord(1l);
 
       journalImpl.debugWait();
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(0, transactions.size());
       assertEquals(0, records.size());
-      
-      
+
    }
 
-   
    public void testReloadWithPreparedTransaction() throws Exception
    {
       final int JOURNAL_SIZE = 3 * 1024;
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1, i, (byte) 1, new SimpleEncoding(50,(byte) 1));
+         journalImpl.appendAddRecordTransactional(1, i, (byte)1, new SimpleEncoding(50, (byte)1));
          journalImpl.forceMoveNextFile();
       }
-      
+
       journalImpl.debugWait();
 
       SimpleEncoding xid1 = new SimpleEncoding(10, (byte)1);
@@ -959,80 +956,80 @@
 
       assertEquals(0, records.size());
       assertEquals(1, transactions.size());
-      
+
       assertEquals(10, transactions.get(0).extraData.length);
       for (int i = 0; i < 10; i++)
       {
          assertEquals((byte)1, transactions.get(0).extraData[i]);
       }
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(10, journalImpl.getDataFilesCount());
-      
+
       assertEquals(12, factory.listFiles("tt").size());
-      
+
       journalImpl.appendCommitRecord(1l);
-      
+
       setupJournal(JOURNAL_SIZE, 1024);
 
       assertEquals(10, records.size());
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendDeleteRecordTransactional(2l, (long)i, null);
+         journalImpl.appendDeleteRecordTransactional(2l, i, null);
       }
-      
+
       SimpleEncoding xid2 = new SimpleEncoding(15, (byte)2);
 
       journalImpl.appendPrepareRecord(2l, xid2);
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(1, transactions.size());
-      
+
       assertEquals(15, transactions.get(0).extraData.length);
-      
-      for (int i = 0; i < transactions.get(0).extraData.length; i++)
+
+      for (byte element : transactions.get(0).extraData)
       {
-         assertEquals(2, transactions.get(0).extraData[i]);
+         assertEquals(2, element);
       }
 
       assertEquals(10, journalImpl.getDataFilesCount());
 
       assertEquals(12, factory.listFiles("tt").size());
-      
+
       journalImpl.appendCommitRecord(2l);
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
 
       journalImpl.forceMoveNextFile();
 
-      // Reclaiming should still be able to reclaim a file if a transaction was ignored
+      // Reclaiming should still be able to reclaim a file if a transaction was
+      // ignored
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(2, factory.listFiles("tt").size());
 
-      
    }
-   
+
    public void testReloadInvalidPrepared() throws Exception
    {
       final int JOURNAL_SIZE = 3000;
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1, i, (byte) 1, new SimpleEncoding(50,(byte) 1));
+         journalImpl.appendAddRecordTransactional(1, i, (byte)1, new SimpleEncoding(50, (byte)1));
          journalImpl.forceMoveNextFile();
       }
 
@@ -1043,174 +1040,172 @@
       assertEquals(1, transactions.size());
 
       SequentialFile file = factory.createSequentialFile("tt-1.tt", 1);
-      
+
       file.open();
-      
+
       ByteBuffer buffer = ByteBuffer.allocate(100);
-      
+
       // Messing up with the first record (removing the position)
       file.position(100);
-      
+
       file.read(buffer);
 
       buffer.position(1);
-      
+
       buffer.putInt(-1);
-      
+
       buffer.rewind();
-      
-      // Messing up with the first record (changing the fileID, so Journal reload will think the record came from a different journal usage)
+
+      // Messing up with the first record (changing the fileID, so Journal
+      // reload will think the record came from a different journal usage)
       file.position(100);
 
       file.write(buffer, true);
-      
+
       file.close();
-      
+
       setupJournal(JOURNAL_SIZE, 100);
 
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
    }
-   
+
    public void testReclaimAfterRollabck() throws Exception
    {
       final int JOURNAL_SIZE = 2000;
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0) );
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0));
          journalImpl.forceMoveNextFile();
       }
-      
+
       journalImpl.appendRollbackRecord(1l);
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(0, journalImpl.getDataFilesCount());
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(0, journalImpl.getDataFilesCount());
-      
+
       assertEquals(2, factory.listFiles("tt").size());
-      
+
    }
-   
+
    // It should be ok to write records on AIO, and later read then on NIO
    public void testDecreaseAlignment() throws Exception
    {
       final int JOURNAL_SIZE = 512 * 4;
-      
+
       setupJournal(JOURNAL_SIZE, 512);
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0) );
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0));
       }
-      
+
       journalImpl.appendCommitRecord(1l);
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(10, records.size());
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(10, records.size());
    }
-   
+
    // It should be ok to write records on NIO, and later read then on AIO
    public void testIncreaseAlignment() throws Exception
    {
       final int JOURNAL_SIZE = 512 * 4;
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       for (int i = 0; i < 10; i++)
       {
-         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0) );
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0));
       }
-      
+
       journalImpl.appendCommitRecord(1l);
-      
+
       setupJournal(JOURNAL_SIZE, 100);
-      
+
       assertEquals(10, records.size());
-      
+
       setupJournal(JOURNAL_SIZE, 512);
-      
+
       assertEquals(10, records.size());
    }
-   
+
    public void testEmptyPrepare() throws Exception
    {
       final int JOURNAL_SIZE = 512 * 4;
-      
+
       setupJournal(JOURNAL_SIZE, 1);
 
       journalImpl.appendPrepareRecord(2l, new SimpleEncoding(10, (byte)'j'));
-      
+
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.appendAddRecord(1l, (byte)0, new SimpleEncoding(10, (byte)'k'));
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(1, journalImpl.getDataFilesCount());
 
       assertEquals(1, transactions.size());
-      
+
       journalImpl.forceMoveNextFile();
 
       setupJournal(JOURNAL_SIZE, 1);
-   
+
       assertEquals(1, journalImpl.getDataFilesCount());
 
       assertEquals(1, transactions.size());
-      
+
       journalImpl.appendCommitRecord(2l);
-      
+
       journalImpl.appendDeleteRecord(1l);
 
       journalImpl.forceMoveNextFile();
 
       setupJournal(JOURNAL_SIZE, 0);
-      
+
       journalImpl.forceMoveNextFile();
       journalImpl.debugWait();
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(0, transactions.size());
       assertEquals(0, journalImpl.getDataFilesCount());
-      
+
    }
-   
-   
-   
+
    public void testReclaimingAfterConcurrentAddsAndDeletes() throws Exception
    {
       final int JOURNAL_SIZE = 10 * 1024;
-      
+
       setupJournal(JOURNAL_SIZE, 1);
-      
+
       assertEquals(0, records.size());
       assertEquals(0, transactions.size());
-      
+
       final CountDownLatch latchReady = new CountDownLatch(2);
       final CountDownLatch latchStart = new CountDownLatch(1);
       final AtomicInteger finishedOK = new AtomicInteger(0);
       final BlockingQueue<Integer> queueDelete = new LinkedBlockingQueue<Integer>();
-      
+
       final int NUMBER_OF_ELEMENTS = 500;
-      
-      
+
       Thread t1 = new Thread()
       {
+         @Override
          public void run()
          {
             try
@@ -1219,8 +1214,8 @@
                latchStart.await();
                for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
                {
-                  journalImpl.appendAddRecordTransactional((long)i, i, (byte) 1, new SimpleEncoding(50,(byte) 1));
-                  journalImpl.appendCommitRecord((long)i);
+                  journalImpl.appendAddRecordTransactional(i, i, (byte)1, new SimpleEncoding(50, (byte)1));
+                  journalImpl.appendCommitRecord(i);
                   queueDelete.offer(i);
                }
                finishedOK.incrementAndGet();
@@ -1231,9 +1226,10 @@
             }
          }
       };
-      
+
       Thread t2 = new Thread()
       {
+         @Override
          public void run()
          {
             try
@@ -1260,36 +1256,35 @@
 
       t1.start();
       t2.start();
-      
+
       latchReady.await();
       latchStart.countDown();
-      
+
       t1.join();
       t2.join();
-      
+
       assertEquals(2, finishedOK.intValue());
 
       journalImpl.forceMoveNextFile();
-      
+
       journalImpl.checkAndReclaimFiles();
-      
+
       assertEquals(0, journalImpl.getDataFilesCount());
 
       assertEquals(2, factory.listFiles("tt").size());
 
-      
    }
-   
+
    public void testAlignmentOverReload() throws Exception
    {
 
       SequentialFileFactory factory = new FakeSequentialFileFactory(512, false);
       JournalImpl impl = new JournalImpl(512 + 512 * 3, 20, true, false, factory, "jbm", "jbm", 1000, 0);
-      
+
       impl.start();
-      
+
       impl.load(dummyLoader);
-      
+
       impl.appendAddRecord(1l, (byte)0, new SimpleEncoding(100, (byte)'a'));
       impl.appendAddRecord(2l, (byte)0, new SimpleEncoding(100, (byte)'b'));
       impl.appendAddRecord(3l, (byte)0, new SimpleEncoding(100, (byte)'b'));
@@ -1300,57 +1295,55 @@
       impl = new JournalImpl(512 + 1024 + 512, 20, true, false, factory, "jbm", "jbm", 1000, 0);
       impl.start();
       impl.load(dummyLoader);
-      
-      
-      // It looks silly, but this forceMoveNextFile is in place to replicate one specific bug caught during development
+
+      // It looks silly, but this forceMoveNextFile is in place to replicate one
+      // specific bug caught during development
       impl.forceMoveNextFile();
 
       impl.appendDeleteRecord(1l);
       impl.appendDeleteRecord(2l);
       impl.appendDeleteRecord(3l);
       impl.appendDeleteRecord(4l);
-      
+
       impl.stop();
-      
-      
+
       impl = new JournalImpl(512 + 1024 + 512, 20, true, false, factory, "jbm", "jbm", 1000, 0);
       impl.start();
-      
+
       ArrayList<RecordInfo> info = new ArrayList<RecordInfo>();
-      ArrayList<PreparedTransactionInfo> trans  = new ArrayList<PreparedTransactionInfo>();
-      
+      ArrayList<PreparedTransactionInfo> trans = new ArrayList<PreparedTransactionInfo>();
+
       impl.load(info, trans);
 
       assertEquals(0, info.size());
       assertEquals(0, trans.size());
-      
+
    }
-   
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
 
    @Override
    protected void setUp() throws Exception
    {
       super.setUp();
-      
+
       records = new ArrayList<RecordInfo>();
 
       transactions = new ArrayList<PreparedTransactionInfo>();
-      
+
       factory = null;
-      
+
       journalImpl = null;
-      
+
    }
 
    @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
-      
+
       if (journalImpl != null)
       {
          try
@@ -1362,8 +1355,7 @@
          }
       }
    }
-   
-  
+
    // Private -------------------------------------------------------
 
    private void setupJournal(final int journalSize, final int alignment) throws Exception
@@ -1375,30 +1367,24 @@
    {
       if (factory == null)
       {
-         factory = new FakeSequentialFileFactory(alignment,
-               true);
+         factory = new FakeSequentialFileFactory(alignment, true);
       }
-      
+
       if (journalImpl != null)
       {
          journalImpl.stop();
       }
-      
-      journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles,
-            true, true,
-            factory, 
-            "tt", "tt", 1000, 0);
-      
+
+      journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles, true, true, factory, "tt", "tt", 1000, 0);
+
       journalImpl.start();
-      
+
       records.clear();
       transactions.clear();
-      
+
       journalImpl.load(records, transactions);
    }
-   
 
    // Inner classes -------------------------------------------------
-   
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/CleanBufferTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/CleanBufferTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/CleanBufferTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,26 +1,25 @@
 /*
- * 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.
+ * 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.journal.impl;
 
 import java.nio.ByteBuffer;
@@ -39,18 +38,17 @@
  */
 public class CleanBufferTest extends UnitTestCase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
-   
+
    public void testCleanOnNIO()
    {
       SequentialFileFactory factory = new NIOSequentialFileFactory("Whatever");
@@ -63,7 +61,7 @@
       if (AsynchronousFileImpl.isLoaded())
       {
          SequentialFileFactory factory = new AIOSequentialFileFactory("Whatever");
-   
+
          testBuffer(factory);
       }
    }
@@ -75,29 +73,27 @@
       testBuffer(factory);
    }
 
-   private void testBuffer(SequentialFileFactory factory)
+   private void testBuffer(final SequentialFileFactory factory)
    {
       ByteBuffer buffer = factory.newBuffer(100);
       for (byte b = 0; b < 100; b++)
       {
          buffer.put(b);
       }
-      
+
       buffer.rewind();
-      
+
       for (byte b = 0; b < 100; b++)
       {
          assertEquals(b, buffer.get());
       }
-      
-      
 
       buffer.limit(10);
       factory.clearBuffer(buffer);
       buffer.limit(100);
-      
+
       buffer.rewind();
-      
+
       for (byte b = 0; b < 100; b++)
       {
          if (b < 10)
@@ -110,13 +106,13 @@
          }
       }
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/EasyMockJournalTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/EasyMockJournalTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/EasyMockJournalTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,28 +1,30 @@
 /*
- * 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.
+ * 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.journal.impl;
 
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.jboss.messaging.core.journal.BufferCallback;
@@ -33,459 +35,445 @@
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
 import org.jboss.messaging.tests.util.UnitTestCase;
 
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-
 public class EasyMockJournalTest extends UnitTestCase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
    SequentialFileFactory mockFactory = null;
+
    SequentialFile file1 = null;
+
    SequentialFile file2 = null;
+
    JournalImpl journalImpl = null;
-   
+
    // Static --------------------------------------------------------
 
    private static final Logger log = Logger.getLogger(EasyMockJournalTest.class);
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
 
    public void testAppendRecord() throws Exception
    {
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD, 
-                                               /*FileID*/1, 
-                                               /* ID */14l, 
-                                               /*RecordLength*/1, 
-                                               /*RecordType*/(byte)33, 
-                                               /* body */(byte)10, 
-                                               JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD,
+              /*FileID*/1,
+              /* ID */14l,
+              /*RecordLength*/1,
+              /*RecordType*/(byte)33,
+              /* body */(byte)10, JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true)))
+              .andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
 
-      
       EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecord(14l, (byte) 33, new SimpleEncoding(1, (byte)10));
-      
+
+      journalImpl.appendAddRecord(14l, (byte)33, new SimpleEncoding(1, (byte)10));
+
       EasyMock.verify(mockFactory, file1, file2);
 
       EasyMock.reset(mockFactory, file1, file2);
-      
+
       stubValues();
 
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD, 
-            /*FileID*/1, 
-            /* ID */14l, 
-            /*RecordLength*/1, 
-            /*RecordType*/(byte)33, 
-            /* body */(byte)10, 
-            JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
-      
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD,
+              /*FileID*/1,
+              /* ID */14l,
+              /*RecordLength*/1,
+              /*RecordType*/(byte)33,
+              /* body */(byte)10, JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true)))
+              .andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
+
       EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecord(14l, (byte)33, new SimpleEncoding(1,(byte)10));
 
+      journalImpl.appendAddRecord(14l, (byte)33, new SimpleEncoding(1, (byte)10));
+
       EasyMock.verify(mockFactory, file1, file2);
 
    }
 
-
    public void testDeleteRecord() throws Exception
    {
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD, 
-                                               /*FileID*/1, 
-                                               /* ID */14l, 
-                                               /*RecordLength*/1, 
-                                               /*RecordType*/(byte)33, 
-                                               /* body */(byte)10, 
-                                               JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD,
+              /*FileID*/1,
+              /* ID */14l,
+              /*RecordLength*/1,
+              /*RecordType*/(byte)33,
+              /* body */(byte)10, JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true)))
+              .andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
 
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.DELETE_RECORD, 
-            /*FileID*/1, 
-            /* ID */14l, 
-            JournalImpl.SIZE_DELETE_RECORD)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_DELETE_RECORD);
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.DELETE_RECORD,
+      /*FileID*/1,
+      /* ID */14l, JournalImpl.SIZE_DELETE_RECORD)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_DELETE_RECORD);
 
       EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecord(14l, (byte) 33, new SimpleEncoding(1, (byte)10));
-      
+
+      journalImpl.appendAddRecord(14l, (byte)33, new SimpleEncoding(1, (byte)10));
+
       journalImpl.appendDeleteRecord(14l);
 
       EasyMock.verify(mockFactory, file1, file2);
    }
-   //todo fix tests
+
+   // todo fix tests
    /*public void testDeleteTransRecord() throws Exception
    {
       EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD, 
             *//*FileID*//*1,
-            *//* ID *//*15l,
-            *//*RecordLength*//*1,
-            *//*RecordType*//*(byte)33,
-            *//* body *//*(byte)10,
-            JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
+                  *//* ID *//*15l,
+                  *//*RecordLength*//*1,
+                  *//*RecordType*//*(byte)33,
+                  *//* body *//*(byte)10,
+                  JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
 
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.DELETE_RECORD_TX, 
-            *//*FileID*//*1,
-            *//* Transaction ID*//* 100l,
-            *//* ID *//*15l,
-            JournalImpl.SIZE_DELETE_RECORD_TX)), EasyMock.eq(false))).andReturn(JournalImpl.SIZE_DELETE_RECORD_TX);
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.PREPARE_RECORD, 
-            *//*FileID*//*1,
-            *//* Transaction ID*//* 100l,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 1,
-            JournalImpl.SIZE_PREPARE_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_PREPARE_RECORD);
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.COMMIT_RECORD, 
-            *//*FileID*//*1,
-            *//* Transaction ID*//* 100l,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 1,
-            JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_COMMIT_RECORD);
-      
-      EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecord(15l, (byte) 33, new byte[]{ (byte) 10 });
-      
-      journalImpl.appendDeleteRecordTransactional(100l, 15l);
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.DELETE_RECORD_TX, 
+                  *//*FileID*//*1,
+                  *//* Transaction ID*//* 100l,
+                  *//* ID *//*15l,
+                  JournalImpl.SIZE_DELETE_RECORD_TX)), EasyMock.eq(false))).andReturn(JournalImpl.SIZE_DELETE_RECORD_TX);
+            
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.PREPARE_RECORD, 
+                  *//*FileID*//*1,
+                  *//* Transaction ID*//* 100l,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 1,
+                  JournalImpl.SIZE_PREPARE_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_PREPARE_RECORD);
+            
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.COMMIT_RECORD, 
+                  *//*FileID*//*1,
+                  *//* Transaction ID*//* 100l,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 1,
+                  JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_COMMIT_RECORD);
+            
+            EasyMock.replay(mockFactory, file1, file2);
+            
+            journalImpl.appendAddRecord(15l, (byte) 33, new byte[]{ (byte) 10 });
+            
+            journalImpl.appendDeleteRecordTransactional(100l, 15l);
 
-		Xid xid = new XidImpl("branch".getBytes(), 1, "globalid".getBytes());
-      journalImpl.appendPrepareRecord(100l, xid);
-      
-      journalImpl.appendCommitRecord(100l);
-      
-      EasyMock.verify(mockFactory, file1, file2);
-   }*/
+      		Xid xid = new XidImpl("branch".getBytes(), 1, "globalid".getBytes());
+            journalImpl.appendPrepareRecord(100l, xid);
+            
+            journalImpl.appendCommitRecord(100l);
+            
+            EasyMock.verify(mockFactory, file1, file2);
+         }*/
 
    /*public void testAppendAndCommitRecord() throws Exception
    {
       EasyMock.expect(
             file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD_TX,
             *//* FileID *//*1,
-            *//* TXID *//*3l,
-            *//* ID *//*14l,
-            *//* RecordLength *//*1,
-            *//* RecordType *//*(byte) 33,
-            *//* body *//*(byte) 10, JournalImpl.SIZE_ADD_RECORD_TX + 1)),
-                  EasyMock.eq(false))).andReturn(
-            JournalImpl.SIZE_ADD_RECORD_TX + 1);
-      
-      EasyMock.expect(
-            file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD_TX,
-            *//* FileID *//*1,
-            *//* TXID *//*3l,
-            *//* ID *//*15l,
-            *//* RecordLength *//*1,
-            *//* RecordType *//*(byte) 33,
-            *//* body *//*(byte) 10, JournalImpl.SIZE_ADD_RECORD_TX + 1)),
-                  EasyMock.eq(false))).andReturn(
-            JournalImpl.SIZE_ADD_RECORD_TX + 1);
+                  *//* TXID *//*3l,
+                  *//* ID *//*14l,
+                  *//* RecordLength *//*1,
+                  *//* RecordType *//*(byte) 33,
+                  *//* body *//*(byte) 10, JournalImpl.SIZE_ADD_RECORD_TX + 1)),
+                        EasyMock.eq(false))).andReturn(
+                  JournalImpl.SIZE_ADD_RECORD_TX + 1);
+            
+            EasyMock.expect(
+                  file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD_TX,
+                  *//* FileID *//*1,
+                  *//* TXID *//*3l,
+                  *//* ID *//*15l,
+                  *//* RecordLength *//*1,
+                  *//* RecordType *//*(byte) 33,
+                  *//* body *//*(byte) 10, JournalImpl.SIZE_ADD_RECORD_TX + 1)),
+                        EasyMock.eq(false))).andReturn(
+                  JournalImpl.SIZE_ADD_RECORD_TX + 1);
 
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.PREPARE_RECORD, 
-            *//*FileID*//*1,
-            *//* TXID *//* 3l,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 2,
-            JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_PREPARE_RECORD + 8);
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.COMMIT_RECORD, 
-            *//*FileID*//*1,
-            *//* TXID *//* 3l,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 2,
-            JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_COMMIT_RECORD + 8);
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.PREPARE_RECORD, 
+                  *//*FileID*//*1,
+                  *//* TXID *//* 3l,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 2,
+                  JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_PREPARE_RECORD + 8);
+            
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.COMMIT_RECORD, 
+                  *//*FileID*//*1,
+                  *//* TXID *//* 3l,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 2,
+                  JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_COMMIT_RECORD + 8);
 
-      EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecordTransactional(3, 14l, (byte)33, new SimpleEncoding(1,(byte)10));
-      
-      journalImpl.appendAddRecordTransactional(3, 15l, (byte) 33, new byte[]{ (byte) 10 });
+            EasyMock.replay(mockFactory, file1, file2);
+            
+            journalImpl.appendAddRecordTransactional(3, 14l, (byte)33, new SimpleEncoding(1,(byte)10));
+            
+            journalImpl.appendAddRecordTransactional(3, 15l, (byte) 33, new byte[]{ (byte) 10 });
 
-		Xid xid = new XidImpl("branch".getBytes(), 1, "globalid".getBytes());
-      journalImpl.appendPrepareRecord(3l, xid);
-      
-      journalImpl.appendCommitRecord(3l);
-      
-      EasyMock.verify(mockFactory, file1, file2);
-   }*/
+      		Xid xid = new XidImpl("branch".getBytes(), 1, "globalid".getBytes());
+            journalImpl.appendPrepareRecord(3l, xid);
+            
+            journalImpl.appendCommitRecord(3l);
+            
+            EasyMock.verify(mockFactory, file1, file2);
+         }*/
 
    public void testAppendAndRollbacktRecord() throws Exception
    {
-      EasyMock.expect(
-            file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD_TX,
-            /* FileID */1,
-            /* TXID */3l,
-            /* ID */14l,
-            /* RecordLength */1,
-            /* RecordType */(byte) 33,
-            /* body */(byte) 10, JournalImpl.SIZE_ADD_RECORD_TX + 1)),
-                  EasyMock.eq(false))).andReturn(
-            JournalImpl.SIZE_ADD_RECORD_TX + 1);
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ROLLBACK_RECORD, 
-            /*FileID*/1, 
-            /* TXID */ 3l,
-            JournalImpl.SIZE_ROLLBACK_RECORD)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ROLLBACK_RECORD);
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD_TX,
+              /* FileID */1,
+              /* TXID */3l,
+              /* ID */14l,
+              /* RecordLength */1,
+              /* RecordType */(byte)33,
+              /* body */(byte)10, JournalImpl.SIZE_ADD_RECORD_TX + 1)), EasyMock.eq(false)))
+              .andReturn(JournalImpl.SIZE_ADD_RECORD_TX + 1);
 
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ROLLBACK_RECORD,
+              /*FileID*/1,
+              /* TXID */3l, JournalImpl.SIZE_ROLLBACK_RECORD)), EasyMock.eq(true)))
+              .andReturn(JournalImpl.SIZE_ROLLBACK_RECORD);
+
       EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecordTransactional(3, 14l, (byte)33, new SimpleEncoding(1,(byte)10));
-      
+
+      journalImpl.appendAddRecordTransactional(3, 14l, (byte)33, new SimpleEncoding(1, (byte)10));
+
       journalImpl.appendRollbackRecord(3l);
-      
+
       EasyMock.verify(mockFactory, file1, file2);
    }
-   
+
    public void testupdateRecordNonTrans() throws Exception
    {
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD, 
-            /* FileID */1, 
-            /* ID */15l, 
-            /* RecordLength */1, 
-            /* RecordType */(byte)33, 
-            /* body */(byte)10, 
-            JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD,
+              /* FileID */1,
+              /* ID */15l,
+              /* RecordLength */1,
+              /* RecordType */(byte)33,
+              /* body */(byte)10, JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true)))
+              .andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
 
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD, 
-            /* FileID */1, 
-            /* ID */15l, 
-            /* RecordLength */1, 
-            /* RecordType */(byte)34, 
-            /* body */(byte)11, 
-            JournalImpl.SIZE_UPDATE_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_UPDATE_RECORD + 1);
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD, 
-            /* FileID */1, 
-            /* ID */15l, 
-            /* RecordLength */1, 
-            /* RecordType */(byte)35, 
-            /* body */(byte)12, 
-            JournalImpl.SIZE_UPDATE_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_UPDATE_RECORD + 1);
-      
-     EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecord(15l, (byte) 33, new SimpleEncoding(1, (byte)10));
-      
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD,
+              /* FileID */1,
+              /* ID */15l,
+              /* RecordLength */1,
+              /* RecordType */(byte)34,
+              /* body */(byte)11, JournalImpl.SIZE_UPDATE_RECORD + 1)), EasyMock.eq(true)))
+              .andReturn(JournalImpl.SIZE_UPDATE_RECORD + 1);
+
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD,
+              /* FileID */1,
+              /* ID */15l,
+              /* RecordLength */1,
+              /* RecordType */(byte)35,
+              /* body */(byte)12, JournalImpl.SIZE_UPDATE_RECORD + 1)), EasyMock.eq(true)))
+              .andReturn(JournalImpl.SIZE_UPDATE_RECORD + 1);
+
+      EasyMock.replay(mockFactory, file1, file2);
+
+      journalImpl.appendAddRecord(15l, (byte)33, new SimpleEncoding(1, (byte)10));
+
       journalImpl.appendUpdateRecord(15l, (byte)34, new SimpleEncoding(1, (byte)11));
-      
+
       journalImpl.appendUpdateRecord(15l, (byte)35, new SimpleEncoding(1, (byte)12));
-      
+
       EasyMock.verify(mockFactory, file1, file2);
 
    }
 
-   
    /*public void testupdateRecordTrans() throws Exception
    {
       EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.ADD_RECORD, 
             *//* FileID *//*1,
-            *//* ID *//*15l,
-            *//* RecordLength *//*1,
-            *//* RecordType *//*(byte)33,
-            *//* body *//*(byte)10,
-            JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
+                  *//* ID *//*15l,
+                  *//* RecordLength *//*1,
+                  *//* RecordType *//*(byte)33,
+                  *//* body *//*(byte)10,
+                  JournalImpl.SIZE_ADD_RECORD + 1)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_ADD_RECORD + 1);
 
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD_TX, 
-            *//* FileID *//*1,
-            *//* TransactionID *//*33l,
-            *//* ID *//*15l,
-            *//* RecordLength *//*1,
-            *//* RecordType *//* (byte)34,
-            *//* body *//*(byte)11,
-            JournalImpl.SIZE_UPDATE_RECORD_TX + 1)), EasyMock.eq(false))).andReturn(JournalImpl.SIZE_UPDATE_RECORD_TX + 1);
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD_TX, 
-            *//* FileID *//*1,
-            *//* TransactionID *//*33l,
-            *//* ID *//*15l,
-            *//* RecordLength *//*1,
-            *//* RecordType *//* (byte)35,
-            *//* body *//*(byte)12,
-            JournalImpl.SIZE_UPDATE_RECORD_TX + 1)), EasyMock.eq(false))).andReturn(JournalImpl.SIZE_UPDATE_RECORD_TX + 1);
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.COMMIT_RECORD, 
-            *//*FileID*//*1,
-            *//* Transaction ID*//* 33l,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 1,
-            *//* Number of Elements *//* 2,
-            JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_COMMIT_RECORD);
-      
-      EasyMock.replay(mockFactory, file1, file2);
-      
-      journalImpl.appendAddRecord(15l, (byte) 33, new byte[]{ (byte) 10 });
-      
-      journalImpl.appendUpdateRecordTransactional(33l, 15l, (byte)34, new SimpleEncoding(1, (byte)11));
-      
-      journalImpl.appendUpdateRecordTransactional(33l, 15l, (byte)35, new byte[]{ (byte) 12});
-      
-      journalImpl.appendCommitRecord(33l);
-      
-      EasyMock.verify(mockFactory, file1, file2);
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD_TX, 
+                  *//* FileID *//*1,
+                  *//* TransactionID *//*33l,
+                  *//* ID *//*15l,
+                  *//* RecordLength *//*1,
+                  *//* RecordType *//* (byte)34,
+                  *//* body *//*(byte)11,
+                  JournalImpl.SIZE_UPDATE_RECORD_TX + 1)), EasyMock.eq(false))).andReturn(JournalImpl.SIZE_UPDATE_RECORD_TX + 1);
+            
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.UPDATE_RECORD_TX, 
+                  *//* FileID *//*1,
+                  *//* TransactionID *//*33l,
+                  *//* ID *//*15l,
+                  *//* RecordLength *//*1,
+                  *//* RecordType *//* (byte)35,
+                  *//* body *//*(byte)12,
+                  JournalImpl.SIZE_UPDATE_RECORD_TX + 1)), EasyMock.eq(false))).andReturn(JournalImpl.SIZE_UPDATE_RECORD_TX + 1);
+            
+            EasyMock.expect(file1.write(compareByteBuffer(autoEncode(JournalImpl.COMMIT_RECORD, 
+                  *//*FileID*//*1,
+                  *//* Transaction ID*//* 33l,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 1,
+                  *//* Number of Elements *//* 2,
+                  JournalImpl.SIZE_COMMIT_RECORD + 8)), EasyMock.eq(true))).andReturn(JournalImpl.SIZE_COMMIT_RECORD);
+            
+            EasyMock.replay(mockFactory, file1, file2);
+            
+            journalImpl.appendAddRecord(15l, (byte) 33, new byte[]{ (byte) 10 });
+            
+            journalImpl.appendUpdateRecordTransactional(33l, 15l, (byte)34, new SimpleEncoding(1, (byte)11));
+            
+            journalImpl.appendUpdateRecordTransactional(33l, 15l, (byte)35, new byte[]{ (byte) 12});
+            
+            journalImpl.appendCommitRecord(33l);
+            
+            EasyMock.verify(mockFactory, file1, file2);
 
-   }*/
+         }*/
 
    // Protected -----------------------------------------------------
-   
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
-      
+
       if (journalImpl != null)
       {
          EasyMock.reset(mockFactory, file1, file2);
          stubValues();
-         try {journalImpl.stop();} catch (Throwable ignored) {}
+         try
+         {
+            journalImpl.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
       }
-      
+
    }
-   
+
+   @Override
    protected void setUp() throws Exception
    {
       journalImpl = newJournal();
    }
-   
+
    // Private -------------------------------------------------------
-   
+
    private JournalImpl newJournal() throws Exception
    {
       mockFactory = EasyMock.createMock(SequentialFileFactory.class);
       file1 = EasyMock.createMock(SequentialFile.class);
       file2 = EasyMock.createMock(SequentialFile.class);
-      
+
       stubValues();
-      
+
       EasyMock.expect(mockFactory.createSequentialFile(EasyMock.isA(String.class), EasyMock.anyInt())).andReturn(file1);
-      
+
       EasyMock.expect(mockFactory.createSequentialFile(EasyMock.isA(String.class), EasyMock.anyInt())).andReturn(file2);
-      
+
       file1.open();
-      
+
       EasyMock.expectLastCall().anyTimes();
-      
+
       file2.open();
-      
+
       EasyMock.expectLastCall().anyTimes();
-      
+
       file1.close();
-      
+
       EasyMock.expectLastCall().anyTimes();
-      
+
       file2.close();
-      
+
       EasyMock.expectLastCall().anyTimes();
-      
-      file1.fill(0, 100 * 1024, (byte) 'J');
-      
-      file2.fill(0, 100 * 1024, (byte) 'J');
-      
-      EasyMock.expect(file1.write(compareByteBuffer(autoEncode((int)1)), EasyMock.eq(true))).andReturn(4);
-      EasyMock.expect(file2.write(compareByteBuffer(autoEncode((int)2)), EasyMock.eq(true))).andReturn(4);
-      
+
+      file1.fill(0, 100 * 1024, (byte)'J');
+
+      file2.fill(0, 100 * 1024, (byte)'J');
+
+      EasyMock.expect(file1.write(compareByteBuffer(autoEncode(1)), EasyMock.eq(true))).andReturn(4);
+      EasyMock.expect(file2.write(compareByteBuffer(autoEncode(2)), EasyMock.eq(true))).andReturn(4);
+
       file1.position(4);
-      
+
       file2.position(4);
-      
+
       EasyMock.replay(mockFactory, file1, file2);
-      
-      JournalImpl journalImpl = new JournalImpl(100 * 1024, 2,
-            true, true,
-            mockFactory,
-            "tt", "tt", 1000, 0);
-      
+
+      JournalImpl journalImpl = new JournalImpl(100 * 1024, 2, true, true, mockFactory, "tt", "tt", 1000, 0);
+
       journalImpl.start();
-      
+
       journalImpl.load(new ArrayList(), new ArrayList());
-      
+
       EasyMock.verify(mockFactory, file1, file2);
-      
+
       EasyMock.reset(mockFactory, file1, file2);
-      
+
       stubValues();
-      
+
       return journalImpl;
    }
 
-
    private void stubValues() throws Exception
    {
       EasyMock.expect(mockFactory.getAlignment()).andStubReturn(1);
       EasyMock.expect(mockFactory.isSupportsCallbacks()).andStubReturn(false);
 
-      EasyMock.expect(mockFactory.listFiles("tt")).andStubReturn(
-            new ArrayList<String>());
-      
-      EasyMock.expect(mockFactory.newBuffer(EasyMock.anyInt())).andStubAnswer(
-            new IAnswer<ByteBuffer>()
-            {
-               
-               public ByteBuffer answer() throws Throwable
-               {
-                  Integer valueInt = (Integer) EasyMock.getCurrentArguments()[0];
-                  
-                  return ByteBuffer.allocateDirect(valueInt);
-               }
-            });
-      
-      EasyMock.expect(file1.calculateBlockStart(EasyMock.anyInt()))
-            .andStubAnswer(new IAnswer<Integer>()
-            {
-               
-               public Integer answer() throws Throwable
-               {
-                  return (Integer) EasyMock.getCurrentArguments()[0];
-               }
-            });
-      
-      EasyMock.expect(file2.calculateBlockStart(EasyMock.anyInt()))
-            .andStubAnswer(new IAnswer<Integer>()
-            {
-               
-               public Integer answer() throws Throwable
-               {
-                  return (Integer) EasyMock.getCurrentArguments()[0];
-               }
-            });
-      
-      
-      EasyMock.expect(mockFactory.calculateBlockSize(EasyMock.anyInt()))
-      .andStubAnswer(new IAnswer<Integer>()
+      EasyMock.expect(mockFactory.listFiles("tt")).andStubReturn(new ArrayList<String>());
+
+      EasyMock.expect(mockFactory.newBuffer(EasyMock.anyInt())).andStubAnswer(new IAnswer<ByteBuffer>()
       {
-         
+
+         public ByteBuffer answer() throws Throwable
+         {
+            Integer valueInt = (Integer)EasyMock.getCurrentArguments()[0];
+
+            return ByteBuffer.allocateDirect(valueInt);
+         }
+      });
+
+      EasyMock.expect(file1.calculateBlockStart(EasyMock.anyInt())).andStubAnswer(new IAnswer<Integer>()
+      {
+
          public Integer answer() throws Throwable
          {
-            return (Integer) EasyMock.getCurrentArguments()[0];
+            return (Integer)EasyMock.getCurrentArguments()[0];
          }
       });
-      
+
+      EasyMock.expect(file2.calculateBlockStart(EasyMock.anyInt())).andStubAnswer(new IAnswer<Integer>()
+      {
+
+         public Integer answer() throws Throwable
+         {
+            return (Integer)EasyMock.getCurrentArguments()[0];
+         }
+      });
+
+      EasyMock.expect(mockFactory.calculateBlockSize(EasyMock.anyInt())).andStubAnswer(new IAnswer<Integer>()
+      {
+
+         public Integer answer() throws Throwable
+         {
+            return (Integer)EasyMock.getCurrentArguments()[0];
+         }
+      });
+
       file1.setBufferCallback(EasyMock.isA(BufferCallback.class));
       EasyMock.expectLastCall().anyTimes();
-      
+
       file2.setBufferCallback(EasyMock.isA(BufferCallback.class));
       EasyMock.expectLastCall().anyTimes();
-      
-      
 
       EasyMock.expect(file1.getAlignment()).andStubReturn(1);
       EasyMock.expect(file2.getAlignment()).andStubReturn(1);
-      
+
    }
-   
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
-   
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeJournalImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeJournalImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeJournalImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,24 +1,24 @@
 /*
- * 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.
- */ 
+ * 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.journal.impl;
 
@@ -34,11 +34,13 @@
  */
 public class FakeJournalImplTest extends JournalImplTestUnit
 {
-	protected SequentialFileFactory getFileFactory() throws Exception
-	{
-		return new FakeSequentialFileFactory();
-	}
+   @Override
+   protected SequentialFileFactory getFileFactory() throws Exception
+   {
+      return new FakeSequentialFileFactory();
+   }
 
+   @Override
    protected int getAlignment()
    {
       return 1;

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeSequentialFileFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeSequentialFileFactoryTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FakeSequentialFileFactoryTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,24 +1,24 @@
 /*
- * 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.
- */ 
+ * 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.journal.impl;
 
@@ -34,14 +34,16 @@
  */
 public class FakeSequentialFileFactoryTest extends SequentialFileFactoryTestBase
 {
-	protected void setUp() throws Exception
-	{
-		super.setUp();
-	}
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+   }
 
-	protected SequentialFileFactory createFactory()
-	{
-		return new FakeSequentialFileFactory();
-	}
+   @Override
+   protected SequentialFileFactory createFactory()
+   {
+      return new FakeSequentialFileFactory();
+   }
 
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FileFactoryTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FileFactoryTestBase.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/FileFactoryTestBase.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,24 +1,24 @@
 /*
- * 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.
- */ 
+ * 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.journal.impl;
 
@@ -27,6 +27,7 @@
 import org.jboss.messaging.core.journal.SequentialFile;
 import org.jboss.messaging.core.journal.SequentialFileFactory;
 import org.jboss.messaging.tests.util.UnitTestCase;
+
 /**
  * 
  * @author clebert.suconic at jboss.org
@@ -35,52 +36,47 @@
 public abstract class FileFactoryTestBase extends UnitTestCase
 {
    protected abstract SequentialFileFactory createFactory();
-   
+
    protected SequentialFileFactory factory;
 
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
-      
+
       factory = createFactory();
    }
-   
 
-   
    // Protected ---------------------------------
-   
-   protected void checkFill(SequentialFile file, int pos, int size, byte fillChar) throws Exception
+
+   protected void checkFill(final SequentialFile file, final int pos, final int size, final byte fillChar) throws Exception
    {
       file.fill(pos, size, fillChar);
-      
+
       file.close();
-      
+
       file.open();
-      
+
       file.position(pos);
-      
-      
-      
+
       ByteBuffer bb = ByteBuffer.allocateDirect(size);
-      
+
       int bytesRead = file.read(bb);
-      
+
       assertEquals(size, bytesRead);
-      
+
       bb.rewind();
-      
+
       byte bytes[] = new byte[size];
-      
+
       bb.get(bytes);
-      
+
       for (int i = 0; i < size; i++)
       {
-         //log.debug(" i is " + i);
+         // log.debug(" i is " + i);
          assertEquals(fillChar, bytes[i]);
       }
-            
+
    }
-   
-   
 
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalAsyncTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalAsyncTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalAsyncTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,26 +1,25 @@
 /*
- * 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.
+ * 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.journal.impl;
 
 import java.util.ArrayList;
@@ -36,48 +35,49 @@
 
 public class JournalAsyncTest extends UnitTestCase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    private FakeSequentialFileFactory factory;
-   
+
    JournalImpl journalImpl = null;
-   
+
    private ArrayList<RecordInfo> records = null;
-   
+
    private ArrayList<PreparedTransactionInfo> transactions = null;
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    public void testAsynchronousCommit() throws Exception
    {
       final int JOURNAL_SIZE = 20000;
-      
+
       setupJournal(JOURNAL_SIZE, 100, 5);
-      
+
       factory.setHoldCallbacks(true);
-      
+
       final CountDownLatch latch = new CountDownLatch(1);
-      
+
       class LocalThread extends Thread
       {
          Exception e;
-         
+
+         @Override
          public void run()
          {
             try
             {
                for (int i = 0; i < 10; i++)
                {
-                  journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1,(byte)0));
+                  journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1, (byte)0));
                }
-               
+
                latch.countDown();
                factory.setHoldCallbacks(false);
                journalImpl.appendCommitRecord(1l);
@@ -89,49 +89,50 @@
             }
          }
       };
-      
+
       LocalThread t = new LocalThread();
       t.start();
 
       assertTrue(latch.await(5, TimeUnit.SECONDS));
-      
+
       Thread.yield();
 
       assertTrue(t.isAlive());
 
       factory.flushAllCallbacks();
-      
+
       t.join();
-      
+
       if (t.e != null)
       {
          throw t.e;
       }
    }
-   
+
    public void testAsynchronousRollbackWithError() throws Exception
    {
       final int JOURNAL_SIZE = 20000;
-      
+
       setupJournal(JOURNAL_SIZE, 100, 5);
-      
+
       factory.setHoldCallbacks(true);
-      
+
       final CountDownLatch latch = new CountDownLatch(1);
-      
+
       class LocalThread extends Thread
       {
          Exception e;
-         
+
+         @Override
          public void run()
          {
             try
             {
                for (int i = 0; i < 10; i++)
                {
-                  journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1,(byte)0));
+                  journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1, (byte)0));
                }
-               
+
                latch.countDown();
                journalImpl.appendRollbackRecord(1l);
             }
@@ -141,54 +142,55 @@
             }
          }
       };
-      
+
       LocalThread t = new LocalThread();
       t.start();
-      
+
       latch.await();
-      
+
       Thread.yield();
 
       assertTrue(t.isAlive());
-      
+
       factory.setCallbackAsError(0);
-      
+
       factory.flushCallback(0);
-      
+
       Thread.yield();
-      
+
       assertTrue(t.isAlive());
-      
+
       factory.flushAllCallbacks();
-      
+
       t.join();
-      
-      assertNotNull (t.e);
+
+      assertNotNull(t.e);
    }
-   
+
    public void testAsynchronousCommitWithError() throws Exception
    {
       final int JOURNAL_SIZE = 20000;
-      
+
       setupJournal(JOURNAL_SIZE, 100, 5);
-      
+
       factory.setHoldCallbacks(true);
-      
+
       final CountDownLatch latch = new CountDownLatch(1);
-      
+
       class LocalThread extends Thread
       {
          Exception e;
-         
+
+         @Override
          public void run()
          {
             try
             {
                for (int i = 0; i < 10; i++)
                {
-                  journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1,(byte)0));
+                  journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1, (byte)0));
                }
-               
+
                latch.countDown();
                journalImpl.appendCommitRecord(1l);
             }
@@ -198,30 +200,30 @@
             }
          }
       };
-      
+
       LocalThread t = new LocalThread();
       t.start();
-      
+
       latch.await();
-      
+
       Thread.yield();
 
       assertTrue(t.isAlive());
-      
+
       factory.setCallbackAsError(0);
-      
+
       factory.flushCallback(0);
-      
+
       Thread.yield();
-      
+
       assertTrue(t.isAlive());
-      
+
       factory.flushAllCallbacks();
-      
+
       t.join();
-      
-      assertNotNull (t.e);
-      
+
+      assertNotNull(t.e);
+
       try
       {
          journalImpl.appendRollbackRecord(1l);
@@ -229,45 +231,49 @@
       }
       catch (Exception e)
       {
-         
+
       }
    }
-   
-   // If a callback error already arrived, we should just throw the exception right away
+
+   // If a callback error already arrived, we should just throw the exception
+   // right away
    public void testPreviousError() throws Exception
    {
       final int JOURNAL_SIZE = 20000;
-      
+
       setupJournal(JOURNAL_SIZE, 100, 5);
-      
+
       factory.setHoldCallbacks(true);
       factory.setGenerateErrors(true);
-      
-      journalImpl.appendAddRecordTransactional(1l, 1, (byte)1, new SimpleEncoding(1,(byte)0));
-      
+
+      journalImpl.appendAddRecordTransactional(1l, 1, (byte)1, new SimpleEncoding(1, (byte)0));
+
       factory.flushAllCallbacks();
-      
+
       factory.setGenerateErrors(false);
       factory.setHoldCallbacks(false);
 
       try
       {
-         journalImpl.appendAddRecordTransactional(1l, 2, (byte)1, new SimpleEncoding(1,(byte)0));
-         fail("Exception expected"); // An exception already happened in one of the elements on this transaction. We can't accept any more elements on the transaction
+         journalImpl.appendAddRecordTransactional(1l, 2, (byte)1, new SimpleEncoding(1, (byte)0));
+         fail("Exception expected"); // An exception already happened in one
+         // of the elements on this transaction.
+         // We can't accept any more elements on
+         // the transaction
       }
       catch (Exception ignored)
       {
       }
    }
-   
+
    public void testSyncNonTransaction() throws Exception
    {
       final int JOURNAL_SIZE = 20000;
-      
+
       setupJournal(JOURNAL_SIZE, 100, 5);
-      
+
       factory.setGenerateErrors(true);
-      
+
       try
       {
          journalImpl.appendAddRecord(1l, (byte)0, new SimpleEncoding(1, (byte)0));
@@ -275,37 +281,35 @@
       }
       catch (Exception ignored)
       {
-         
+
       }
-      
-      
+
    }
-   
-   
-    // Package protected ---------------------------------------------
-   
+
+   // Package protected ---------------------------------------------
+
    // Protected -----------------------------------------------------
-   
+
    @Override
    protected void setUp() throws Exception
    {
       super.setUp();
-      
+
       records = new ArrayList<RecordInfo>();
-      
+
       transactions = new ArrayList<PreparedTransactionInfo>();
-      
+
       factory = null;
-      
+
       journalImpl = null;
-      
+
    }
-   
+
    @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
-      
+
       if (journalImpl != null)
       {
          try
@@ -317,32 +321,30 @@
          }
       }
    }
-   
+
    // Private -------------------------------------------------------
-   private void setupJournal(final int journalSize, final int alignment,
-         final int numberOfMinimalFiles) throws Exception
+   private void setupJournal(final int journalSize, final int alignment, final int numberOfMinimalFiles) throws Exception
    {
       if (factory == null)
       {
          factory = new FakeSequentialFileFactory(alignment, true);
       }
-      
+
       if (journalImpl != null)
       {
          journalImpl.stop();
       }
-      
-      journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles, true,
-            true, factory, "tt", "tt", 1000, 0);
-      
+
+      journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles, true, true, factory, "tt", "tt", 1000, 0);
+
       journalImpl.start();
-      
+
       records.clear();
       transactions.clear();
-      
+
       journalImpl.load(records, transactions);
    }
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,27 +1,35 @@
 /*
- * 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.
- */ 
+ * 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.journal.impl;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+
 import org.jboss.messaging.core.asyncio.impl.AsynchronousFileImpl;
 import org.jboss.messaging.core.journal.EncodingSupport;
 import org.jboss.messaging.core.journal.PreparedTransactionInfo;
@@ -33,7 +41,6 @@
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
 import org.jboss.messaging.tests.util.RandomUtil;
 import org.jboss.messaging.tests.util.UnitTestCase;
-import java.util.*;
 
 /**
  * 
@@ -44,423 +51,429 @@
  */
 public abstract class JournalImplTestBase extends UnitTestCase
 {
-	private static final Logger log = Logger.getLogger(JournalImplTestBase.class);
-	
-	protected List<RecordInfo> records = new LinkedList<RecordInfo>();
-	
-	protected TestableJournal journal;
-	
-	protected int recordLength = 1024;
-	
-	protected Map<Long, TransactionHolder> transactions = new LinkedHashMap<Long, TransactionHolder>();
-	
-	protected int maxAIO;
-	
-	protected int minFiles;
-	
-	protected int fileSize;
-	
-	protected boolean sync;
-	
-	protected String filePrefix = "jbm";
-	
-	protected String fileExtension = "jbm";
-	
-	protected SequentialFileFactory fileFactory;
-	
-	protected void setUp() throws Exception
-	{
-		super.setUp();
-		
-		resetFileFactory();
-		
-		transactions.clear();
-		
-		records.clear();
-	}
-	
-	protected void tearDown() throws Exception
-	{
-		super.tearDown();
-		
-		if (journal != null)
-		{
-			try
-			{
-				journal.stop();
-			}
-			catch (Exception ignore)
-			{           
-			}
-		}
-		
-		fileFactory = null;
-		
-		journal = null;
-		
-		assertEquals(0, AsynchronousFileImpl.getTotalMaxIO());
-	}
-	
-	protected void resetFileFactory() throws Exception
-	{
-		fileFactory = getFileFactory();
-	}
-	
-	protected void checkAndReclaimFiles() throws Exception
-	{
-	   journal.debugWait();
-	   journal.checkAndReclaimFiles();
+   private static final Logger log = Logger.getLogger(JournalImplTestBase.class);
+
+   protected List<RecordInfo> records = new LinkedList<RecordInfo>();
+
+   protected TestableJournal journal;
+
+   protected int recordLength = 1024;
+
+   protected Map<Long, TransactionHolder> transactions = new LinkedHashMap<Long, TransactionHolder>();
+
+   protected int maxAIO;
+
+   protected int minFiles;
+
+   protected int fileSize;
+
+   protected boolean sync;
+
+   protected String filePrefix = "jbm";
+
+   protected String fileExtension = "jbm";
+
+   protected SequentialFileFactory fileFactory;
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      resetFileFactory();
+
+      transactions.clear();
+
+      records.clear();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+
+      if (journal != null)
+      {
+         try
+         {
+            journal.stop();
+         }
+         catch (Exception ignore)
+         {
+         }
+      }
+
+      fileFactory = null;
+
+      journal = null;
+
+      assertEquals(0, AsynchronousFileImpl.getTotalMaxIO());
+   }
+
+   protected void resetFileFactory() throws Exception
+   {
+      fileFactory = getFileFactory();
+   }
+
+   protected void checkAndReclaimFiles() throws Exception
+   {
       journal.debugWait();
-	}
-	
-	protected abstract SequentialFileFactory getFileFactory() throws Exception;
-	
-	// Private ---------------------------------------------------------------------------------
-	
-   protected void setup(int minFreeFiles, int fileSize, boolean sync, int maxAIO)
-   {     
-      this.minFiles = minFreeFiles;
+      journal.checkAndReclaimFiles();
+      journal.debugWait();
+   }
+
+   protected abstract SequentialFileFactory getFileFactory() throws Exception;
+
+   // Private
+   // ---------------------------------------------------------------------------------
+
+   protected void setup(final int minFreeFiles, final int fileSize, final boolean sync, final int maxAIO)
+   {
+      minFiles = minFreeFiles;
       this.fileSize = fileSize;
       this.sync = sync;
       this.maxAIO = maxAIO;
    }
-   
-   protected void setup(int minFreeFiles, int fileSize, boolean sync)
-   {     
-      this.minFiles = minFreeFiles;
+
+   protected void setup(final int minFreeFiles, final int fileSize, final boolean sync)
+   {
+      minFiles = minFreeFiles;
       this.fileSize = fileSize;
       this.sync = sync;
-      this.maxAIO = 50;
+      maxAIO = 50;
    }
-   
-	public void createJournal() throws Exception
-	{     
-		journal = new JournalImpl(fileSize, minFiles, sync, sync, fileFactory, filePrefix, fileExtension, maxAIO, 0);
-		journal.setAutoReclaim(false);
-	}
-	
-	protected void startJournal() throws Exception
-	{
-		journal.start();
-	}
-	
-	protected void stopJournal() throws Exception
-	{
-		stopJournal(true);
-	}
-	
-	protected void stopJournal(boolean reclaim) throws Exception
-	{
-		//We do a reclaim in here
-		if (reclaim)
-		{
-			checkAndReclaimFiles();
-		}
-		
-		journal.stop();      
-	}
-	
-	protected void loadAndCheck() throws Exception
-	{
-		List<RecordInfo> committedRecords = new ArrayList<RecordInfo>();
-		
-		List<PreparedTransactionInfo> preparedTransactions = new ArrayList<PreparedTransactionInfo>();
-		
-		journal.load(committedRecords, preparedTransactions);
-		
-		checkRecordsEquivalent(records, committedRecords);
-		
-		//check prepared transactions
-		
-		List<PreparedTransactionInfo> prepared = new ArrayList<PreparedTransactionInfo>();
-		
-		for (Map.Entry<Long, TransactionHolder> entry : transactions.entrySet())
-		{
-			if (entry.getValue().prepared)
-			{
-				PreparedTransactionInfo info = new PreparedTransactionInfo(entry.getKey(), null);
-				
-				info.records.addAll(entry.getValue().records);
-				
-				info.recordsToDelete.addAll(entry.getValue().deletes);
-				
-				prepared.add(info);
-			}
-		}
-		
-		checkTransactionsEquivalent(prepared, preparedTransactions);
-	}     
-	
-	protected void load() throws Exception
-	{
-		journal.load(null, null);
-	}
-	
-	protected void add(long... arguments) throws Exception
-	{
-		addWithSize(recordLength, arguments);
-	}
-	
-	protected void addWithSize(int size, long... arguments) throws Exception
-	{
-		for (int i = 0; i < arguments.length; i++)
-		{     
-			byte[] record = generateRecord(size);
-			
-			journal.appendAddRecord(arguments[i], (byte)0, new ByteArrayEncoding(record));
-			
-			records.add(new RecordInfo(arguments[i], (byte)0, record, false));         
-		}
-		
-		journal.debugWait();
-	}
-	
-	protected void update(long... arguments) throws Exception
-	{
-		for (int i = 0; i < arguments.length; i++)
-		{     
-			byte[] updateRecord = generateRecord(recordLength);
-			
-			journal.appendUpdateRecord(arguments[i], (byte)0, new ByteArrayEncoding(updateRecord));
-			
-			records.add(new RecordInfo(arguments[i], (byte)0, updateRecord, true)); 
-		}
-		
-		journal.debugWait();
-	}
-	
-	protected void delete(long... arguments) throws Exception
-	{
-		for (int i = 0; i < arguments.length; i++)
-		{     
-			journal.appendDeleteRecord(arguments[i]);
-			
-			removeRecordsForID(arguments[i]);
-		}
 
-		journal.debugWait();
-	}
-	
-	protected void addTx(long txID, long... arguments) throws Exception
-	{
-		TransactionHolder tx = getTransaction(txID);
-		
-		for (int i = 0; i < arguments.length; i++)
-		{  
-			// SIZE_BYTE + SIZE_LONG + SIZE_LONG + SIZE_INT + record.length + SIZE_BYTE
-			byte[] record = generateRecord(recordLength - JournalImpl.SIZE_ADD_RECORD_TX );
-			
-			journal.appendAddRecordTransactional(txID, arguments[i], (byte)0, new ByteArrayEncoding(record));
-			
-			tx.records.add(new RecordInfo(arguments[i], (byte)0, record, false));
-			
-		}
-		
-		journal.debugWait();
-	}
-	
-	protected void updateTx(long txID, long... arguments) throws Exception
-	{
-		TransactionHolder tx = getTransaction(txID);
-		
-		for (int i = 0; i < arguments.length; i++)
-		{     
-			byte[] updateRecord = generateRecord(recordLength - JournalImpl.SIZE_UPDATE_RECORD_TX );
-			
-			journal.appendUpdateRecordTransactional(txID, arguments[i], (byte)0, new ByteArrayEncoding(updateRecord));
-			
-			tx.records.add(new RecordInfo(arguments[i], (byte)0, updateRecord, true));
-		}     
+   public void createJournal() throws Exception
+   {
+      journal = new JournalImpl(fileSize, minFiles, sync, sync, fileFactory, filePrefix, fileExtension, maxAIO, 0);
+      journal.setAutoReclaim(false);
+   }
+
+   protected void startJournal() throws Exception
+   {
+      journal.start();
+   }
+
+   protected void stopJournal() throws Exception
+   {
+      stopJournal(true);
+   }
+
+   protected void stopJournal(final boolean reclaim) throws Exception
+   {
+      // We do a reclaim in here
+      if (reclaim)
+      {
+         checkAndReclaimFiles();
+      }
+
+      journal.stop();
+   }
+
+   protected void loadAndCheck() throws Exception
+   {
+      List<RecordInfo> committedRecords = new ArrayList<RecordInfo>();
+
+      List<PreparedTransactionInfo> preparedTransactions = new ArrayList<PreparedTransactionInfo>();
+
+      journal.load(committedRecords, preparedTransactions);
+
+      checkRecordsEquivalent(records, committedRecords);
+
+      // check prepared transactions
+
+      List<PreparedTransactionInfo> prepared = new ArrayList<PreparedTransactionInfo>();
+
+      for (Map.Entry<Long, TransactionHolder> entry : transactions.entrySet())
+      {
+         if (entry.getValue().prepared)
+         {
+            PreparedTransactionInfo info = new PreparedTransactionInfo(entry.getKey(), null);
+
+            info.records.addAll(entry.getValue().records);
+
+            info.recordsToDelete.addAll(entry.getValue().deletes);
+
+            prepared.add(info);
+         }
+      }
+
+      checkTransactionsEquivalent(prepared, preparedTransactions);
+   }
+
+   protected void load() throws Exception
+   {
+      journal.load(null, null);
+   }
+
+   protected void add(final long... arguments) throws Exception
+   {
+      addWithSize(recordLength, arguments);
+   }
+
+   protected void addWithSize(final int size, final long... arguments) throws Exception
+   {
+      for (long element : arguments)
+      {
+         byte[] record = generateRecord(size);
+
+         journal.appendAddRecord(element, (byte)0, new ByteArrayEncoding(record));
+
+         records.add(new RecordInfo(element, (byte)0, record, false));
+      }
+
       journal.debugWait();
-	}
-	
-	protected void deleteTx(long txID, long... arguments) throws Exception
-	{
-		TransactionHolder tx = getTransaction(txID);
-		
-		for (int i = 0; i < arguments.length; i++)
-		{                 
-			journal.appendDeleteRecordTransactional(txID, arguments[i], null);
-			
-			tx.deletes.add(new RecordInfo(arguments[i], (byte)0, null, true));
-		}
-		
+   }
+
+   protected void update(final long... arguments) throws Exception
+   {
+      for (long element : arguments)
+      {
+         byte[] updateRecord = generateRecord(recordLength);
+
+         journal.appendUpdateRecord(element, (byte)0, new ByteArrayEncoding(updateRecord));
+
+         records.add(new RecordInfo(element, (byte)0, updateRecord, true));
+      }
+
       journal.debugWait();
-	}
-	
-	protected void prepare(long txID, EncodingSupport xid) throws Exception
-	{
-		TransactionHolder tx = transactions.get(txID);
-		
-		if (tx == null)
-		{
-			throw new IllegalStateException("Cannot find tx " + txID);
-		}
-		
-		if (tx.prepared)
-		{
-			throw new IllegalStateException("Transaction is already prepared");
-		}
-		journal.appendPrepareRecord(txID, xid);
-		
-		tx.prepared = true;
+   }
 
-		journal.debugWait();
-	}
-	
-	protected void commit(long txID) throws Exception
-	{
-		TransactionHolder tx = transactions.get(txID);
-		
-		if (tx == null)
-		{
-			throw new IllegalStateException("Cannot find tx " + txID);
-		}
-		
-		journal.appendCommitRecord(txID);
-		
-		this.commitTx(txID);
-		
-		journal.debugWait();
-	}
-	
-	protected void rollback(long txID) throws Exception
-	{
-		TransactionHolder tx = transactions.remove(txID);
-		
-		if (tx == null)
-		{
-			throw new IllegalStateException("Cannot find tx " + txID);
-		}
-		
-		journal.appendRollbackRecord(txID);
+   protected void delete(final long... arguments) throws Exception
+   {
+      for (long element : arguments)
+      {
+         journal.appendDeleteRecord(element);
 
-		journal.debugWait();
-	}
-	
-	private void commitTx(long txID)
-	{
-		TransactionHolder tx = transactions.remove(txID);
-		
-		if (tx == null)
-		{
-			throw new IllegalStateException("Cannot find tx " + txID);
-		}
-		
-		records.addAll(tx.records);
-		
-		for (RecordInfo l: tx.deletes)
-		{
-			removeRecordsForID(l.id);
-		}
-	}
-	
-	protected void removeRecordsForID(long id)
-	{
-		for (ListIterator<RecordInfo> iter = records.listIterator(); iter.hasNext();)
-		{
-			RecordInfo info = iter.next();
-			
-			if (info.id == id)
-			{
-				iter.remove();
-			}
-		}
-	}
-	
-	protected TransactionHolder getTransaction(long txID)
-	{
-		TransactionHolder tx = transactions.get(txID);
-		
-		if (tx == null)
-		{
-			tx = new TransactionHolder();
-			
-			transactions.put(txID, tx);
-		}
-		
-		return tx;
-	}
-	
-	protected void checkTransactionsEquivalent(List<PreparedTransactionInfo> expected, List<PreparedTransactionInfo> actual)
-	{
-		assertEquals("Lists not same length", expected.size(), actual.size());
-		
-		Iterator<PreparedTransactionInfo> iterExpected = expected.iterator();
-		
-		Iterator<PreparedTransactionInfo> iterActual = actual.iterator();
-		
-		while (iterExpected.hasNext())
-		{
-			PreparedTransactionInfo rexpected = iterExpected.next();
-			
-			PreparedTransactionInfo ractual = iterActual.next();
-			
-			assertEquals("ids not same", rexpected.id, ractual.id);
-			
-			checkRecordsEquivalent(rexpected.records, ractual.records);
-			
-			assertEquals("deletes size not same", rexpected.recordsToDelete.size(), ractual.recordsToDelete.size());
-			
-			Iterator<RecordInfo> iterDeletesExpected = rexpected.recordsToDelete.iterator();
-			
-			Iterator<RecordInfo> iterDeletesActual = ractual.recordsToDelete.iterator();
-			
-			while (iterDeletesExpected.hasNext())
-			{
-				long lexpected = iterDeletesExpected.next().id;
-				
-				long lactual = iterDeletesActual.next().id;
-				
-				assertEquals("Delete ids not same", lexpected, lactual);
-			}
-		}
-	}
-	
-	protected void checkRecordsEquivalent(List<RecordInfo> expected, List<RecordInfo> actual)
-	{
-		assertEquals("Lists not same length", expected.size(), actual.size());
-		
-		Iterator<RecordInfo> iterExpected = expected.iterator();
-		
-		Iterator<RecordInfo> iterActual = actual.iterator();
-		
-		while (iterExpected.hasNext())
-		{
-			RecordInfo rexpected = iterExpected.next();
-			
-			RecordInfo ractual = iterActual.next();
-			
-			assertEquals("ids not same", rexpected.id, ractual.id);
-			
-			assertEquals("type not same", rexpected.isUpdate, ractual.isUpdate);
-			
-			assertEqualsByteArrays(rexpected.data, ractual.data);
-		}     
-	}
-	
-	protected byte[] generateRecord(int length)
-	{
-		byte[] record = new byte[length];
-		for (int i = 0; i < length; i++)
-		{
-			record[i] = RandomUtil.randomByte();
-		}
-		return record;
-	}
-	
-	protected String debugJournal() throws Exception
-	{
-		return "***************************************************\n" + ((JournalImpl)journal).debug() + "***************************************************\n" ;
-	}
-	
-	class TransactionHolder
-	{
-		List<RecordInfo> records = new ArrayList<RecordInfo>();
-		
-		List<RecordInfo> deletes = new ArrayList<RecordInfo>();
-		
-		boolean prepared;
-	}
-	
+         removeRecordsForID(element);
+      }
+
+      journal.debugWait();
+   }
+
+   protected void addTx(final long txID, final long... arguments) throws Exception
+   {
+      TransactionHolder tx = getTransaction(txID);
+
+      for (long element : arguments)
+      {
+         // SIZE_BYTE + SIZE_LONG + SIZE_LONG + SIZE_INT + record.length +
+         // SIZE_BYTE
+         byte[] record = generateRecord(recordLength - JournalImpl.SIZE_ADD_RECORD_TX);
+
+         journal.appendAddRecordTransactional(txID, element, (byte)0, new ByteArrayEncoding(record));
+
+         tx.records.add(new RecordInfo(element, (byte)0, record, false));
+
+      }
+
+      journal.debugWait();
+   }
+
+   protected void updateTx(final long txID, final long... arguments) throws Exception
+   {
+      TransactionHolder tx = getTransaction(txID);
+
+      for (long element : arguments)
+      {
+         byte[] updateRecord = generateRecord(recordLength - JournalImpl.SIZE_UPDATE_RECORD_TX);
+
+         journal.appendUpdateRecordTransactional(txID, element, (byte)0, new ByteArrayEncoding(updateRecord));
+
+         tx.records.add(new RecordInfo(element, (byte)0, updateRecord, true));
+      }
+      journal.debugWait();
+   }
+
+   protected void deleteTx(final long txID, final long... arguments) throws Exception
+   {
+      TransactionHolder tx = getTransaction(txID);
+
+      for (long element : arguments)
+      {
+         journal.appendDeleteRecordTransactional(txID, element, null);
+
+         tx.deletes.add(new RecordInfo(element, (byte)0, null, true));
+      }
+
+      journal.debugWait();
+   }
+
+   protected void prepare(final long txID, final EncodingSupport xid) throws Exception
+   {
+      TransactionHolder tx = transactions.get(txID);
+
+      if (tx == null)
+      {
+         throw new IllegalStateException("Cannot find tx " + txID);
+      }
+
+      if (tx.prepared)
+      {
+         throw new IllegalStateException("Transaction is already prepared");
+      }
+      journal.appendPrepareRecord(txID, xid);
+
+      tx.prepared = true;
+
+      journal.debugWait();
+   }
+
+   protected void commit(final long txID) throws Exception
+   {
+      TransactionHolder tx = transactions.get(txID);
+
+      if (tx == null)
+      {
+         throw new IllegalStateException("Cannot find tx " + txID);
+      }
+
+      journal.appendCommitRecord(txID);
+
+      commitTx(txID);
+
+      journal.debugWait();
+   }
+
+   protected void rollback(final long txID) throws Exception
+   {
+      TransactionHolder tx = transactions.remove(txID);
+
+      if (tx == null)
+      {
+         throw new IllegalStateException("Cannot find tx " + txID);
+      }
+
+      journal.appendRollbackRecord(txID);
+
+      journal.debugWait();
+   }
+
+   private void commitTx(final long txID)
+   {
+      TransactionHolder tx = transactions.remove(txID);
+
+      if (tx == null)
+      {
+         throw new IllegalStateException("Cannot find tx " + txID);
+      }
+
+      records.addAll(tx.records);
+
+      for (RecordInfo l : tx.deletes)
+      {
+         removeRecordsForID(l.id);
+      }
+   }
+
+   protected void removeRecordsForID(final long id)
+   {
+      for (ListIterator<RecordInfo> iter = records.listIterator(); iter.hasNext();)
+      {
+         RecordInfo info = iter.next();
+
+         if (info.id == id)
+         {
+            iter.remove();
+         }
+      }
+   }
+
+   protected TransactionHolder getTransaction(final long txID)
+   {
+      TransactionHolder tx = transactions.get(txID);
+
+      if (tx == null)
+      {
+         tx = new TransactionHolder();
+
+         transactions.put(txID, tx);
+      }
+
+      return tx;
+   }
+
+   protected void checkTransactionsEquivalent(final List<PreparedTransactionInfo> expected,
+                                              final List<PreparedTransactionInfo> actual)
+   {
+      assertEquals("Lists not same length", expected.size(), actual.size());
+
+      Iterator<PreparedTransactionInfo> iterExpected = expected.iterator();
+
+      Iterator<PreparedTransactionInfo> iterActual = actual.iterator();
+
+      while (iterExpected.hasNext())
+      {
+         PreparedTransactionInfo rexpected = iterExpected.next();
+
+         PreparedTransactionInfo ractual = iterActual.next();
+
+         assertEquals("ids not same", rexpected.id, ractual.id);
+
+         checkRecordsEquivalent(rexpected.records, ractual.records);
+
+         assertEquals("deletes size not same", rexpected.recordsToDelete.size(), ractual.recordsToDelete.size());
+
+         Iterator<RecordInfo> iterDeletesExpected = rexpected.recordsToDelete.iterator();
+
+         Iterator<RecordInfo> iterDeletesActual = ractual.recordsToDelete.iterator();
+
+         while (iterDeletesExpected.hasNext())
+         {
+            long lexpected = iterDeletesExpected.next().id;
+
+            long lactual = iterDeletesActual.next().id;
+
+            assertEquals("Delete ids not same", lexpected, lactual);
+         }
+      }
+   }
+
+   protected void checkRecordsEquivalent(final List<RecordInfo> expected, final List<RecordInfo> actual)
+   {
+      assertEquals("Lists not same length", expected.size(), actual.size());
+
+      Iterator<RecordInfo> iterExpected = expected.iterator();
+
+      Iterator<RecordInfo> iterActual = actual.iterator();
+
+      while (iterExpected.hasNext())
+      {
+         RecordInfo rexpected = iterExpected.next();
+
+         RecordInfo ractual = iterActual.next();
+
+         assertEquals("ids not same", rexpected.id, ractual.id);
+
+         assertEquals("type not same", rexpected.isUpdate, ractual.isUpdate);
+
+         assertEqualsByteArrays(rexpected.data, ractual.data);
+      }
+   }
+
+   protected byte[] generateRecord(final int length)
+   {
+      byte[] record = new byte[length];
+      for (int i = 0; i < length; i++)
+      {
+         record[i] = RandomUtil.randomByte();
+      }
+      return record;
+   }
+
+   protected String debugJournal() throws Exception
+   {
+      return "***************************************************\n" + ((JournalImpl)journal).debug() +
+             "***************************************************\n";
+   }
+
+   class TransactionHolder
+   {
+      List<RecordInfo> records = new ArrayList<RecordInfo>();
+
+      List<RecordInfo> deletes = new ArrayList<RecordInfo>();
+
+      boolean prepared;
+   }
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,36 +1,35 @@
 /*
- * 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.
- */ 
+ * 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.journal.impl;
 
+import java.util.List;
+
 import org.jboss.messaging.core.journal.EncodingSupport;
 import org.jboss.messaging.core.journal.RecordInfo;
 import org.jboss.messaging.core.journal.impl.JournalImpl;
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.transaction.impl.XidImpl;
+import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
-import javax.transaction.xa.Xid;
-import java.util.List;
 
 /**
  * 
@@ -42,2769 +41,2901 @@
  */
 public abstract class JournalImplTestUnit extends JournalImplTestBase
 {
-	private static final Logger log = Logger.getLogger(JournalImplTestUnit.class);
-	
-	// General tests
-	// =============
-	
-	public void testState() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		try
-		{
-			load();
-			fail("Should throw exception");
-		}
-		catch (IllegalStateException e)
-		{
-			//OK
-		}
-		try
-		{
-			stopJournal();
-			fail("Should throw exception");
-		}
-		catch (IllegalStateException e)
-		{
-			//OK
-		}
-		startJournal();
-		try
-		{
-			startJournal();
-			fail("Should throw exception");
-		}
-		catch (IllegalStateException e)
-		{
-			//OK
-		}
-		stopJournal();
-		startJournal();
-		load();
-		try
-		{
-			load();
-			fail("Should throw exception");
-		}
-		catch (IllegalStateException e)
-		{
-			//OK
-		}
-		try
-		{
-			startJournal();
-			fail("Should throw exception");
-		}
-		catch (IllegalStateException e)
-		{
-			//OK
-		}
-		stopJournal();    
-	}
-	
-	public void testRestartJournal() throws Exception
-	{
+   private static final Logger log = Logger.getLogger(JournalImplTestUnit.class);
+
+   // General tests
+   // =============
+
+   public void testState() throws Exception
+   {
       setup(10, 10 * 1024, true);
       createJournal();
+      try
+      {
+         load();
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         // OK
+      }
+      try
+      {
+         stopJournal();
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         // OK
+      }
       startJournal();
+      try
+      {
+         startJournal();
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         // OK
+      }
+      stopJournal();
+      startJournal();
       load();
+      try
+      {
+         load();
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         // OK
+      }
+      try
+      {
+         startJournal();
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         // OK
+      }
       stopJournal();
+   }
+
+   public void testRestartJournal() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
       startJournal();
       load();
+      stopJournal();
+      startJournal();
+      load();
       byte[] record = new byte[1000];
       for (int i = 0; i < record.length; i++)
       {
          record[i] = (byte)'a';
       }
-      // Appending records after restart should be valid (not throwing any exceptions)
+      // Appending records after restart should be valid (not throwing any
+      // exceptions)
       for (int i = 0; i < 100; i++)
       {
          journal.appendAddRecord(1, (byte)1, new SimpleEncoding(2, (byte)'a'));
       }
       stopJournal();
-	}
-	
-	public void testParams() throws Exception
-	{
-		try
-		{
-			new JournalImpl(JournalImpl.MIN_FILE_SIZE - 1, 10, true, true, fileFactory, filePrefix, fileExtension, 1, 0);
-			
-			fail("Should throw exception");
-		}
-		catch (IllegalArgumentException e)
-		{
-			//Ok
-		}
-		
-		try
-		{
-			new JournalImpl(10 * 1024, 1, true, true, fileFactory, filePrefix, fileExtension, 1, 0);
-			
-			fail("Should throw exception");
-		}
-		catch (IllegalArgumentException e)
-		{
-			//Ok
-		}
-		
-		try
-		{
-			new JournalImpl(10 * 1024, 10, true, true, null, filePrefix, fileExtension, 1, 0);
-			
-			fail("Should throw exception");
-		}
-		catch (NullPointerException e)
-		{
-			//Ok
-		}
-		
-		try
-		{
-			new JournalImpl(10 * 1024, 10, true, true, fileFactory, null, fileExtension, 1, 0);
-			
-			fail("Should throw exception");
-		}
-		catch (NullPointerException e)
-		{
-			//Ok
-		}
-		
+   }
+
+   public void testParams() throws Exception
+   {
       try
       {
+         new JournalImpl(JournalImpl.MIN_FILE_SIZE - 1, 10, true, true, fileFactory, filePrefix, fileExtension, 1, 0);
+
+         fail("Should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         // Ok
+      }
+
+      try
+      {
+         new JournalImpl(10 * 1024, 1, true, true, fileFactory, filePrefix, fileExtension, 1, 0);
+
+         fail("Should throw exception");
+      }
+      catch (IllegalArgumentException e)
+      {
+         // Ok
+      }
+
+      try
+      {
+         new JournalImpl(10 * 1024, 10, true, true, null, filePrefix, fileExtension, 1, 0);
+
+         fail("Should throw exception");
+      }
+      catch (NullPointerException e)
+      {
+         // Ok
+      }
+
+      try
+      {
+         new JournalImpl(10 * 1024, 10, true, true, fileFactory, null, fileExtension, 1, 0);
+
+         fail("Should throw exception");
+      }
+      catch (NullPointerException e)
+      {
+         // Ok
+      }
+
+      try
+      {
          new JournalImpl(10 * 1024, 10, true, true, fileFactory, filePrefix, null, 1, 0);
-         
+
          fail("Should throw exception");
       }
       catch (NullPointerException e)
       {
-         //Ok
+         // Ok
       }
-      
+
       try
       {
          new JournalImpl(10 * 1024, 10, true, true, fileFactory, filePrefix, null, 0, 0);
-         
+
          fail("Should throw exception");
       }
       catch (NullPointerException e)
       {
-         //Ok
+         // Ok
       }
 
-	}
-	
-	public void testFilesImmediatelyAfterload() throws Exception
-	{
-		try
-		{
-			setup(10, 10 * 1024, true);
-			createJournal();
-			startJournal();
-			load();
-			
-			List<String> files = fileFactory.listFiles(fileExtension);
-			
-			assertEquals(10, files.size());
-			
-			for (String file: files)
-			{
-				assertTrue(file.startsWith(filePrefix));
-			}
-			
-			stopJournal();
-			
-			resetFileFactory();
-			
-			setup(20, 10 * 1024, true);
-			createJournal();
-			startJournal();
-			load();
-			
-			files = fileFactory.listFiles(fileExtension);
-			
-			assertEquals(20, files.size());
-			
-			for (String file: files)
-			{
-				assertTrue(file.startsWith(filePrefix));
-			}
-			
-			stopJournal(); 
-			
-			fileExtension = "tim";
-			
-			resetFileFactory();
-			
-			setup(17, 10 * 1024, true);
-			createJournal();
-			startJournal();
-			load();
-			
-			files = fileFactory.listFiles(fileExtension);
-			
-			assertEquals(17, files.size());
-			
-			for (String file: files)
-			{
-				assertTrue(file.startsWith(filePrefix));
-			}
-			
-			stopJournal(); 
-			
-			filePrefix = "echidna";
-			
-			resetFileFactory();
-			
-			setup(11, 10 * 1024, true);
-			createJournal();
-			startJournal();
-			load();
-			
-			files = fileFactory.listFiles(fileExtension);
-			
-			assertEquals(11, files.size());
-			
-			for (String file: files)
-			{
-				assertTrue(file.startsWith(filePrefix));
-			}
-			
-			stopJournal(); 
-		}
-		finally
-		{
-			filePrefix = "jbm";
-			
-			fileExtension = "jbm";
-		}
-	}
-	
-	public void testEmptyReopen() throws Exception
-	{
-		setup(2, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		stopJournal();
-		
-		setup(2, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files2.size());
-		
-		for (String file: files1)
-		{
-			assertTrue(files2.contains(file));
-		}
-		
-		stopJournal(); 
-	}
-	
-	public void testCreateFilesOnLoad() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		stopJournal();
-		
-		//Now restart with different number of minFiles - should create 10 more
-		
-		setup(20, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(20, files2.size());
-		
-		for (String file: files1)
-		{
-			assertTrue(files2.contains(file));
-		}
-		
-		stopJournal(); 
-	}
-	
-	public void testReduceFreeFiles() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		stopJournal();
-		
-		setup(5, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files2.size());
-		
-		for (String file: files1)
-		{
-			assertTrue(files2.contains(file));
-		}
-		
-		stopJournal(); 
-	}
-	
-	private int calculateRecordsPerFile(int fileSize, int alignment, int recordSize)
-	{
-		recordSize = calculateRecordSize(recordSize, alignment);
-		return fileSize / recordSize;
-	}
-	
-	/** 
-	 * 
-	 * Use: calculateNumberOfFiles (fileSize, numberOfRecords, recordSize,  numberOfRecords2, recordSize2, , ...., numberOfRecordsN, recordSizeN);
-	 * */
-	private int calculateNumberOfFiles(int fileSize, int alignment, int ... record) throws Exception
-	{
-		int headerSize = calculateRecordSize(JournalImpl.SIZE_HEADER, alignment);
-		int currentPosition = headerSize;
-		int totalFiles = 0;
-		
-		for (int i=0; i<record.length; i+=2)
-		{
-			int numberOfRecords = record[i];
-			int recordSize = calculateRecordSize(record[i+1], alignment);
-			
-			while (numberOfRecords>0)
-			{
-				int recordsFit = (fileSize - currentPosition) / recordSize;
-				if (numberOfRecords < recordsFit)
-				{
-					currentPosition = currentPosition + numberOfRecords*recordSize;
-					numberOfRecords = 0;
-				}
-				else if (recordsFit > 0)
-				{
-					currentPosition = currentPosition + recordsFit*recordSize;
-					numberOfRecords -= recordsFit;
-				}
-				else
-				{
-					totalFiles++;
-					currentPosition = headerSize;
-				}
-			}
-		}
-		
-		return totalFiles;
-		
-	}
-	
-	public void testCheckCreateMoreFiles() throws Exception
-	{
-		setup(2, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		//Fill all the files
-		
-		for (int i = 0; i < 91; i++)
-		{
-			add(i);
-		}
-		
-		int numberOfFiles = calculateNumberOfFiles(10*1024, journal.getAlignment(), 91, JournalImpl.SIZE_ADD_RECORD + this.recordLength);
-		
-		assertEquals(numberOfFiles, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(91, journal.getIDMapSize());
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		// The Journal will aways have a file ready to be opened
-		assertEquals(numberOfFiles + 2, files2.size());
-		
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files2.contains(file));
-		}
-		
-		//Now add some more
-		
-		for (int i = 90; i < 95; i++)
-		{
-			add(i);
-		}
-		
-		numberOfFiles = calculateNumberOfFiles(10*1024,journal.getAlignment(), 95, JournalImpl.SIZE_ADD_RECORD + this.recordLength);
-		
-		assertEquals(numberOfFiles, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(95, journal.getIDMapSize());
-		
-		List<String> files3 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(numberOfFiles + 2, files3.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files3.contains(file));
-		}
-		
-		//And a load more
-		
-		for (int i = 95; i < 200; i++)
-		{
-			add(i);
-		}
-		
-		numberOfFiles = calculateNumberOfFiles(10*1024,journal.getAlignment(), 200, JournalImpl.SIZE_ADD_RECORD + this.recordLength);
-		
-		assertEquals(numberOfFiles, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(200, journal.getIDMapSize());
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(numberOfFiles + 2, files4.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files4.contains(file));
-		}
-		
-		stopJournal(); 
-	}
-	
-	// Validate the methods that are used on assertions
-	public void testCalculations() throws Exception
-	{
-		
-		assertEquals(0,calculateNumberOfFiles(10*1024, 1, 1, 10, 2, 20));
-		assertEquals(0,calculateNumberOfFiles(10*1024, 512, 1, 1));
-		assertEquals(0,calculateNumberOfFiles(10*1024, 512, 19, 10));
-		assertEquals(1,calculateNumberOfFiles(10*1024, 512, 20, 10));
-		assertEquals(0,calculateNumberOfFiles(3000, 500, 2, 1000, 1, 500));
-		assertEquals(1,calculateNumberOfFiles(3000, 500, 2, 1000, 1, 1000));
-		assertEquals(9,calculateNumberOfFiles(10240, 1, 90, 1038, 45, 10));      
-		assertEquals(11,calculateNumberOfFiles(10*1024, 512, 60, 14 + 1024, 30, 14));
-	}
-	
-	public void testReclaim() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(8, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		
-		int addRecordsPerFile = calculateRecordsPerFile(10*1024, journal.getAlignment(), JournalImpl.SIZE_ADD_RECORD + this.recordLength);
-		
-		
-		// Fills exactly 10 files
-		int initialNumberOfAddRecords = addRecordsPerFile * 10;
-		for (int i = 0; i < initialNumberOfAddRecords; i++)
-		{
-			add(i);
-		}
-		
-		// We have already 10 files, but since we have the last file on exact size, the counter will be numberOfUsedFiles -1
-		assertEquals(9, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(initialNumberOfAddRecords, journal.getIDMapSize());
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(11, files4.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files4.contains(file));
-		}
-		
-		//Now delete half of them
-		
-		int deleteRecordsPerFile = calculateRecordsPerFile(10*1024, journal.getAlignment(), JournalImpl.SIZE_DELETE_RECORD);
-		
-		for (int i = 0; i < initialNumberOfAddRecords / 2; i++)
-		{
-			delete(i);
-		}
-		
-		
-		
-		int numberOfFiles = calculateNumberOfFiles(10*1024, journal.getAlignment(), initialNumberOfAddRecords, JournalImpl.SIZE_ADD_RECORD + this.recordLength, 
-				initialNumberOfAddRecords/2, JournalImpl.SIZE_DELETE_RECORD);
-		
-		
-		if ((initialNumberOfAddRecords / 2) % deleteRecordsPerFile == 0)
-		{
-			// The file is already full, next add would fix it
-			numberOfFiles --;
-		}
-		
-		assertEquals(numberOfFiles, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(initialNumberOfAddRecords/2, journal.getIDMapSize());
-		
-		//Make sure the deletes aren't in the current file
-		
-		for (int i = 0; i < 10; i++)
-		{
-			add(initialNumberOfAddRecords + i);
-		}
-		
-		numberOfFiles = calculateNumberOfFiles(10*1024, journal.getAlignment(), 
-				initialNumberOfAddRecords, JournalImpl.SIZE_ADD_RECORD + this.recordLength, 
-				initialNumberOfAddRecords / 2, JournalImpl.SIZE_DELETE_RECORD,
-				10, JournalImpl.SIZE_ADD_RECORD + this.recordLength);
-		
-		
-		assertEquals(numberOfFiles, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(initialNumberOfAddRecords/2 + 10, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		//Several of them should be reclaimed - and others deleted - the total number of files should not drop below
-		//10
-		
-		assertEquals(journal.getAlignment()==1?6:7, journal.getDataFilesCount());
-		assertEquals(journal.getAlignment()==1?2:1, journal.getFreeFilesCount());
-		assertEquals(initialNumberOfAddRecords /2 + 10, journal.getIDMapSize());
-		
-		List<String> files5 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files5.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		//Now delete the rest
-		
-		for (int i = initialNumberOfAddRecords /2; i < initialNumberOfAddRecords + 10; i++)
-		{
-			delete(i);
-		}
-		
-		//And fill the current file
-		
-		for (int i = 110; i < 120; i++)
-		{
-			add(i);
-			delete(i);
-		}
-		
-		checkAndReclaimFiles();
-		
-		assertEquals(journal.getAlignment()==1?0:1, journal.getDataFilesCount());
-		assertEquals(journal.getAlignment()==1?8:7, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		List<String> files6 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files6.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		stopJournal(); 
-	}
-	
-	public void testReclaimAddUpdateDeleteDifferentFiles1() throws Exception
-	{
-		setup(2, calculateRecordSize(8, getAlignment()) +  calculateRecordSize(JournalImpl.SIZE_ADD_RECORD + recordLength, getAlignment()), true); //Make sure there is one record per file
-		createJournal();
-		startJournal();
-		load();
-		
-		add(1);
-		update(1);
-		delete(1);
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files1.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		// 1 file for nextOpenedFile
-		assertEquals(4, files2.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		//1 gets deleted and 1 gets reclaimed
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		stopJournal();
-	}
-	
-	public void testReclaimAddUpdateDeleteDifferentFiles2() throws Exception
-	{
-		setup(2, calculateRecordSize(8, getAlignment()) +  calculateRecordSize(JournalImpl.SIZE_ADD_RECORD + recordLength, getAlignment()), true); //Make sure there is one record per file
-		createJournal();
-		startJournal();
-		load();
-		
-		add(1);
-		update(1);
-		add(2);
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files1.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files2.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		
-		stopJournal();
-	}
-	
-	public void testReclaimTransactionalAddCommit() throws Exception
-	{
-		testReclaimTransactionalAdd(true);
-	}
-	
-	public void testReclaimTransactionalAddRollback() throws Exception
-	{
-		testReclaimTransactionalAdd(false);
-	}
-	
-	//TODO commit and rollback, also transactional deletes
-	
-	private void testReclaimTransactionalAdd(boolean commit) throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(8, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		for (int i = 0; i < 100; i++)
-		{
-			addTx(1, i);
-		}
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 100, recordLength), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 100, recordLength) + 2, files2.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files2.contains(file));
-		}
-		
-		checkAndReclaimFiles();
-		
-		//Make sure nothing reclaimed
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 100, recordLength), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		List<String> files3 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 100, recordLength) + 2, files3.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files3.contains(file));
-		}
-		
-		//Add a load more updates
-		
-		for (int i = 100; i < 200; i++)
-		{
-			updateTx(1, i);
-		}
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 200, recordLength), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 200, recordLength) + 2, files4.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files4.contains(file));
-		}
-		
-		checkAndReclaimFiles();
-		
-		//Make sure nothing reclaimed
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 200, recordLength) , journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		List<String> files5 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(24, files5.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files5.contains(file));
-		}
-		
-		//Now delete them
-		
-		for (int i = 0; i < 200; i++)
-		{
-			deleteTx(1, i);
-		}
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 200, recordLength, 200, JournalImpl.SIZE_DELETE_RECORD_TX), journal.getDataFilesCount());
-		
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		List<String> files7 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 200, recordLength, 200, JournalImpl.SIZE_DELETE_RECORD_TX) + 2, files7.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files7.contains(file));
-		}
-		
-		checkAndReclaimFiles();
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 200, recordLength, 200, JournalImpl.SIZE_DELETE_RECORD_TX), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		List<String> files8 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 200, recordLength, 200, JournalImpl.SIZE_DELETE_RECORD_TX) + 2, files8.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files8.contains(file));
-		}
-		
-		//Commit
-		
-		if (commit)
-		{
-			commit(1);
-		}
-		else
-		{
-			rollback(1);
-		}
-		
-		//Add more records to make sure we get to the next file
-		
-		for (int i = 200; i < 210; i++)
-		{
-			add(i);
-		}
-		
-		
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 
-				200, recordLength, 
-				200, JournalImpl.SIZE_DELETE_RECORD_TX, 
-				1, JournalImpl.SIZE_COMMIT_RECORD,
-				10, JournalImpl.SIZE_ADD_RECORD + recordLength), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(10, journal.getIDMapSize());
-		
-		List<String> files9 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize , journal.getAlignment(), 
-				200, recordLength, 
-				200, JournalImpl.SIZE_DELETE_RECORD_TX, 
-				1, JournalImpl.SIZE_COMMIT_RECORD,
-				10, JournalImpl.SIZE_ADD_RECORD + recordLength) + 2, files9.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		for (String file: files1)
-		{
-			assertTrue(files9.contains(file));
-		}
-		
-		checkAndReclaimFiles();
-		
-		//Most Should now be reclaimed - leaving 10 left in total
-		
-		assertEquals(journal.getAlignment()==1?1:2, journal.getDataFilesCount());
-		assertEquals(journal.getAlignment()==1?7:6, journal.getFreeFilesCount());
-		assertEquals(10, journal.getIDMapSize());
-		
-		List<String> files10 = fileFactory.listFiles(fileExtension);
-		
-		// The journal will aways keep one file opened (even if there are no more files on freeFiles)
-		assertEquals(10, files10.size());   
-		assertEquals(1, journal.getOpenedFilesCount());
-	}
-	
+   }
+
+   public void testFilesImmediatelyAfterload() throws Exception
+   {
+      try
+      {
+         setup(10, 10 * 1024, true);
+         createJournal();
+         startJournal();
+         load();
+
+         List<String> files = fileFactory.listFiles(fileExtension);
+
+         assertEquals(10, files.size());
+
+         for (String file : files)
+         {
+            assertTrue(file.startsWith(filePrefix));
+         }
+
+         stopJournal();
+
+         resetFileFactory();
+
+         setup(20, 10 * 1024, true);
+         createJournal();
+         startJournal();
+         load();
+
+         files = fileFactory.listFiles(fileExtension);
+
+         assertEquals(20, files.size());
+
+         for (String file : files)
+         {
+            assertTrue(file.startsWith(filePrefix));
+         }
+
+         stopJournal();
+
+         fileExtension = "tim";
+
+         resetFileFactory();
+
+         setup(17, 10 * 1024, true);
+         createJournal();
+         startJournal();
+         load();
+
+         files = fileFactory.listFiles(fileExtension);
+
+         assertEquals(17, files.size());
+
+         for (String file : files)
+         {
+            assertTrue(file.startsWith(filePrefix));
+         }
+
+         stopJournal();
+
+         filePrefix = "echidna";
+
+         resetFileFactory();
+
+         setup(11, 10 * 1024, true);
+         createJournal();
+         startJournal();
+         load();
+
+         files = fileFactory.listFiles(fileExtension);
+
+         assertEquals(11, files.size());
+
+         for (String file : files)
+         {
+            assertTrue(file.startsWith(filePrefix));
+         }
+
+         stopJournal();
+      }
+      finally
+      {
+         filePrefix = "jbm";
+
+         fileExtension = "jbm";
+      }
+   }
+
+   public void testEmptyReopen() throws Exception
+   {
+      setup(2, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      stopJournal();
+
+      setup(2, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files2.size());
+
+      for (String file : files1)
+      {
+         assertTrue(files2.contains(file));
+      }
+
+      stopJournal();
+   }
+
+   public void testCreateFilesOnLoad() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      stopJournal();
+
+      // Now restart with different number of minFiles - should create 10 more
+
+      setup(20, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(20, files2.size());
+
+      for (String file : files1)
+      {
+         assertTrue(files2.contains(file));
+      }
+
+      stopJournal();
+   }
+
+   public void testReduceFreeFiles() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      stopJournal();
+
+      setup(5, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files2.size());
+
+      for (String file : files1)
+      {
+         assertTrue(files2.contains(file));
+      }
+
+      stopJournal();
+   }
+
+   private int calculateRecordsPerFile(final int fileSize, final int alignment, int recordSize)
+   {
+      recordSize = calculateRecordSize(recordSize, alignment);
+      return fileSize / recordSize;
+   }
+
+   /** 
+    * 
+    * Use: calculateNumberOfFiles (fileSize, numberOfRecords, recordSize,  numberOfRecords2, recordSize2, , ...., numberOfRecordsN, recordSizeN);
+    * */
+   private int calculateNumberOfFiles(final int fileSize, final int alignment, final int... record) throws Exception
+   {
+      int headerSize = calculateRecordSize(JournalImpl.SIZE_HEADER, alignment);
+      int currentPosition = headerSize;
+      int totalFiles = 0;
+
+      for (int i = 0; i < record.length; i += 2)
+      {
+         int numberOfRecords = record[i];
+         int recordSize = calculateRecordSize(record[i + 1], alignment);
+
+         while (numberOfRecords > 0)
+         {
+            int recordsFit = (fileSize - currentPosition) / recordSize;
+            if (numberOfRecords < recordsFit)
+            {
+               currentPosition = currentPosition + numberOfRecords * recordSize;
+               numberOfRecords = 0;
+            }
+            else if (recordsFit > 0)
+            {
+               currentPosition = currentPosition + recordsFit * recordSize;
+               numberOfRecords -= recordsFit;
+            }
+            else
+            {
+               totalFiles++;
+               currentPosition = headerSize;
+            }
+         }
+      }
+
+      return totalFiles;
+
+   }
+
+   public void testCheckCreateMoreFiles() throws Exception
+   {
+      setup(2, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      // Fill all the files
+
+      for (int i = 0; i < 91; i++)
+      {
+         add(i);
+      }
+
+      int numberOfFiles = calculateNumberOfFiles(10 * 1024,
+                                                 journal.getAlignment(),
+                                                 91,
+                                                 JournalImpl.SIZE_ADD_RECORD + recordLength);
+
+      assertEquals(numberOfFiles, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(91, journal.getIDMapSize());
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      // The Journal will aways have a file ready to be opened
+      assertEquals(numberOfFiles + 2, files2.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files2.contains(file));
+      }
+
+      // Now add some more
+
+      for (int i = 90; i < 95; i++)
+      {
+         add(i);
+      }
+
+      numberOfFiles = calculateNumberOfFiles(10 * 1024,
+                                             journal.getAlignment(),
+                                             95,
+                                             JournalImpl.SIZE_ADD_RECORD + recordLength);
+
+      assertEquals(numberOfFiles, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(95, journal.getIDMapSize());
+
+      List<String> files3 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(numberOfFiles + 2, files3.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files3.contains(file));
+      }
+
+      // And a load more
+
+      for (int i = 95; i < 200; i++)
+      {
+         add(i);
+      }
+
+      numberOfFiles = calculateNumberOfFiles(10 * 1024,
+                                             journal.getAlignment(),
+                                             200,
+                                             JournalImpl.SIZE_ADD_RECORD + recordLength);
+
+      assertEquals(numberOfFiles, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(200, journal.getIDMapSize());
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(numberOfFiles + 2, files4.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files4.contains(file));
+      }
+
+      stopJournal();
+   }
+
+   // Validate the methods that are used on assertions
+   public void testCalculations() throws Exception
+   {
+
+      assertEquals(0, calculateNumberOfFiles(10 * 1024, 1, 1, 10, 2, 20));
+      assertEquals(0, calculateNumberOfFiles(10 * 1024, 512, 1, 1));
+      assertEquals(0, calculateNumberOfFiles(10 * 1024, 512, 19, 10));
+      assertEquals(1, calculateNumberOfFiles(10 * 1024, 512, 20, 10));
+      assertEquals(0, calculateNumberOfFiles(3000, 500, 2, 1000, 1, 500));
+      assertEquals(1, calculateNumberOfFiles(3000, 500, 2, 1000, 1, 1000));
+      assertEquals(9, calculateNumberOfFiles(10240, 1, 90, 1038, 45, 10));
+      assertEquals(11, calculateNumberOfFiles(10 * 1024, 512, 60, 14 + 1024, 30, 14));
+   }
+
+   public void testReclaim() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(8, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      int addRecordsPerFile = calculateRecordsPerFile(10 * 1024,
+                                                      journal.getAlignment(),
+                                                      JournalImpl.SIZE_ADD_RECORD + recordLength);
+
+      // Fills exactly 10 files
+      int initialNumberOfAddRecords = addRecordsPerFile * 10;
+      for (int i = 0; i < initialNumberOfAddRecords; i++)
+      {
+         add(i);
+      }
+
+      // We have already 10 files, but since we have the last file on exact
+      // size, the counter will be numberOfUsedFiles -1
+      assertEquals(9, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(initialNumberOfAddRecords, journal.getIDMapSize());
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(11, files4.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files4.contains(file));
+      }
+
+      // Now delete half of them
+
+      int deleteRecordsPerFile = calculateRecordsPerFile(10 * 1024,
+                                                         journal.getAlignment(),
+                                                         JournalImpl.SIZE_DELETE_RECORD);
+
+      for (int i = 0; i < initialNumberOfAddRecords / 2; i++)
+      {
+         delete(i);
+      }
+
+      int numberOfFiles = calculateNumberOfFiles(10 * 1024,
+                                                 journal.getAlignment(),
+                                                 initialNumberOfAddRecords,
+                                                 JournalImpl.SIZE_ADD_RECORD + recordLength,
+                                                 initialNumberOfAddRecords / 2,
+                                                 JournalImpl.SIZE_DELETE_RECORD);
+
+      if (initialNumberOfAddRecords / 2 % deleteRecordsPerFile == 0)
+      {
+         // The file is already full, next add would fix it
+         numberOfFiles--;
+      }
+
+      assertEquals(numberOfFiles, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(initialNumberOfAddRecords / 2, journal.getIDMapSize());
+
+      // Make sure the deletes aren't in the current file
+
+      for (int i = 0; i < 10; i++)
+      {
+         add(initialNumberOfAddRecords + i);
+      }
+
+      numberOfFiles = calculateNumberOfFiles(10 * 1024,
+                                             journal.getAlignment(),
+                                             initialNumberOfAddRecords,
+                                             JournalImpl.SIZE_ADD_RECORD + recordLength,
+                                             initialNumberOfAddRecords / 2,
+                                             JournalImpl.SIZE_DELETE_RECORD,
+                                             10,
+                                             JournalImpl.SIZE_ADD_RECORD + recordLength);
+
+      assertEquals(numberOfFiles, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(initialNumberOfAddRecords / 2 + 10, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      // Several of them should be reclaimed - and others deleted - the total
+      // number of files should not drop below
+      // 10
+
+      assertEquals(journal.getAlignment() == 1 ? 6 : 7, journal.getDataFilesCount());
+      assertEquals(journal.getAlignment() == 1 ? 2 : 1, journal.getFreeFilesCount());
+      assertEquals(initialNumberOfAddRecords / 2 + 10, journal.getIDMapSize());
+
+      List<String> files5 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files5.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      // Now delete the rest
+
+      for (int i = initialNumberOfAddRecords / 2; i < initialNumberOfAddRecords + 10; i++)
+      {
+         delete(i);
+      }
+
+      // And fill the current file
+
+      for (int i = 110; i < 120; i++)
+      {
+         add(i);
+         delete(i);
+      }
+
+      checkAndReclaimFiles();
+
+      assertEquals(journal.getAlignment() == 1 ? 0 : 1, journal.getDataFilesCount());
+      assertEquals(journal.getAlignment() == 1 ? 8 : 7, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      List<String> files6 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files6.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      stopJournal();
+   }
+
+   public void testReclaimAddUpdateDeleteDifferentFiles1() throws Exception
+   {
+      setup(2, calculateRecordSize(8, getAlignment()) + calculateRecordSize(JournalImpl.SIZE_ADD_RECORD + recordLength,
+                                                                            getAlignment()), true); // Make
+      // sure
+      // there
+      // is
+      // one
+      // record
+      // per
+      // file
+      createJournal();
+      startJournal();
+      load();
+
+      add(1);
+      update(1);
+      delete(1);
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files1.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      // 1 file for nextOpenedFile
+      assertEquals(4, files2.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      // 1 gets deleted and 1 gets reclaimed
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      stopJournal();
+   }
+
+   public void testReclaimAddUpdateDeleteDifferentFiles2() throws Exception
+   {
+      setup(2, calculateRecordSize(8, getAlignment()) + calculateRecordSize(JournalImpl.SIZE_ADD_RECORD + recordLength,
+                                                                            getAlignment()), true); // Make
+      // sure
+      // there
+      // is
+      // one
+      // record
+      // per
+      // file
+      createJournal();
+      startJournal();
+      load();
+
+      add(1);
+      update(1);
+      add(2);
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files1.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files2.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
+      stopJournal();
+   }
+
+   public void testReclaimTransactionalAddCommit() throws Exception
+   {
+      testReclaimTransactionalAdd(true);
+   }
+
+   public void testReclaimTransactionalAddRollback() throws Exception
+   {
+      testReclaimTransactionalAdd(false);
+   }
+
+   // TODO commit and rollback, also transactional deletes
+
+   private void testReclaimTransactionalAdd(final boolean commit) throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(8, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      for (int i = 0; i < 100; i++)
+      {
+         addTx(1, i);
+      }
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 100, recordLength),
+                   journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 100, recordLength) + 2, files2.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files2.contains(file));
+      }
+
+      checkAndReclaimFiles();
+
+      // Make sure nothing reclaimed
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 100, recordLength),
+                   journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      List<String> files3 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 100, recordLength) + 2, files3.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files3.contains(file));
+      }
+
+      // Add a load more updates
+
+      for (int i = 100; i < 200; i++)
+      {
+         updateTx(1, i);
+      }
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 200, recordLength),
+                   journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 200, recordLength) + 2, files4.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files4.contains(file));
+      }
+
+      checkAndReclaimFiles();
+
+      // Make sure nothing reclaimed
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 200, recordLength),
+                   journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      List<String> files5 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(24, files5.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files5.contains(file));
+      }
+
+      // Now delete them
+
+      for (int i = 0; i < 200; i++)
+      {
+         deleteTx(1, i);
+      }
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          200,
+                                          recordLength,
+                                          200,
+                                          JournalImpl.SIZE_DELETE_RECORD_TX), journal.getDataFilesCount());
+
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      List<String> files7 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          200,
+                                          recordLength,
+                                          200,
+                                          JournalImpl.SIZE_DELETE_RECORD_TX) + 2, files7.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files7.contains(file));
+      }
+
+      checkAndReclaimFiles();
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          200,
+                                          recordLength,
+                                          200,
+                                          JournalImpl.SIZE_DELETE_RECORD_TX), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      List<String> files8 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          200,
+                                          recordLength,
+                                          200,
+                                          JournalImpl.SIZE_DELETE_RECORD_TX) + 2, files8.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files8.contains(file));
+      }
+
+      // Commit
+
+      if (commit)
+      {
+         commit(1);
+      }
+      else
+      {
+         rollback(1);
+      }
+
+      // Add more records to make sure we get to the next file
+
+      for (int i = 200; i < 210; i++)
+      {
+         add(i);
+      }
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          200,
+                                          recordLength,
+                                          200,
+                                          JournalImpl.SIZE_DELETE_RECORD_TX,
+                                          1,
+                                          JournalImpl.SIZE_COMMIT_RECORD,
+                                          10,
+                                          JournalImpl.SIZE_ADD_RECORD + recordLength), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(10, journal.getIDMapSize());
+
+      List<String> files9 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          200,
+                                          recordLength,
+                                          200,
+                                          JournalImpl.SIZE_DELETE_RECORD_TX,
+                                          1,
+                                          JournalImpl.SIZE_COMMIT_RECORD,
+                                          10,
+                                          JournalImpl.SIZE_ADD_RECORD + recordLength) + 2, files9.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      for (String file : files1)
+      {
+         assertTrue(files9.contains(file));
+      }
+
+      checkAndReclaimFiles();
+
+      // Most Should now be reclaimed - leaving 10 left in total
+
+      assertEquals(journal.getAlignment() == 1 ? 1 : 2, journal.getDataFilesCount());
+      assertEquals(journal.getAlignment() == 1 ? 7 : 6, journal.getFreeFilesCount());
+      assertEquals(10, journal.getIDMapSize());
+
+      List<String> files10 = fileFactory.listFiles(fileExtension);
+
+      // The journal will aways keep one file opened (even if there are no more
+      // files on freeFiles)
+      assertEquals(10, files10.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+   }
+
    public void testReclaimTransactionalSimple() throws Exception
    {
-      setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + 
-            calculateRecordSize(recordLength, getAlignment()), true);
+      setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength,
+                                                                                                  getAlignment()), true);
       createJournal();
       startJournal();
       load();
       List<String> files1 = fileFactory.listFiles(fileExtension);
-      
+
       assertEquals(2, files1.size());
-      
+
       assertEquals(0, journal.getDataFilesCount());
       assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
       assertEquals(0, journal.getIDMapSize());
-      
-      addTx(1, 1);           // in file 0
-      
-      deleteTx(1, 1);        // in file 1
-      
+
+      addTx(1, 1); // in file 0
+
+      deleteTx(1, 1); // in file 1
+
       journal.debugWait();
-      
+
       System.out.println("journal tmp :" + journal.debug());
-      
+
       List<String> files2 = fileFactory.listFiles(fileExtension);
-      
+
       assertEquals(3, files2.size());
       assertEquals(1, journal.getOpenedFilesCount());
-      
+
       assertEquals(1, journal.getDataFilesCount());
       assertEquals(0, journal.getFreeFilesCount());
       assertEquals(0, journal.getIDMapSize());
-      
-      //Make sure we move on to the next file
-      
-      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2);                // in file 2
-      
+
+      // Make sure we move on to the next file
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2); // in file 2
+
       journal.debugWait();
-      
+
       System.out.println("journal tmp2 :" + journal.debug());
 
       List<String> files3 = fileFactory.listFiles(fileExtension);
-      
+
       assertEquals(4, files3.size());
       assertEquals(1, journal.getOpenedFilesCount());
-      
-      log.debug("data files count "+ journal.getDataFilesCount());
-      log.debug("free files count "+ journal.getFreeFilesCount());
-      
+
+      log.debug("data files count " + journal.getDataFilesCount());
+      log.debug("free files count " + journal.getFreeFilesCount());
+
       assertEquals(2, journal.getDataFilesCount());
       assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getIDMapSize());
-      
-      commit(1);            // in file 3
-      
+
+      commit(1); // in file 3
+
       List<String> files4 = fileFactory.listFiles(fileExtension);
-      
+
       assertEquals(5, files4.size());
       assertEquals(1, journal.getOpenedFilesCount());
-      
+
       assertEquals(3, journal.getDataFilesCount());
       assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getIDMapSize());
-      
-      //Make sure we move on to the next file
-      
-      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 3);                // in file 4
-      
+
+      // Make sure we move on to the next file
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 3); // in file 4
+
       List<String> files5 = fileFactory.listFiles(fileExtension);
-      
+
       assertEquals(6, files5.size());
       assertEquals(1, journal.getOpenedFilesCount());
-      
+
       assertEquals(4, journal.getDataFilesCount());
       assertEquals(0, journal.getFreeFilesCount());
       assertEquals(2, journal.getIDMapSize());
-      
+
       checkAndReclaimFiles();
-      
+
       List<String> files6 = fileFactory.listFiles(fileExtension);
-      
-      //Three should get deleted (files 0, 1, 3)
-      
+
+      // Three should get deleted (files 0, 1, 3)
+
       assertEquals(3, files6.size());
       assertEquals(1, journal.getOpenedFilesCount());
-      
+
       assertEquals(1, journal.getDataFilesCount());
       assertEquals(0, journal.getFreeFilesCount());
-      assertEquals(2, journal.getIDMapSize());     
+      assertEquals(2, journal.getIDMapSize());
 
-      //Now restart
-      
+      // Now restart
+
       journal.checkAndReclaimFiles();
-      
+
       System.out.println("journal:" + journal.debug());
-      
+
       stopJournal(false);
       createJournal();
       startJournal();
       loadAndCheck();
-      
+
       assertEquals(3, files6.size());
       assertEquals(1, journal.getOpenedFilesCount());
-      
+
       assertEquals(1, journal.getDataFilesCount());
       assertEquals(0, journal.getFreeFilesCount());
-      assertEquals(2, journal.getIDMapSize());     
+      assertEquals(2, journal.getIDMapSize());
    }
-   
-	public void testAddDeleteCommitTXIDMap1() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(8, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(8, journal.getFreeFilesCount());
+
+   public void testAddDeleteCommitTXIDMap1() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		deleteTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		commit(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      deleteTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());           
-	}
-	
-	public void testAddCommitTXIDMap1() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      commit(1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+   }
+
+   public void testAddCommitTXIDMap1() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		commit(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());           
-	}
-	
-	public void testAddDeleteCommitTXIDMap2() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      commit(1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		add(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+   }
+
+   public void testAddDeleteCommitTXIDMap2() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		deleteTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      add(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		commit(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      deleteTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());           
-	}
-	
-	
-	public void testAddDeleteRollbackTXIDMap1() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      commit(1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+   }
+
+   public void testAddDeleteRollbackTXIDMap1() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		deleteTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		rollback(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      deleteTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());           
-	}
-	
-	public void testAddRollbackTXIDMap1() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      rollback(1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+   }
+
+   public void testAddRollbackTXIDMap1() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		rollback(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());           
-	}
-	
-	public void testAddDeleteRollbackTXIDMap2() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      rollback(1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		add(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+   }
+
+   public void testAddDeleteRollbackTXIDMap2() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		deleteTx(1, 1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      add(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		rollback(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      deleteTx(1, 1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());           
-	}
-	
-	public void testAddDeleteIDMap() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(10, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      rollback(1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		add(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+   }
+
+   public void testAddDeleteIDMap() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(10, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		delete(1);
-		
-		assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      add(1);
+
+      assertEquals(0, journal.getDataFilesCount());
       assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-	}
-	
-	public void testCommitRecordsInFileReclaim() throws Exception
-	{
-		setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()), true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files2.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		//Make sure we move on to the next file
-		
-		commit(1);
-		
-		List<String> files3 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3, files3.size());
-		
-		assertEquals(1, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2);
-		
-		//Move on to another file
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files4.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		//Nothing should be reclaimed
-		
-		List<String> files5 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files5.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());     
-	}
-	
-	
-	// file 1: add 1 tx,
-	// file 2: commit 1, add 2, delete 2
-	// file 3: add 3
-	
-	public void testCommitRecordsInFileNoReclaim() throws Exception
-	{
-		setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);           // in file 0
-		
-		//Make sure we move on to the next file
-		
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2);               // in file 1
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3, files2.size());
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 2, recordLength), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		commit(1);            // in file 1
-		
-		List<String> files3 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_COMMIT_RECORD) +2, files3.size());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_COMMIT_RECORD), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		delete(2);            // in file 1
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_COMMIT_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD)+2, files4.size());
-	    assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(1, journal.getIDMapSize());
 
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_COMMIT_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		//Move on to another file
-		
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 3);               // in file 2
-		
-		List<String> files5 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files5.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+      delete(1);
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(8, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		List<String> files6 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files6.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+   }
+
+   public void testCommitRecordsInFileReclaim() throws Exception
+   {
+      setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength,
+                                                                                                  getAlignment()), true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());  
-		
-		//Restart
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		
-		List<String> files7 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files7.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1);
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files2.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-	}
-	
-	public void testRollbackRecordsInFileNoReclaim() throws Exception
-	{
-		setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);          // in file 0
-		
-		//Make sure we move on to the next file
-		
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD ,2);               // in file 1
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3, files2.size());
-		
-		assertEquals(1, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      // Make sure we move on to the next file
+
+      commit(1);
+
+      List<String> files3 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files3.size());
+
+      assertEquals(1, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		rollback(1);          // in file 1
-		
-		List<String> files3 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_ROLLBACK_RECORD) +2, files3.size());
+      assertEquals(1, journal.getIDMapSize());
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2);
+
+      // Move on to another file
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files4.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_ROLLBACK_RECORD), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		delete(2);            // in file 1
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_ROLLBACK_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD)+2, files4.size());
+      assertEquals(2, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      // Nothing should be reclaimed
+
+      List<String> files5 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files5.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_ROLLBACK_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		//Move on to another file
-		
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD,3);                // in file 2 (current file)
-		
-		List<String> files5 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_ROLLBACK_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD,
-				1, recordLength)+2, files5.size());
+      assertEquals(2, journal.getIDMapSize());
+   }
 
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_ROLLBACK_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD,
-				1, recordLength), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		
-		List<String> files6 = fileFactory.listFiles(fileExtension);
-		
-		// files 0 and 1 should be deleted
-		
-		assertEquals(journal.getAlignment()==1?2:3, files6.size());
-		
-		assertEquals(journal.getAlignment()==1?0:1, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+   // file 1: add 1 tx,
+   // file 2: commit 1, add 2, delete 2
+   // file 3: add 3
+
+   public void testCommitRecordsInFileNoReclaim() throws Exception
+   {
+      setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength,
+                                                                                                  getAlignment()) +
+               512, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());  
-		
-		//Restart
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		
-		List<String> files7 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(journal.getAlignment()==1?2:3, files7.size());
-		
-		assertEquals(journal.getAlignment()==1?0:1, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1); // in file 0
+
+      // Make sure we move on to the next file
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2); // in file 1
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files2.size());
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 2, recordLength),
+                   journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-	}
-	
-	public void testPrepareNoReclaim() throws Exception
-	{
-		setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);          // in file 0
-		
-		//Make sure we move on to the next file
-		
-		addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD,2);               // in file 1
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3, files2.size());
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 2, recordLength), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
+      assertEquals(1, journal.getIDMapSize());
 
-		EncodingSupport xid = new SimpleEncoding(10, (byte)0);
-		prepare(1, xid);          // in file 1
-		
-		List<String> files3 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3, files3.size());
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_PREPARE_RECORD), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		delete(2);            // in file 1
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_PREPARE_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD) + 2, files4.size());
-		
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_PREPARE_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD), journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		//Move on to another file
-		
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 3);                // in file 2
-		
-		List<String> files5 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_PREPARE_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD,
-				1, recordLength) + 2, files5.size());
-		
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 
-				2, recordLength,
-				1, JournalImpl.SIZE_PREPARE_RECORD,
-				1, JournalImpl.SIZE_DELETE_RECORD,
-				1, recordLength), journal.getDataFilesCount());
-		
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		List<String> files6 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files6.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 4);    // in file 3
-		
-		List<String> files7 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(5, files7.size());
-		
-		assertEquals(3, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		commit(1);   // in file 4
-		
-		List<String> files8 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(5, files8.size());
-		
-		assertEquals(3, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(3, journal.getIDMapSize());
-		
-		//Restart
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		
-	}
-	
-	public void testPrepareReclaim() throws Exception
-	{
-		setup(2, 100 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		List<String> files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		addTx(1, 1);          // in file 0
-		
-		files1 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(2, files1.size());
-		
-		assertEquals(0, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		//Make sure we move on to the next file
+      commit(1); // in file 1
 
+      List<String> files3 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_COMMIT_RECORD) + 2, files3.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_COMMIT_RECORD), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
+      delete(2); // in file 1
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_COMMIT_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD) + 2, files4.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_COMMIT_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      // Move on to another file
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 3); // in file 2
+
+      List<String> files5 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files5.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      List<String> files6 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files6.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
+      // Restart
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+
+      List<String> files7 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files7.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+   }
+
+   public void testRollbackRecordsInFileNoReclaim() throws Exception
+   {
+      setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength,
+                                                                                                  getAlignment()) +
+               512, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1); // in file 0
+
+      // Make sure we move on to the next file
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2); // in file 1
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files2.size());
+
+      assertEquals(1, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      rollback(1); // in file 1
+
+      List<String> files3 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_ROLLBACK_RECORD) + 2, files3.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_ROLLBACK_RECORD), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      delete(2); // in file 1
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_ROLLBACK_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD) + 2, files4.size());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_ROLLBACK_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      // Move on to another file
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 3); // in file 2
+      // (current
+      // file)
+
+      List<String> files5 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_ROLLBACK_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD,
+                                          1,
+                                          recordLength) + 2, files5.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_ROLLBACK_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD,
+                                          1,
+                                          recordLength), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      List<String> files6 = fileFactory.listFiles(fileExtension);
+
+      // files 0 and 1 should be deleted
+
+      assertEquals(journal.getAlignment() == 1 ? 2 : 3, files6.size());
+
+      assertEquals(journal.getAlignment() == 1 ? 0 : 1, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      // Restart
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+
+      List<String> files7 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(journal.getAlignment() == 1 ? 2 : 3, files7.size());
+
+      assertEquals(journal.getAlignment() == 1 ? 0 : 1, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+   }
+
+   public void testPrepareNoReclaim() throws Exception
+   {
+      setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength,
+                                                                                                  getAlignment()) +
+               512, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1); // in file 0
+
+      // Make sure we move on to the next file
+
+      addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 2); // in file 1
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files2.size());
+
+      assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 2, recordLength),
+                   journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      EncodingSupport xid = new SimpleEncoding(10, (byte)0);
+      prepare(1, xid); // in file 1
+
+      List<String> files3 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files3.size());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_PREPARE_RECORD), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      delete(2); // in file 1
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_PREPARE_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD) + 2, files4.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_PREPARE_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD), journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      // Move on to another file
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 3); // in file 2
+
+      List<String> files5 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_PREPARE_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD,
+                                          1,
+                                          recordLength) + 2, files5.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(calculateNumberOfFiles(fileSize,
+                                          journal.getAlignment(),
+                                          2,
+                                          recordLength,
+                                          1,
+                                          JournalImpl.SIZE_PREPARE_RECORD,
+                                          1,
+                                          JournalImpl.SIZE_DELETE_RECORD,
+                                          1,
+                                          recordLength), journal.getDataFilesCount());
+
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      List<String> files6 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files6.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 4); // in file 3
+
+      List<String> files7 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(5, files7.size());
+
+      assertEquals(3, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
+      commit(1); // in file 4
+
+      List<String> files8 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(5, files8.size());
+
+      assertEquals(3, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(3, journal.getIDMapSize());
+
+      // Restart
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+
+   }
+
+   public void testPrepareReclaim() throws Exception
+   {
+      setup(2, 100 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      List<String> files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      addTx(1, 1); // in file 0
+
+      files1 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(2, files1.size());
+
+      assertEquals(0, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      // Make sure we move on to the next file
+
       journal.forceMoveNextFile();
-      
+
       journal.debugWait();
-      
-		addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2);               // in file 1
-		
-		List<String> files2 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3 , files2.size());
-		
-		assertEquals(1, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
 
+      addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2); // in file 1
+
+      List<String> files2 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files2.size());
+
+      assertEquals(1, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
       EncodingSupport xid = new SimpleEncoding(10, (byte)0);
-		prepare(1, xid);          // in file 1
-		
-		List<String> files3 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3, files3.size());
-		
-		assertEquals(1, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		
-		delete(2);            // in file 1
-		
-		List<String> files4 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(3, files4.size());
-		
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(1, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(0, journal.getIDMapSize());
-		
-		//Move on to another file
-		
+      prepare(1, xid); // in file 1
+
+      List<String> files3 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files3.size());
+
+      assertEquals(1, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+
+      delete(2); // in file 1
+
+      List<String> files4 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(3, files4.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(1, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(0, journal.getIDMapSize());
+
+      // Move on to another file
+
       journal.forceMoveNextFile();
 
-      addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD,3);                // in file 2
-		
-		checkAndReclaimFiles();
-		
-		List<String> files5 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files5.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		checkAndReclaimFiles();
-		
-		List<String> files6 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files6.size());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(1, journal.getIDMapSize());
+      addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 3); // in file 2
+
+      checkAndReclaimFiles();
+
+      List<String> files5 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files5.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
       assertEquals(1, journal.getOpenedFilesCount());
-      
+
+      checkAndReclaimFiles();
+
+      List<String> files6 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files6.size());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(1, journal.getIDMapSize());
+      assertEquals(1, journal.getOpenedFilesCount());
+
       journal.forceMoveNextFile();
-		
-		addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD,4);    // in file 3
-		
-		List<String> files7 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(5, files7.size());
-		
-		assertEquals(3, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+
+      addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 4); // in file 3
+
+      List<String> files7 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(5, files7.size());
+
+      assertEquals(3, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		commit(1);   // in file 3
-		
-		List<String> files8 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(5, files8.size());
-		
-		assertEquals(3, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(3, journal.getIDMapSize());
+      assertEquals(2, journal.getIDMapSize());
+
+      commit(1); // in file 3
+
+      List<String> files8 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(5, files8.size());
+
+      assertEquals(3, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(3, journal.getIDMapSize());
       assertEquals(1, journal.getOpenedFilesCount());
-		
-		delete(1);   // in file 3
-		
-		List<String> files9 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(5, files9.size());
-		
-		assertEquals(3, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+
+      delete(1); // in file 3
+
+      List<String> files9 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(5, files9.size());
+
+      assertEquals(3, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		List<String> files10 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(journal.getAlignment()==1?5:5, files10.size());
-		
-		assertEquals(journal.getAlignment()==1?3:3, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
+      assertEquals(2, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      List<String> files10 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(journal.getAlignment() == 1 ? 5 : 5, files10.size());
+
+      assertEquals(journal.getAlignment() == 1 ? 3 : 3, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
       journal.forceMoveNextFile();
-      
-		addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD,5);       // in file 4
-		
-		List<String> files11 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(6, files11.size());
-		
-		assertEquals(4, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
+
+      addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 5); // in file 4
+
+      List<String> files11 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(6, files11.size());
+
+      assertEquals(4, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(3, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		List<String> files12 = fileFactory.listFiles(fileExtension);
-		
-		//File 0, and File 1  should be deleted
-		
-		assertEquals(4, files12.size());
+      assertEquals(3, journal.getIDMapSize());
 
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(3, journal.getIDMapSize());
-		
-		
-		//Restart
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		
-		delete(4);
-		
-		List<String> files13 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files13.size());
-		
-		assertEquals(1, journal.getOpenedFilesCount());
-		
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(2, journal.getIDMapSize());
-		
-		addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD,6);
-		
-		List<String> files14 = fileFactory.listFiles(fileExtension);
-		
-		log.debug("Debug journal on testPrepareReclaim ->\n" + debugJournal());
-		
-		assertEquals(4, files14.size());
-		
-		assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(3, journal.getIDMapSize());
-		
-		checkAndReclaimFiles();
-		
-		//file 3 should now be deleted
-		
-		List<String> files15 = fileFactory.listFiles(fileExtension);
-		
-		assertEquals(4, files15.size());
-		
+      checkAndReclaimFiles();
+
+      List<String> files12 = fileFactory.listFiles(fileExtension);
+
+      // File 0, and File 1 should be deleted
+
+      assertEquals(4, files12.size());
+
       assertEquals(1, journal.getOpenedFilesCount());
-		assertEquals(2, journal.getDataFilesCount());
-		assertEquals(0, journal.getFreeFilesCount());
-		assertEquals(3, journal.getIDMapSize());
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();   
-	}
-	
-	// Non transactional tests
-	// =======================
-	
-	public void testSimpleAdd() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1);  
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAdd() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,2,3,4,5,6,7,8,9,10);    
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddNonContiguous() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,3,5,7,10,13,56,100,102,200,201,202,203);     
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testSimpleAddUpdate() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1);     
-		update(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdate() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,2,3,4,5,6,7,8,9,10);    
-		update(1,2,4,7,9,10);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdateAll() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,2,3,4,5,6,7,8,9,10);    
-		update(1,2,3,4,5,6,7,8,9,10);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdateNonContiguous() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,3,5,7,10,13,56,100,102,200,201,202,203);  
-		add(3,7,10,13,56,100,200,202,203);  
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdateAllNonContiguous() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,3,5,7,10,13,56,100,102,200,201,202,203);
-		update(1,3,5,7,10,13,56,100,102,200,201,202,203);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testSimpleAddUpdateDelete() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1);     
-		update(1);
-		delete(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdateDelete() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,2,3,4,5,6,7,8,9,10);    
-		update(1,2,4,7,9,10);
-		delete(1,4,7,9,10);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdateDeleteAll() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,2,3,4,5,6,7,8,9,10);    
-		update(1,2,3,4,5,6,7,8,9,10);
-		update(1,2,3,4,5,6,7,8,9,10);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdateDeleteNonContiguous() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,3,5,7,10,13,56,100,102,200,201,202,203);  
-		add(3,7,10,13,56,100,200,202,203);  
-		delete(3,10,56,100,200,203);  
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleAddUpdateDeleteAllNonContiguous() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,3,5,7,10,13,56,100,102,200,201,202,203);
-		update(1,3,5,7,10,13,56,100,102,200,201,202,203);
-		delete(1,3,5,7,10,13,56,100,102,200,201,202,203);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testMultipleAddUpdateDeleteDifferentOrder() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,3,5,7,10,13,56,100,102,200,201,202,203);
-		update(203, 202, 201, 200, 102, 100, 1, 3, 5, 7, 10, 13, 56);
-		delete(56, 13, 10, 7, 5, 3, 1, 203, 202, 201, 200, 102, 100);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testMultipleAddUpdateDeleteDifferentRecordLengths() throws Exception
-	{
-		setup(10, 2048, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		for (int i = 0; i < 100; i++)
-		{
-			byte[] record = generateRecord(10 + (int)(1500 * Math.random()));
-			
-			journal.appendAddRecord(i, (byte)0, new ByteArrayEncoding(record));
-			
-			records.add(new RecordInfo(i, (byte)0, record, false));
-		}
-		
-		for (int i = 0; i < 100; i++)
-		{
-			byte[] record = generateRecord(10 + (int)(1024 * Math.random()));
-			
-			journal.appendUpdateRecord(i, (byte)0, new ByteArrayEncoding(record));
-			
-			records.add(new RecordInfo(i, (byte)0, record, true));
-		}
-		
-		for (int i = 0; i < 100; i++)
-		{
-			journal.appendDeleteRecord(i);
-			
-			removeRecordsForID(i);
-		}
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		stopJournal();       
-	}
-	
-	
-	public void testAddUpdateDeleteRestartAndContinue() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1, 2, 3);
-		update(1, 2);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		add(4, 5, 6);
-		update(5);
-		delete(3);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		add(7, 8);
-		delete(1, 2);
-		delete(4, 5, 6);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testAddUpdateDeleteTransactionalRestartAndContinue() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1, 2, 3);
-		updateTx(1, 1, 2);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		addTx(2, 4, 5, 6);
-		update(2, 2);
-		delete(2, 3);
-		commit(2);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		addTx(3, 7, 8);
-		deleteTx(3, 1);
-		deleteTx(3, 4, 5, 6);
-		commit(3);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testFillFileExactly() throws Exception
-	{     
-		this.recordLength = 500;
-		
-		int numRecords = 2;
-		
-		//The real appended record size in the journal file = SIZE_BYTE + SIZE_LONG + SIZE_INT + recordLength + SIZE_BYTE
-		
-		int realLength = calculateRecordSize(JournalImpl.SIZE_ADD_RECORD + this.recordLength, getAlignment());
-		
-		int fileSize = numRecords * realLength + calculateRecordSize(8, getAlignment()); //8 for timestamp
-		
-		setup(10, fileSize, true);
-		
-		createJournal();
-		startJournal();
-		load();
-		
-		add(1, 2);
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		
-		add(3, 4);
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-		
-		add(4, 5, 6, 7, 8, 9, 10);
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	// Transactional tests
-	// ===================
-		
-		public void testSimpleTransaction() throws Exception
-		{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		addTx(1, 1);
-		updateTx(1, 1);      
-		deleteTx(1, 1);   
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-		}
-	
-	public void testTransactionDontDeleteAll() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		addTx(1, 1, 2, 3);
-		updateTx(1, 1, 2);      
-		deleteTx(1, 1);   
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testTransactionDeleteAll() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		addTx(1, 1, 2, 3);
-		updateTx(1, 1, 2);      
-		deleteTx(1, 1, 2, 3);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testTransactionUpdateFromBeforeTx() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1, 2, 3);
-		addTx(1, 4, 5, 6);
-		updateTx(1, 1, 5);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testTransactionDeleteFromBeforeTx() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1, 2, 3);
-		addTx(1, 4, 5, 6);
-		deleteTx(1, 1, 2, 3, 4, 5, 6);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testTransactionChangesNotVisibleOutsideTX() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1, 2, 3);
-		addTx(1, 4, 5, 6);
-		updateTx(1, 1, 2, 4, 5);
-		deleteTx(1, 1, 2, 3, 4, 5, 6);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testMultipleTransactionsDifferentIDs() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		addTx(1, 1, 2, 3, 4, 5, 6);
-		updateTx(1, 1, 3, 5);
-		deleteTx(1, 1, 2, 3, 4, 5, 6);
-		commit(1);
-		
-		addTx(2, 11, 12, 13, 14, 15, 16);
-		updateTx(2, 11, 13, 15);
-		deleteTx(2, 11, 12, 13, 14, 15, 16);
-		commit(2);
-		
-		addTx(3, 21, 22, 23, 24, 25, 26);
-		updateTx(3, 21, 23, 25);
-		deleteTx(3, 21, 22, 23, 24, 25, 26);
-		commit(3);
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleInterleavedTransactionsDifferentIDs() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		addTx(1, 1, 2, 3, 4, 5, 6);      
-		addTx(3, 21, 22, 23, 24, 25, 26);            
-		updateTx(1, 1, 3, 5);      
-		addTx(2, 11, 12, 13, 14, 15, 16);            
-		deleteTx(1, 1, 2, 3, 4, 5, 6);                  
-		updateTx(2, 11, 13, 15);      
-		updateTx(3, 21, 23, 25);         
-		deleteTx(2, 11, 12, 13, 14, 15, 16);      
-		deleteTx(3, 21, 22, 23, 24, 25, 26);
-		
-		commit(1);
-		commit(2);
-		commit(3);
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testMultipleInterleavedTransactionsSameIDs() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		
-		add(1, 2, 3, 4, 5, 6, 7, 8);     
-		addTx(1, 9, 10, 11, 12);      
-		addTx(2, 13, 14, 15, 16, 17);    
-		addTx(3, 18, 19, 20, 21, 22);    
-		updateTx(1, 1, 2, 3);      
-		updateTx(2, 4, 5, 6);      
-		commit(2);     
-		updateTx(3, 7, 8);      
-		deleteTx(1, 1, 2);      
-		commit(1);     
-		deleteTx(3, 7, 8);      
-		commit(3);
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testTransactionMixed() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();
-		add(1,3,5,7,10,13,56,100,102,200,201,202,203);     
-		addTx(1, 675, 676, 677, 700, 703);
-		update(1,3,5,7,10,13,56,100,102,200,201,202,203);     
-		updateTx(1, 677, 700);     
-		delete(1,3,5,7,10,13,56,100,102,200,201,202,203);     
-		deleteTx(1, 703, 675);     
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testTransactionAddDeleteDifferentOrder() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);               
-		deleteTx(1, 9, 8, 5, 3, 7, 6, 2, 1, 4);   
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testAddOutsideTXThenUpdateInsideTX() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3);
-		updateTx(1, 1, 2, 3);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testAddOutsideTXThenDeleteInsideTX() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3);
-		deleteTx(1, 1, 2, 3);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testRollback() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3);
-		deleteTx(1, 1, 2, 3);
-		rollback(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testRollbackMultiple() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3);
-		deleteTx(1, 1, 2, 3);
-		addTx(2, 4, 5, 6);
-		rollback(1);
-		rollback(2);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testIsolation1() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();        
-		addTx(1, 1, 2, 3);      
-		deleteTx(1, 1, 2, 3);      
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testIsolation2() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();        
-		addTx(1, 1, 2, 3);      
-		try
-		{
-			update(1);
-			fail("Should throw exception");
-		}
-		catch (IllegalStateException e)
-		{
-			//Ok
-		}
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	public void testIsolation3() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();        
-		addTx(1, 1, 2, 3);      
-		try
-		{
-			delete(1);
-			fail("Should throw exception");
-		}
-		catch (IllegalStateException e)
-		{
-			//Ok
-		}
-		
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
-	
-	
-	// XA tests
-	// ========
-		
-		public void testXASimpleNotPrepared() throws Exception
-		{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);               
-		updateTx(1, 1, 2, 3, 4, 7, 8);
-		deleteTx(1, 1, 2, 3, 4, 5);      
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-		}
-	
-	public void testXASimplePrepared() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);               
-		updateTx(1, 1, 2, 3, 4, 7, 8);
-		deleteTx(1, 1, 2, 3, 4, 5);
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(3, journal.getIDMapSize());
 
+      // Restart
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+
+      delete(4);
+
+      List<String> files13 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files13.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(2, journal.getIDMapSize());
+
+      addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 6);
+
+      List<String> files14 = fileFactory.listFiles(fileExtension);
+
+      log.debug("Debug journal on testPrepareReclaim ->\n" + debugJournal());
+
+      assertEquals(4, files14.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(3, journal.getIDMapSize());
+
+      checkAndReclaimFiles();
+
+      // file 3 should now be deleted
+
+      List<String> files15 = fileFactory.listFiles(fileExtension);
+
+      assertEquals(4, files15.size());
+
+      assertEquals(1, journal.getOpenedFilesCount());
+      assertEquals(2, journal.getDataFilesCount());
+      assertEquals(0, journal.getFreeFilesCount());
+      assertEquals(3, journal.getIDMapSize());
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   // Non transactional tests
+   // =======================
+
+   public void testSimpleAdd() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAdd() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddNonContiguous() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testSimpleAddUpdate() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1);
+      update(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdate() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      update(1, 2, 4, 7, 9, 10);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateAll() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      update(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateNonContiguous() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      add(3, 7, 10, 13, 56, 100, 200, 202, 203);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateAllNonContiguous() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      update(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testSimpleAddUpdateDelete() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1);
+      update(1);
+      delete(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateDelete() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      update(1, 2, 4, 7, 9, 10);
+      delete(1, 4, 7, 9, 10);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateDeleteAll() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      update(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      update(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateDeleteNonContiguous() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      add(3, 7, 10, 13, 56, 100, 200, 202, 203);
+      delete(3, 10, 56, 100, 200, 203);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateDeleteAllNonContiguous() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      update(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      delete(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateDeleteDifferentOrder() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      update(203, 202, 201, 200, 102, 100, 1, 3, 5, 7, 10, 13, 56);
+      delete(56, 13, 10, 7, 5, 3, 1, 203, 202, 201, 200, 102, 100);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleAddUpdateDeleteDifferentRecordLengths() throws Exception
+   {
+      setup(10, 2048, true);
+      createJournal();
+      startJournal();
+      load();
+
+      for (int i = 0; i < 100; i++)
+      {
+         byte[] record = generateRecord(10 + (int)(1500 * Math.random()));
+
+         journal.appendAddRecord(i, (byte)0, new ByteArrayEncoding(record));
+
+         records.add(new RecordInfo(i, (byte)0, record, false));
+      }
+
+      for (int i = 0; i < 100; i++)
+      {
+         byte[] record = generateRecord(10 + (int)(1024 * Math.random()));
+
+         journal.appendUpdateRecord(i, (byte)0, new ByteArrayEncoding(record));
+
+         records.add(new RecordInfo(i, (byte)0, record, true));
+      }
+
+      for (int i = 0; i < 100; i++)
+      {
+         journal.appendDeleteRecord(i);
+
+         removeRecordsForID(i);
+      }
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+      stopJournal();
+   }
+
+   public void testAddUpdateDeleteRestartAndContinue() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      update(1, 2);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+      add(4, 5, 6);
+      update(5);
+      delete(3);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+      add(7, 8);
+      delete(1, 2);
+      delete(4, 5, 6);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testAddUpdateDeleteTransactionalRestartAndContinue() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      updateTx(1, 1, 2);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+      addTx(2, 4, 5, 6);
+      update(2, 2);
+      delete(2, 3);
+      commit(2);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+      addTx(3, 7, 8);
+      deleteTx(3, 1);
+      deleteTx(3, 4, 5, 6);
+      commit(3);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testFillFileExactly() throws Exception
+   {
+      recordLength = 500;
+
+      int numRecords = 2;
+
+      // The real appended record size in the journal file = SIZE_BYTE +
+      // SIZE_LONG + SIZE_INT + recordLength + SIZE_BYTE
+
+      int realLength = calculateRecordSize(JournalImpl.SIZE_ADD_RECORD + recordLength, getAlignment());
+
+      int fileSize = numRecords * realLength + calculateRecordSize(8, getAlignment()); // 8
+      // for
+      // timestamp
+
+      setup(10, fileSize, true);
+
+      createJournal();
+      startJournal();
+      load();
+
+      add(1, 2);
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+
+      add(3, 4);
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+
+      add(4, 5, 6, 7, 8, 9, 10);
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   // Transactional tests
+   // ===================
+
+   public void testSimpleTransaction() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1);
+      updateTx(1, 1);
+      deleteTx(1, 1);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testTransactionDontDeleteAll() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3);
+      updateTx(1, 1, 2);
+      deleteTx(1, 1);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testTransactionDeleteAll() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3);
+      updateTx(1, 1, 2);
+      deleteTx(1, 1, 2, 3);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testTransactionUpdateFromBeforeTx() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      addTx(1, 4, 5, 6);
+      updateTx(1, 1, 5);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testTransactionDeleteFromBeforeTx() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      addTx(1, 4, 5, 6);
+      deleteTx(1, 1, 2, 3, 4, 5, 6);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testTransactionChangesNotVisibleOutsideTX() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      addTx(1, 4, 5, 6);
+      updateTx(1, 1, 2, 4, 5);
+      deleteTx(1, 1, 2, 3, 4, 5, 6);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleTransactionsDifferentIDs() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      addTx(1, 1, 2, 3, 4, 5, 6);
+      updateTx(1, 1, 3, 5);
+      deleteTx(1, 1, 2, 3, 4, 5, 6);
+      commit(1);
+
+      addTx(2, 11, 12, 13, 14, 15, 16);
+      updateTx(2, 11, 13, 15);
+      deleteTx(2, 11, 12, 13, 14, 15, 16);
+      commit(2);
+
+      addTx(3, 21, 22, 23, 24, 25, 26);
+      updateTx(3, 21, 23, 25);
+      deleteTx(3, 21, 22, 23, 24, 25, 26);
+      commit(3);
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleInterleavedTransactionsDifferentIDs() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      addTx(1, 1, 2, 3, 4, 5, 6);
+      addTx(3, 21, 22, 23, 24, 25, 26);
+      updateTx(1, 1, 3, 5);
+      addTx(2, 11, 12, 13, 14, 15, 16);
+      deleteTx(1, 1, 2, 3, 4, 5, 6);
+      updateTx(2, 11, 13, 15);
+      updateTx(3, 21, 23, 25);
+      deleteTx(2, 11, 12, 13, 14, 15, 16);
+      deleteTx(3, 21, 22, 23, 24, 25, 26);
+
+      commit(1);
+      commit(2);
+      commit(3);
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testMultipleInterleavedTransactionsSameIDs() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+
+      add(1, 2, 3, 4, 5, 6, 7, 8);
+      addTx(1, 9, 10, 11, 12);
+      addTx(2, 13, 14, 15, 16, 17);
+      addTx(3, 18, 19, 20, 21, 22);
+      updateTx(1, 1, 2, 3);
+      updateTx(2, 4, 5, 6);
+      commit(2);
+      updateTx(3, 7, 8);
+      deleteTx(1, 1, 2);
+      commit(1);
+      deleteTx(3, 7, 8);
+      commit(3);
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testTransactionMixed() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      addTx(1, 675, 676, 677, 700, 703);
+      update(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      updateTx(1, 677, 700);
+      delete(1, 3, 5, 7, 10, 13, 56, 100, 102, 200, 201, 202, 203);
+      deleteTx(1, 703, 675);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testTransactionAddDeleteDifferentOrder() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+      deleteTx(1, 9, 8, 5, 3, 7, 6, 2, 1, 4);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testAddOutsideTXThenUpdateInsideTX() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      updateTx(1, 1, 2, 3);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testAddOutsideTXThenDeleteInsideTX() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      deleteTx(1, 1, 2, 3);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testRollback() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      deleteTx(1, 1, 2, 3);
+      rollback(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testRollbackMultiple() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3);
+      deleteTx(1, 1, 2, 3);
+      addTx(2, 4, 5, 6);
+      rollback(1);
+      rollback(2);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testIsolation1() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3);
+      deleteTx(1, 1, 2, 3);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testIsolation2() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3);
+      try
+      {
+         update(1);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         // Ok
+      }
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testIsolation3() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3);
+      try
+      {
+         delete(1);
+         fail("Should throw exception");
+      }
+      catch (IllegalStateException e)
+      {
+         // Ok
+      }
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   // XA tests
+   // ========
+
+   public void testXASimpleNotPrepared() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+      updateTx(1, 1, 2, 3, 4, 7, 8);
+      deleteTx(1, 1, 2, 3, 4, 5);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testXASimplePrepared() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+      updateTx(1, 1, 2, 3, 4, 7, 8);
+      deleteTx(1, 1, 2, 3, 4, 5);
+
       EncodingSupport xid = new SimpleEncoding(10, (byte)0);
 
       prepare(1, xid);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testXASimpleCommit() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);               
-		updateTx(1, 1, 2,3, 4, 7, 8);
-		deleteTx(1, 1, 2, 3, 4, 5);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
 
-		EncodingSupport xid = new SimpleEncoding(10, (byte)0);
+   public void testXASimpleCommit() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+      updateTx(1, 1, 2, 3, 4, 7, 8);
+      deleteTx(1, 1, 2, 3, 4, 5);
 
-		prepare(1, xid);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testXASimpleRollback() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);               
-		updateTx(1, 1, 2,3, 4, 7, 8);
-		deleteTx(1, 1, 2, 3, 4, 5);
+      EncodingSupport xid = new SimpleEncoding(10, (byte)0);
 
+      prepare(1, xid);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testXASimpleRollback() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+      updateTx(1, 1, 2, 3, 4, 7, 8);
+      deleteTx(1, 1, 2, 3, 4, 5);
+
       EncodingSupport xid = new SimpleEncoding(10, (byte)0);
 
       prepare(1, xid);
-		rollback(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testXAChangesNotVisibleNotPrepared() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3, 4, 5, 6);
-		addTx(1, 7, 8, 9, 10);              
-		updateTx(1, 1, 2, 3, 7, 8, 9);
-		deleteTx(1, 1, 2, 3, 4, 5);   
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testXAChangesNotVisiblePrepared() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3, 4, 5, 6);
-		addTx(1, 7, 8, 9, 10);              
-		updateTx(1, 1, 2, 3, 7, 8, 9);
-		deleteTx(1, 1, 2, 3, 4, 5);
+      rollback(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
 
+   public void testXAChangesNotVisibleNotPrepared() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6);
+      addTx(1, 7, 8, 9, 10);
+      updateTx(1, 1, 2, 3, 7, 8, 9);
+      deleteTx(1, 1, 2, 3, 4, 5);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   public void testXAChangesNotVisiblePrepared() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6);
+      addTx(1, 7, 8, 9, 10);
+      updateTx(1, 1, 2, 3, 7, 8, 9);
+      deleteTx(1, 1, 2, 3, 4, 5);
+
       EncodingSupport xid = new SimpleEncoding(10, (byte)0);
 
-		prepare(1, xid);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testXAChangesNotVisibleRollback() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3, 4, 5, 6);
-		addTx(1, 7, 8, 9, 10);              
-		updateTx(1, 1, 2, 3, 7, 8, 9);
-		deleteTx(1, 1, 2, 3, 4, 5);
+      prepare(1, xid);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
 
+   public void testXAChangesNotVisibleRollback() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6);
+      addTx(1, 7, 8, 9, 10);
+      updateTx(1, 1, 2, 3, 7, 8, 9);
+      deleteTx(1, 1, 2, 3, 4, 5);
+
       EncodingSupport xid = new SimpleEncoding(10, (byte)0);
 
-		prepare(1, xid);
-		rollback(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testXAChangesisibleCommit() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3, 4, 5, 6);
-		addTx(1, 7, 8, 9, 10);              
-		updateTx(1, 1, 2, 3, 7, 8, 9);
-		deleteTx(1, 1, 2, 3, 4, 5);
+      prepare(1, xid);
+      rollback(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
 
+   public void testXAChangesisibleCommit() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6);
+      addTx(1, 7, 8, 9, 10);
+      updateTx(1, 1, 2, 3, 7, 8, 9);
+      deleteTx(1, 1, 2, 3, 4, 5);
+
       EncodingSupport xid = new SimpleEncoding(10, (byte)0);
 
-		prepare(1, xid);
-		commit(1);
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();      
-	}
-	
-	public void testXAMultiple() throws Exception
-	{
-		setup(10, 10 * 1024, true);
-		createJournal();
-		startJournal();
-		load();     
-		add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
-		addTx(1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
-		addTx(2, 21, 22, 23, 24, 25, 26, 27);
-		updateTx(1, 1, 3, 6, 11, 14, 17);
-		addTx(3, 28, 29, 30, 31, 32, 33, 34, 35);
-		updateTx(3, 7, 8, 9, 10);
-		deleteTx(2, 4, 5, 6, 23, 25, 27);
+      prepare(1, xid);
+      commit(1);
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
 
+   public void testXAMultiple() throws Exception
+   {
+      setup(10, 10 * 1024, true);
+      createJournal();
+      startJournal();
+      load();
+      add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+      addTx(1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
+      addTx(2, 21, 22, 23, 24, 25, 26, 27);
+      updateTx(1, 1, 3, 6, 11, 14, 17);
+      addTx(3, 28, 29, 30, 31, 32, 33, 34, 35);
+      updateTx(3, 7, 8, 9, 10);
+      deleteTx(2, 4, 5, 6, 23, 25, 27);
+
       EncodingSupport xid = new SimpleEncoding(10, (byte)0);
 
-		prepare(2, xid);
-		deleteTx(1, 1, 2, 11, 14, 15);
-		prepare(1, xid);
-		deleteTx(3, 28, 31, 32, 9);
-		prepare(3, xid);
-		
-		commit(1);
-		rollback(2);
-		commit(3);
-	}
-	
-	public void testTransactionOnDifferentFiles() throws Exception
-	{
-		setup(2, 512 + 2*1024, true);
-		
-		createJournal();
-		startJournal();
-		load();
-		
-		addTx(1, 1, 2, 3, 4, 5, 6);
-		updateTx(1, 1, 3, 5);
-		commit(1);
-		deleteTx(2, 1, 2, 3, 4, 5, 6);
-		commit(2);
+      prepare(2, xid);
+      deleteTx(1, 1, 2, 11, 14, 15);
+      prepare(1, xid);
+      deleteTx(3, 28, 31, 32, 9);
+      prepare(3, xid);
 
-      // Just to make sure the commit won't be released. The commit will be on the same file as addTx(3);
-		addTx(3, 11);
-		addTx(4, 31);
-		commit(3);
+      commit(1);
+      rollback(2);
+      commit(3);
+   }
 
-		log.debug("Debug on Journal before stopJournal - \n" + debugJournal());
+   public void testTransactionOnDifferentFiles() throws Exception
+   {
+      setup(2, 512 + 2 * 1024, true);
 
-		stopJournal();
-		createJournal();
-		startJournal();
-		loadAndCheck();
-	}
+      createJournal();
+      startJournal();
+      load();
 
-	protected abstract int getAlignment();
+      addTx(1, 1, 2, 3, 4, 5, 6);
+      updateTx(1, 1, 3, 5);
+      commit(1);
+      deleteTx(2, 1, 2, 3, 4, 5, 6);
+      commit(2);
 
+      // Just to make sure the commit won't be released. The commit will be on
+      // the same file as addTx(3);
+      addTx(3, 11);
+      addTx(4, 31);
+      commit(3);
+
+      log.debug("Debug on Journal before stopJournal - \n" + debugJournal());
+
+      stopJournal();
+      createJournal();
+      startJournal();
+      loadAndCheck();
+   }
+
+   protected abstract int getAlignment();
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/ReclaimerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/ReclaimerTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/ReclaimerTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,24 +1,24 @@
 /*
- * 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.
- */ 
+ * 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.journal.impl;
 
@@ -42,832 +42,826 @@
  */
 public class ReclaimerTest extends UnitTestCase
 {
-	private static final Logger log = Logger.getLogger(ReclaimerTest.class);	
-	
-	private JournalFile[] files;
-	
-	private Reclaimer reclaimer;
-	
-	protected void setUp() throws Exception
-	{
-		super.setUp();
-		
-		reclaimer = new Reclaimer();
-	}
-		
-	public void testOneFilePosNegAll() throws Exception
-	{
-		setup(1);
-		
-		setupPosNeg(0, 10, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);		
-	}
-	
-	public void testOneFilePosNegNotAll() throws Exception
-	{
-		setup(1);
-		
-		setupPosNeg(0, 10, 7);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);		
-	}
-	
-	public void testOneFilePosOnly() throws Exception
-	{
-		setup(1);
-		
-		setupPosNeg(0, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);		
-	}
-	
-	public void testOneFileNegOnly() throws Exception
-	{
-		setup(1);
-		
-		setupPosNeg(0, 0, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);		
-	}
-	
-	
-	public void testTwoFilesPosNegAllDifferentFiles() throws Exception
-	{
-		setup(2);
-		
-		setupPosNeg(0, 10);
-		setupPosNeg(1, 0, 10);
-	
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		
-	}
-	
-	public void testTwoFilesPosNegAllSameFiles() throws Exception
-	{
-		setup(2);
-		
-		setupPosNeg(0, 10, 10);
-		setupPosNeg(1, 10, 0, 10);
-	
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		
-	}
-	
-	public void testTwoFilesPosNegMixedFiles() throws Exception
-	{
-		setup(2);
-		
-		setupPosNeg(0, 10, 7);
-		setupPosNeg(1, 10, 3, 10);
-	
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);		
-	}
-	
-	public void testTwoFilesPosNegAllFirstFile() throws Exception
-	{
-		setup(2);
-		
-		setupPosNeg(0, 10, 10);
-		setupPosNeg(1, 10);
-	
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCantDelete(1);		
-	}
-	
-	public void testTwoFilesPosNegAllSecondFile() throws Exception
-	{
-		setup(2);
-		
-		setupPosNeg(0, 10);
-		setupPosNeg(1, 10, 0, 10);
-	
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);		
-	}
-	
-	public void testTwoFilesPosOnly() throws Exception
-	{
-		setup(2);
-		
-		setupPosNeg(0, 10);
-		setupPosNeg(1, 10);
-	
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);		
-	}
-	
-	public void testTwoFilesxyz() throws Exception
-	{
-		setup(2);
-		
-		setupPosNeg(0, 10);
-		setupPosNeg(1, 10, 10);
-	
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCantDelete(1);		
-	}
-	
-	//Can-can-can
-	
-	public void testThreeFiles1() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 10, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 10, 0, 0, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	public void testThreeFiles2() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 7, 0, 0);
-		setupPosNeg(1, 10, 3, 5, 0);
-		setupPosNeg(2, 10, 0, 5, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	public void testThreeFiles3() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 1, 0, 0);
-		setupPosNeg(1, 10, 6, 5, 0);
-		setupPosNeg(2, 10, 3, 5, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	public void testThreeFiles3_1() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 1, 0, 0);
-		setupPosNeg(1, 10, 6, 5, 0);
-		setupPosNeg(2, 0, 3, 5, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	public void testThreeFiles3_2() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 1, 0, 0);
-		setupPosNeg(1, 0, 6, 0, 0);
-		setupPosNeg(2, 0, 3, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	
-	
-	
-	//Cant-can-can
-	
-	
-	public void testThreeFiles4() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 5, 0);
-		setupPosNeg(2, 10, 0, 5, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	public void testThreeFiles5() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 5, 0);
-		setupPosNeg(2, 0, 0, 5, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	public void testThreeFiles6() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 0, 0, 0);
-		setupPosNeg(1, 10, 0, 5, 0);
-		setupPosNeg(2, 0, 0, 5, 10);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	public void testThreeFiles7() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 0, 0, 0);
-		setupPosNeg(1, 10, 0, 5, 0);
-		setupPosNeg(2, 0, 0, 5, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCanDelete(2);
-	}
-	
-	
-	//Cant can cant
-	
-	public void testThreeFiles8() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 10, 0, 0, 2);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles9() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 10, 1, 0, 2);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles10() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 10, 1, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles11() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 0, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 10, 0, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles12() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 0, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 0, 3, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	//Cant-cant-cant
-	
-	public void testThreeFiles13() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 2, 3, 0);
-		setupPosNeg(2, 10, 1, 5, 7);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles14() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 0, 2, 0, 0);
-		setupPosNeg(2, 10, 1, 0, 7);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles15() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 2, 3, 0);
-		setupPosNeg(2, 0, 1, 5, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles16() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 0, 2, 0, 0);
-		setupPosNeg(2, 0, 1, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles17() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 3, 0);
-		setupPosNeg(2, 10, 1, 5, 7);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles18() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 3, 0);
-		setupPosNeg(2, 10, 1, 0, 7);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles19() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 3, 0);
-		setupPosNeg(2, 10, 1, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles20() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 3, 0, 0);
-		setupPosNeg(1, 10, 0, 0, 0);
-		setupPosNeg(2, 10, 1, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles21() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 0, 0, 0);
-		setupPosNeg(1, 10, 0, 0, 0);
-		setupPosNeg(2, 10, 0, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCantDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	// Can-can-cant
-	
-	public void testThreeFiles22() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 10, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 10, 0, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles23() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 10, 0, 0);
-		setupPosNeg(1, 10, 0, 10, 0);
-		setupPosNeg(2, 10, 3, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles24() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 7, 0, 0);
-		setupPosNeg(1, 10, 3, 10, 0);
-		setupPosNeg(2, 10, 3, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles25() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 7, 0, 0);
-		setupPosNeg(1, 0, 3, 10, 0);
-		setupPosNeg(2, 10, 3, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles26() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 7, 0, 0);
-		setupPosNeg(1, 0, 3, 10, 0);
-		setupPosNeg(2, 10, 0, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCanDelete(1);
-		assertCantDelete(2);
-	}
-	
+   private static final Logger log = Logger.getLogger(ReclaimerTest.class);
 
-	//Can-cant-cant
-	
-	public void testThreeFiles27() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 10, 0, 0);
-		setupPosNeg(1, 10, 0, 0, 0);
-		setupPosNeg(2, 10, 0, 0, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles28() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 10, 0, 0);
-		setupPosNeg(1, 10, 0, 3, 0);
-		setupPosNeg(2, 10, 0, 0, 5);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles29() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 10, 0, 0);
-		setupPosNeg(1, 10, 0, 3, 0);
-		setupPosNeg(2, 10, 0, 6, 5);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	public void testThreeFiles30() throws Exception
-	{
-		setup(3);
-		
-		setupPosNeg(0, 10, 10, 0, 0);
-		setupPosNeg(1, 10, 0, 3, 0);
-		setupPosNeg(2, 0, 0, 6, 0);
-		
-		reclaimer.scan(files);
-		
-		assertCanDelete(0);
-		assertCantDelete(1);
-		assertCantDelete(2);
-	}
-	
-	
-	// Private ------------------------------------------------------------------------
-		
-	private void setup(int numFiles)
-	{
-		files = new JournalFile[numFiles];
-		
-		for (int i = 0; i < numFiles; i++)
-		{
-			files[i] = new MockJournalFile();
-		}		                       
-	}
-		
-	private void setupPosNeg(int fileNumber, int pos, int... neg)
-	{
-		JournalFile file = files[fileNumber];
-		
-		for (int i = 0; i < pos; i++)
-		{
-			file.incPosCount();
-		}
-		
-		for (int i = 0; i < neg.length; i++)
-		{
-			JournalFile reclaimable2 = files[i];
-			
-			for (int j = 0; j < neg[i]; j++)
-			{
-				file.incNegCount(reclaimable2);
-			}
-		}
-	}
-	
-	private void assertCanDelete(int... fileNumber)
-	{
-		for (int num: fileNumber)
-		{
-			assertTrue(files[num].isCanReclaim());
-		}
-	}
-	
-	private void assertCantDelete(int... fileNumber)
-	{
-		for (int num: fileNumber)
-		{
-			assertFalse(files[num].isCanReclaim());
-		}
-	}
-	
-	class MockJournalFile implements JournalFile
-	{
-	   private Set<Long> transactionIDs = new HashSet<Long>();
-		
-		private Set<Long> transactionTerminationIDs = new HashSet<Long>();
-		
-		private Set<Long> transactionPrepareIDs = new HashSet<Long>();
+   private JournalFile[] files;
 
-		private Map<JournalFile, Integer> negCounts = new HashMap<JournalFile, Integer>();
-		
-		private int posCount;
-		
-		private boolean canDelete;
-		
-		public void extendOffset(int delta)
-		{
-		}
+   private Reclaimer reclaimer;
 
-		public SequentialFile getFile()
-		{
-			return null;
-		}
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
 
-		public int getOffset()
-		{
-			return 0;
-		}
+      reclaimer = new Reclaimer();
+   }
 
-		public int getOrderingID()
-		{
-			return 0;
-		}
+   public void testOneFilePosNegAll() throws Exception
+   {
+      setup(1);
 
-		public void setOffset(int offset)
-		{
-		}
-		
-		public int getNegCount(final JournalFile file)
-		{
-			Integer count = negCounts.get(file);
-			
-			if (count != null)
-			{
-				return count.intValue();
-			}
-			else
-			{
-				return 0;
-			}
-		}
-		
-		public void incNegCount(final JournalFile file)
-		{
-			Integer count = negCounts.get(file);
-			
-			int c = count == null ? 1 : count.intValue() + 1;
-			
-			negCounts.put(file, c);
-		}
-		
-		public int getPosCount()
-		{
-			return posCount;
-		}
-		
-		public void incPosCount()
-		{
-			this.posCount++;
-		}
-		
-		public void decPosCount()
-		{
-			this.posCount--;
-		}
+      setupPosNeg(0, 10, 10);
 
-		public boolean isCanReclaim()
-		{
-			return canDelete;
-		}
+      reclaimer.scan(files);
 
-		public void setCanReclaim(boolean canDelete)
-		{
-			this.canDelete = canDelete;
-		}		
-		
-		public void addTransactionID(long id)
-		{
-			transactionIDs.add(id);
-		}
+      assertCanDelete(0);
+   }
 
-		public void addTransactionPrepareID(long id)
-		{
-			transactionPrepareIDs.add(id);
-		}
+   public void testOneFilePosNegNotAll() throws Exception
+   {
+      setup(1);
 
-		public void addTransactionTerminationID(long id)
-		{
-			transactionTerminationIDs.add(id);
-		}
+      setupPosNeg(0, 10, 7);
 
-		public boolean containsTransactionID(long id)
-		{
-			return transactionIDs.contains(id);
-		}
+      reclaimer.scan(files);
 
-		public boolean containsTransactionPrepareID(long id)
-		{
-			return transactionPrepareIDs.contains(id);
-		}
+      assertCantDelete(0);
+   }
 
-		public boolean containsTransactionTerminationID(long id)
-		{
-			return transactionTerminationIDs.contains(id);
-		}
-		
-		public Set<Long> getTranactionTerminationIDs()
-		{
-			return transactionTerminationIDs;
-		}
+   public void testOneFilePosOnly() throws Exception
+   {
+      setup(1);
 
-		public Set<Long> getTransactionPrepareIDs()
-		{
-			return transactionPrepareIDs;
-		}
+      setupPosNeg(0, 10);
 
-		public Set<Long> getTransactionsIDs()
-		{
-			return transactionIDs;
-		}
-	}
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+   }
+
+   public void testOneFileNegOnly() throws Exception
+   {
+      setup(1);
+
+      setupPosNeg(0, 0, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+   }
+
+   public void testTwoFilesPosNegAllDifferentFiles() throws Exception
+   {
+      setup(2);
+
+      setupPosNeg(0, 10);
+      setupPosNeg(1, 0, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+
+   }
+
+   public void testTwoFilesPosNegAllSameFiles() throws Exception
+   {
+      setup(2);
+
+      setupPosNeg(0, 10, 10);
+      setupPosNeg(1, 10, 0, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+
+   }
+
+   public void testTwoFilesPosNegMixedFiles() throws Exception
+   {
+      setup(2);
+
+      setupPosNeg(0, 10, 7);
+      setupPosNeg(1, 10, 3, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+   }
+
+   public void testTwoFilesPosNegAllFirstFile() throws Exception
+   {
+      setup(2);
+
+      setupPosNeg(0, 10, 10);
+      setupPosNeg(1, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCantDelete(1);
+   }
+
+   public void testTwoFilesPosNegAllSecondFile() throws Exception
+   {
+      setup(2);
+
+      setupPosNeg(0, 10);
+      setupPosNeg(1, 10, 0, 10);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+   }
+
+   public void testTwoFilesPosOnly() throws Exception
+   {
+      setup(2);
+
+      setupPosNeg(0, 10);
+      setupPosNeg(1, 10);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+   }
+
+   public void testTwoFilesxyz() throws Exception
+   {
+      setup(2);
+
+      setupPosNeg(0, 10);
+      setupPosNeg(1, 10, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCantDelete(1);
+   }
+
+   // Can-can-can
+
+   public void testThreeFiles1() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 10, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 10, 0, 0, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   public void testThreeFiles2() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 7, 0, 0);
+      setupPosNeg(1, 10, 3, 5, 0);
+      setupPosNeg(2, 10, 0, 5, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   public void testThreeFiles3() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 1, 0, 0);
+      setupPosNeg(1, 10, 6, 5, 0);
+      setupPosNeg(2, 10, 3, 5, 10);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   public void testThreeFiles3_1() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 1, 0, 0);
+      setupPosNeg(1, 10, 6, 5, 0);
+      setupPosNeg(2, 0, 3, 5, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   public void testThreeFiles3_2() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 1, 0, 0);
+      setupPosNeg(1, 0, 6, 0, 0);
+      setupPosNeg(2, 0, 3, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   // Cant-can-can
+
+   public void testThreeFiles4() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 5, 0);
+      setupPosNeg(2, 10, 0, 5, 10);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   public void testThreeFiles5() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 5, 0);
+      setupPosNeg(2, 0, 0, 5, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   public void testThreeFiles6() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 0, 0, 0);
+      setupPosNeg(1, 10, 0, 5, 0);
+      setupPosNeg(2, 0, 0, 5, 10);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   public void testThreeFiles7() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 0, 0, 0);
+      setupPosNeg(1, 10, 0, 5, 0);
+      setupPosNeg(2, 0, 0, 5, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCanDelete(2);
+   }
+
+   // Cant can cant
+
+   public void testThreeFiles8() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 10, 0, 0, 2);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles9() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 10, 1, 0, 2);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles10() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 10, 1, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles11() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 0, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 10, 0, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles12() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 0, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 0, 3, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   // Cant-cant-cant
+
+   public void testThreeFiles13() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 2, 3, 0);
+      setupPosNeg(2, 10, 1, 5, 7);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles14() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 0, 2, 0, 0);
+      setupPosNeg(2, 10, 1, 0, 7);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles15() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 2, 3, 0);
+      setupPosNeg(2, 0, 1, 5, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles16() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 0, 2, 0, 0);
+      setupPosNeg(2, 0, 1, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles17() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 3, 0);
+      setupPosNeg(2, 10, 1, 5, 7);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles18() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 3, 0);
+      setupPosNeg(2, 10, 1, 0, 7);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles19() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 3, 0);
+      setupPosNeg(2, 10, 1, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles20() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 3, 0, 0);
+      setupPosNeg(1, 10, 0, 0, 0);
+      setupPosNeg(2, 10, 1, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles21() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 0, 0, 0);
+      setupPosNeg(1, 10, 0, 0, 0);
+      setupPosNeg(2, 10, 0, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCantDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   // Can-can-cant
+
+   public void testThreeFiles22() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 10, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 10, 0, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles23() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 10, 0, 0);
+      setupPosNeg(1, 10, 0, 10, 0);
+      setupPosNeg(2, 10, 3, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles24() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 7, 0, 0);
+      setupPosNeg(1, 10, 3, 10, 0);
+      setupPosNeg(2, 10, 3, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles25() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 7, 0, 0);
+      setupPosNeg(1, 0, 3, 10, 0);
+      setupPosNeg(2, 10, 3, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles26() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 7, 0, 0);
+      setupPosNeg(1, 0, 3, 10, 0);
+      setupPosNeg(2, 10, 0, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCanDelete(1);
+      assertCantDelete(2);
+   }
+
+   // Can-cant-cant
+
+   public void testThreeFiles27() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 10, 0, 0);
+      setupPosNeg(1, 10, 0, 0, 0);
+      setupPosNeg(2, 10, 0, 0, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles28() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 10, 0, 0);
+      setupPosNeg(1, 10, 0, 3, 0);
+      setupPosNeg(2, 10, 0, 0, 5);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles29() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 10, 0, 0);
+      setupPosNeg(1, 10, 0, 3, 0);
+      setupPosNeg(2, 10, 0, 6, 5);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   public void testThreeFiles30() throws Exception
+   {
+      setup(3);
+
+      setupPosNeg(0, 10, 10, 0, 0);
+      setupPosNeg(1, 10, 0, 3, 0);
+      setupPosNeg(2, 0, 0, 6, 0);
+
+      reclaimer.scan(files);
+
+      assertCanDelete(0);
+      assertCantDelete(1);
+      assertCantDelete(2);
+   }
+
+   // Private
+   // ------------------------------------------------------------------------
+
+   private void setup(final int numFiles)
+   {
+      files = new JournalFile[numFiles];
+
+      for (int i = 0; i < numFiles; i++)
+      {
+         files[i] = new MockJournalFile();
+      }
+   }
+
+   private void setupPosNeg(final int fileNumber, final int pos, final int... neg)
+   {
+      JournalFile file = files[fileNumber];
+
+      for (int i = 0; i < pos; i++)
+      {
+         file.incPosCount();
+      }
+
+      for (int i = 0; i < neg.length; i++)
+      {
+         JournalFile reclaimable2 = files[i];
+
+         for (int j = 0; j < neg[i]; j++)
+         {
+            file.incNegCount(reclaimable2);
+         }
+      }
+   }
+
+   private void assertCanDelete(final int... fileNumber)
+   {
+      for (int num : fileNumber)
+      {
+         assertTrue(files[num].isCanReclaim());
+      }
+   }
+
+   private void assertCantDelete(final int... fileNumber)
+   {
+      for (int num : fileNumber)
+      {
+         assertFalse(files[num].isCanReclaim());
+      }
+   }
+
+   class MockJournalFile implements JournalFile
+   {
+      private final Set<Long> transactionIDs = new HashSet<Long>();
+
+      private final Set<Long> transactionTerminationIDs = new HashSet<Long>();
+
+      private final Set<Long> transactionPrepareIDs = new HashSet<Long>();
+
+      private final Map<JournalFile, Integer> negCounts = new HashMap<JournalFile, Integer>();
+
+      private int posCount;
+
+      private boolean canDelete;
+
+      public void extendOffset(final int delta)
+      {
+      }
+
+      public SequentialFile getFile()
+      {
+         return null;
+      }
+
+      public int getOffset()
+      {
+         return 0;
+      }
+
+      public int getOrderingID()
+      {
+         return 0;
+      }
+
+      public void setOffset(final int offset)
+      {
+      }
+
+      public int getNegCount(final JournalFile file)
+      {
+         Integer count = negCounts.get(file);
+
+         if (count != null)
+         {
+            return count.intValue();
+         }
+         else
+         {
+            return 0;
+         }
+      }
+
+      public void incNegCount(final JournalFile file)
+      {
+         Integer count = negCounts.get(file);
+
+         int c = count == null ? 1 : count.intValue() + 1;
+
+         negCounts.put(file, c);
+      }
+
+      public int getPosCount()
+      {
+         return posCount;
+      }
+
+      public void incPosCount()
+      {
+         posCount++;
+      }
+
+      public void decPosCount()
+      {
+         posCount--;
+      }
+
+      public boolean isCanReclaim()
+      {
+         return canDelete;
+      }
+
+      public void setCanReclaim(final boolean canDelete)
+      {
+         this.canDelete = canDelete;
+      }
+
+      public void addTransactionID(final long id)
+      {
+         transactionIDs.add(id);
+      }
+
+      public void addTransactionPrepareID(final long id)
+      {
+         transactionPrepareIDs.add(id);
+      }
+
+      public void addTransactionTerminationID(final long id)
+      {
+         transactionTerminationIDs.add(id);
+      }
+
+      public boolean containsTransactionID(final long id)
+      {
+         return transactionIDs.contains(id);
+      }
+
+      public boolean containsTransactionPrepareID(final long id)
+      {
+         return transactionPrepareIDs.contains(id);
+      }
+
+      public boolean containsTransactionTerminationID(final long id)
+      {
+         return transactionTerminationIDs.contains(id);
+      }
+
+      public Set<Long> getTranactionTerminationIDs()
+      {
+         return transactionTerminationIDs;
+      }
+
+      public Set<Long> getTransactionPrepareIDs()
+      {
+         return transactionPrepareIDs;
+      }
+
+      public Set<Long> getTransactionsIDs()
+      {
+         return transactionIDs;
+      }
+   }
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -1,24 +1,24 @@
 /*
- * 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.
- */ 
+ * 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.journal.impl;
 
@@ -43,264 +43,263 @@
 public abstract class SequentialFileFactoryTestBase extends UnitTestCase
 {
    protected final Logger log = Logger.getLogger(this.getClass());
-   
-   
+
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
-      
+
       factory = createFactory();
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
       assertEquals(0, AsynchronousFileImpl.getTotalMaxIO());
    }
-   
+
    protected abstract SequentialFileFactory createFactory();
-   
+
    protected SequentialFileFactory factory;
-      
+
    public void testCreateAndListFiles() throws Exception
    {
       List<String> expectedFiles = new ArrayList<String>();
-      
+
       final int numFiles = 10;
-      
+
       for (int i = 0; i < numFiles; i++)
       {
          String fileName = UUID.randomUUID().toString() + ".jbm";
-         
+
          expectedFiles.add(fileName);
-         
+
          SequentialFile sf = factory.createSequentialFile(fileName, 1);
-         
+
          sf.open();
-         
+
          assertEquals(fileName, sf.getFileName());
-         
+
          sf.close();
-      }           
-      
-      //Create a couple with a different extension - they shouldn't be picked up
-      
+      }
+
+      // Create a couple with a different extension - they shouldn't be picked
+      // up
+
       SequentialFile sf1 = factory.createSequentialFile("different.file", 1);
       sf1.open();
-      
+
       SequentialFile sf2 = factory.createSequentialFile("different.cheese", 1);
       sf2.open();
-                  
+
       List<String> fileNames = factory.listFiles("jbm");
-      
+
       assertEquals(expectedFiles.size(), fileNames.size());
-      
-      for (String fileName: expectedFiles)
+
+      for (String fileName : expectedFiles)
       {
          assertTrue(fileNames.contains(fileName));
       }
-      
+
       fileNames = factory.listFiles("file");
-      
+
       assertEquals(1, fileNames.size());
-      
-      assertTrue(fileNames.contains("different.file"));  
-      
+
+      assertTrue(fileNames.contains("different.file"));
+
       fileNames = factory.listFiles("cheese");
-      
+
       assertEquals(1, fileNames.size());
-      
-      assertTrue(fileNames.contains("different.cheese"));   
-      
+
+      assertTrue(fileNames.contains("different.cheese"));
+
       sf1.close();
       sf2.close();
    }
-   
-   
+
    public void testFill() throws Exception
    {
       SequentialFile sf = factory.createSequentialFile("fill.jbm", 1);
-      
+
       sf.open();
-      
+
       try
       {
-      
+
          checkFill(sf, 0, 2048, (byte)'X');
-         
+
          checkFill(sf, 512, 512, (byte)'Y');
-         
+
          checkFill(sf, 0, 1, (byte)'Z');
-         
+
          checkFill(sf, 512, 1, (byte)'A');
-         
-         checkFill(sf, 1024, 512*4, (byte)'B');
+
+         checkFill(sf, 1024, 512 * 4, (byte)'B');
       }
       finally
       {
          sf.close();
       }
    }
-   
+
    public void testDelete() throws Exception
    {
       SequentialFile sf = factory.createSequentialFile("delete-me.jbm", 1);
-      
+
       sf.open();
-      
+
       SequentialFile sf2 = factory.createSequentialFile("delete-me2.jbm", 1);
-      
+
       sf2.open();
-      
+
       List<String> fileNames = factory.listFiles("jbm");
-      
+
       assertEquals(2, fileNames.size());
-      
+
       assertTrue(fileNames.contains("delete-me.jbm"));
-      
+
       assertTrue(fileNames.contains("delete-me2.jbm"));
-      
+
       sf.delete();
-      
+
       fileNames = factory.listFiles("jbm");
-      
+
       assertEquals(1, fileNames.size());
-      
+
       assertTrue(fileNames.contains("delete-me2.jbm"));
-      
+
       sf2.close();
-      
+
    }
-   
+
    public void testWriteandRead() throws Exception
    {
       SequentialFile sf = factory.createSequentialFile("write.jbm", 1);
-      
+
       sf.open();
-      
+
       String s1 = "aardvark";
       byte[] bytes1 = s1.getBytes("UTF-8");
       ByteBuffer bb1 = factory.wrapBuffer(bytes1);
-      
+
       String s2 = "hippopotamus";
       byte[] bytes2 = s2.getBytes("UTF-8");
       ByteBuffer bb2 = factory.wrapBuffer(bytes2);
-      
+
       String s3 = "echidna";
       byte[] bytes3 = s3.getBytes("UTF-8");
       ByteBuffer bb3 = factory.wrapBuffer(bytes3);
-      
+
       int bytesWritten = sf.write(bb1, true);
-      
+
       assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesWritten);
-      
+
       bytesWritten = sf.write(bb2, true);
-      
+
       assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesWritten);
-      
+
       bytesWritten = sf.write(bb3, true);
-      
+
       assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesWritten);
-      
+
       sf.position(0);
-      
+
       ByteBuffer rb1 = factory.newBuffer(bytes1.length);
       ByteBuffer rb2 = factory.newBuffer(bytes2.length);
       ByteBuffer rb3 = factory.newBuffer(bytes3.length);
 
       int bytesRead = sf.read(rb1);
-      assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesRead);     
+      assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesRead);
 
-      for (int i=0; i<bytes1.length; i++)
+      for (int i = 0; i < bytes1.length; i++)
       {
-      	assertEquals(bytes1[i], rb1.get(i));
+         assertEquals(bytes1[i], rb1.get(i));
       }
-      
+
       bytesRead = sf.read(rb2);
-      assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesRead);     
-      for (int i=0; i<bytes2.length; i++)
+      assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesRead);
+      for (int i = 0; i < bytes2.length; i++)
       {
-      	assertEquals(bytes2[i], rb2.get(i));
+         assertEquals(bytes2[i], rb2.get(i));
       }
-      
-      
+
       bytesRead = sf.read(rb3);
-      assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesRead);     
-      for (int i=0; i<bytes3.length; i++)
+      assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesRead);
+      for (int i = 0; i < bytes3.length; i++)
       {
-      	assertEquals(bytes3[i], rb3.get(i));
+         assertEquals(bytes3[i], rb3.get(i));
       }
-      
+
       sf.close();
-      
+
    }
-   
+
    public void testPosition() throws Exception
    {
       SequentialFile sf = factory.createSequentialFile("position.jbm", 1);
-      
+
       sf.open();
-      
+
       try
       {
-         
+
          sf.fill(0, 3 * 512, (byte)0);
-         
+
          String s1 = "orange";
          byte[] bytes1 = s1.getBytes("UTF-8");
-         ByteBuffer bb1 = factory.wrapBuffer(bytes1); 
-         
-         String s2 = "grapefruit";
+         ByteBuffer bb1 = factory.wrapBuffer(bytes1);
+
          byte[] bytes2 = s1.getBytes("UTF-8");
          ByteBuffer bb2 = factory.wrapBuffer(bytes2);
-         
+
          String s3 = "lemon";
          byte[] bytes3 = s3.getBytes("UTF-8");
          ByteBuffer bb3 = factory.wrapBuffer(bytes3);
-         
+
          int bytesWritten = sf.write(bb1, true);
-         
+
          assertEquals(bb1.limit(), bytesWritten);
-         
+
          bytesWritten = sf.write(bb2, true);
-         
+
          assertEquals(bb2.limit(), bytesWritten);
-         
+
          bytesWritten = sf.write(bb3, true);
-         
+
          assertEquals(bb3.limit(), bytesWritten);
-         
+
          byte[] rbytes1 = new byte[bytes1.length];
-         
+
          byte[] rbytes2 = new byte[bytes2.length];
-         
+
          byte[] rbytes3 = new byte[bytes3.length];
-         
+
          ByteBuffer rb1 = factory.newBuffer(rbytes1.length);
          ByteBuffer rb2 = factory.newBuffer(rbytes2.length);
          ByteBuffer rb3 = factory.newBuffer(rbytes3.length);
-         
+
          sf.position(bb1.limit() + bb2.limit());
-         
+
          int bytesRead = sf.read(rb3);
          assertEquals(rb3.limit(), bytesRead);
          rb3.rewind();
          rb3.get(rbytes3);
-         assertEqualsByteArrays(bytes3, rbytes3);    
-         
+         assertEqualsByteArrays(bytes3, rbytes3);
+
          sf.position(rb1.limit());
-         
+
          bytesRead = sf.read(rb2);
          assertEquals(rb2.limit(), bytesRead);
          rb2.get(rbytes2);
          assertEqualsByteArrays(bytes2, rbytes2);
-         
+
          sf.position(0);
-         
+
          bytesRead = sf.read(rb1);
          assertEquals(rb1.limit(), bytesRead);
          rb1.get(rbytes1);
-         
+
          assertEqualsByteArrays(bytes1, rbytes1);
 
       }
@@ -315,67 +314,67 @@
          }
       }
    }
-    
+
    public void testOpenClose() throws Exception
    {
       SequentialFile sf = factory.createSequentialFile("openclose.jbm", 1);
-      
+
       sf.open();
-      
+
       sf.fill(0, 512, (byte)0);
-      
+
       String s1 = "cheesecake";
       byte[] bytes1 = s1.getBytes("UTF-8");
       ByteBuffer bb1 = factory.wrapBuffer(bytes1);
-      
+
       int bytesWritten = sf.write(bb1, true);
-      
+
       assertEquals(bb1.limit(), bytesWritten);
-      
+
       sf.close();
-      
+
       try
       {
          sf.write(bb1, true);
-         
+
          fail("Should throw exception");
       }
       catch (Exception e)
       {
-         //OK
+         // OK
       }
-      
+
       sf.open();
-      
+
       sf.write(bb1, true);
-      
+
       sf.close();
    }
-   
+
    // Private ---------------------------------
-   
-   protected void checkFill(SequentialFile file, int pos, int size, byte fillChar) throws Exception
+
+   protected void checkFill(final SequentialFile file, final int pos, final int size, final byte fillChar) throws Exception
    {
       file.fill(pos, size, fillChar);
-      
+
       file.close();
-      
+
       file.open();
-      
+
       file.position(pos);
-      
+
       ByteBuffer bb = factory.newBuffer(size);
-      
+
       int bytesRead = file.read(bb);
-      
+
       assertEquals(calculateRecordSize(size, file.getAlignment()), bytesRead);
-      
+
       for (int i = 0; i < size; i++)
       {
-         //log.debug(" i is " + i);
+         // log.debug(" i is " + i);
          assertEquals(fillChar, bb.get(i));
       }
-            
+
    }
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.tests.unit.core.journal.impl.fakes;
 
 import org.jboss.messaging.core.journal.EncodingSupport;
@@ -33,23 +32,21 @@
  */
 public class ByteArrayEncoding implements EncodingSupport
 {
-   
+
    // Constants -----------------------------------------------------
    final byte[] data;
-   
-  
+
    // Attributes ----------------------------------------------------
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
 
    public ByteArrayEncoding(final byte[] data)
    {
       this.data = data;
    }
-   
-  
+
    // Public --------------------------------------------------------
 
    public void decode(final MessagingBuffer buffer)
@@ -66,14 +63,13 @@
    {
       return data.length;
    }
-   
 
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeCallback.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeCallback.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeCallback.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl.fakes;
 
@@ -34,18 +34,19 @@
 public class FakeCallback implements IOCallback
 {
    volatile String msg;
+
    final CountDownLatch latch;
-   
+
    public FakeCallback(final CountDownLatch latch)
    {
       this.latch = latch;
    }
-   
+
    public FakeCallback()
    {
-      this.latch = new CountDownLatch(1);
+      latch = new CountDownLatch(1);
    }
-   
+
    public void done()
    {
       latch.countDown();
@@ -54,13 +55,12 @@
    public void onError(final int errorCode, final String errorMessage)
    {
       latch.countDown();
-      this.msg = errorMessage;
+      msg = errorMessage;
    }
-   
+
    public void waitComplete() throws Exception
    {
       latch.await();
    }
-   
+
 }
-

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -18,7 +18,7 @@
  * 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.journal.impl.fakes;
 
@@ -45,27 +45,27 @@
 public class FakeSequentialFileFactory implements SequentialFileFactory
 {
    private static final Logger log = Logger.getLogger(FakeSequentialFileFactory.class);
-      
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
    private final Map<String, FakeSequentialFile> fileMap = new ConcurrentHashMap<String, FakeSequentialFile>();
-   
+
    private final int alignment;
-   
-   private final boolean supportsCallback; 
-   
+
+   private final boolean supportsCallback;
+
    private volatile boolean holdCallbacks;
-   
+
    private volatile boolean generateErrors;
-   
+
    private final List<CallbackRunnable> callbacksInHold;
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    public FakeSequentialFileFactory(final int alignment, final boolean supportsCallback)
    {
       this.alignment = alignment;
@@ -78,27 +78,25 @@
       this(1, false);
    }
 
-   
-   
    // Public --------------------------------------------------------
-   
+
    public SequentialFile createSequentialFile(final String fileName, final int maxAIO) throws Exception
    {
       FakeSequentialFile sf = fileMap.get(fileName);
-      
+
       if (sf == null)
-      {                 
+      {
          sf = newSequentialFile(fileName);
-         
+
          fileMap.put(fileName, sf);
       }
       else
-      { 
-          sf.getData().position(0);
-         
-         //log.debug("positioning data to 0");
+      {
+         sf.getData().position(0);
+
+         // log.debug("positioning data to 0");
       }
-                  
+
       return sf;
    }
 
@@ -106,45 +104,45 @@
    {
       final int limit = buffer.limit();
       buffer.rewind();
-      
+
       for (int i = 0; i < limit; i++)
       {
          buffer.put((byte)0);
       }
-      
+
       buffer.rewind();
    }
-   
+
    public List<String> listFiles(final String extension)
    {
       List<String> files = new ArrayList<String>();
-      
-      for (String s: fileMap.keySet())
+
+      for (String s : fileMap.keySet())
       {
          if (s.endsWith("." + extension))
          {
             files.add(s);
          }
       }
-      
+
       return files;
    }
-   
+
    public Map<String, FakeSequentialFile> getFileMap()
    {
       return fileMap;
    }
-   
+
    public void clear()
    {
       fileMap.clear();
    }
-   
+
    public boolean isSupportsCallbacks()
    {
       return supportsCallback;
    }
-   
+
    public ByteBuffer newBuffer(int size)
    {
       if (size % alignment != 0)
@@ -153,37 +151,37 @@
       }
       return ByteBuffer.allocateDirect(size);
    }
-   
-   public int calculateBlockSize(int position)
+
+   public int calculateBlockSize(final int position)
    {
       int alignment = getAlignment();
-      
-      int pos = ((position / alignment) + (position % alignment != 0 ? 1 : 0)) * alignment;
-      
+
+      int pos = (position / alignment + (position % alignment != 0 ? 1 : 0)) * alignment;
+
       return pos;
    }
-   
-   public ByteBuffer wrapBuffer(byte[] bytes)
+
+   public ByteBuffer wrapBuffer(final byte[] bytes)
    {
       return ByteBuffer.wrap(bytes);
    }
-   
+
    public boolean isHoldCallbacks()
    {
       return holdCallbacks;
    }
 
-   public void setHoldCallbacks(boolean holdCallbacks)
+   public void setHoldCallbacks(final boolean holdCallbacks)
    {
       this.holdCallbacks = holdCallbacks;
    }
-   
+
    public boolean isGenerateErrors()
    {
       return generateErrors;
    }
 
-   public void setGenerateErrors(boolean generateErrors)
+   public void setGenerateErrors(final boolean generateErrors)
    {
       this.generateErrors = generateErrors;
    }
@@ -194,55 +192,56 @@
       {
          action.run();
       }
-      
+
       callbacksInHold.clear();
    }
 
-   public void flushCallback(int position)
+   public void flushCallback(final int position)
    {
       Runnable run = callbacksInHold.get(position);
       run.run();
       callbacksInHold.remove(run);
    }
-   
-   public void setCallbackAsError(int position)
+
+   public void setCallbackAsError(final int position)
    {
       callbacksInHold.get(position).setSendError(true);
    }
-   
+
    public int getNumberOfCallbacks()
    {
       return callbacksInHold.size();
    }
-   
+
    public int getAlignment()
    {
       return alignment;
    }
-   
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
 
    protected FakeSequentialFile newSequentialFile(final String fileName)
    {
       return new FakeSequentialFile(fileName);
    }
-   
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
 
    private class CallbackRunnable implements Runnable
    {
-      
+
       final FakeSequentialFile file;
+
       final ByteBuffer bytes;
+
       final IOCallback callback;
+
       volatile boolean sendError;
-      
+
       CallbackRunnable(final FakeSequentialFile file, final ByteBuffer bytes, final IOCallback callback)
       {
          this.file = file;
@@ -252,7 +251,7 @@
 
       public void run()
       {
-         
+
          if (sendError)
          {
             callback.onError(1, "Fake aio error");
@@ -262,8 +261,11 @@
             try
             {
                file.data.put(bytes);
-               if (callback!=null) callback.done();
-               
+               if (callback != null)
+               {
+                  callback.done();
+               }
+
                if (file.bufferCallback != null)
                {
                   file.bufferCallback.bufferDone(bytes);
@@ -282,19 +284,18 @@
          return sendError;
       }
 
-      public void setSendError(boolean sendError)
+      public void setSendError(final boolean sendError)
       {
          this.sendError = sendError;
       }
    }
-   
-   
+
    public class FakeSequentialFile implements SequentialFile
    {
       private volatile boolean open;
-      
+
       private final String fileName;
-      
+
       private ByteBuffer data;
 
       private BufferCallback bufferCallback;
@@ -303,22 +304,23 @@
       {
          return data;
       }
-      
+
       public boolean isOpen()
       {
-         //log.debug("is open" + System.identityHashCode(this) +" open is now " + open);
+         // log.debug("is open" + System.identityHashCode(this) +" open is now "
+         // + open);
          return open;
       }
-      
+
       public FakeSequentialFile(final String fileName)
       {
-         this.fileName = fileName;   
+         this.fileName = fileName;
       }
 
       public void close() throws Exception
       {
          open = false;
-         
+
          if (data != null)
          {
             data.position(0);
@@ -332,7 +334,7 @@
             throw new IllegalStateException("Is closed");
          }
          close();
-         
+
          fileMap.remove(fileName);
       }
 
@@ -343,61 +345,64 @@
 
       public void open() throws Exception
       {
-        open(0);
+         open(0);
       }
-      
-      public synchronized void open(int currentMaxIO) throws Exception
+
+      public synchronized void open(final int currentMaxIO) throws Exception
       {
          open = true;
          checkAndResize(0);
       }
 
-      public void setBufferCallback(BufferCallback callback)
+      public void setBufferCallback(final BufferCallback callback)
       {
-         this.bufferCallback = callback;
+         bufferCallback = callback;
       }
 
       public void fill(final int pos, final int size, final byte fillCharacter) throws Exception
-      {     
+      {
          if (!open)
          {
             throw new IllegalStateException("Is closed");
          }
-         
+
          checkAndResize(pos + size);
-         
-         //log.debug("size is " + size + " pos is " + pos);
-         
+
+         // log.debug("size is " + size + " pos is " + pos);
+
          for (int i = pos; i < size + pos; i++)
          {
             data.array()[i] = fillCharacter;
-            
-            //log.debug("Filling " + pos + " with char " + fillCharacter);
-         }                 
+
+            // log.debug("Filling " + pos + " with char " + fillCharacter);
+         }
       }
-      
+
       public int read(final ByteBuffer bytes) throws Exception
       {
          return read(bytes, null);
       }
-      
+
       public int read(final ByteBuffer bytes, final IOCallback callback) throws Exception
       {
          if (!open)
          {
             throw new IllegalStateException("Is closed");
          }
-         
+
          byte[] bytesRead = new byte[bytes.limit()];
-         
+
          data.get(bytesRead);
-         
+
          bytes.put(bytesRead);
-         
+
          bytes.rewind();
-         
-         if (callback != null) callback.done();
-         
+
+         if (callback != null)
+         {
+            callback.done();
+         }
+
          return bytesRead.length;
       }
 
@@ -407,12 +412,12 @@
          {
             throw new IllegalStateException("Is closed");
          }
-         
+
          checkAlignment(pos);
-         
+
          data.position(pos);
       }
-      
+
       public int position() throws Exception
       {
          return data.position();
@@ -424,17 +429,17 @@
          {
             throw new IllegalStateException("Is closed");
          }
-         
+
          final int position = data == null ? 0 : data.position();
-         
+
          checkAlignment(position);
-         
+
          checkAlignment(bytes.limit());
-         
+
          checkAndResize(bytes.limit() + position);
-         
+
          CallbackRunnable action = new CallbackRunnable(this, bytes, callback);
-         
+
          if (generateErrors)
          {
             action.setSendError(true);
@@ -442,17 +447,17 @@
 
          if (holdCallbacks)
          {
-            FakeSequentialFileFactory.this.callbacksInHold.add(action);
+            callbacksInHold.add(action);
          }
          else
          {
             action.run();
          }
-         
+
          return bytes.limit();
-         
+
       }
-      
+
       public void sync() throws Exception
       {
          if (supportsCallback)
@@ -460,7 +465,7 @@
             throw new IllegalStateException("sync is not supported when supportsCallback=true");
          }
       }
-      
+
       public long size() throws Exception
       {
          if (data == null)
@@ -472,28 +477,27 @@
             return data.limit();
          }
       }
-      
-      
+
       public int write(final ByteBuffer bytes, final boolean sync) throws Exception
       {
          return write(bytes, null);
       }
-      
+
       private void checkAndResize(final int size)
       {
          int oldpos = data == null ? 0 : data.position();
-         
+
          if (data == null || data.array().length < size)
          {
             byte[] newBytes = new byte[size];
-            
+
             if (data != null)
             {
                System.arraycopy(data.array(), 0, newBytes, 0, data.array().length);
             }
-            
+
             data = ByteBuffer.wrap(newBytes);
-            
+
             data.position(oldpos);
          }
       }
@@ -505,26 +509,25 @@
 
       public int calculateBlockStart(final int position) throws Exception
       {
-         int pos = ((position / alignment) + (position % alignment != 0 ? 1 : 0)) * alignment;
-         
+         int pos = (position / alignment + (position % alignment != 0 ? 1 : 0)) * alignment;
+
          return pos;
       }
-      
+
+      @Override
       public String toString()
       {
-         return "FakeSequentialFile:" + this.fileName;
+         return "FakeSequentialFile:" + fileName;
       }
-      
-      private void checkAlignment (final int position)
+
+      private void checkAlignment(final int position)
       {
-         if ( position % alignment != 0)
+         if (position % alignment != 0)
          {
             throw new IllegalStateException("Position is not aligned to " + alignment);
          }
       }
 
-
-
    }
 
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/SimpleEncoding.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/SimpleEncoding.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/SimpleEncoding.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -32,33 +32,32 @@
  */
 public class SimpleEncoding implements EncodingSupport
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
    private final int size;
+
    private final byte bytetosend;
-   
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
 
-   public SimpleEncoding(int size, byte bytetosend)
+   public SimpleEncoding(final int size, final byte bytetosend)
    {
       this.size = size;
       this.bytetosend = bytetosend;
    }
-   
 
    // Public --------------------------------------------------------
-   public void decode(MessagingBuffer buffer)
+   public void decode(final MessagingBuffer buffer)
    {
       throw new UnsupportedOperationException();
-      
+
    }
 
-   public void encode(MessagingBuffer buffer)
+   public void encode(final MessagingBuffer buffer)
    {
       for (int i = 0; i < size; i++)
       {
@@ -70,14 +69,13 @@
    {
       return size;
    }
-   
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,12 +20,10 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.tests.unit.core.paging.impl;
 
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
 
-
 /**
  * 
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
@@ -33,37 +31,33 @@
  */
 public class PageImplTest extends PageImplTestBase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    public void testPageFakeWithCallbacks() throws Exception
    {
       testAdd(new FakeSequentialFileFactory(512, true), 10);
    }
-   
+
    public void testPageFakeWithoutCallbacks() throws Exception
    {
       testAdd(new FakeSequentialFileFactory(1, false), 10);
    }
-   
-   
-   
-    
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 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;
@@ -45,93 +44,96 @@
  */
 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 factory, int numberOfElements) throws Exception
+   protected void testAdd(final SequentialFileFactory factory, final int numberOfElements) throws Exception
    {
-      
+
       SequentialFile file = factory.createSequentialFile("00010.page", 1);
-      
+
       PageImpl impl = new PageImpl(factory, file, 10);
-      
+
       assertEquals(10, impl.getPageId());
-      
+
       impl.open();
 
       assertEquals(1, factory.listFiles("page").size());
 
       ArrayList<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
-      
+
       SimpleString simpleDestination = new SimpleString("Test");
-      
+
       for (int i = 0; i < numberOfElements; 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);
-         
+         ServerMessage msg = new ServerMessageImpl((byte)1,
+                                                   true,
+                                                   0,
+                                                   System.currentTimeMillis(),
+                                                   (byte)0,
+                                                   new ByteBufferWrapper(buffer));
+
+         msg.setMessageID(i);
+
          msg.setDestination(simpleDestination);
-         
+
          impl.write(new PageMessageImpl(msg));
-         
+
          assertEquals(i + 1, impl.getNumberOfMessages());
       }
-      
+
       impl.sync();
       impl.close();
-      
+
       file = factory.createSequentialFile("00010.page", 1);
       file.open();
       impl = new PageImpl(factory, file, 10);
-      
+
       PageMessage msgs[] = impl.read();
-      
+
       assertEquals(numberOfElements, msgs.length);
 
       assertEquals(numberOfElements, impl.getNumberOfMessages());
-      
+
       for (int i = 0; i < msgs.length; i++)
       {
-         assertEquals((long)0, msgs[i].getMessage().getMessageID());
-         
+         assertEquals(0, msgs[i].getMessage().getMessageID());
+
          assertEquals(simpleDestination, msgs[i].getMessage().getDestination());
-         
+
          assertEqualsByteArrays(buffers.get(i).array(), msgs[i].getMessage().getBody().array());
       }
 
       impl.delete();
-      
-      
+
       assertEquals(0, factory.listFiles(".page").size());
-      
+
    }
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
-
 package org.jboss.messaging.tests.unit.core.paging.impl;
 
 import java.util.ArrayList;
@@ -41,27 +40,23 @@
 
 public class PageManagerImplTest extends UnitTestCase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
-   
+
    private static HierarchicalRepository<QueueSettings> repoSettings = new HierarchicalObjectRepository<QueueSettings>();
    static
    {
       repoSettings.setDefault(new QueueSettings());
    }
 
-
-   
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
-   
+
    public void testGetStore() throws Exception
    {
       HierarchicalRepository<QueueSettings> queueSettings = new HierarchicalObjectRepository<QueueSettings>();
@@ -69,83 +64,88 @@
 
       PagingStoreFactory spi = EasyMock.createMock(PagingStoreFactory.class);
       PagingManagerImpl manager = new PagingManagerImpl(spi, null, queueSettings, -1);
-      
+
       SimpleString destination = new SimpleString("some-destination");
 
       try
       {
          manager.getPageStore(destination);
-         fail ("supposed to throw an exception");
+         fail("supposed to throw an exception");
       }
       catch (Exception ignored)
       {
       }
-      
+
       manager.start();
-      
+
       PagingStore store = EasyMock.createNiceMock(PagingStore.class);
-      
+
       EasyMock.expect(spi.newStore(EasyMock.eq(destination), EasyMock.isA(QueueSettings.class))).andReturn(store);
-      
+
       store.start();
-      
-      
+
       EasyMock.replay(spi, store);
-      
+
       assertEquals(store, manager.getPageStore(destination));
-      
+
       EasyMock.verify(spi, store);
-      
+
       EasyMock.reset(spi, store);
-      
+
       EasyMock.replay(spi, store);
 
-      // it should use the cached store, so nothing else should be called on any SPI
+      // it should use the cached store, so nothing else should be called on any
+      // SPI
       assertEquals(store, manager.getPageStore(destination));
-      
+
       EasyMock.verify(spi, store);
-      
+
       EasyMock.reset(spi, store);
-      
+
       store.stop();
-      
+
       EasyMock.replay(spi, store);
-      
+
       manager.stop();
-      
+
       EasyMock.verify(spi, store);
 
    }
-   
-   
+
    public void testMultipleThreadsGetStore() throws Exception
    {
       PagingStoreFactory spi = EasyMock.createMock(PagingStoreFactory.class);
       final PagingManagerImpl manager = new PagingManagerImpl(spi, null, repoSettings, -1);
-      
+
       final SimpleString destination = new SimpleString("some-destination");
 
       final SequentialFileFactory factory = EasyMock.createNiceMock(SequentialFileFactory.class);
-      
+
       EasyMock.expect(factory.listFiles(EasyMock.isA(String.class))).andStubReturn(new ArrayList<String>());
-      
-      PagingStoreImpl storeImpl = new PagingStoreImpl(manager, factory, destination, new QueueSettings(), Executors.newSingleThreadExecutor());
-      
-      EasyMock.expect(spi.newStore(EasyMock.eq(destination), EasyMock.isA(QueueSettings.class))).andStubReturn(storeImpl);
-      
+
+      PagingStoreImpl storeImpl = new PagingStoreImpl(manager,
+                                                      factory,
+                                                      destination,
+                                                      new QueueSettings(),
+                                                      Executors.newSingleThreadExecutor());
+
+      EasyMock.expect(spi.newStore(EasyMock.eq(destination), EasyMock.isA(QueueSettings.class)))
+              .andStubReturn(storeImpl);
+
       EasyMock.replay(spi, factory);
-      
+
       manager.start();
-      
+
       int NUMBER_OF_THREADS = 100;
-      
+
       final CountDownLatch latchPositioned = new CountDownLatch(NUMBER_OF_THREADS);
       final CountDownLatch latchReady = new CountDownLatch(1);
-      
+
       class GetPageThread extends Thread
       {
-         Exception  e;
-         
+         Exception e;
+
+         @Override
          public void run()
          {
             try
@@ -153,28 +153,28 @@
                latchPositioned.countDown();
                latchReady.await();
                manager.getPageStore(destination);
-               
+
             }
             catch (Exception e)
             {
                e.printStackTrace();
                this.e = e;
             }
-            
+
          }
       }
-      
+
       GetPageThread threads[] = new GetPageThread[NUMBER_OF_THREADS];
       for (int i = 0; i < NUMBER_OF_THREADS; i++)
       {
          threads[i] = new GetPageThread();
          threads[i].start();
       }
-      
+
       latchPositioned.await();
       latchReady.countDown();
-      
-      for (GetPageThread thread: threads)
+
+      for (GetPageThread thread : threads)
       {
          thread.join();
          if (thread.e != null)
@@ -184,16 +184,15 @@
       }
 
       EasyMock.verify(spi, factory);
-      
+
    }
-   
 
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,15 +20,14 @@
  * 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 org.jboss.messaging.core.paging.PageTransactionInfo;
 import org.jboss.messaging.core.paging.impl.PageTransactionInfoImpl;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.tests.util.RandomUtil;
 import org.jboss.messaging.tests.util.UnitTestCase;
 
@@ -37,59 +36,57 @@
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  */
-public class PageTransactionImplTest extends UnitTestCase 
+public class PageTransactionImplTest extends UnitTestCase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    public void testAddAndRemoveMessages()
    {
       long id1 = RandomUtil.randomLong();
       long id2 = RandomUtil.randomLong();
       PageTransactionInfo trans = new PageTransactionInfoImpl(id2);
-      
+
       trans.setRecordID(id1);
-      
+
       // anything between 2 and 100
-      int nr1 = RandomUtil.randomPositiveInt()%98 + 2;
+      int nr1 = RandomUtil.randomPositiveInt() % 98 + 2;
 
-      
       for (int i = 0; i < nr1; i++)
       {
          trans.increment();
       }
-      
-      
+
       assertEquals(nr1, trans.getNumberOfMessages());
-      
+
       ByteBuffer buffer = ByteBuffer.allocate(trans.getEncodeSize());
       MessagingBuffer wrapper = new ByteBufferWrapper(buffer);
-      
+
       trans.encode(wrapper);
       wrapper.rewind();
-      
+
       PageTransactionInfo trans2 = new PageTransactionInfoImpl(id1);
       trans2.decode(wrapper);
-      
+
       assertEquals(id2, trans2.getTransactionID());
-      
+
       assertEquals(nr1, trans2.getNumberOfMessages());
-      
+
       for (int i = 0; i < nr1; i++)
       {
          trans.decrement();
       }
-      
+
       assertEquals(0, trans.getNumberOfMessages());
-      
+
       try
       {
          trans.decrement();
@@ -98,16 +95,15 @@
       catch (Throwable ignored)
       {
       }
-      
-      
+
    }
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 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;
@@ -45,268 +44,268 @@
  */
 public class PagingStoreImplTest extends PagingStoreTestBase
 {
-   
+
    // Constants -----------------------------------------------------
-   
+
    private final static SimpleString destinationTestName = new SimpleString("test");
-   
+
    // Attributes ----------------------------------------------------
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
- 
+
    public void testDoubleStart() throws Exception
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory();
-      
+
       PagingStore storeImpl = new PagingStoreImpl(null, factory, destinationTestName, new QueueSettings(), executor);
-      
+
       storeImpl.start();
-      
+
       // this is not supposed to throw an exception.
-      // As you could have start being called twice as Stores are dynamically created, on a multi-thread environment
+      // As you could have start being called twice as Stores are dynamically
+      // created, on a multi-thread environment
       storeImpl.start();
 
       storeImpl.stop();
-      
+
    }
-   
+
    public void testStore() throws Exception
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory();
-      
+
       PagingStore storeImpl = new PagingStoreImpl(null, factory, destinationTestName, new QueueSettings(), executor);
-      
+
       storeImpl.start();
-      
+
       assertEquals(0, storeImpl.getNumberOfPages());
-      
+
       storeImpl.startPaging();
 
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       List<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
 
       ByteBuffer buffer = createRandomBuffer(0, 10);
-      
+
       buffers.add(buffer);
       SimpleString destination = new SimpleString("test");
 
       PageMessageImpl msg = createMessage(destination, buffer);
-      
+
       assertTrue(storeImpl.isPaging());
-      
+
       assertTrue(storeImpl.page(msg));
-      
+
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       storeImpl.sync();
-      
+
       storeImpl = new PagingStoreImpl(null, factory, destinationTestName, new QueueSettings(), executor);
-      
+
       storeImpl.start();
-      
+
       assertEquals(2, storeImpl.getNumberOfPages());
-      
+
    }
-   
+
    public void testDepageOnCurrentPage() throws Exception
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory();
-      
+
       PagingStore storeImpl = new PagingStoreImpl(null, factory, destinationTestName, new QueueSettings(), executor);
-      
+
       storeImpl.start();
-      
+
       assertEquals(0, storeImpl.getNumberOfPages());
-      
+
       storeImpl.startPaging();
-      
+
       List<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
-      
+
       SimpleString destination = new SimpleString("test");
 
       for (int i = 0; i < 10; i++)
       {
 
-         ByteBuffer buffer = createRandomBuffer(i+1l, 10);
-         
+         ByteBuffer buffer = createRandomBuffer(i + 1l, 10);
+
          buffers.add(buffer);
-   
+
          PageMessageImpl msg = createMessage(destination, buffer);
 
          assertTrue(storeImpl.page(msg));
       }
-      
-      
+
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       storeImpl.sync();
-      
+
       Page page = storeImpl.depage();
-      
+
       page.open();
-      
+
       PageMessage msg[] = page.read();
-      
+
       assertEquals(10, msg.length);
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       page = storeImpl.depage();
-      
+
       assertNull(page);
-      
+
       assertEquals(0, storeImpl.getNumberOfPages());
-      
+
       for (int i = 0; i < 10; i++)
       {
          assertEquals(0, msg[i].getMessage().getMessageID());
          assertEqualsByteArrays(buffers.get(i).array(), msg[i].getMessage().getBody().array());
       }
-      
+
    }
-   
+
    public void testDepageMultiplePages() throws Exception
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory();
-      
-      TestSupportPageStore storeImpl = new PagingStoreImpl(null, factory, destinationTestName, new QueueSettings(), executor);
-      
+
+      TestSupportPageStore storeImpl = new PagingStoreImpl(null,
+                                                           factory,
+                                                           destinationTestName,
+                                                           new QueueSettings(),
+                                                           executor);
+
       storeImpl.start();
-      
+
       assertEquals(0, storeImpl.getNumberOfPages());
-      
+
       storeImpl.startPaging();
-      
+
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       List<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
-      
+
       SimpleString destination = new SimpleString("test");
 
       for (int i = 0; i < 10; i++)
       {
 
-         ByteBuffer buffer = createRandomBuffer(i+1l, 10);
-         
+         ByteBuffer buffer = createRandomBuffer(i + 1l, 10);
+
          buffers.add(buffer);
-   
+
          if (i == 5)
          {
             storeImpl.forceAnotherPage();
          }
-         
-         
+
          PageMessageImpl msg = createMessage(destination, buffer);
 
          assertTrue(storeImpl.page(msg));
       }
-      
-      
+
       assertEquals(2, storeImpl.getNumberOfPages());
-      
+
       storeImpl.sync();
-      
+
       for (int pageNr = 0; pageNr < 2; pageNr++)
       {
          Page page = storeImpl.depage();
-         
+
          page.open();
-         
+
          PageMessage msg[] = page.read();
-         
+
          page.close();
 
          assertEquals(5, msg.length);
-         
+
          for (int i = 0; i < 5; i++)
          {
             assertEquals(0, msg[i].getMessage().getMessageID());
-            assertEqualsByteArrays(buffers.get(pageNr*5 + i).array(), msg[i].getMessage().getBody().array());
+            assertEqualsByteArrays(buffers.get(pageNr * 5 + i).array(), msg[i].getMessage().getBody().array());
          }
       }
-      
+
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       assertTrue(storeImpl.isPaging());
 
       PageMessageImpl msg = createMessage(destination, buffers.get(0));
-      
+
       assertTrue(storeImpl.page(msg));
-      
+
       Page newPage = storeImpl.depage();
-      
+
       newPage.open();
-      
+
       assertEquals(1, newPage.read().length);
-      
+
       newPage.delete();
-      
+
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       assertTrue(storeImpl.isPaging());
-      
-      assertNull(storeImpl.depage());      
-      
+
+      assertNull(storeImpl.depage());
+
       assertFalse(storeImpl.isPaging());
-      
+
       assertFalse(storeImpl.page(msg));
-      
+
       storeImpl.startPaging();
 
       assertTrue(storeImpl.page(msg));
-      
+
       Page page = storeImpl.depage();
-      
+
       page.open();
-      
+
       PageMessage msgs[] = page.read();
-      
+
       assertEquals(1, msgs.length);
-      
+
       assertEquals(0l, msgs[0].getMessage().getMessageID());
-      
+
       assertEqualsByteArrays(buffers.get(0).array(), msgs[0].getMessage().getBody().array());
-      
+
       assertEquals(1, storeImpl.getNumberOfPages());
-      
+
       assertTrue(storeImpl.isPaging());
-      
+
       assertNull(storeImpl.depage());
-      
+
       assertEquals(0, storeImpl.getNumberOfPages());
-      
+
       page.open();
-      
-      
-      
+
    }
-   
-   
+
    public void testConcurrentDepage() throws Exception
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory(1, false);
-      
+
       testConcurrentPaging(factory, 10);
-      
+
    }
-   
+
    // Protected ----------------------------------------------------
-   
+
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
    }
-   
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -20,7 +20,6 @@
  * 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;
@@ -56,74 +55,78 @@
 public abstract class PagingStoreTestBase extends UnitTestCase
 {
    // Constants -----------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
    protected ExecutorService executor;
-   
+
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    // Public --------------------------------------------------------
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
 
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
       executor = Executors.newSingleThreadExecutor();
    }
-   
+
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
       executor.shutdown();
    }
-   
-   protected void testConcurrentPaging(SequentialFileFactory factory, final int numberOfThreads) throws Exception,
-         InterruptedException
+
+   protected void testConcurrentPaging(final SequentialFileFactory factory, final int numberOfThreads) throws Exception,
+                                                                                                      InterruptedException
    {
-      
+
       final int MAX_SIZE = 1024 * 10;
-      
+
       final AtomicLong messageIdGenerator = new AtomicLong(0);
-      
+
       final AtomicInteger aliveProducers = new AtomicInteger(numberOfThreads);
-      
+
       final CountDownLatch latchStart = new CountDownLatch(numberOfThreads);
-      
+
       final ConcurrentHashMap<Long, PageMessageImpl> buffers = new ConcurrentHashMap<Long, PageMessageImpl>();
-      
+
       final ArrayList<Page> readPages = new ArrayList<Page>();
-      
+
       QueueSettings settings = new QueueSettings();
       settings.setPageSizeBytes(MAX_SIZE);
-      
-      final TestSupportPageStore storeImpl = new PagingStoreImpl(null, factory, new SimpleString("test"), settings, executor);
-      
+
+      final TestSupportPageStore storeImpl = new PagingStoreImpl(null,
+                                                                 factory,
+                                                                 new SimpleString("test"),
+                                                                 settings,
+                                                                 executor);
+
       storeImpl.start();
-      
+
       assertEquals(0, storeImpl.getNumberOfPages());
-      
+
       storeImpl.startPaging();
-      
+
       assertEquals(1, storeImpl.getNumberOfPages());
-      
-      
-   
-      
+
       final SimpleString destination = new SimpleString("test");
-      
+
       class ProducerThread extends Thread
       {
-         
+
          Exception e;
-         
+
+         @Override
          public void run()
          {
-            
+
             try
             {
                boolean firstTime = true;
@@ -139,7 +142,7 @@
                   {
                      break;
                   }
-                  
+
                   if (firstTime)
                   {
                      latchStart.countDown();
@@ -158,11 +161,12 @@
             }
          }
       }
-      
+
       class ConsumerThread extends Thread
       {
          Exception e;
-         
+
+         @Override
          public void run()
          {
             try
@@ -185,18 +189,18 @@
             }
          }
       }
-      
+
       ProducerThread producerThread[] = new ProducerThread[numberOfThreads];
-      
+
       for (int i = 0; i < numberOfThreads; i++)
       {
          producerThread[i] = new ProducerThread();
          producerThread[i].start();
       }
-      
+
       ConsumerThread consumer = new ConsumerThread();
       consumer.start();
-      
+
       for (int i = 0; i < numberOfThreads; i++)
       {
          producerThread[i].join();
@@ -205,73 +209,70 @@
             throw producerThread[i].e;
          }
       }
-      
+
       consumer.join();
-      
+
       if (consumer.e != null)
       {
          throw consumer.e;
       }
-   
+
       System.out.println("Reading " + buffers.size() + " messages, " + readPages.size() + " pages");
-      
+
       final ConcurrentHashMap<Long, PageMessage> buffers2 = new ConcurrentHashMap<Long, PageMessage>();
-      
-      for (Page page: readPages)
+
+      for (Page page : readPages)
       {
          page.open();
          PageMessage msgs[] = page.read();
          page.close();
-         
+
          for (PageMessage msg : msgs)
          {
             msg.getMessage().getBody().rewind();
             long id = msg.getMessage().getBody().getLong();
             msg.getMessage().getBody().rewind();
-            
+
             PageMessageImpl msgWritten = buffers.remove(id);
             buffers2.put(id, msg);
             assertNotNull(msgWritten);
-            assertEquals (msg.getMessage().getDestination(), msgWritten.getMessage().getDestination());
+            assertEquals(msg.getMessage().getDestination(), msgWritten.getMessage().getDestination());
             assertEqualsByteArrays(msgWritten.getMessage().getBody().array(), msg.getMessage().getBody().array());
          }
       }
-      
-      assertEquals (0, buffers.size());
-      
+
+      assertEquals(0, buffers.size());
+
       List<String> files = factory.listFiles("page");
-      
+
       assertTrue(files.size() != 0);
-      
-      for (String file: files)
+
+      for (String file : files)
       {
          SequentialFile fileTmp = factory.createSequentialFile(file, 1);
          fileTmp.open();
-         assertTrue (fileTmp.size() + " <= " + MAX_SIZE, fileTmp.size() <= MAX_SIZE);
-         fileTmp.close();         
+         assertTrue(fileTmp.size() + " <= " + MAX_SIZE, fileTmp.size() <= MAX_SIZE);
+         fileTmp.close();
       }
-      
+
       TestSupportPageStore storeImpl2 = new PagingStoreImpl(null, factory, new SimpleString("test"), settings, executor);
       storeImpl2.start();
-      
+
       int numberOfPages = storeImpl2.getNumberOfPages();
       assertTrue(numberOfPages != 0);
-      
+
       storeImpl2.startPaging();
-      
 
-      
       storeImpl2.startPaging();
 
-      
       assertEquals(numberOfPages, storeImpl2.getNumberOfPages());
-      
+
       long lastMessageId = messageIdGenerator.incrementAndGet();
       PageMessage lastMsg = createMessage(destination, createRandomBuffer(lastMessageId, 5));
-      
+
       storeImpl2.page(lastMsg);
       buffers2.put(lastMessageId, lastMsg);
-      
+
       Page lastPage = null;
       while (true)
       {
@@ -280,66 +281,68 @@
          {
             break;
          }
-         
+
          lastPage = page;
-         
+
          page.open();
-         
+
          PageMessage[] msgs = page.read();
-         
+
          page.close();
 
-         for (PageMessage msg: msgs)
+         for (PageMessage msg : msgs)
          {
-            
+
             msg.getMessage().getBody().rewind();
             long id = msg.getMessage().getBody().getLong();
             PageMessage msgWritten = buffers2.remove(id);
             assertNotNull(msgWritten);
-            assertEquals (msg.getMessage().getDestination(), msgWritten.getMessage().getDestination());
+            assertEquals(msg.getMessage().getDestination(), msgWritten.getMessage().getDestination());
             assertEqualsByteArrays(msgWritten.getMessage().getBody().array(), msg.getMessage().getBody().array());
          }
       }
-      
-      
+
       lastPage.open();
       PageMessage lastMessages[] = lastPage.read();
       lastPage.close();
       assertEquals(1, lastMessages.length);
-      
+
       lastMessages[0].getMessage().getBody().rewind();
       assertEquals(lastMessages[0].getMessage().getBody().getLong(), lastMessageId);
       assertEqualsByteArrays(lastMessages[0].getMessage().getBody().array(), lastMsg.getMessage().getBody().array());
-      
+
       assertEquals(0, buffers2.size());
-      
-      
+
    }
 
-   protected PageMessageImpl createMessage(SimpleString destination, ByteBuffer buffer)
+   protected PageMessageImpl createMessage(final SimpleString destination, final ByteBuffer buffer)
    {
-      ServerMessage msg = new ServerMessageImpl((byte)1, true, 0,
-            System.currentTimeMillis(), (byte)0, new ByteBufferWrapper(buffer));
-      
+      ServerMessage msg = new ServerMessageImpl((byte)1,
+                                                true,
+                                                0,
+                                                System.currentTimeMillis(),
+                                                (byte)0,
+                                                new ByteBufferWrapper(buffer));
+
       msg.setDestination(destination);
       return new PageMessageImpl(msg);
    }
 
-   protected ByteBuffer createRandomBuffer(long id, int size)
+   protected ByteBuffer createRandomBuffer(final long id, final int size)
    {
       ByteBuffer buffer = ByteBuffer.allocate(size + 8);
-      
+
       buffer.putLong(id);
-      
+
       for (int j = 8; j < buffer.limit(); j++)
       {
          buffer.put(RandomUtil.randomByte());
       }
       return buffer;
    }
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java	2008-09-17 19:28:17 UTC (rev 4971)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java	2008-09-17 19:49:57 UTC (rev 4972)
@@ -21,13 +21,27 @@
  */
 package org.jboss.messaging.tests.unit.core.persistence.impl.journal;
 
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.transaction.xa.Xid;
+
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.easymock.IArgumentMatcher;
 import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.filter.Filter;
-import org.jboss.messaging.core.journal.*;
+import org.jboss.messaging.core.journal.EncodingSupport;
+import org.jboss.messaging.core.journal.Journal;
+import org.jboss.messaging.core.journal.PreparedTransactionInfo;
+import org.jboss.messaging.core.journal.RecordInfo;
+import org.jboss.messaging.core.journal.TestableJournal;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager;
 import org.jboss.messaging.core.postoffice.Binding;
@@ -35,22 +49,17 @@
 import org.jboss.messaging.core.postoffice.impl.BindingImpl;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-import org.jboss.messaging.core.server.*;
+import org.jboss.messaging.core.server.HandleStatus;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.QueueFactory;
+import org.jboss.messaging.core.server.ServerMessage;
 import org.jboss.messaging.core.server.impl.ServerMessageImpl;
 import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.messaging.tests.util.RandomUtil;
 import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.messaging.util.SimpleString;
 
-import javax.transaction.xa.Xid;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * 
  * A JournalStorageManagerTest
@@ -61,163 +70,168 @@
 public class JournalStorageManagerTest extends UnitTestCase
 {
    private static final Logger log = Logger.getLogger(JournalStorageManagerTest.class);
-   
+
    public void testStoreMessage() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
       Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
-      
+
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
-      ServerMessage msg = EasyMock.createStrictMock(ServerMessage.class);      
-      long msgID = 1021092;      
+
+      ServerMessage msg = EasyMock.createStrictMock(ServerMessage.class);
+      long msgID = 1021092;
       EasyMock.expect(msg.getMessageID()).andReturn(msgID);
-      messageJournal.appendAddRecord(msgID, JournalStorageManager.ADD_MESSAGE, msg);      
-      EasyMock.replay(messageJournal, bindingsJournal, msg);      
-      jsm.storeMessage(msg);      
+      messageJournal.appendAddRecord(msgID, JournalStorageManager.ADD_MESSAGE, msg);
+      EasyMock.replay(messageJournal, bindingsJournal, msg);
+      jsm.storeMessage(msg);
       EasyMock.verify(messageJournal, bindingsJournal, msg, msg);
    }
-   
+
    public void testStoreAcknowledge() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long queueID = 1210981;
       final long messageID = 101921092;
-      
-      messageJournal.appendUpdateRecord(EasyMock.eq(messageID), EasyMock.eq(JournalStorageManager.ACKNOWLEDGE_REF), encodingMatch(autoEncode(queueID)));  
-      EasyMock.replay(messageJournal, bindingsJournal);      
-      jsm.storeAcknowledge(queueID, messageID);     
+
+      messageJournal.appendUpdateRecord(EasyMock.eq(messageID),
+                                        EasyMock.eq(JournalStorageManager.ACKNOWLEDGE_REF),
+                                        encodingMatch(autoEncode(queueID)));
+      EasyMock.replay(messageJournal, bindingsJournal);
+      jsm.storeAcknowledge(queueID, messageID);
       EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testStoreDelete() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long messageID = 101921092;
-      
-      messageJournal.appendDeleteRecord(messageID);  
-      EasyMock.replay(messageJournal, bindingsJournal);      
-      jsm.storeDelete(messageID);  
+
+      messageJournal.appendDeleteRecord(messageID);
+      EasyMock.replay(messageJournal, bindingsJournal);
+      jsm.storeDelete(messageID);
       EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testStoreMessageTransactional() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);     
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
-      ServerMessage msg = EasyMock.createStrictMock(ServerMessage.class);      
-      long msgID = 1021092;      
+
+      ServerMessage msg = EasyMock.createStrictMock(ServerMessage.class);
+      long msgID = 1021092;
       EasyMock.expect(msg.getMessageID()).andReturn(msgID);
       long txID = 192872;
-      messageJournal.appendAddRecordTransactional(txID, msgID, JournalStorageManager.ADD_MESSAGE, msg);      
-      EasyMock.replay(messageJournal, bindingsJournal, msg);      
-      jsm.storeMessageTransactional(txID, msg);   
+      messageJournal.appendAddRecordTransactional(txID, msgID, JournalStorageManager.ADD_MESSAGE, msg);
+      EasyMock.replay(messageJournal, bindingsJournal, msg);
+      jsm.storeMessageTransactional(txID, msg);
       EasyMock.verify(messageJournal, bindingsJournal, msg, msg);
    }
-   
+
    public void testStoreAcknowledgeTransactional() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);   
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long queueID = 1210981;
       final long messageID = 101921092;
-      
+
       final long txID = 12091921;
-      messageJournal.appendUpdateRecordTransactional(EasyMock.eq(txID), EasyMock.eq(messageID), EasyMock.eq(JournalStorageManager.ACKNOWLEDGE_REF), encodingMatch(autoEncode(queueID)));  
-      EasyMock.replay(messageJournal, bindingsJournal);      
-      jsm.storeAcknowledgeTransactional(txID, queueID, messageID);     
+      messageJournal.appendUpdateRecordTransactional(EasyMock.eq(txID),
+                                                     EasyMock.eq(messageID),
+                                                     EasyMock.eq(JournalStorageManager.ACKNOWLEDGE_REF),
+                                                     encodingMatch(autoEncode(queueID)));
+      EasyMock.replay(messageJournal, bindingsJournal);
+      jsm.storeAcknowledgeTransactional(txID, queueID, messageID);
       EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testStoreDeleteTransactional() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);  
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long messageID = 101921092;
       final long txID = 1209373;
-      
-      messageJournal.appendDeleteRecordTransactional(txID, messageID, null);  
-      EasyMock.replay(messageJournal, bindingsJournal);      
-      jsm.storeDeleteTransactional(txID, messageID);  
+
+      messageJournal.appendDeleteRecordTransactional(txID, messageID, null);
+      EasyMock.replay(messageJournal, bindingsJournal);
+      jsm.storeDeleteTransactional(txID, messageID);
       EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testPrepare() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long txID = 1209373;
 
-		Xid xid = new XidImpl("branch".getBytes(), 1, "globalid".getBytes());
-		
+      Xid xid = new XidImpl("branch".getBytes(), 1, "globalid".getBytes());
+
       messageJournal.appendPrepareRecord(EasyMock.eq(txID), EasyMock.isA(EncodingSupport.class));
-      EasyMock.replay(messageJournal, bindingsJournal);      
-      
+      EasyMock.replay(messageJournal, bindingsJournal);
+
       jsm.prepare(txID, xid);
       EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testCommit() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long txID = 1209373;
-      
+
       messageJournal.appendCommitRecord(txID);
-      EasyMock.replay(messageJournal, bindingsJournal);      
+      EasyMock.replay(messageJournal, bindingsJournal);
       jsm.commit(txID);
       EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testRollback() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long txID = 1209373;
-      
+
       messageJournal.appendRollbackRecord(txID);
-      EasyMock.replay(messageJournal, bindingsJournal);      
+      EasyMock.replay(messageJournal, bindingsJournal);
       jsm.rollback(txID);
       EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testUpdateDeliveryCount() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       final long msgID = 120912901;
       final long queueID = 1283743;
       final int deliveryCount = 4757;
-      
+
       MessageReference ref = EasyMock.createStrictMock(MessageReference.class);
       ServerMessage msg = EasyMock.createStrictMock(ServerMessage.class);
       Queue queue = EasyMock.createStrictMock(Queue.class);
@@ -226,24 +240,26 @@
       EasyMock.expect(ref.getMessage()).andStubReturn(msg);
       EasyMock.expect(msg.getMessageID()).andStubReturn(msgID);
       EasyMock.expect(ref.getDeliveryCount()).andReturn(deliveryCount);
-      
-      messageJournal.appendUpdateRecord(EasyMock.eq(msgID), EasyMock.eq(JournalStorageManager.UPDATE_DELIVERY_COUNT), compareEncodingSupport(autoEncode(queueID, deliveryCount)));
-      EasyMock.replay(messageJournal, bindingsJournal, ref, msg, queue);      
+
+      messageJournal.appendUpdateRecord(EasyMock.eq(msgID),
+                                        EasyMock.eq(JournalStorageManager.UPDATE_DELIVERY_COUNT),
+                                        compareEncodingSupport(autoEncode(queueID, deliveryCount)));
+      EasyMock.replay(messageJournal, bindingsJournal, ref, msg, queue);
       jsm.updateDeliveryCount(ref);
       EasyMock.verify(messageJournal, bindingsJournal, ref, msg, queue);
    }
-   
+
    public void testLoadMessages() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-     
-      messageJournal.load((List<RecordInfo>) EasyMock.anyObject(), (List<PreparedTransactionInfo>) EasyMock.anyObject());
-      
-      List<RecordInfo> records = new ArrayList<RecordInfo>();      
-      
+
+      messageJournal.load((List<RecordInfo>)EasyMock.anyObject(), (List<PreparedTransactionInfo>)EasyMock.anyObject());
+
+      List<RecordInfo> records = new ArrayList<RecordInfo>();
+
       /*
        * Two add messages
        * Three ack messages - two for msg1 and one for msg2
@@ -255,8 +271,12 @@
       final byte msg1Priority = 7;
       final byte[] msg1Bytes = RandomUtil.randomBytes(1000);
       final long msg1ID = 32748;
-      ServerMessage msg1 = new ServerMessageImpl(msg1Type, true, msg1Expiration, msg1Timestamp,
-            msg1Priority, new ByteBufferWrapper(ByteBuffer.wrap(msg1Bytes)));
+      ServerMessage msg1 = new ServerMessageImpl(msg1Type,
+                                                 true,
+                                                 msg1Expiration,
+                                                 msg1Timestamp,
+                                                 msg1Priority,
+                                                 new ByteBufferWrapper(ByteBuffer.wrap(msg1Bytes)));
       msg1.setDestination(new SimpleString("qwuiuqwi"));
       msg1.setMessageID(msg1ID);
       msg1.putStringProperty(new SimpleString("prop1"), new SimpleString("wibble"));
@@ -264,15 +284,19 @@
       MessagingBuffer encodeBuffer = new ByteBufferWrapper(ByteBuffer.wrap(encode));
       msg1.encode(encodeBuffer);
       RecordInfo record1 = new RecordInfo(msg1ID, JournalStorageManager.ADD_MESSAGE, encode, false);
-      
+
       final byte msg2Type = 3;
       final long msg2Expiration = 98448;
       final long msg2Timestamp = 1626999;
       final byte msg2Priority = 2;
       final byte[] msg2Bytes = RandomUtil.randomBytes(1000);
       final long msg2ID = 7446;
-      ServerMessage msg2 = new ServerMessageImpl(msg2Type, true, msg2Expiration, msg2Timestamp,
-            msg2Priority, new ByteBufferWrapper(ByteBuffer.wrap(msg2Bytes)));
+      ServerMessage msg2 = new ServerMessageImpl(msg2Type,
+                                                 true,
+                                                 msg2Expiration,
+                                                 msg2Timestamp,
+                                                 msg2Priority,
+                                                 new ByteBufferWrapper(ByteBuffer.wrap(msg2Bytes)));
       msg2.setDestination(new SimpleString("qw12ihjwdijwqd"));
       msg2.setMessageID(msg2ID);
       msg2.putStringProperty(new SimpleString("prop2"), new SimpleString("wibble"));
@@ -280,46 +304,46 @@
       MessagingBuffer encodeBuffer2 = new ByteBufferWrapper(ByteBuffer.wrap(encode2));
       msg2.encode(encodeBuffer2);
       RecordInfo record2 = new RecordInfo(msg2ID, JournalStorageManager.ADD_MESSAGE, encode2, false);
-      
-      final long queue1ID = 1210981;       
-      final byte[] ack1Bytes = new byte[16];      
-      ByteBuffer bb1 = ByteBuffer.wrap(ack1Bytes);      
-      bb1.putLong(queue1ID);      
+
+      final long queue1ID = 1210981;
+      final byte[] ack1Bytes = new byte[16];
+      ByteBuffer bb1 = ByteBuffer.wrap(ack1Bytes);
+      bb1.putLong(queue1ID);
       bb1.putLong(msg1ID);
       RecordInfo record3 = new RecordInfo(msg1ID, JournalStorageManager.ACKNOWLEDGE_REF, ack1Bytes, true);
-      
-      final long queue2ID = 112323;    
-      final byte[] ack2Bytes = new byte[16];      
-      ByteBuffer bb2 = ByteBuffer.wrap(ack2Bytes);      
-      bb2.putLong(queue2ID);      
+
+      final long queue2ID = 112323;
+      final byte[] ack2Bytes = new byte[16];
+      ByteBuffer bb2 = ByteBuffer.wrap(ack2Bytes);
+      bb2.putLong(queue2ID);
       bb2.putLong(msg1ID);
       RecordInfo record4 = new RecordInfo(msg1ID, JournalStorageManager.ACKNOWLEDGE_REF, ack2Bytes, true);
-      
-      final long queue3ID = 374764;   
-      final byte[] ack3Bytes = new byte[16];      
-      ByteBuffer bb3 = ByteBuffer.wrap(ack3Bytes);      
-      bb3.putLong(queue3ID);      
+
+      final long queue3ID = 374764;
+      final byte[] ack3Bytes = new byte[16];
+      ByteBuffer bb3 = ByteBuffer.wrap(ack3Bytes);
+      bb3.putLong(queue3ID);
       bb3.putLong(msg2ID);
       RecordInfo record5 = new RecordInfo(msg2ID, JournalStorageManager.ACKNOWLEDGE_REF, ack3Bytes, true);
-      
-      final int deliveryCount = 4757;      
-      byte[] updateBytes = new byte[12];      
-      ByteBuffer bb4 = ByteBuffer.wrap(updateBytes);      
-      bb4.putLong(queue1ID);      
+
+      final int deliveryCount = 4757;
+      byte[] updateBytes = new byte[12];
+      ByteBuffer bb4 = ByteBuffer.wrap(updateBytes);
+      bb4.putLong(queue1ID);
       bb4.putInt(deliveryCount);
       RecordInfo record6 = new RecordInfo(msg1ID, JournalStorageManager.UPDATE_DELIVERY_COUNT, updateBytes, true);
-      
+
       records.add(record1);
       records.add(record2);
       records.add(record3);
       records.add(record4);
       records.add(record5);
       records.add(record6);
-      
+
       EasyMock.expectLastCall().andAnswer(new LoadRecordsIAnswer(msg1ID, records, null));
-      
+
       PostOffice po = EasyMock.createStrictMock(PostOffice.class);
-      
+
       List<MessageReference> refs1 = new ArrayList<MessageReference>();
       MessageReference ref1_1 = EasyMock.createStrictMock(MessageReference.class);
       MessageReference ref1_2 = EasyMock.createStrictMock(MessageReference.class);
@@ -328,20 +352,19 @@
       refs1.add(ref1_2);
       refs1.add(ref1_3);
       EasyMock.expect(po.route(eqServerMessage(msg1))).andReturn(refs1);
-      
+
       Queue queue1 = EasyMock.createStrictMock(Queue.class);
       Queue queue2 = EasyMock.createStrictMock(Queue.class);
       Queue queue3 = EasyMock.createStrictMock(Queue.class);
-      
+
       EasyMock.expect(ref1_1.getQueue()).andReturn(queue1);
       EasyMock.expect(ref1_2.getQueue()).andReturn(queue2);
       EasyMock.expect(ref1_3.getQueue()).andReturn(queue3);
-      
+
       EasyMock.expect(queue1.addLast(ref1_1)).andReturn(HandleStatus.HANDLED);
       EasyMock.expect(queue2.addLast(ref1_2)).andReturn(HandleStatus.HANDLED);
       EasyMock.expect(queue3.addLast(ref1_3)).andReturn(HandleStatus.HANDLED);
-      
-      
+
       List<MessageReference> refs2 = new ArrayList<MessageReference>();
       MessageReference ref2_1 = EasyMock.createStrictMock(MessageReference.class);
       MessageReference ref2_2 = EasyMock.createStrictMock(MessageReference.class);
@@ -350,100 +373,102 @@
       refs2.add(ref2_2);
       refs2.add(ref2_3);
       EasyMock.expect(po.route(eqServerMessage(msg2))).andReturn(refs2);
-      
+
       EasyMock.expect(ref2_1.getQueue()).andReturn(queue1);
       EasyMock.expect(ref2_2.getQueue()).andReturn(queue2);
       EasyMock.expect(ref2_3.getQueue()).andReturn(queue3);
-      
+
       EasyMock.expect(queue1.addLast(ref2_1)).andReturn(HandleStatus.HANDLED);
       EasyMock.expect(queue2.addLast(ref2_2)).andReturn(HandleStatus.HANDLED);
       EasyMock.expect(queue3.addLast(ref2_3)).andReturn(HandleStatus.HANDLED);
-      
+
       Map<Long, Queue> queues = new HashMap<Long, Queue>();
       queues.put(queue1ID, queue1);
       queues.put(queue2ID, queue2);
       queues.put(queue3ID, queue3);
-      
+
       EasyMock.expect(queue1.removeReferenceWithID(msg1ID)).andReturn(ref1_1);
       EasyMock.expect(queue2.removeReferenceWithID(msg1ID)).andReturn(ref1_2);
       EasyMock.expect(queue3.removeReferenceWithID(msg2ID)).andReturn(ref2_3);
-      
+
       EasyMock.expect(queue1.getReference(msg1ID)).andReturn(ref1_1);
       ref1_1.setDeliveryCount(deliveryCount);
-      
+
       EasyMock.replay(messageJournal, bindingsJournal, po);
       EasyMock.replay(refs1.toArray());
       EasyMock.replay(refs2.toArray());
       EasyMock.replay(queue1, queue2, queue3);
-      
+
       jsm.loadMessages(po, queues, null);
-      
+
       EasyMock.verify(messageJournal, bindingsJournal, po);
       EasyMock.verify(refs1.toArray());
       EasyMock.verify(refs2.toArray());
       EasyMock.verify(queue1, queue2, queue3);
-      
+
       assertEquals(msg1ID + 1, jsm.generateID());
    }
-   
+
    public void testAddBindingWithFilter() throws Exception
    {
       testAddBindingWithFilter(true);
    }
-   
+
    public void testAddBindingWithoutFilter() throws Exception
    {
       testAddBindingWithFilter(false);
    }
-   
-   private void testAddBindingWithFilter(boolean useFilter) throws Exception
+
+   private void testAddBindingWithFilter(final boolean useFilter) throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-           
+
       Queue queue = EasyMock.createStrictMock(Queue.class);
       SimpleString queueName = new SimpleString("saiohsiudh");
-      EasyMock.expect(queue.getName()).andStubReturn(queueName); 
+      EasyMock.expect(queue.getName()).andStubReturn(queueName);
       Filter filter = null;
       SimpleString queueFilter = new SimpleString("ihjuhyg");
       if (useFilter)
-      {         
+      {
          filter = EasyMock.createStrictMock(Filter.class);
-         EasyMock.expect(filter.getFilterString()).andStubReturn(queueFilter);         
+         EasyMock.expect(filter.getFilterString()).andStubReturn(queueFilter);
       }
       EasyMock.expect(queue.getFilter()).andStubReturn(filter);
-            
+
       SimpleString address = new SimpleString("aijsiajs");
       Binding binding = new BindingImpl(address, queue);
-      
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();      
+
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
       DataOutputStream daos = new DataOutputStream(baos);
-      
+
       queue.setPersistenceID(0);
 
-      byte[] nameBytes = queueName.getData();      
-      daos.writeInt(nameBytes.length);      
-      daos.write(nameBytes);      
+      byte[] nameBytes = queueName.getData();
+      daos.writeInt(nameBytes.length);
+      daos.write(nameBytes);
       byte[] addressBytes = binding.getAddress().getData();
-      daos.writeInt(addressBytes.length);      
+      daos.writeInt(addressBytes.length);
       daos.write(addressBytes);
       daos.writeBoolean(filter != null);
       if (filter != null)
       {
          byte[] filterBytes = queueFilter.getData();
-         daos.writeInt(filterBytes.length);         
+         daos.writeInt(filterBytes.length);
          daos.write(filterBytes);
       }
       daos.flush();
       byte[] data = baos.toByteArray();
-      
+
       log.debug("** data length is " + data.length);
       log.debug(UnitTestCase.dumpBytes(data));
-       
-      bindingsJournal.appendAddRecord(EasyMock.eq(0L), EasyMock.eq(JournalStorageManager.BINDING_RECORD), compareEncodingSupport(data));
-      
+
+      bindingsJournal.appendAddRecord(EasyMock.eq(0L),
+                                      EasyMock.eq(JournalStorageManager.BINDING_RECORD),
+                                      compareEncodingSupport(data));
+
       if (useFilter)
       {
          EasyMock.replay(queue, filter, messageJournal, bindingsJournal);
@@ -452,9 +477,9 @@
       {
          EasyMock.replay(queue, messageJournal, bindingsJournal);
       }
-      
+
       jsm.addBinding(binding);
-      
+
       if (useFilter)
       {
          EasyMock.verify(queue, filter, messageJournal, bindingsJournal);
@@ -462,46 +487,46 @@
       else
       {
          EasyMock.verify(queue, messageJournal, bindingsJournal);
-      }      
+      }
    }
-   
+
    public void testDeleteBinding() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       Binding binding = EasyMock.createStrictMock(Binding.class);
       Queue queue = EasyMock.createStrictMock(Queue.class);
       EasyMock.expect(binding.getQueue()).andStubReturn(queue);
       long queueID = 1209129;
       EasyMock.expect(queue.getPersistenceID()).andStubReturn(queueID);
-      
+
       bindingsJournal.appendDeleteRecord(queueID);
-      
+
       EasyMock.replay(messageJournal, bindingsJournal, binding, queue);
-      
+
       jsm.deleteBinding(binding);
-      
+
       EasyMock.verify(messageJournal, bindingsJournal, binding, queue);
    }
-   
+
    public void testDeleteBindingUnPersistedQueue() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       Binding binding = EasyMock.createStrictMock(Binding.class);
       Queue queue = EasyMock.createStrictMock(Queue.class);
       EasyMock.expect(binding.getQueue()).andStubReturn(queue);
       long queueID = -1;
       EasyMock.expect(queue.getPersistenceID()).andStubReturn(queueID);
-                  
+
       EasyMock.replay(messageJournal, bindingsJournal, binding, queue);
-      
+
       try
       {
          jsm.deleteBinding(binding);
@@ -509,141 +534,147 @@
       }
       catch (IllegalArgumentException e)
       {
-         //OK
+         // OK
       }
-      
+
       EasyMock.verify(messageJournal, bindingsJournal, binding, queue);
    }
-   
+
    public void testAddDeleteDestination() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       SimpleString dest = new SimpleString("oaskokas");
-      
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();      
-      DataOutputStream daos = new DataOutputStream(baos);      
+
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      DataOutputStream daos = new DataOutputStream(baos);
       byte[] destBytes = dest.getData();
-      daos.writeInt(destBytes.length);      
-      daos.write(destBytes);      
-      daos.flush();      
+      daos.writeInt(destBytes.length);
+      daos.write(destBytes);
+      daos.flush();
       byte[] data = baos.toByteArray();
-      bindingsJournal.appendAddRecord(EasyMock.eq(0L), EasyMock.eq(JournalStorageManager.DESTINATION_RECORD), compareEncodingSupport(data));
-                  
+      bindingsJournal.appendAddRecord(EasyMock.eq(0L),
+                                      EasyMock.eq(JournalStorageManager.DESTINATION_RECORD),
+                                      compareEncodingSupport(data));
+
       EasyMock.replay(messageJournal, bindingsJournal);
-      
+
       jsm.addDestination(dest);
 
       EasyMock.verify(messageJournal, bindingsJournal);
-      
+
       EasyMock.reset(messageJournal, bindingsJournal);
-      
-      //Adding again should do nothing
-      
+
+      // Adding again should do nothing
+
       EasyMock.replay(messageJournal, bindingsJournal);
-      
+
       jsm.addDestination(dest);
 
       EasyMock.verify(messageJournal, bindingsJournal);
-      
+
       EasyMock.reset(messageJournal, bindingsJournal);
-      
-      //Add diffferent dest
-      
+
+      // Add diffferent dest
+
       SimpleString dest2 = new SimpleString("ihjij");
-      
-      baos = new ByteArrayOutputStream();      
-      daos = new DataOutputStream(baos);      
+
+      baos = new ByteArrayOutputStream();
+      daos = new DataOutputStream(baos);
       destBytes = dest2.getData();
-      daos.writeInt(destBytes.length);      
-      daos.write(destBytes);      
-      daos.flush();      
+      daos.writeInt(destBytes.length);
+      daos.write(destBytes);
+      daos.flush();
       data = baos.toByteArray();
-      bindingsJournal.appendAddRecord(EasyMock.eq(2L), EasyMock.eq(JournalStorageManager.DESTINATION_RECORD), compareEncodingSupport(data));
+      bindingsJournal.appendAddRecord(EasyMock.eq(2L),
+                                      EasyMock.eq(JournalStorageManager.DESTINATION_RECORD),
+                                      compareEncodingSupport(data));
 
       EasyMock.replay(messageJournal, bindingsJournal);
-      
+
       jsm.addDestination(dest2);
 
       EasyMock.verify(messageJournal, bindingsJournal);
-      
+
       EasyMock.reset(messageJournal, bindingsJournal);
-      
+
       bindingsJournal.appendDeleteRecord(2);
-      
+
       EasyMock.replay(messageJournal, bindingsJournal);
-      
+
       jsm.deleteDestination(dest2);
-      
+
       EasyMock.verify(messageJournal, bindingsJournal);
-      
+
       EasyMock.reset(messageJournal, bindingsJournal);
-      
+
       EasyMock.replay(messageJournal, bindingsJournal);
-      
-      //Should do nothing
-      
+
+      // Should do nothing
+
       jsm.deleteDestination(dest2);
-      
-      EasyMock.verify(messageJournal, bindingsJournal);            
+
+      EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
-   private RecordInfo createBindingRecord(final long id, final SimpleString queueName, final SimpleString address,
-         final SimpleString filter) throws Exception
+
+   private RecordInfo createBindingRecord(final long id,
+                                          final SimpleString queueName,
+                                          final SimpleString address,
+                                          final SimpleString filter) throws Exception
    {
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();      
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
       DataOutputStream daos = new DataOutputStream(baos);
-      
-      byte[] nameBytes = queueName.getData();      
-      daos.writeInt(nameBytes.length);      
-      daos.write(nameBytes);      
+
+      byte[] nameBytes = queueName.getData();
+      daos.writeInt(nameBytes.length);
+      daos.write(nameBytes);
       byte[] addressBytes = address.getData();
-      daos.writeInt(addressBytes.length);      
+      daos.writeInt(addressBytes.length);
       daos.write(addressBytes);
       daos.writeBoolean(filter != null);
       if (filter != null)
       {
          byte[] filterBytes = filter.getData();
-         daos.writeInt(filterBytes.length);         
+         daos.writeInt(filterBytes.length);
          daos.write(filterBytes);
       }
       daos.flush();
       byte[] data = baos.toByteArray();
-      
+
       RecordInfo record = new RecordInfo(id, JournalStorageManager.BINDING_RECORD, data, false);
-      
+
       return record;
    }
-   
+
    private RecordInfo createDestinationRecord(final long id, final SimpleString dest) throws Exception
    {
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();      
-      DataOutputStream daos = new DataOutputStream(baos);      
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      DataOutputStream daos = new DataOutputStream(baos);
       byte[] destBytes = dest.getData();
-      daos.writeInt(destBytes.length);      
-      daos.write(destBytes);      
-      daos.flush();      
+      daos.writeInt(destBytes.length);
+      daos.write(destBytes);
+      daos.flush();
       byte[] data = baos.toByteArray();
-      
+
       RecordInfo record = new RecordInfo(id, JournalStorageManager.DESTINATION_RECORD, data, false);
-      
+
       return record;
    }
-   
+
    public void testLoadBindings() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-     
-      bindingsJournal.load((List<RecordInfo>) EasyMock.anyObject(), (List<PreparedTransactionInfo>) EasyMock.anyObject());
-      
-      List<RecordInfo> records = new ArrayList<RecordInfo>();      
-      
+
+      bindingsJournal.load((List<RecordInfo>)EasyMock.anyObject(), (List<PreparedTransactionInfo>)EasyMock.anyObject());
+
+      List<RecordInfo> records = new ArrayList<RecordInfo>();
+
       SimpleString squeue1 = new SimpleString("queue1");
       SimpleString squeue2 = new SimpleString("queue2");
       SimpleString squeue3 = new SimpleString("queue3");
@@ -651,148 +682,151 @@
       SimpleString saddress2 = new SimpleString("address2");
       SimpleString saddress3 = new SimpleString("address3");
       SimpleString sfilter1 = new SimpleString("JBMMessageID=123");
-      
-      records.add(this.createBindingRecord(0, squeue1, saddress1, sfilter1));
-      records.add(this.createBindingRecord(1, squeue2, saddress2, null));
-      records.add(this.createBindingRecord(2, squeue3, saddress3, null));
-      
+
+      records.add(createBindingRecord(0, squeue1, saddress1, sfilter1));
+      records.add(createBindingRecord(1, squeue2, saddress2, null));
+      records.add(createBindingRecord(2, squeue3, saddress3, null));
+
       SimpleString sdest1 = new SimpleString("dest1");
       SimpleString sdest2 = new SimpleString("dest2");
       SimpleString sdest3 = new SimpleString("dest3");
-      
-      records.add(this.createDestinationRecord(10, sdest1));
-      records.add(this.createDestinationRecord(11, sdest2));
-      records.add(this.createDestinationRecord(12, sdest3));
-            
+
+      records.add(createDestinationRecord(10, sdest1));
+      records.add(createDestinationRecord(11, sdest2));
+      records.add(createDestinationRecord(12, sdest3));
+
       EasyMock.expectLastCall().andAnswer(new LoadRecordsIAnswer(12, records, null));
-     
+
       QueueFactory qf = EasyMock.createStrictMock(QueueFactory.class);
-      
+
       Queue queue1 = EasyMock.createStrictMock(Queue.class);
       Queue queue2 = EasyMock.createStrictMock(Queue.class);
       Queue queue3 = EasyMock.createStrictMock(Queue.class);
-      EasyMock.expect(qf.createQueue(EasyMock.eq(0L), EasyMock.eq(squeue1), EasyMock.isA(Filter.class), EasyMock.eq(true))).andReturn(queue1);
+      EasyMock.expect(qf.createQueue(EasyMock.eq(0L),
+                                     EasyMock.eq(squeue1),
+                                     EasyMock.isA(Filter.class),
+                                     EasyMock.eq(true))).andReturn(queue1);
       EasyMock.expect(qf.createQueue(1L, squeue2, null, true)).andReturn(queue1);
       EasyMock.expect(qf.createQueue(2L, squeue3, null, true)).andReturn(queue1);
-      
+
       EasyMock.replay(messageJournal, bindingsJournal, queue1, queue2, queue3, qf);
-  
+
       List<Binding> bindings = new ArrayList<Binding>();
       List<SimpleString> destinations = new ArrayList<SimpleString>();
-      
+
       jsm.loadBindings(qf, bindings, destinations);
-      
+
       EasyMock.verify(messageJournal, bindingsJournal, queue1, queue2, queue3, qf);
-      
+
       assertEquals(3, bindings.size());
       assertEquals(3, destinations.size());
-      
+
       assertEquals(saddress1, bindings.get(0).getAddress());
       assertEquals(saddress2, bindings.get(1).getAddress());
       assertEquals(saddress3, bindings.get(2).getAddress());
-      
+
       assertEquals(sdest1, destinations.get(0));
       assertEquals(sdest2, destinations.get(1));
       assertEquals(sdest3, destinations.get(2));
    }
-   
+
    public void testStartStop() throws Exception
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       assertFalse(jsm.isStarted());
       bindingsJournal.start();
       messageJournal.start();
-      
+
       EasyMock.replay(messageJournal, bindingsJournal);
-      
+
       jsm.start();
-      
+
       assertTrue(jsm.isStarted());
-      
+
       EasyMock.verify(messageJournal, bindingsJournal);
-      
+
       EasyMock.reset(messageJournal, bindingsJournal);
-      
-      EasyMock.replay(messageJournal, bindingsJournal);  
-      
+
+      EasyMock.replay(messageJournal, bindingsJournal);
+
       jsm.start();
-      
+
       EasyMock.verify(messageJournal, bindingsJournal);
-      
+
       assertTrue(jsm.isStarted());
-      
+
       EasyMock.reset(messageJournal, bindingsJournal);
-      
+
       bindingsJournal.stop();
-      
+
       messageJournal.stop();
-      
-      EasyMock.replay(messageJournal, bindingsJournal);  
-      
+
+      EasyMock.replay(messageJournal, bindingsJournal);
+
       jsm.stop();
-      
+
       EasyMock.verify(messageJournal, bindingsJournal);
-      
+
       assertFalse(jsm.isStarted());
-      
+
       EasyMock.reset(messageJournal, bindingsJournal);
-      
-      EasyMock.replay(messageJournal, bindingsJournal);  
-      
+
+      EasyMock.replay(messageJournal, bindingsJournal);
+
       jsm.stop();
-      
+
       EasyMock.verify(messageJournal, bindingsJournal);
-      
-      assertFalse(jsm.isStarted());     
+
+      assertFalse(jsm.isStarted());
    }
-   
+
    public void testGenerateMessageID()
    {
       long id = 0;
-      
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
 
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
+
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       assertEquals(id++, jsm.generateID());
       assertEquals(id++, jsm.generateID());
       assertEquals(id++, jsm.generateID());
       assertEquals(id++, jsm.generateID());
-      assertEquals(id++, jsm.generateID());      
+      assertEquals(id++, jsm.generateID());
    }
-   
+
    public void testGenerateTransactionID()
    {
-      Journal messageJournal = EasyMock.createStrictMock(Journal.class);      
-      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);      
+      Journal messageJournal = EasyMock.createStrictMock(Journal.class);
+      Journal bindingsJournal = EasyMock.createStrictMock(Journal.class);
 
       JournalStorageManager jsm = new JournalStorageManager(messageJournal, bindingsJournal);
-      
+
       long id = 1212;
       EasyMock.expect(messageJournal.getTransactionID()).andReturn(id);
-      
+
       EasyMock.replay(messageJournal, bindingsJournal);
-            
+
       assertEquals(id, jsm.generateTransactionID());
-      
-      EasyMock.verify(messageJournal, bindingsJournal);      
+
+      EasyMock.verify(messageJournal, bindingsJournal);
    }
-   
+
    public void testConstructor()
    {
       Configuration config = new ConfigurationImpl();
 
       JournalStorageManager jsm = new JournalStorageManager(config);
-     
+
       assertNotNull(jsm.getMessageJournal());
-      
+
       TestableJournal messageJournal = (TestableJournal)jsm.getMessageJournal();
-      
+
       assertEquals(config.getJournalFileSize(), messageJournal.getFileSize());
       assertEquals(config.getJournalMinFiles(), messageJournal.getMinFiles());
       assertEquals(config.isJournalSyncTransactional(), messageJournal.isSyncTransactional());
@@ -800,11 +834,11 @@
       assertEquals("jbm-data", messageJournal.getFilePrefix());
       assertEquals("jbm", messageJournal.getFileExtension());
       assertEquals(config.getJournalMaxAIO(), messageJournal.getMaxAIO());
-       
+
       assertNotNull(jsm.getBindingsJournal());
-      
+
       TestableJournal bindingsJournal = (TestableJournal)jsm.getBindingsJournal();
-      
+
       assertEquals(1024 * 1024, bindingsJournal.getFileSize());
       assertEquals(2, bindingsJournal.getMinFiles());
       assertEquals(true, bindingsJournal.isSyncTransactional());
@@ -813,36 +847,36 @@
       assertEquals("bindings", bindingsJournal.getFileExtension());
       assertEquals(1, bindingsJournal.getMaxAIO());
    }
-   
+
    private EncodingSupport encodingMatch(final byte expectedRecord[])
    {
-      
+
       EasyMock.reportMatcher(new IArgumentMatcher()
       {
 
-         public void appendTo(StringBuffer buffer)
+         public void appendTo(final StringBuffer buffer)
          {
          }
 
-         public boolean matches(Object argument)
+         public boolean matches(final Object argument)
          {
             EncodingSupport support = (EncodingSupport)argument;
-            
+
             if (support.getEncodeSize() != expectedRecord.length)
             {
                return false;
             }
 
             byte newByte[] = new byte[expectedRecord.length];
-            
+
             ByteBuffer buffer = ByteBuffer.wrap(newByte);
-            
+
             ByteBufferWrapper wrapper = new ByteBufferWrapper(buffer);
-            
+
             support.encode(wrapper);
-            
+
             byte encodingBytes[] = wrapper.array();
-            
+
             for (int i = 0; i < encodingBytes.length; i++)
             {
                if (encodingBytes[i] != expectedRecord[i])
@@ -850,45 +884,41 @@
                   return false;
                }
             }
-            
+
             return true;
          }
-         
+
       });
-      
+
       return null;
    }
-   
 
-   
-   public static ServerMessage eqServerMessage(ServerMessage serverMessage)
+   public static ServerMessage eqServerMessage(final ServerMessage serverMessage)
    {
       EasyMock.reportMatcher(new ServerMessageMatcher(serverMessage));
       return serverMessage;
    }
-   
+
    static class ServerMessageMatcher implements IArgumentMatcher
    {
       ServerMessage msg;
 
-      public ServerMessageMatcher(ServerMessage msg)
+      public ServerMessageMatcher(final ServerMessage msg)
       {
          this.msg = msg;
       }
 
-      public boolean matches(Object o)
+      public boolean matches(final Object o)
       {
-         ServerMessage that = (ServerMessage) o;
-         
-         boolean matches = 
-            msg.getMessageID() == that.getMessageID() &&
-            msg.isDurable() == that.isDurable() &&
-            msg.getType() == that.getType() &&
-            msg.getTimestamp() == that.getTimestamp() &&
-            msg.getExpiration() == that.getExpiration() &&
-            msg.getPriority() == that.getPriority() &&
-            msg.getDestination().equals(that.getDestination());
-         
+         ServerMessage that = (ServerMessage)o;
+
+         boolean matches = msg.getMessageID() == that.getMessageID() && msg.isDurable() == that.isDurable() &&
+                           msg.getType() == that.getType() &&
+                           msg.getTimestamp() == that.getTimestamp() &&
+                           msg.getExpiration() == that.getExpiration() &&
+                           msg.getPriority() == that.getPriority() &&
+                           msg.getDestination().equals(that.getDestination());
+
          if (matches)
          {
             byte[] bod1 = msg.getBody().array();
@@ -900,7 +930,7 @@
                   if (bod1[i] != bod2[i])
                   {
                      return false;
-                  }                  
+                  }
                }
                return true;
             }
@@ -909,19 +939,23 @@
          return matches;
       }
 
-      public void appendTo(StringBuffer stringBuffer)
+      public void appendTo(final StringBuffer stringBuffer)
       {
          stringBuffer.append("Aunty Mabel knits great socks");
       }
    }
-   
+
    class LoadRecordsIAnswer implements IAnswer
    {
       long maxID;
+
       List<RecordInfo> records;
+
       List<PreparedTransactionInfo> preparedTransactions;
 
-      public LoadRecordsIAnswer(final long maxID, final List<RecordInfo> records, final List<PreparedTransactionInfo> preparedTransactions)
+      public LoadRecordsIAnswer(final long maxID,
+                                final List<RecordInfo> records,
+                                final List<PreparedTransactionInfo> preparedTransactions)
       {
          this.maxID = maxID;
          this.records = records;
@@ -929,16 +963,16 @@
       }
 
       public Object answer() throws Throwable
-      { 
-         if (this.records != null)
+      {
+         if (records != null)
          {
-            List<RecordInfo> theRecords = (List<RecordInfo>) EasyMock.getCurrentArguments()[0];
-            theRecords.addAll(this.records);
+            List<RecordInfo> theRecords = (List<RecordInfo>)EasyMock.getCurrentArguments()[0];
+            theRecords.addAll(records);
          }
-         if (this.preparedTransactions != null)
+         if (preparedTransactions != null)
          {
-            List<PreparedTransactionInfo> thePreparedTxs = (List<PreparedTransactionInfo>) EasyMock.getCurrentArguments()[1];
-            thePreparedTxs.addAll(this.preparedTransactions);
+            List<PreparedTransactionInfo> thePreparedTxs = (List<PreparedTransactionInfo>)EasyMock.getCurrentArguments()[1];
+            thePreparedTxs.addAll(preparedTransactions);
          }
          return maxID;
       }




More information about the jboss-cvs-commits mailing list