[jboss-cvs] JBoss Messaging SVN: r6145 - in trunk/tests/src/org/jboss/messaging/tests: unit/core/journal/impl and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 23 15:56:44 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-03-23 15:56:44 -0400 (Mon, 23 Mar 2009)
New Revision: 6145

Removed:
   trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/EasyMockJournalTest.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/PageTransactionImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java
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/PagingStoreImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
Refactoring on Paging Unit Tests

Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingIntegrationTest.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -1,75 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.integration.paging;
-
-import java.io.File;
-
-import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
-import org.jboss.messaging.tests.unit.core.paging.impl.PageImplTestBase;
-
-/**
- * 
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public class PagingIntegrationTest extends PageImplTestBase
-{
-
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   public void testPageWithNIO() throws Exception
-   {
-      testAdd(new NIOSequentialFileFactory(getTestDir()), 1000);
-   }
-
-   public void testDamagedDataWithNIO() throws Exception
-   {
-      testDamagedPage(new NIOSequentialFileFactory(getTestDir()), 1000);
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   @Override
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      File fileJournalDir = new File(getTestDir());
-      deleteDirectory(fileJournalDir);
-      fileJournalDir.mkdirs();
-   }
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-}

Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/paging/PagingStoreIntegrationTest.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -1,86 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.integration.paging;
-
-import java.io.File;
-
-import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
-import org.jboss.messaging.tests.unit.core.paging.impl.PagingStoreTestBase;
-
-/**
- * 
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public class PagingStoreIntegrationTest extends PagingStoreTestBase
-{
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   public void testPageWithNIO() throws Exception
-   {
-      // This integration test could fail 1 in 100 due to race conditions.
-      for (int i = 0; i < 100; i++)
-      {
-         recreateDirectory();
-         testConcurrentPaging(new NIOSequentialFileFactory(getTestDir()), 1);
-      }
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   @Override
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      recreateDirectory();
-   }
-
-   @Override
-   protected void tearDown() throws Exception
-   {
-      super.tearDown();
-      // deleteDirectory(new File(journalDir));
-   }
-
-   // Private -------------------------------------------------------
-
-   private void recreateDirectory()
-   {
-      File fileJournalDir = new File(getTestDir());
-      deleteDirectory(fileJournalDir);
-      fileJournalDir.mkdirs();
-   }
-
-   // Inner classes -------------------------------------------------
-
-}

Deleted: 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	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/EasyMockJournalTest.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -1,520 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source Copyright 2005-2008, Red Hat
- * Middleware LLC, and individual contributors by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of individual
- * contributors.
- * 
- * This is free software; you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- * 
- * This software is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this software; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
- * site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.journal.impl;
-
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-import org.easymock.IArgumentMatcher;
-import org.jboss.messaging.core.journal.BufferCallback;
-import org.jboss.messaging.core.journal.SequentialFile;
-import org.jboss.messaging.core.journal.SequentialFileFactory;
-import org.jboss.messaging.core.journal.impl.JournalImpl;
-import org.jboss.messaging.core.logging.Logger;
-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.replay(mockFactory, file1, file2);
-
-      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.replay(mockFactory, file1, file2);
-
-      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.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.appendDeleteRecord(14l);
-
-      EasyMock.verify(mockFactory, file1, file2);
-   }
-
-   // 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);
-
-            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);
-         }*/
-
-   /*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);
-
-            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 });
-
-      		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.replay(mockFactory, file1, file2);
-
-      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.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);
-
-            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
-   {
-      if (journalImpl != null)
-      {
-         EasyMock.reset(mockFactory, file1, file2);
-         stubValues();
-         try
-         {
-            journalImpl.stop();
-         }
-         catch (Throwable ignored)
-         {
-         }
-      }
-
-      super.tearDown();
-   }
-
-   @Override
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      
-      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(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.start();
-
-      journalImpl.load(new ArrayList(), new ArrayList());
-
-      EasyMock.verify(mockFactory, file1, file2);
-
-      EasyMock.reset(mockFactory, file1, file2);
-
-      stubValues();
-
-      return journalImpl;
-   }
-   protected ByteBuffer compareByteBuffer(final byte expectedArray[])
-      {
-
-         EasyMock.reportMatcher(new IArgumentMatcher()
-         {
-
-            public void appendTo(StringBuffer buffer)
-            {
-               buffer.append("ByteArray");
-            }
-
-            public boolean matches(Object argument)
-            {
-               ByteBuffer buffer = (ByteBuffer)argument;
-
-               buffer.rewind();
-               byte[] compareArray = new byte[buffer.limit()];
-               buffer.get(compareArray);
-
-               if (compareArray.length != expectedArray.length)
-               {
-                  return false;
-               }
-
-               for (int i = 0; i < expectedArray.length; i++)
-               {
-                  if (expectedArray[i] != compareArray[i])
-                  {
-                     return false;
-                  }
-               }
-
-               return true;
-            }
-
-         });
-
-         return null;
-      }
-       
-   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>()
-      {
-
-         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/paging/impl/PageImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTest.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -22,14 +22,30 @@
 
 package org.jboss.messaging.tests.unit.core.paging.impl;
 
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.messaging.core.buffers.ChannelBuffers;
+import org.jboss.messaging.core.journal.SequentialFile;
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
+import org.jboss.messaging.core.paging.PagedMessage;
+import org.jboss.messaging.core.paging.impl.PageImpl;
+import org.jboss.messaging.core.paging.impl.PagedMessageImpl;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.server.impl.ServerMessageImpl;
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.utils.SimpleString;
 
 /**
  * 
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  */
-public class PageImplTest extends PageImplTestBase
+public class PageImplTest extends UnitTestCase
 {
    // Constants -----------------------------------------------------
 
@@ -40,7 +56,19 @@
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
+ 
+   public void testPageWithNIO() throws Exception
+   {
+      recreateDirectory(getTestDir());
+      testAdd(new NIOSequentialFileFactory(getTestDir()), 1000);
+   }
 
+   public void testDamagedDataWithNIO() throws Exception
+   {
+      recreateDirectory(getTestDir());
+      testDamagedPage(new NIOSequentialFileFactory(getTestDir()), 1000);
+   }
+
    public void testPageFakeWithoutCallbacks() throws Exception
    {
       testAdd(new FakeSequentialFileFactory(1, false), 10);
@@ -52,10 +80,180 @@
       testDamagedPage(new FakeSequentialFileFactory(1, false), 100);
    }
    
+   /** Validate if everything we add is recovered */
+   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());
+
+      SimpleString simpleDestination = new SimpleString("Test");
+
+      ArrayList<MessagingBuffer> buffers = addPageElements(simpleDestination, impl, numberOfElements);
+
+      impl.sync();
+      impl.close();
+
+      file = factory.createSequentialFile("00010.page", 1);
+      file.open();
+      impl = new PageImpl(factory, file, 10);
+
+      List<PagedMessage> msgs = impl.read();
+
+      assertEquals(numberOfElements, msgs.size());
+
+      assertEquals(numberOfElements, impl.getNumberOfMessages());
+
+      for (int i = 0; i < msgs.size(); i++)
+      {
+         assertEquals(i, (msgs.get(i).getMessage(null)).getMessageID());
+
+         assertEquals(simpleDestination, (msgs.get(i).getMessage(null)).getDestination());
+
+         assertEqualsByteArrays(buffers.get(i).array(), (msgs.get(i).getMessage(null)).getBody().array());
+      }
+
+      impl.delete();
+
+      assertEquals(0, factory.listFiles(".page").size());
+
+   }
+
+   
+   
+   protected void testDamagedPage(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());
+
+      SimpleString simpleDestination = new SimpleString("Test");
+
+      ArrayList<MessagingBuffer> buffers = addPageElements(simpleDestination, impl, numberOfElements);
+
+      impl.sync();
+
+      long positionA = file.position();
+
+      // Add one record that will be damaged
+      addPageElements(simpleDestination, impl, 1);
+      
+      long positionB = file.position();
+      
+      // Add more 10 as they will need to be ignored
+      addPageElements(simpleDestination, impl, 10);
+      
+
+      // Damage data... position the file on the middle between points A and B
+      file.position(positionA + (positionB - positionA) / 2);
+      
+      ByteBuffer buffer = ByteBuffer.allocate((int)(positionB - file.position()));
+      
+      for (int i = 0; i< buffer.capacity(); i++)
+      {
+         buffer.put((byte)'Z');
+      }
+      
+      buffer.rewind();
+      
+      file.write(buffer, true);
+      
+      impl.close();
+
+      file = factory.createSequentialFile("00010.page", 1);
+      file.open();
+      impl = new PageImpl(factory, file, 10);
+
+      List<PagedMessage> msgs = impl.read();
+
+      assertEquals(numberOfElements, msgs.size());
+
+      assertEquals(numberOfElements, impl.getNumberOfMessages());
+
+      for (int i = 0; i < msgs.size(); i++)
+      {
+         assertEquals(i, (msgs.get(i).getMessage(null)).getMessageID());
+
+         assertEquals(simpleDestination, (msgs.get(i).getMessage(null)).getDestination());
+
+         assertEqualsByteArrays(buffers.get(i).array(), (msgs.get(i).getMessage(null)).getBody().array());
+      }
+
+      impl.delete();
+
+      assertEquals(0, factory.listFiles("page").size());
+
+      assertEquals(1, factory.listFiles("invalidPage").size());
+
+   }
+   
+   /**
+    * @param simpleDestination
+    * @param page
+    * @param numberOfElements
+    * @return
+    * @throws Exception
+    */
+   protected ArrayList<MessagingBuffer> addPageElements(SimpleString simpleDestination, PageImpl page, int numberOfElements) throws Exception
+   {
+      ArrayList<MessagingBuffer> buffers = new ArrayList<MessagingBuffer>();
+      
+      int initialNumberOfMessages = page.getNumberOfMessages();
+
+      for (int i = 0; i < numberOfElements; i++)
+      {
+         MessagingBuffer buffer = ChannelBuffers.buffer(10); 
+
+         for (int j = 0; j < buffer.capacity(); j++)
+         {
+            //buffer.writeByte(RandomUtil.randomByte());
+            buffer.writeByte((byte)'b');
+         }
+
+         buffers.add(buffer);
+
+         ServerMessage msg = new ServerMessageImpl((byte)1,
+                                                   true,
+                                                   0,
+                                                   System.currentTimeMillis(),
+                                                   (byte)0,
+                                                   buffer);
+
+         msg.setMessageID(i);
+
+         msg.setDestination(simpleDestination);
+
+         page.write(new PagedMessageImpl(msg));
+
+         assertEquals(initialNumberOfMessages + i + 1, page.getNumberOfMessages());
+      }
+      return buffers;
+   }
+
+
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
 
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------

Deleted: 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	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageImplTestBase.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -1,232 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.paging.impl;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.messaging.core.buffers.ChannelBuffers;
-import org.jboss.messaging.core.journal.SequentialFile;
-import org.jboss.messaging.core.journal.SequentialFileFactory;
-import org.jboss.messaging.core.paging.PagedMessage;
-import org.jboss.messaging.core.paging.impl.PageImpl;
-import org.jboss.messaging.core.paging.impl.PagedMessageImpl;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-import org.jboss.messaging.core.server.ServerMessage;
-import org.jboss.messaging.core.server.impl.ServerMessageImpl;
-import org.jboss.messaging.tests.util.UnitTestCase;
-import org.jboss.messaging.utils.SimpleString;
-
-/**
- * 
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public abstract class PageImplTestBase extends UnitTestCase
-{
-
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   /** Validate if everything we add is recovered */
-   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());
-
-      SimpleString simpleDestination = new SimpleString("Test");
-
-      ArrayList<MessagingBuffer> buffers = addPageElements(simpleDestination, impl, numberOfElements);
-
-      impl.sync();
-      impl.close();
-
-      file = factory.createSequentialFile("00010.page", 1);
-      file.open();
-      impl = new PageImpl(factory, file, 10);
-
-      List<PagedMessage> msgs = impl.read();
-
-      assertEquals(numberOfElements, msgs.size());
-
-      assertEquals(numberOfElements, impl.getNumberOfMessages());
-
-      for (int i = 0; i < msgs.size(); i++)
-      {
-         assertEquals(i, (msgs.get(i).getMessage(null)).getMessageID());
-
-         assertEquals(simpleDestination, (msgs.get(i).getMessage(null)).getDestination());
-
-         assertEqualsByteArrays(buffers.get(i).array(), (msgs.get(i).getMessage(null)).getBody().array());
-      }
-
-      impl.delete();
-
-      assertEquals(0, factory.listFiles(".page").size());
-
-   }
-
-   
-   
-   public void testDamagedPage(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());
-
-      SimpleString simpleDestination = new SimpleString("Test");
-
-      ArrayList<MessagingBuffer> buffers = addPageElements(simpleDestination, impl, numberOfElements);
-
-      impl.sync();
-
-      long positionA = file.position();
-
-      // Add one record that will be damaged
-      addPageElements(simpleDestination, impl, 1);
-      
-      long positionB = file.position();
-      
-      // Add more 10 as they will need to be ignored
-      addPageElements(simpleDestination, impl, 10);
-      
-
-      // Damage data... position the file on the middle between points A and B
-      file.position(positionA + (positionB - positionA) / 2);
-      
-      ByteBuffer buffer = ByteBuffer.allocate((int)(positionB - file.position()));
-      
-      for (int i = 0; i< buffer.capacity(); i++)
-      {
-         buffer.put((byte)'Z');
-      }
-      
-      buffer.rewind();
-      
-      file.write(buffer, true);
-      
-      impl.close();
-
-      file = factory.createSequentialFile("00010.page", 1);
-      file.open();
-      impl = new PageImpl(factory, file, 10);
-
-      List<PagedMessage> msgs = impl.read();
-
-      assertEquals(numberOfElements, msgs.size());
-
-      assertEquals(numberOfElements, impl.getNumberOfMessages());
-
-      for (int i = 0; i < msgs.size(); i++)
-      {
-         assertEquals(i, (msgs.get(i).getMessage(null)).getMessageID());
-
-         assertEquals(simpleDestination, (msgs.get(i).getMessage(null)).getDestination());
-
-         assertEqualsByteArrays(buffers.get(i).array(), (msgs.get(i).getMessage(null)).getBody().array());
-      }
-
-      impl.delete();
-
-      assertEquals(0, factory.listFiles("page").size());
-
-      assertEquals(1, factory.listFiles("invalidPage").size());
-
-   }
-   
-   /**
-    * @param simpleDestination
-    * @param page
-    * @param numberOfElements
-    * @return
-    * @throws Exception
-    */
-   protected ArrayList<MessagingBuffer> addPageElements(SimpleString simpleDestination, PageImpl page, int numberOfElements) throws Exception
-   {
-      ArrayList<MessagingBuffer> buffers = new ArrayList<MessagingBuffer>();
-      
-      int initialNumberOfMessages = page.getNumberOfMessages();
-
-      for (int i = 0; i < numberOfElements; i++)
-      {
-         MessagingBuffer buffer = ChannelBuffers.buffer(10); 
-
-         for (int j = 0; j < buffer.capacity(); j++)
-         {
-            //buffer.writeByte(RandomUtil.randomByte());
-            buffer.writeByte((byte)'b');
-         }
-
-         buffers.add(buffer);
-
-         ServerMessage msg = new ServerMessageImpl((byte)1,
-                                                   true,
-                                                   0,
-                                                   System.currentTimeMillis(),
-                                                   (byte)0,
-                                                   buffer);
-
-         msg.setMessageID(i);
-
-         msg.setDestination(simpleDestination);
-
-         page.write(new PagedMessageImpl(msg));
-
-         assertEquals(initialNumberOfMessages + i + 1, page.getNumberOfMessages());
-      }
-      return buffers;
-   }
-
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-}

Deleted: 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	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageTransactionImplTest.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -1,106 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.paging.impl;
-
-import org.jboss.messaging.core.buffers.ChannelBuffers;
-import org.jboss.messaging.core.buffers.HeapChannelBuffer;
-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.tests.util.RandomUtil;
-import org.jboss.messaging.tests.util.UnitTestCase;
-
-/**
- * 
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-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;
-
-      for (int i = 0; i < nr1; i++)
-      {
-         trans.increment();
-      }
-
-      assertEquals(nr1, trans.getNumberOfMessages());
-
-      MessagingBuffer buffer = ChannelBuffers.buffer(trans.getEncodeSize());
-
-      trans.encode(buffer);
-
-      PageTransactionInfo trans2 = new PageTransactionInfoImpl(id1);
-      trans2.decode(buffer);
-
-      assertEquals(id2, trans2.getTransactionID());
-
-      assertEquals(nr1, trans2.getNumberOfMessages());
-
-      for (int i = 0; i < nr1; i++)
-      {
-         trans.decrement();
-      }
-
-      assertEquals(0, trans.getNumberOfMessages());
-
-      try
-      {
-         trans.decrement();
-         fail("Exception expected!");
-      }
-      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	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -24,19 +24,38 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.easymock.classextension.EasyMock;
+import org.jboss.messaging.core.buffers.ChannelBuffers;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.journal.SequentialFile;
 import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
 import org.jboss.messaging.core.paging.Page;
+import org.jboss.messaging.core.paging.PageTransactionInfo;
 import org.jboss.messaging.core.paging.PagedMessage;
+import org.jboss.messaging.core.paging.PagingManager;
 import org.jboss.messaging.core.paging.PagingStore;
 import org.jboss.messaging.core.paging.PagingStoreFactory;
+import org.jboss.messaging.core.paging.impl.PageTransactionInfoImpl;
 import org.jboss.messaging.core.paging.impl.PagedMessageImpl;
 import org.jboss.messaging.core.paging.impl.PagingStoreImpl;
 import org.jboss.messaging.core.paging.impl.TestSupportPageStore;
+import org.jboss.messaging.core.persistence.StorageManager;
+import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.server.impl.ServerMessageImpl;
 import org.jboss.messaging.core.settings.impl.AddressSettings;
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
+import org.jboss.messaging.tests.util.RandomUtil;
+import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.messaging.utils.SimpleString;
 
 /**
@@ -44,7 +63,7 @@
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  */
-public class PagingStoreImplTest extends PagingStoreTestBase
+public class PagingStoreImplTest extends UnitTestCase
 {
 
    // Constants -----------------------------------------------------
@@ -53,12 +72,62 @@
 
    // Attributes ----------------------------------------------------
 
+   protected ExecutorService executor;
+
    // 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;
+
+      for (int i = 0; i < nr1; i++)
+      {
+         trans.increment();
+      }
+
+      assertEquals(nr1, trans.getNumberOfMessages());
+
+      MessagingBuffer buffer = ChannelBuffers.buffer(trans.getEncodeSize());
+
+      trans.encode(buffer);
+
+      PageTransactionInfo trans2 = new PageTransactionInfoImpl(id1);
+      trans2.decode(buffer);
+
+      assertEquals(id2, trans2.getTransactionID());
+
+      assertEquals(nr1, trans2.getNumberOfMessages());
+
+      for (int i = 0; i < nr1; i++)
+      {
+         trans.decrement();
+      }
+
+      assertEquals(0, trans.getNumberOfMessages());
+
+      try
+      {
+         trans.decrement();
+         fail("Exception expected!");
+      }
+      catch (Throwable ignored)
+      {
+      }
+
+   }
+
+
    public void testDoubleStart() throws Exception
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory();
@@ -83,12 +152,23 @@
 
    }
 
+   public void testPageWithNIO() throws Exception
+   {
+      // This integration test could fail 1 in 100 due to race conditions.
+      for (int i = 0; i < 100; i++)
+      {
+         recreateDirectory(getTestDir());
+         testConcurrentPaging(new NIOSequentialFileFactory(getTestDir()), 1);
+      }
+   }
+
+
    public void testStore() throws Exception
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory();
-      
+
       PagingStoreFactory storeFactory = EasyMock.createNiceMock(PagingStoreFactory.class);
-      
+
       EasyMock.replay(storeFactory);
 
       PagingStore storeImpl = new PagingStoreImpl(createMockManager(),
@@ -145,19 +225,19 @@
       SequentialFileFactory factory = new FakeSequentialFileFactory();
 
       SimpleString destination = new SimpleString("test");
-      
+
       PagingStoreFactory storeFactory = EasyMock.createMock(PagingStoreFactory.class);
-      
+
       EasyMock.replay(storeFactory);
 
       TestSupportPageStore storeImpl = new PagingStoreImpl(createMockManager(),
-                                                  createStorageManagerMock(),
-                                                  createPostOfficeMock(),
-                                                  factory,
-                                                  storeFactory,
-                                                  destinationTestName,
-                                                  new AddressSettings(),
-                                                  executor);
+                                                           createStorageManagerMock(),
+                                                           createPostOfficeMock(),
+                                                           factory,
+                                                           storeFactory,
+                                                           destinationTestName,
+                                                           new AddressSettings(),
+                                                           executor);
 
       storeImpl.start();
 
@@ -210,11 +290,11 @@
    {
       SequentialFileFactory factory = new FakeSequentialFileFactory();
       SimpleString destination = new SimpleString("test");
-      
+
       PagingStoreFactory storeFactory = EasyMock.createNiceMock(PagingStoreFactory.class);
-      
+
       EasyMock.expect(storeFactory.newFileFactory(destination)).andReturn(factory);
-      
+
       EasyMock.replay(storeFactory);
 
       TestSupportPageStore storeImpl = new PagingStoreImpl(createMockManager(),
@@ -341,20 +421,328 @@
    {
    }
 
+   protected void testConcurrentPaging(final SequentialFileFactory factory, final int numberOfThreads) throws Exception,
+                                                                                                      InterruptedException
+   {
+
+      PagingStoreFactory storeFactory = EasyMock.createNiceMock(PagingStoreFactory.class);
+
+      EasyMock.replay(storeFactory);
+
+      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, PagedMessageImpl> buffers = new ConcurrentHashMap<Long, PagedMessageImpl>();
+
+      final ArrayList<Page> readPages = new ArrayList<Page>();
+
+      AddressSettings settings = new AddressSettings();
+      settings.setPageSizeBytes(MAX_SIZE);
+
+      final TestSupportPageStore storeImpl = new PagingStoreImpl(createMockManager(),
+                                                                 createStorageManagerMock(),
+                                                                 createPostOfficeMock(),
+                                                                 factory,
+                                                                 storeFactory,
+                                                                 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;
+               while (true)
+               {
+                  long id = messageIdGenerator.incrementAndGet();
+                  PagedMessageImpl msg = createMessage(destination, createRandomBuffer(id, 5));
+                  if (storeImpl.page(msg, false, true))
+                  {
+                     buffers.put(id, msg);
+                  }
+                  else
+                  {
+                     break;
+                  }
+
+                  if (firstTime)
+                  {
+                     latchStart.countDown();
+                     firstTime = false;
+                  }
+               }
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+               this.e = e;
+            }
+            finally
+            {
+               aliveProducers.decrementAndGet();
+            }
+         }
+      }
+
+      class ConsumerThread extends Thread
+      {
+         Exception e;
+
+         @Override
+         public void run()
+         {
+            try
+            {
+               // Wait every producer to produce at least one message
+               latchStart.await();
+               while (aliveProducers.get() > 0)
+               {
+                  Page page = storeImpl.depage();
+                  if (page != null)
+                  {
+                     readPages.add(page);
+                  }
+               }
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+               this.e = e;
+            }
+         }
+      }
+
+      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();
+         if (producerThread[i].e != null)
+         {
+            throw producerThread[i].e;
+         }
+      }
+
+      consumer.join();
+
+      if (consumer.e != null)
+      {
+         throw consumer.e;
+      }
+
+      final ConcurrentHashMap<Long, PagedMessage> buffers2 = new ConcurrentHashMap<Long, PagedMessage>();
+
+      for (Page page : readPages)
+      {
+         page.open();
+         List<PagedMessage> msgs = page.read();
+         page.close();
+
+         for (PagedMessage msg : msgs)
+         {
+            long id = msg.getMessage(null).getBody().readLong();
+            msg.getMessage(null).getBody().resetReaderIndex();
+
+            PagedMessageImpl msgWritten = buffers.remove(id);
+            buffers2.put(id, msg);
+            assertNotNull(msgWritten);
+            assertEquals(msg.getMessage(null).getDestination(), msgWritten.getMessage(null).getDestination());
+            assertEqualsByteArrays(msgWritten.getMessage(null).getBody().array(), msg.getMessage(null)
+                                                                                     .getBody()
+                                                                                     .array());
+         }
+      }
+
+      assertEquals(0, buffers.size());
+
+      List<String> files = factory.listFiles("page");
+
+      assertTrue(files.size() != 0);
+
+      for (String file : files)
+      {
+         SequentialFile fileTmp = factory.createSequentialFile(file, 1);
+         fileTmp.open();
+         assertTrue(fileTmp.size() + " <= " + MAX_SIZE, fileTmp.size() <= MAX_SIZE);
+         fileTmp.close();
+      }
+
+      TestSupportPageStore storeImpl2 = new PagingStoreImpl(createMockManager(),
+                                                            createStorageManagerMock(),
+                                                            createPostOfficeMock(),
+                                                            factory,
+                                                            storeFactory,
+                                                            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();
+      PagedMessage lastMsg = createMessage(destination, createRandomBuffer(lastMessageId, 5));
+
+      storeImpl2.page(lastMsg, false, true);
+      buffers2.put(lastMessageId, lastMsg);
+
+      Page lastPage = null;
+      while (true)
+      {
+         Page page = storeImpl2.depage();
+         if (page == null)
+         {
+            break;
+         }
+
+         lastPage = page;
+
+         page.open();
+
+         List<PagedMessage> msgs = page.read();
+
+         page.close();
+
+         for (PagedMessage msg : msgs)
+         {
+
+            long id = msg.getMessage(null).getBody().readLong();
+            PagedMessage msgWritten = buffers2.remove(id);
+            assertNotNull(msgWritten);
+            assertEquals(msg.getMessage(null).getDestination(), msgWritten.getMessage(null).getDestination());
+            assertEqualsByteArrays(msgWritten.getMessage(null).getBody().array(), msg.getMessage(null)
+                                                                                     .getBody()
+                                                                                     .array());
+         }
+      }
+
+      lastPage.open();
+      List<PagedMessage> lastMessages = lastPage.read();
+      lastPage.close();
+      assertEquals(1, lastMessages.size());
+
+      lastMessages.get(0).getMessage(null).getBody().resetReaderIndex();
+      assertEquals(lastMessages.get(0).getMessage(null).getBody().readLong(), lastMessageId);
+      assertEqualsByteArrays(lastMessages.get(0).getMessage(null).getBody().array(), lastMsg.getMessage(null)
+                                                                                            .getBody()
+                                                                                            .array());
+
+      assertEquals(0, buffers2.size());
+
+      assertEquals(0, storeImpl.getAddressSize());
+
+   }
+
+   /**
+   * @return
+   */
+   protected PagingManager createMockManager()
+   {
+      PagingManager mockManager = EasyMock.createNiceMock(PagingManager.class);
+      org.easymock.EasyMock.expect(mockManager.getGlobalDepageWatermarkBytes())
+                           .andStubReturn(ConfigurationImpl.DEFAULT_PAGE_WATERMARK_SIZE);
+      EasyMock.replay(mockManager);
+      return mockManager;
+   }
+
+   private StorageManager createStorageManagerMock()
+   {
+      StorageManager storageManager = EasyMock.createNiceMock(StorageManager.class);
+      EasyMock.replay(storageManager);
+      return storageManager;
+   }
+
+   private PostOffice createPostOfficeMock()
+   {
+      PostOffice postOffice = EasyMock.createNiceMock(PostOffice.class);
+      EasyMock.replay(postOffice);
+      return postOffice;
+   }
+
+
+   private PagedMessageImpl createMessage(final SimpleString destination, final MessagingBuffer buffer)
+   {
+      ServerMessage msg = new ServerMessageImpl((byte)1,
+                                                true,
+                                                0,
+                                                System.currentTimeMillis(),
+                                                (byte)0,
+                                                buffer);
+
+      msg.setDestination(destination);
+      return new PagedMessageImpl(msg);
+   }
+
+   private MessagingBuffer createRandomBuffer(final long id, final int size)
+   {
+      MessagingBuffer buffer = ChannelBuffers.buffer(size + 8);
+
+      buffer.writeLong(id);
+
+      for (int j = 8; j < buffer.capacity(); j++)
+      {
+         buffer.writeByte(RandomUtil.randomByte());
+      }
+      return buffer;
+   }
+
    // Protected ----------------------------------------------------
 
    @Override
    protected void setUp() throws Exception
    {
       super.setUp();
+      executor = Executors.newSingleThreadExecutor();
    }
 
    @Override
    protected void tearDown() throws Exception
    {
+      executor.shutdown();
       super.tearDown();
    }
 
+
+   
+
    // Inner classes -------------------------------------------------
 
 }

Deleted: 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	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -1,398 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.paging.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.easymock.classextension.EasyMock;
-import org.jboss.messaging.core.buffers.ChannelBuffers;
-import org.jboss.messaging.core.buffers.HeapChannelBuffer;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.journal.SequentialFile;
-import org.jboss.messaging.core.journal.SequentialFileFactory;
-import org.jboss.messaging.core.paging.Page;
-import org.jboss.messaging.core.paging.PagedMessage;
-import org.jboss.messaging.core.paging.PagingManager;
-import org.jboss.messaging.core.paging.PagingStoreFactory;
-import org.jboss.messaging.core.paging.impl.PagedMessageImpl;
-import org.jboss.messaging.core.paging.impl.PagingStoreImpl;
-import org.jboss.messaging.core.paging.impl.TestSupportPageStore;
-import org.jboss.messaging.core.persistence.StorageManager;
-import org.jboss.messaging.core.postoffice.PostOffice;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-import org.jboss.messaging.core.server.ServerMessage;
-import org.jboss.messaging.core.server.impl.ServerMessageImpl;
-import org.jboss.messaging.core.settings.impl.AddressSettings;
-import org.jboss.messaging.tests.util.RandomUtil;
-import org.jboss.messaging.tests.util.UnitTestCase;
-import org.jboss.messaging.utils.SimpleString;
-
-/**
- * 
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-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(final SequentialFileFactory factory, final int numberOfThreads) throws Exception,
-                                                                                                      InterruptedException
-   {
-      
-      PagingStoreFactory storeFactory = EasyMock.createNiceMock(PagingStoreFactory.class);
-      
-      EasyMock.replay(storeFactory);
-
-      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, PagedMessageImpl> buffers = new ConcurrentHashMap<Long, PagedMessageImpl>();
-
-      final ArrayList<Page> readPages = new ArrayList<Page>();
-
-      AddressSettings settings = new AddressSettings();
-      settings.setPageSizeBytes(MAX_SIZE);
-
-      final TestSupportPageStore storeImpl = new PagingStoreImpl(createMockManager(),
-                                                                 createStorageManagerMock(),
-                                                                 createPostOfficeMock(),
-                                                                 factory,
-                                                                 storeFactory,
-                                                                 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;
-               while (true)
-               {
-                  long id = messageIdGenerator.incrementAndGet();
-                  PagedMessageImpl msg = createMessage(destination, createRandomBuffer(id, 5));
-                  if (storeImpl.page(msg, false, true))
-                  {
-                     buffers.put(id, msg);
-                  }
-                  else
-                  {
-                     break;
-                  }
-
-                  if (firstTime)
-                  {
-                     latchStart.countDown();
-                     firstTime = false;
-                  }
-               }
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-               this.e = e;
-            }
-            finally
-            {
-               aliveProducers.decrementAndGet();
-            }
-         }
-      }
-
-      class ConsumerThread extends Thread
-      {
-         Exception e;
-
-         @Override
-         public void run()
-         {
-            try
-            {
-               // Wait every producer to produce at least one message
-               latchStart.await();
-               while (aliveProducers.get() > 0)
-               {
-                  Page page = storeImpl.depage();
-                  if (page != null)
-                  {
-                     readPages.add(page);
-                  }
-               }
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-               this.e = e;
-            }
-         }
-      }
-
-      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();
-         if (producerThread[i].e != null)
-         {
-            throw producerThread[i].e;
-         }
-      }
-
-      consumer.join();
-
-      if (consumer.e != null)
-      {
-         throw consumer.e;
-      }
-
-      final ConcurrentHashMap<Long, PagedMessage> buffers2 = new ConcurrentHashMap<Long, PagedMessage>();
-
-      for (Page page : readPages)
-      {
-         page.open();
-         List<PagedMessage> msgs = page.read();
-         page.close();
-
-         for (PagedMessage msg : msgs)
-         {
-            long id = msg.getMessage(null).getBody().readLong();
-            msg.getMessage(null).getBody().resetReaderIndex();
-
-            PagedMessageImpl msgWritten = buffers.remove(id);
-            buffers2.put(id, msg);
-            assertNotNull(msgWritten);
-            assertEquals(msg.getMessage(null).getDestination(), msgWritten.getMessage(null).getDestination());
-            assertEqualsByteArrays(msgWritten.getMessage(null).getBody().array(), msg.getMessage(null)
-                                                                                     .getBody()
-                                                                                     .array());
-         }
-      }
-
-      assertEquals(0, buffers.size());
-
-      List<String> files = factory.listFiles("page");
-
-      assertTrue(files.size() != 0);
-
-      for (String file : files)
-      {
-         SequentialFile fileTmp = factory.createSequentialFile(file, 1);
-         fileTmp.open();
-         assertTrue(fileTmp.size() + " <= " + MAX_SIZE, fileTmp.size() <= MAX_SIZE);
-         fileTmp.close();
-      }
-
-      TestSupportPageStore storeImpl2 = new PagingStoreImpl(createMockManager(),
-                                                            createStorageManagerMock(),
-                                                            createPostOfficeMock(),
-                                                            factory,
-                                                            storeFactory,
-                                                            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();
-      PagedMessage lastMsg = createMessage(destination, createRandomBuffer(lastMessageId, 5));
-
-      storeImpl2.page(lastMsg, false, true);
-      buffers2.put(lastMessageId, lastMsg);
-
-      Page lastPage = null;
-      while (true)
-      {
-         Page page = storeImpl2.depage();
-         if (page == null)
-         {
-            break;
-         }
-
-         lastPage = page;
-
-         page.open();
-
-         List<PagedMessage> msgs = page.read();
-
-         page.close();
-
-         for (PagedMessage msg : msgs)
-         {
-
-            long id = msg.getMessage(null).getBody().readLong();
-            PagedMessage msgWritten = buffers2.remove(id);
-            assertNotNull(msgWritten);
-            assertEquals(msg.getMessage(null).getDestination(), msgWritten.getMessage(null).getDestination());
-            assertEqualsByteArrays(msgWritten.getMessage(null).getBody().array(), msg.getMessage(null)
-                                                                                     .getBody()
-                                                                                     .array());
-         }
-      }
-
-      lastPage.open();
-      List<PagedMessage> lastMessages = lastPage.read();
-      lastPage.close();
-      assertEquals(1, lastMessages.size());
-
-      lastMessages.get(0).getMessage(null).getBody().resetReaderIndex();
-      assertEquals(lastMessages.get(0).getMessage(null).getBody().readLong(), lastMessageId);
-      assertEqualsByteArrays(lastMessages.get(0).getMessage(null).getBody().array(), lastMsg.getMessage(null)
-                                                                                            .getBody()
-                                                                                            .array());
-
-      assertEquals(0, buffers2.size());
-
-      assertEquals(0, storeImpl.getAddressSize());
-
-   }
-
-   protected PagedMessageImpl createMessage(final SimpleString destination, final MessagingBuffer buffer)
-   {
-      ServerMessage msg = new ServerMessageImpl((byte)1,
-                                                true,
-                                                0,
-                                                System.currentTimeMillis(),
-                                                (byte)0,
-                                                buffer);
-
-      msg.setDestination(destination);
-      return new PagedMessageImpl(msg);
-   }
-
-   protected MessagingBuffer createRandomBuffer(final long id, final int size)
-   {
-      MessagingBuffer buffer = ChannelBuffers.buffer(size + 8);
-
-      buffer.writeLong(id);
-
-      for (int j = 8; j < buffer.capacity(); j++)
-      {
-         buffer.writeByte(RandomUtil.randomByte());
-      }
-      return buffer;
-   }
-
-   /**
-    * @return
-    */
-   protected PagingManager createMockManager()
-   {
-      PagingManager mockManager = EasyMock.createNiceMock(PagingManager.class);
-      org.easymock.EasyMock.expect(mockManager.getGlobalDepageWatermarkBytes()).andStubReturn(ConfigurationImpl.DEFAULT_PAGE_WATERMARK_SIZE);
-      EasyMock.replay(mockManager);
-      return mockManager;
-   }
-
-   protected StorageManager createStorageManagerMock()
-   {
-      StorageManager storageManager = EasyMock.createNiceMock(StorageManager.class);
-      EasyMock.replay(storageManager);
-      return storageManager;
-   }
-
-   protected PostOffice createPostOfficeMock()
-   {
-      PostOffice postOffice = EasyMock.createNiceMock(PostOffice.class);
-      EasyMock.replay(postOffice);
-      return postOffice;
-   }
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-}

Modified: trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -109,21 +109,14 @@
 
    protected void clearData(String testDir)
    {
-      deleteAndCreateDir(getJournalDir(testDir));
-      deleteAndCreateDir(getBindingsDir(testDir));
-      deleteAndCreateDir(getPageDir(testDir));
-      deleteAndCreateDir(getLargeMessagesDir(testDir));
-      deleteAndCreateDir(getClientLargeMessagesDir(testDir));
-      deleteAndCreateDir(getTemporaryDir(testDir));
+      recreateDirectory(getJournalDir(testDir));
+      recreateDirectory(getBindingsDir(testDir));
+      recreateDirectory(getPageDir(testDir));
+      recreateDirectory(getLargeMessagesDir(testDir));
+      recreateDirectory(getClientLargeMessagesDir(testDir));
+      recreateDirectory(getTemporaryDir(testDir));
    }
 
-   protected void deleteAndCreateDir(String directory)
-   {
-      File file = new File(directory);
-      deleteDirectory(file);
-      file.mkdirs();
-   }
-
    protected FileConfiguration createFileConfig()
    {
       FileConfiguration config = new FileConfiguration();

Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2009-03-23 17:49:42 UTC (rev 6144)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2009-03-23 19:56:44 UTC (rev 6145)
@@ -425,7 +425,15 @@
 
    
 
+   
+   protected void recreateDirectory(String directory)
+   {
+      File file = new File(directory);
+      deleteDirectory(file);
+      file.mkdirs();
+   }
 
+
    protected boolean deleteDirectory(File directory)
    {
       if (directory.isDirectory())




More information about the jboss-cvs-commits mailing list