[jboss-cvs] JBoss Messaging SVN: r4927 - in trunk: src/main/org/jboss/messaging/core/journal/impl and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 10 11:59:07 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-09-10 11:59:07 -0400 (Wed, 10 Sep 2008)
New Revision: 4927

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java
Modified:
   trunk/src/main/org/jboss/messaging/core/journal/Journal.java
   trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java
   trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
   trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java
   trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java
   trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.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/EasyMockJournalTest.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
Log:
Journal Tweaks

Modified: trunk/src/main/org/jboss/messaging/core/journal/Journal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/Journal.java	2008-09-10 10:51:55 UTC (rev 4926)
+++ trunk/src/main/org/jboss/messaging/core/journal/Journal.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -60,10 +60,10 @@
     * <p>If the system crashed after a prepare was called, it should store information that is required to bring the transaction 
     *     back to a state it could be committed. </p>
     * 
-    * <p> transactionData is usually a safe space you could use to store things like XIDs or any other supporting user-data required to replay the transaction </p>
+    * <p> transactionData allows you to store any other supporting user-data related to the transaction</p>
     * 
     * @param txID
-    * @param transactionData Information to support the system replaying the transaction
+    * @param transactionData - extra user data for the prepare
     * @throws Exception
     */
    void appendPrepareRecord(long txID, EncodingSupport transactionData) throws Exception;

Modified: trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java	2008-09-10 10:51:55 UTC (rev 4926)
+++ trunk/src/main/org/jboss/messaging/core/journal/TestableJournal.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -60,7 +60,7 @@
    
    int getMaxAIO();
    
-   /** This method could be promoted to Journal interface when we decide to use the loadManager 
+   /** 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;
@@ -72,18 +72,4 @@
    
    boolean isAutoReclaim();
    
-   
-   // These add methods are only used by testCases
-   
-   //FIXME: These methods should be removed - they are only used by tests
-   
-   void appendAddRecord(long id, byte recordType, byte[] record) throws Exception;
-   
-   void appendUpdateRecord(long id, byte recordType, byte[] record) throws Exception;
-   
-   void appendAddRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception;
-   
-   void appendUpdateRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception;
-   
-   
 }

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-10 10:51:55 UTC (rev 4926)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -60,7 +60,6 @@
 import org.jboss.messaging.core.journal.TestableJournal;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.util.Pair;
 import org.jboss.messaging.util.VariableLatch;
 
@@ -70,6 +69,9 @@
  * 
  * <p>WIKI Page: <a href="http://wiki.jboss.org/auth/wiki/JBossMessaging2Journal"> http://wiki.jboss.org/auth/wiki/JBossMessaging2Journal</a></p>
  * 
+ * 
+ * <p>Look at {@link JournalImpl#load(LoadManager)} for the file layout
+ * 
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * 
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
@@ -280,14 +282,12 @@
       ByteBufferWrapper bb = new ByteBufferWrapper(newBuffer(size));
       
       bb.putByte(ADD_RECORD);     
-      //bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1); // skip ID part
       bb.putLong(id);
       bb.putInt(recordLength);
       bb.putByte(recordType);
       record.encode(bb);
       bb.putInt(size);        
-      bb.rewind();  // TODO is rewind necessary?
       
       try
       {                 
@@ -322,14 +322,12 @@
       ByteBufferWrapper bb = new ByteBufferWrapper(newBuffer(size));
       
       bb.putByte(UPDATE_RECORD);     
-    //  bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1); // skip ID part
       bb.putLong(id);      
       bb.putInt(record.getEncodeSize());
       bb.putByte(recordType);
       record.encode(bb);
       bb.putInt(size);     
-      bb.rewind(); //Is this necessary?
       
       lock.acquire();
 
@@ -364,11 +362,9 @@
       ByteBuffer bb = newBuffer(size); 
       
       bb.put(DELETE_RECORD);     
-      //bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1); // skip ID part
       bb.putLong(id);      
       bb.putInt(size);     
-      bb.rewind();  //Is this necessary?
       
       lock.acquire();
       
@@ -404,7 +400,6 @@
       ByteBufferWrapper bb = new ByteBufferWrapper(newBuffer(size)); 
       
       bb.putByte(ADD_RECORD_TX);
-     // bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1); // skip ID part
       bb.putLong(txID);
       bb.putLong(id);
@@ -412,7 +407,6 @@
       bb.putByte(recordType);
       record.encode(bb);
       bb.putInt(size);     
-      bb.rewind();  //Is this necessary?
       
       lock.acquire();
       
@@ -442,7 +436,6 @@
       ByteBufferWrapper bb = new ByteBufferWrapper(newBuffer(size)); 
             
       bb.putByte(UPDATE_RECORD_TX);     
-      //bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1); // skip ID part
       bb.putLong(txID);
       bb.putLong(id);      
@@ -450,7 +443,6 @@
       bb.putByte(recordType);
       record.encode(bb);
       bb.putInt(size);     
-      bb.rewind(); //Is this necessary?
       
       lock.acquire();
       
@@ -480,12 +472,10 @@
       ByteBuffer bb = newBuffer(size); 
       
       bb.put(DELETE_RECORD_TX);     
-      //bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1);
       bb.putLong(txID);    
       bb.putLong(id);      
       bb.putInt(size);     
-      bb.rewind(); //Is this necessary
       
       lock.acquire();
       
@@ -523,7 +513,7 @@
       
       JournalTransaction tx = getTransactionInfo(txID);
       
-      ByteBuffer bb = writePrepareTransaction(PREPARE_RECORD, txID, tx, transactionData);
+      ByteBuffer bb = writeTransaction(PREPARE_RECORD, txID, tx, transactionData);
       
       lock.acquire();
       
@@ -553,7 +543,7 @@
          throw new IllegalStateException("Cannot find tx with id " + txID);
       }
       
-      ByteBuffer bb = writeCommitTransaction(COMMIT_RECORD, txID, tx);
+      ByteBuffer bb = writeTransaction(COMMIT_RECORD, txID, tx, null);
       
       lock.acquire();
       
@@ -590,11 +580,9 @@
       ByteBuffer bb = newBuffer(size); 
       
       bb.put(ROLLBACK_RECORD);      
-      //bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1); // skip ID part
       bb.putLong(txID);
       bb.putInt(size);        
-      bb.rewind(); // Is this necessary?
       
       lock.acquire();
       
@@ -612,6 +600,9 @@
       }
    }
    
+   /**
+    * @see JournalImpl#load(LoadManager)
+    */
    public synchronized long load(final List<RecordInfo> committedRecords,
                                  final List<PreparedTransactionInfo> preparedTransactions) throws Exception
    {      
@@ -651,7 +642,42 @@
       
       return maxID;
    }
-      
+
+   /** 
+    * <p>Load data accordingly to the record layouts</p>
+    * 
+    * <p>Basic record laytout:</p>
+    * <table border=1>
+    *   <tr><td><b>Field Name</b></td><td><b>Size</b></td></tr>
+    *   <tr><td>RecordType</td><td>Byte (1)</td></tr>
+    *   <tr><td>FileID</td><td>Integer (4 bytes)</td></tr>
+    *   <tr><td>TransactionID <i>(if record is transactional)</i></td><td>Long (8 bytes)</td></tr>
+    *   <tr><td>RecordID</td><td>Long (8 bytes)</td></tr>
+    *   <tr><td>BodySize(only on Add and update)</td><td>Integer (4 bytes)</td></tr>
+    *   <tr><td>UserDefinedRecordType</td><td>Byte (1)</td</tr>
+    *   <tr><td>RecordBody</td><td>Byte Array (size=BodySize)</td></tr>
+    *   <tr><td>Check Size</td><td>Integer (4 bytes)</td></tr>
+    * </table>
+    * 
+    * <p> The check-size is used to validate if the record is valid and complete </p>
+    * 
+    * <p>Commit/Prepare record layout:</p>
+    * <table border=1>
+    *   <tr><td><b>Field Name</b></td><td><b>Size</b></td></tr>
+    *   <tr><td>RecordType</td><td>Byte (1)</td></tr>
+    *   <tr><td>FileID</td><td>Integer (4 bytes)</td></tr>
+    *   <tr><td>TransactionID <i>(if record is transactional)</i></td><td>Long (8 bytes)</td></tr>
+    *   <tr><td>ExtraDataLength (Prepares only)</td><td>Integer (4 bytes)</td></tr>
+    *   <tr><td>Number Of Files (N)</td><td>Integer (4 bytes)</td></tr>
+    *   <tr><td>ExtraDataBytes</td><td>Bytes (sized by ExtraDataLength)</td></tr>
+    *   <tr><td>* FileID(n)</td><td>Integer (4 bytes)</td></tr>
+    *   <tr><td>* NumberOfElements(n)</td><td>Integer (4 bytes)</td></tr>
+    *   <tr><td>CheckSize</td><td>Integer (4 bytes)</td</tr>
+    * </table>
+    * 
+    * <p> * FileID and NumberOfElements are the transaction summary, and they will be repeated (N)umberOfFiles times </p> 
+    * 
+    * */
    public synchronized long load(final LoadManager loadManager) throws Exception
    {      
       if (state != STATE_STARTED)
@@ -775,7 +801,7 @@
                
                if (bb.position() + variableSize > fileSize)
                {
-                  //TODO - isn't this an error?
+                  log.warn("Record at position " + pos + " file:" + file.getFile().getFileName() + " is corrupted and it is being ignored");
                   continue;
                }
                
@@ -790,9 +816,10 @@
             {
                if (recordType == PREPARE_RECORD)
                {
+                  // Add the variable size required for preparedTransactions 
                   preparedTransactionExtraDataSize = bb.getInt();
                }               
-               //Comment required: I'm guessing this is because commits and prepares also include the record ids?
+               //Both commit and record contain the recordSummary, and this is used to calculate the record-size on both record-types
                variableSize += bb.getInt() * SIZE_INT * 2;
             }
 
@@ -803,9 +830,10 @@
             if (pos + recordSize + variableSize  + preparedTransactionExtraDataSize > fileSize)
             {
                // Avoid a buffer overflow caused by damaged data... continue scanning for more records...
+               log.warn("Record at position " + pos + " file:" + file.getFile().getFileName() + " is corrupted and it is being ignored");
+               // If a file has damaged records, we make it a dataFile, and the next reclaiming will fix it
+               hasData = true;
                
-               //TODO - isn't this an error?
-               
                continue;
             }
             
@@ -822,7 +850,6 @@
                log.warn("Record at position " + pos + " file:" + file.getFile().getFileName() + " is corrupted and it is being ignored");
                
                // If a file has damaged records, we make it a dataFile, and the next reclaiming will fix it
-               
                hasData = true;
                
                bb.position(pos + SIZE_BYTE);
@@ -945,12 +972,11 @@
                                     
                   if (tx == null)
                   {
+                     // The user could choose to prepare empty transactions
                      tx = new TransactionHolder(transactionID);  
                      
                      transactions.put(transactionID, tx);
                   }
-                                    
-                  // We need to read it even if transaction was not found, or the reading checks would fail
 
                   byte extraData[] = new byte[preparedTransactionExtraDataSize];
                   
@@ -996,6 +1022,9 @@
                   // Pair <OrderId, NumberOfElements>
                   Pair<Integer, Integer>[] recordedSummary = readTransactionalElementsSummary(variableSize, bb);
 
+                  // The commit could be alone on its own journal-file and the whole transaction body was reclaimed but not the commit-record
+                  // So it is completely legal to not find a transaction at this point
+                  // If we can't find it, we assume the TX was reclaimed and we ignore this
                   if (tx != null)
                   {                     
                      JournalTransaction journalTransaction = transactionInfos.remove(transactionID);
@@ -1037,10 +1066,6 @@
                      
                      hasData = true;         
                   }
-                  else
-                  {
-                     //TODO isn't this an error?
-                  }
                   
                   break;
                }
@@ -1048,6 +1073,8 @@
                {                  
                   TransactionHolder tx = transactions.remove(transactionID);
                   
+                  // The rollback could be alone on its own journal-file and the whole transaction body was reclaimed but the commit-record
+                  // So it is completely legal to not find a transaction at this point
                   if (tx != null)
                   {                       
                      JournalTransaction tnp = transactionInfos.remove(transactionID);
@@ -1062,10 +1089,6 @@
                      
                      hasData = true;         
                   }
-                  else
-                  {
-                     //TODO is this an error?
-                  }
                   
                   break;
                }
@@ -1380,32 +1403,6 @@
       debugWait();
    }
 
-   // Add/update methods only used on testcases (using a byte[]). Those methods are now part of the Test interface ------------------------
-   
-   //FIXME - why have these methods?? Why not just use the normal public interface methods
-   //They should be removed
-   
-   public void appendAddRecord(final long id, final byte recordType, final byte[] record) throws Exception
-   {
-      appendAddRecord(id, recordType, new ByteArrayEncoding(record));
-   }
-   
-   public void appendUpdateRecord(final long id, final byte recordType, final byte[] record) throws Exception
-   {
-      appendUpdateRecord(id, recordType, new ByteArrayEncoding(record));
-   }
-   
-   public void appendAddRecordTransactional(final long txID, final long id, final byte recordType, final byte[] record) throws Exception
-   {
-      appendAddRecordTransactional(txID, id, recordType, new ByteArrayEncoding(record));
-   }
-   
-   public void appendUpdateRecordTransactional(final long txID, final long id, byte recordType, final byte[] record) throws Exception
-   {
-      appendUpdateRecordTransactional(txID, id, recordType, new ByteArrayEncoding(record));
-   }
-   
-   
    // MessagingComponent implementation ---------------------------------------------------
    
    public synchronized boolean isStarted()
@@ -1504,11 +1501,7 @@
    {
       int numberOfFiles = variableSize / (SIZE_INT * 2);
       
-      // This line aways throws a compilation-warning, even thought is a completely legal operation.
-      // We could remove the SuppressWarnings as soon as we find better expression on this line:
-      
-      //TODO sure - if something throws a warning doesn't mean it's illegal - if it were illegal it wouldn't compile!
-      
+      // 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];
       
       for (int i = 0; i < numberOfFiles; i++)
@@ -1526,7 +1519,7 @@
     *     When we load the records we build a new summary and we check the original summary to the current summary.
     *     This method is basically verifying if the entire transaction is being loaded </p> 
     *     
-    *     Summary means what? More info please
+    * <p>Look at the javadoc on {@link JournalImpl#writeTransaction(byte, long, org.jboss.messaging.core.journal.impl.JournalImpl.JournalTransaction, EncodingSupport)} about how the transaction-summary is recorded</p> 
     *     
     * @param journalTransaction
     * @param orderedFiles
@@ -1598,7 +1591,7 @@
     * <p>FileID3, 10</p>
     * 
     * <br>
-    * <p> During the load the transaction needs to have 30 records, spread across the files as originally written.</p>
+    * <p> During the load, the transaction needs to have 30 records spread across the files as originally written.</p>
     * <p> If for any reason there are missing records, that means the transaction was not completed and we should ignore the whole transaction </p>
     * <p> We can't just use a global counter as reclaiming could delete files after the transaction was successfully committed. 
     *     That also means not having a whole file on journal-reload doesn't mean we have to invalidate the transaction </p>
@@ -1610,59 +1603,37 @@
     * @return
     * @throws Exception
     */
-   private ByteBuffer writeCommitTransaction(final byte recordType, final long txID, final JournalTransaction tx) throws Exception
+   private ByteBuffer writeTransaction(final byte recordType, final long txID, final JournalTransaction tx, EncodingSupport transactionData) throws Exception
    {
-      int size = SIZE_COMPLETE_TRANSACTION_RECORD + tx.getElementsSummary().size() * SIZE_INT * 2;
+      int size = SIZE_COMPLETE_TRANSACTION_RECORD + tx.getElementsSummary().size() * SIZE_INT * 2 +
+                  (transactionData != null ? transactionData.getEncodeSize() + SIZE_INT : 0);
       
       ByteBuffer bb = newBuffer(size); 
       
       bb.put(recordType);    
-     // bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
       bb.putInt(-1); // skip ID part
       bb.putLong(txID);
 
-      bb.putInt(tx.getElementsSummary().size());
-
-      for (Map.Entry<Integer, AtomicInteger> entry: tx.getElementsSummary().entrySet())
+      if (transactionData != null)
       {
-         bb.putInt(entry.getKey());
-         bb.putInt(entry.getValue().get());
+         bb.putInt(transactionData.getEncodeSize());
       }
       
-      bb.putInt(size);           
-      bb.rewind(); //Is this necessary?
+      bb.putInt(tx.getElementsSummary().size());
       
-      return bb;
-   }
+      if (transactionData != null)
+      {
+         transactionData.encode(new ByteBufferWrapper(bb));
+      }
 
-   /**
-    * TODO: Merge this method back into writeCommitTransaction (as it was done originally).
-    * For more explanations read the javadoc on writeCommitTransaction
-    */
-   private ByteBuffer writePrepareTransaction(final byte recordType, final long txID, final JournalTransaction tx, EncodingSupport transactionData) throws Exception
-   {
-      int xidSize = transactionData.getEncodeSize();
-      int size = SIZE_COMPLETE_TRANSACTION_RECORD + tx.getElementsSummary().size() * SIZE_INT * 2 + xidSize + SIZE_INT;
-
-      ByteBuffer bb = newBuffer(size);
-
-      bb.put(recordType);
-      //bb.position(SIZE_BYTE + SIZE_INT); // skip ID part
-      bb.putInt(-1); // skip ID part
-      bb.putLong(txID);
-      bb.putInt(xidSize);
-      bb.putInt(tx.getElementsSummary().size());
-      transactionData.encode(new ByteBufferWrapper(bb));
-
       for (Map.Entry<Integer, AtomicInteger> entry: tx.getElementsSummary().entrySet())
       {
          bb.putInt(entry.getKey());
          bb.putInt(entry.getValue().get());
       }
-
-      bb.putInt(size);
-      bb.rewind();  //Is this necessary?
-
+      
+      bb.putInt(size);           
+       
       return bb;
    }
 
@@ -1898,7 +1869,7 @@
    }
    
    /** 
-    * This method will immediatly return the opened file, and schedule opening and reclaiming.
+    * This method will instantly return the opened file, and schedule opening and reclaiming.
     * In case there are no cached opened files, this method will block until the file was opened. (what would happen only if the system is under load).
     * 
     * Warning: You need to guarantee lock.acquire() before calling this method
@@ -2143,9 +2114,9 @@
    {
       private volatile long bufferReuseLastTime = System.currentTimeMillis();
       
-      // This queue is feeded by LocalBufferCallback which is called directly by NIO or NIO.
-      // On the case of the AIO this is almost called by the native layer as soon as the buffer is not being used any more
-      // and ready to reuse or GC
+      /** This queue is fed by {@link JournalImpl.ReuseBuffersController.LocalBufferCallback}} which is called directly by NIO or NIO.
+       * On the case of the AIO this is almost called by the native layer as soon as the buffer is not being used any more
+       * and ready to reused or GCed */
       private final ConcurrentLinkedQueue<ByteBuffer> reuseBuffers = new ConcurrentLinkedQueue<ByteBuffer>();
       
       final BufferCallback callback = new LocalBufferCallback();
@@ -2156,7 +2127,7 @@
          // This is being done this way as we don't need another Timeout Thread just to cleanup this
          if (reuseBufferSize > 0 && System.currentTimeMillis() - bufferReuseLastTime > 10000)
          {
-            log.debug("Clearing reuse buffers queue with " + reuseBuffers.size() + " elements");
+            System.out.println("Clearing reuse buffers queue with " + reuseBuffers.size() + " elements");
             
             bufferReuseLastTime = System.currentTimeMillis();
             
@@ -2204,7 +2175,6 @@
             bufferReuseLastTime = System.currentTimeMillis();
             
             // If a buffer has any other than the configured size, the buffer will be just sent to GC
-            // This could happen if 
             if (buffer.capacity() == reuseBufferSize)
             {
                reuseBuffers.offer(buffer);
@@ -2364,33 +2334,4 @@
    }
    
    
-   //FIXME: This class should be removed it is only used by methods called by tests - move it to the test not the core code !!
-   private static class ByteArrayEncoding implements EncodingSupport
-   {
-      final byte[] data;
-      
-      ByteArrayEncoding(final byte[] data)
-      {
-         this.data = data;
-      }
-      
-      public void decode(MessagingBuffer buffer)
-      {
-         throw new IllegalStateException("operation not supported");
-      }
-
-      public void encode(MessagingBuffer buffer)
-      {
-         buffer.putBytes(data);
-      }
-
-      public int getEncodeSize()
-      {
-         return data.length;
-      }
-      
-   }
-   
-
-   
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java	2008-09-10 10:51:55 UTC (rev 4926)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -31,6 +31,7 @@
 import org.jboss.messaging.core.journal.impl.JournalImpl;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.tests.unit.core.journal.impl.JournalImplTestBase;
+import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
 
 /**
@@ -156,7 +157,7 @@
 
       for (int count = 0; count < NUMBER_OF_RECORDS; count++)
       {
-         journal.appendAddRecord(count, (byte)0, record);
+         journal.appendAddRecord(count, (byte)0, new ByteArrayEncoding(record));
          
          if (count >= NUMBER_OF_RECORDS / 2)
          {

Modified: trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java	2008-09-10 10:51:55 UTC (rev 4926)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -32,6 +32,7 @@
 import org.jboss.messaging.core.journal.impl.AIOSequentialFileFactory;
 import org.jboss.messaging.core.journal.impl.JournalImpl;
 import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
+import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
 
 /**
  * 
@@ -211,7 +212,7 @@
                
                if (transactionSize != 0)
                {
-                  journal.appendAddRecordTransactional(transactionId, id, (byte)99, buffer.array());
+                  journal.appendAddRecordTransactional(transactionId, id, (byte)99, new ByteArrayEncoding(buffer.array()));
         
                   if (++transactionCounter == transactionSize)
                   {
@@ -223,7 +224,7 @@
                }
                else
                {
-                  journal.appendAddRecord(id, (byte)99, buffer.array());
+                  journal.appendAddRecord(id, (byte)99, new ByteArrayEncoding(buffer.array()));
                }
             }
    

Modified: trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.java	2008-09-10 10:51:55 UTC (rev 4926)
+++ trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -29,6 +29,7 @@
 import org.jboss.messaging.core.journal.RecordInfo;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.tests.unit.core.journal.impl.JournalImplTestBase;
+import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
 
 /**
  * 
@@ -152,7 +153,7 @@
 
       for (int count = 0; count < NUMBER_OF_RECORDS; count++)
       {
-         journal.appendAddRecord(count, (byte)0, record);
+         journal.appendAddRecord(count, (byte)0, new ByteArrayEncoding(record));
          
          if (count >= NUMBER_OF_RECORDS / 2)
          {

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-10 10:51:55 UTC (rev 4926)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -39,6 +39,7 @@
 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.ByteArrayEncoding;
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
 import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
 import org.jboss.messaging.tests.util.UnitTestCase;
@@ -214,7 +215,7 @@
          {
             bytes[j] = (byte)i;
          }
-         journalImpl.appendAddRecord(i * 100l, (byte)i, bytes);
+         journalImpl.appendAddRecord(i * 100l, (byte)i, new ByteArrayEncoding(bytes));
       }
       
       for (int i = 25; i < 50; i++)
@@ -249,7 +250,7 @@
             bytes[j] = (byte)'x';
          }
          
-         journalImpl.appendUpdateRecord(i * 100l, (byte)i, bytes);
+         journalImpl.appendUpdateRecord(i * 100l, (byte)i, new ByteArrayEncoding(bytes));
       }
       
       setupJournal(JOURNAL_SIZE, 1024);

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-10 10:51:55 UTC (rev 4926)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/EasyMockJournalTest.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -69,7 +69,7 @@
       
       EasyMock.replay(mockFactory, file1, file2);
       
-      journalImpl.appendAddRecord(14l, (byte) 33, new byte[]{ (byte) 10 });
+      journalImpl.appendAddRecord(14l, (byte) 33, new SimpleEncoding(1, (byte)10));
       
       EasyMock.verify(mockFactory, file1, file2);
 
@@ -112,7 +112,7 @@
 
       EasyMock.replay(mockFactory, file1, file2);
       
-      journalImpl.appendAddRecord(14l, (byte) 33, new byte[]{ (byte) 10 });
+      journalImpl.appendAddRecord(14l, (byte) 33, new SimpleEncoding(1, (byte)10));
       
       journalImpl.appendDeleteRecord(14l);
 
@@ -274,11 +274,11 @@
       
      EasyMock.replay(mockFactory, file1, file2);
       
-      journalImpl.appendAddRecord(15l, (byte) 33, new byte[]{ (byte) 10 });
+      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 byte[]{ (byte) 12});
+      journalImpl.appendUpdateRecord(15l, (byte)35, new SimpleEncoding(1, (byte)12));
       
       EasyMock.verify(mockFactory, file1, file2);
 

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-10 10:51:55 UTC (rev 4926)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -30,10 +30,9 @@
 import org.jboss.messaging.core.journal.TestableJournal;
 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.ByteArrayEncoding;
 import org.jboss.messaging.tests.util.RandomUtil;
 import org.jboss.messaging.tests.util.UnitTestCase;
-
-import javax.transaction.xa.Xid;
 import java.util.*;
 
 /**
@@ -208,7 +207,7 @@
 		{     
 			byte[] record = generateRecord(size);
 			
-			journal.appendAddRecord(arguments[i], (byte)0, record);
+			journal.appendAddRecord(arguments[i], (byte)0, new ByteArrayEncoding(record));
 			
 			records.add(new RecordInfo(arguments[i], (byte)0, record, false));         
 		}
@@ -222,7 +221,7 @@
 		{     
 			byte[] updateRecord = generateRecord(recordLength);
 			
-			journal.appendUpdateRecord(arguments[i], (byte)0, updateRecord);
+			journal.appendUpdateRecord(arguments[i], (byte)0, new ByteArrayEncoding(updateRecord));
 			
 			records.add(new RecordInfo(arguments[i], (byte)0, updateRecord, true)); 
 		}
@@ -251,7 +250,7 @@
 			// 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, record);
+			journal.appendAddRecordTransactional(txID, arguments[i], (byte)0, new ByteArrayEncoding(record));
 			
 			tx.records.add(new RecordInfo(arguments[i], (byte)0, record, false));
 			
@@ -268,7 +267,7 @@
 		{     
 			byte[] updateRecord = generateRecord(recordLength - JournalImpl.SIZE_UPDATE_RECORD_TX );
 			
-			journal.appendUpdateRecordTransactional(txID, arguments[i], (byte)0, updateRecord);
+			journal.appendUpdateRecordTransactional(txID, arguments[i], (byte)0, new ByteArrayEncoding(updateRecord));
 			
 			tx.records.add(new RecordInfo(arguments[i], (byte)0, updateRecord, true));
 		}     

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-10 10:51:55 UTC (rev 4926)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -28,7 +28,7 @@
 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.SimpleEncoding;
-
+import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
 import javax.transaction.xa.Xid;
 import java.util.List;
 
@@ -120,7 +120,7 @@
       // Appending records after restart should be valid (not throwing any exceptions)
       for (int i = 0; i < 100; i++)
       {
-         journal.appendAddRecord(1, (byte)1, new byte[] {(byte)'a', (byte)'a'});
+         journal.appendAddRecord(1, (byte)1, new SimpleEncoding(2, (byte)'a'));
       }
       stopJournal();
 	}
@@ -2130,7 +2130,7 @@
 		{
 			byte[] record = generateRecord(10 + (int)(1500 * Math.random()));
 			
-			journal.appendAddRecord(i, (byte)0, record);
+			journal.appendAddRecord(i, (byte)0, new ByteArrayEncoding(record));
 			
 			records.add(new RecordInfo(i, (byte)0, record, false));
 		}
@@ -2139,7 +2139,7 @@
 		{
 			byte[] record = generateRecord(10 + (int)(1024 * Math.random()));
 			
-			journal.appendUpdateRecord(i, (byte)0, record);
+			journal.appendUpdateRecord(i, (byte)0, new ByteArrayEncoding(record));
 			
 			records.add(new RecordInfo(i, (byte)0, record, true));
 		}

Added: 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	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java	2008-09-10 15:59:07 UTC (rev 4927)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.tests.unit.core.journal.impl.fakes;
+
+import org.jboss.messaging.core.journal.EncodingSupport;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+
+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)
+   {
+      throw new IllegalStateException("operation not supported");
+   }
+
+   public void encode(final MessagingBuffer buffer)
+   {
+      buffer.putBytes(data);
+   }
+
+   public int getEncodeSize()
+   {
+      return data.length;
+   }
+   
+
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+   
+}




More information about the jboss-cvs-commits mailing list