directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1227712 [2/2] - in /directory/apacheds/branches/apacheds-txns/core-shared/src: main/java/org/apache/directory/server/core/shared/ main/java/org/apache/directory/server/core/shared/log/ main/java/org/apache/directory/server/core/shared/part...
Date Thu, 05 Jan 2012 17:28:50 GMT
Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogManager.java?rev=1227712&r1=1227711&r2=1227712&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/log/LogManager.java Thu Jan  5 17:28:50 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.shared.log;
 
+
 import java.nio.ByteBuffer;
 
 import java.util.concurrent.locks.ReentrantLock;
@@ -38,61 +39,62 @@ import org.apache.directory.server.core.
 
 import org.apache.directory.server.i18n.I18n;
 
+
 /**
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-/* Package protected */ class LogManager
+/* Package protected */class LogManager
 {
     /**  Controlfile record size */
     private final static int CONTROLFILE_RECORD_SIZE = 44;
-    
+
     /**  Controlfile checksum size */
     private final static int CONTROLFILE_CHECKSUM_SIZE = CONTROLFILE_RECORD_SIZE - 8 - 4;
-    
+
     /** Controlfile file magic number */
     private final static int CONTROLFILE_MAGIC_NUMBER = 0xFF11FF11;
-    
+
     /** Controlfile log file number */
     private final static long CONTROLFILE_LOG_FILE_NUMBER = -1;
-    
+
     /** Shadow Controlfile log file number */
     private final static long CONTROLFILE_SHADOW_LOG_FILE_NUMBER = -2;
-    
+
     /** buffer used to do IO on controlfile */
     private byte controlFileBuffer[] = new byte[CONTROLFILE_RECORD_SIZE];
-    
+
     /** ByteBuffer used to IO on checkpoint file */
     private ByteBuffer controlFileMarker = ByteBuffer.wrap( controlFileBuffer );
-    
+
     /** Current checkpoint record in memory */
     private ControlFileRecord controlFileRecord = new ControlFileRecord();
-    
+
     /** Min neeeded point in the log */
     private LogAnchor minLogAnchor = new LogAnchor();
-    
+
     /** Protects minLogAchor */
     private Lock minLogAnchorLock = new ReentrantLock();
-    
+
     /** Log file manager */
     private LogFileManager logFileManager;
-        
+
     /** Log Anchor comparator */
     private LogAnchorComparator anchorComparator = new LogAnchorComparator();
-    
+
     /** Current log file */
     private long currentLogFileNumber;
-    
+
     /** Buffer used to read log file markers */
     private byte markerBuffer[] = new byte[LogFileRecords.LOG_FILE_HEADER_SIZE];
-    
+
     /** ByteBuffer wrapper for the marker buffer */
     private ByteBuffer markerHead = ByteBuffer.wrap( markerBuffer );
-    
+
     /** The Checksum used */
     private Checksum checksum = new Adler32();
 
-    
+
     /**
      * Creates a new instance of LogManager. It manages the control file and 
      * 
@@ -102,8 +104,8 @@ import org.apache.directory.server.i18n.
     {
         this.logFileManager = logFileManager;
     }
-    
-    
+
+
     /**
      *Initializes the log management:
      * 1) Checks if control file exists and creates it if necessary. If it exists, it reads it and loads 
@@ -121,32 +123,32 @@ import org.apache.directory.server.i18n.
         LogScanner scanner;
         UserLogRecord logRecord;
         LogFileManager.LogFileReader reader;
-        
+
         // Read and verify control file
         boolean controlFileExists = true;
-        
+
         try
         {
             readControlFile();
         }
-        catch( FileNotFoundException e )
+        catch ( FileNotFoundException e )
         {
             controlFileExists = false;
         }
-        
+
         if ( controlFileExists )
         {
             boolean invalidLog = false;
-            
+
             // Set the min log anchor from the control file
-            minLogAnchor.resetLogAnchor( controlFileRecord.minNeededLogFile, 
-                    controlFileRecord.minNeededLogFileOffset, controlFileRecord.minNeededLSN );
-            
+            minLogAnchor.resetLogAnchor( controlFileRecord.minNeededLogFile,
+                controlFileRecord.minNeededLogFileOffset, controlFileRecord.minNeededLSN );
+
             scanPoint.resetLogAnchor( minLogAnchor );
-            
+
             logRecord = new UserLogRecord();
             scanner = new DefaultLogScanner( scanPoint, logFileManager );
-            
+
             // Now, scan all the logged user records to check if they are all valid
             try
             {
@@ -156,7 +158,7 @@ import org.apache.directory.server.i18n.
                     // read all of them to check that they are all valid.
                 }
             }
-            catch( InvalidLogException e )
+            catch ( InvalidLogException e )
             {
                 invalidLog = true;
             }
@@ -164,25 +166,25 @@ import org.apache.directory.server.i18n.
             {
                 scanner.close();
             }
-            
+
             long lastGoodLogFileNumber = scanner.getLastGoodFileNumber();
             long lastGoodLogFileOffset = scanner.getLastGoodOffset();
             currentLogFileNumber = lastGoodLogFileNumber;
-            
-            if ( ( lastGoodLogFileNumber < LogAnchor.MIN_LOG_NUMBER ) || 
-                ( lastGoodLogFileOffset < LogAnchor.MIN_LOG_OFFSET ))
+
+            if ( ( lastGoodLogFileNumber < LogAnchor.MIN_LOG_NUMBER ) ||
+                ( lastGoodLogFileOffset < LogAnchor.MIN_LOG_OFFSET ) )
             {
                 throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
             }
-            
-            scanPoint.resetLogAnchor( lastGoodLogFileNumber, lastGoodLogFileOffset, 
-                    LogAnchor.UNKNOWN_LSN );
-            
+
+            scanPoint.resetLogAnchor( lastGoodLogFileNumber, lastGoodLogFileOffset,
+                LogAnchor.UNKNOWN_LSN );
+
             if ( anchorComparator.compare( scanPoint, minLogAnchor ) < 0 )
             {
                 throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
             }
-            
+
             /*
              * If invalid content at the end of file:
              * if we are past the header of file, then
@@ -196,7 +198,7 @@ import org.apache.directory.server.i18n.
             {
                 // Check if next log file exists
                 reader = null;
-                
+
                 try
                 {
                     reader = logFileManager.getReaderForLogFile( ( lastGoodLogFileNumber + 1 ) );
@@ -212,20 +214,20 @@ import org.apache.directory.server.i18n.
                         reader.close();
                     }
                 }
-                
+
                 if ( reader != null )
                 {
                     throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
                 }
-                
-                if  ( lastGoodLogFileOffset >= LogFileRecords.LOG_FILE_HEADER_SIZE  )
+
+                if ( lastGoodLogFileOffset >= LogFileRecords.LOG_FILE_HEADER_SIZE )
                 {
                     logFileManager.truncateLogFile( lastGoodLogFileNumber, lastGoodLogFileOffset );
                 }
                 else
                 {
                     // Reformat the existing log file
-                    createNextLogFile( true);
+                    createNextLogFile( true );
                 }
             }
         }
@@ -238,16 +240,16 @@ import org.apache.directory.server.i18n.
         reader = null;
         boolean fileExists = false;
         currentLogFileNumber = LogAnchor.MIN_LOG_NUMBER - 1;
-       
+
         try
         {
             reader = logFileManager.getReaderForLogFile( LogAnchor.MIN_LOG_NUMBER );
-           
+
             if ( reader.getLength() > LogFileRecords.LOG_FILE_HEADER_SIZE )
             {
                 throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
             }
-           
+
             fileExists = true;
             currentLogFileNumber++;
         }
@@ -262,16 +264,17 @@ import org.apache.directory.server.i18n.
                 reader.close();
             }
         }
-       
+
         createNextLogFile( fileExists );
-        
+
         // Prepare the min log anchor and control file and write the control file
-        minLogAnchor.resetLogAnchor( LogAnchor.MIN_LOG_NUMBER, LogFileRecords.LOG_FILE_HEADER_SIZE, LogAnchor.UNKNOWN_LSN );
-       
+        minLogAnchor.resetLogAnchor( LogAnchor.MIN_LOG_NUMBER, LogFileRecords.LOG_FILE_HEADER_SIZE,
+            LogAnchor.UNKNOWN_LSN );
+
         writeControlFile();
     }
-    
-    
+
+
     /**
      * Called by LogFlushManager to switch to the next file.
      *
@@ -283,7 +286,8 @@ import org.apache.directory.server.i18n.
      * @throws IOException If we had an issue accessing the log files
      * @throws InvalidLogException If any of the user record is invalid
      */
-    public LogFileManager.LogFileWriter switchToNextLogFile( LogFileManager.LogFileWriter currentWriter ) throws IOException, InvalidLogException
+    public LogFileManager.LogFileWriter switchToNextLogFile( LogFileManager.LogFileWriter currentWriter )
+        throws IOException, InvalidLogException
     {
         if ( currentWriter != null )
         {
@@ -291,33 +295,33 @@ import org.apache.directory.server.i18n.
             writeControlFile();
             createNextLogFile( false );
         }
-        
-        LogFileManager.LogFileWriter writer =  logFileManager.getWriterForLogFile( currentLogFileNumber );
+
+        LogFileManager.LogFileWriter writer = logFileManager.getWriterForLogFile( currentLogFileNumber );
         long currentOffset = writer.getLength();
-        
+
         if ( currentOffset > 0 )
         {
             writer.seek( currentOffset );
         }
-        
+
         return writer;
     }
-    
-    
+
+
     /**
      * @return The anchor associated with the last valid checkpoint.
      */
-    /* Package protected */ LogAnchor getMinLogAnchor()
+    /* Package protected */LogAnchor getMinLogAnchor()
     {
         minLogAnchorLock.lock();
         LogAnchor anchor = new LogAnchor();
         anchor.resetLogAnchor( minLogAnchor );
         minLogAnchorLock.unlock();
-        
+
         return anchor;
     }
-    
-    
+
+
     /**
      * Called when the logging subsystem is notified about the minimum position 
      * in the log files that is needed. Log manager uses this information to advance
@@ -331,18 +335,18 @@ import org.apache.directory.server.i18n.
         {
             return;
         }
-        
+
         minLogAnchorLock.lock();
-        
+
         if ( anchorComparator.compare( minLogAnchor, newLogAnchor ) < 0 )
         {
             minLogAnchor.resetLogAnchor( newLogAnchor );
         }
-        
+
         minLogAnchorLock.unlock();
     }
-    
-    
+
+
     /**
      * Writes the control file. To make partially written control files unlikely,
      * data is first written to a shadow file and then moved(renamed) to the controlfile.
@@ -366,60 +370,61 @@ import org.apache.directory.server.i18n.
     {
         // Copy the min log file anchor
         minLogAnchorLock.lock();
-        
+
         controlFileRecord.minNeededLogFile = minLogAnchor.getLogFileNumber();
         controlFileRecord.minNeededLogFileOffset = minLogAnchor.getLogFileOffset();
         controlFileRecord.minNeededLSN = minLogAnchor.getLogLSN();
-        
+
         minLogAnchorLock.unlock();
-        
-        if ( controlFileRecord.minNeededLogFile > controlFileRecord.minExistingLogFile  )
+
+        if ( controlFileRecord.minNeededLogFile > controlFileRecord.minExistingLogFile )
         {
-            deleteUnnecessaryLogFiles( controlFileRecord.minExistingLogFile,controlFileRecord.minNeededLogFile );
+            deleteUnnecessaryLogFiles( controlFileRecord.minExistingLogFile, controlFileRecord.minNeededLogFile );
             controlFileRecord.minExistingLogFile = controlFileRecord.minNeededLogFile;
-            
+
         }
-        
+
         // Create the control file record
         controlFileMarker.rewind();
         controlFileMarker.putLong( controlFileRecord.minExistingLogFile );
         controlFileMarker.putLong( controlFileRecord.minNeededLogFile );
         controlFileMarker.putLong( controlFileRecord.minNeededLogFileOffset );
         controlFileMarker.putLong( controlFileRecord.minNeededLSN );
-        
+
         // Compute the checksum
         checksum.reset();
         checksum.update( controlFileMarker.array(), 0, CONTROLFILE_CHECKSUM_SIZE );
         controlFileRecord.checksum = checksum.getValue();
-        
+
         controlFileMarker.putLong( controlFileRecord.checksum );
         controlFileMarker.putInt( CONTROLFILE_MAGIC_NUMBER );
-        
+
         // Create the shadow file, and write the header into it
-        boolean shadowFileExists = logFileManager.createLogFile( CONTROLFILE_SHADOW_LOG_FILE_NUMBER  );
-        
+        boolean shadowFileExists = logFileManager.createLogFile( CONTROLFILE_SHADOW_LOG_FILE_NUMBER );
+
         if ( shadowFileExists )
         {
             logFileManager.truncateLogFile( CONTROLFILE_SHADOW_LOG_FILE_NUMBER, 0 );
         }
-        
-        LogFileManager.LogFileWriter controlFileWriter = logFileManager.getWriterForLogFile( CONTROLFILE_SHADOW_LOG_FILE_NUMBER );
-        
+
+        LogFileManager.LogFileWriter controlFileWriter = logFileManager
+            .getWriterForLogFile( CONTROLFILE_SHADOW_LOG_FILE_NUMBER );
+
         try
         {
-            controlFileWriter.append( controlFileBuffer, 0, CONTROLFILE_RECORD_SIZE);
+            controlFileWriter.append( controlFileBuffer, 0, CONTROLFILE_RECORD_SIZE );
             controlFileWriter.sync();
         }
         finally
         {
             controlFileWriter.close();
         }
-        
+
         // Do the move now
-        logFileManager.rename( CONTROLFILE_SHADOW_LOG_FILE_NUMBER , CONTROLFILE_LOG_FILE_NUMBER );
+        logFileManager.rename( CONTROLFILE_SHADOW_LOG_FILE_NUMBER, CONTROLFILE_LOG_FILE_NUMBER );
     }
-    
-    
+
+
     /**
      * Read and verifies the control file.
      *
@@ -429,21 +434,22 @@ import org.apache.directory.server.i18n.
      */
     private void readControlFile() throws IOException, InvalidLogException, FileNotFoundException
     {
-        LogFileManager.LogFileReader controlFileReader = logFileManager.getReaderForLogFile( CONTROLFILE_LOG_FILE_NUMBER );
-        
+        LogFileManager.LogFileReader controlFileReader = logFileManager
+            .getReaderForLogFile( CONTROLFILE_LOG_FILE_NUMBER );
+
         try
         {
             controlFileReader.read( controlFileBuffer, 0, CONTROLFILE_RECORD_SIZE );
         }
-        catch( EOFException e )
+        catch ( EOFException e )
         {
-            throw new InvalidLogException( I18n.err( I18n.ERR_750 ) , e);
+            throw new InvalidLogException( I18n.err( I18n.ERR_750 ), e );
         }
         finally
         {
             controlFileReader.close();
         }
-        
+
         controlFileMarker.rewind();
         controlFileRecord.minExistingLogFile = controlFileMarker.getLong();
         controlFileRecord.minNeededLogFile = controlFileMarker.getLong();
@@ -451,22 +457,22 @@ import org.apache.directory.server.i18n.
         controlFileRecord.minNeededLSN = controlFileMarker.getLong();
         controlFileRecord.checksum = controlFileMarker.getLong();
         int magicNumber = controlFileMarker.getInt();
-        
+
         checksum.reset();
         checksum.update( controlFileMarker.array(), 0, CONTROLFILE_CHECKSUM_SIZE );
-        
+
         if ( ( controlFileRecord.minExistingLogFile < LogAnchor.MIN_LOG_NUMBER ) ||
-             ( controlFileRecord.minNeededLogFile < LogAnchor.MIN_LOG_NUMBER ) ||
-             ( controlFileRecord.minNeededLogFileOffset < LogAnchor.MIN_LOG_OFFSET ) ||
-             ( controlFileRecord.minExistingLogFile > controlFileRecord.minNeededLogFile ) ||
-             ( magicNumber != CONTROLFILE_MAGIC_NUMBER ) || 
-             ( controlFileRecord.checksum != checksum.getValue() ) )
+            ( controlFileRecord.minNeededLogFile < LogAnchor.MIN_LOG_NUMBER ) ||
+            ( controlFileRecord.minNeededLogFileOffset < LogAnchor.MIN_LOG_OFFSET ) ||
+            ( controlFileRecord.minExistingLogFile > controlFileRecord.minNeededLogFile ) ||
+            ( magicNumber != CONTROLFILE_MAGIC_NUMBER ) ||
+            ( controlFileRecord.checksum != checksum.getValue() ) )
         {
             throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
         }
     }
-    
-    
+
+
     /**
      * Creates the next log file. If the log file already exists, then it is reformatted, that is,
      * its size is truncated to zero and file header is written again.
@@ -478,31 +484,31 @@ import org.apache.directory.server.i18n.
     private void createNextLogFile( boolean reformatExistingFile ) throws IOException, InvalidLogException
     {
         LogFileManager.LogFileWriter writer = null;
-        
+
         long logFileNumber = currentLogFileNumber;
-        
+
         if ( reformatExistingFile == false )
         {
             logFileNumber++;
         }
-        
+
         // Try to create the file.
         boolean fileAlreadyExists = logFileManager.createLogFile( logFileNumber );
-        
+
         if ( reformatExistingFile != fileAlreadyExists )
         {
             // Didnt expect the file to be around
             throw new InvalidLogException( I18n.err( I18n.ERR_750 ) );
         }
-        
+
         if ( reformatExistingFile )
         {
             logFileManager.truncateLogFile( logFileNumber, LogAnchor.MIN_LOG_OFFSET );
-           
+
         }
-        
+
         writer = logFileManager.getWriterForLogFile( logFileNumber );
-        
+
         try
         {
             markerHead.rewind();
@@ -515,43 +521,41 @@ import org.apache.directory.server.i18n.
         {
             writer.close();
         }
-        
+
         currentLogFileNumber = logFileNumber;
     }
-    
-    
+
+
     /**
      * Purge the useless log files
      */
     private void deleteUnnecessaryLogFiles( long startingLogFileNumber, long endingLogFileNumber )
     {
-        for ( long logFileNumber = startingLogFileNumber; logFileNumber < endingLogFileNumber; 
-                logFileNumber++ )
+        for ( long logFileNumber = startingLogFileNumber; logFileNumber < endingLogFileNumber; logFileNumber++ )
         {
             // Do a best effort delete
             logFileManager.deleteLogFile( logFileNumber );
         }
     }
-    
-    
+
     /**
      * Checkpoint record
      */
-     private class ControlFileRecord
-     {
-         /** The smallest existing log file number */
-         private long minExistingLogFile;
-         
-         /** The log file number associated with a checkpoint */
-         private long minNeededLogFile;
-         
-         /** The offset in the min needed log file */
-         private long minNeededLogFileOffset;
-         
-         /** The LSN of the first user record in the min needed log file at the offset position */
-         private long minNeededLSN;
-         
-         /** The control file checksum */
-         private long checksum;
-     }
+    private class ControlFileRecord
+    {
+        /** The smallest existing log file number */
+        private long minExistingLogFile;
+
+        /** The log file number associated with a checkpoint */
+        private long minNeededLogFile;
+
+        /** The offset in the min needed log file */
+        private long minNeededLogFileOffset;
+
+        /** The LSN of the first user record in the min needed log file at the offset position */
+        private long minNeededLSN;
+
+        /** The control file checksum */
+        private long checksum;
+    }
 }

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java?rev=1227712&r1=1227711&r2=1227712&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java Thu Jan  5 17:28:50 2012
@@ -44,15 +44,17 @@ import org.apache.directory.shared.ldap.
 public class EntryCursorAdaptor implements Cursor<Entry>
 {
     /** Underlying partition */
-    private  Partition db;
-    
+    private Partition db;
+
     /** Wrapped cursor */
-    private  IndexCursor<UUID> indexCursor;
+    private IndexCursor<UUID> indexCursor;
 
     /** Master table of the partition */
     MasterTable masterTable;
 
-    public EntryCursorAdaptor( Partition db, IndexCursor<UUID> indexCursor, TxnManagerFactory txnManagerFactory ) throws Exception
+
+    public EntryCursorAdaptor( Partition db, IndexCursor<UUID> indexCursor, TxnManagerFactory txnManagerFactory )
+        throws Exception
     {
         this.db = db;
         this.indexCursor = indexCursor;

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java?rev=1227712&r1=1227711&r2=1227712&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java Thu Jan  5 17:28:50 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.shared.txn;
 
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.NavigableSet;
@@ -36,6 +37,7 @@ import org.apache.directory.server.i18n.
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
 import org.apache.directory.shared.ldap.model.name.Dn;
 
+
 /**
  * Wraps an index's cursor and provides a transactionally consistent view.
  * 
@@ -57,74 +59,77 @@ public class IndexCursorWrapper extends 
 {
     /** Cursors to merge */
     private ArrayList<IndexCursor<Object>> cursors;
-    
+
     /** list of values available per cursor */
     private ArrayList<IndexEntry<Object>> values;
-    
+
     /** index get should get the value from */
     private int getIndex = -1;
-    
+
     /** Dn of the partition */
     private Dn partitionDn;
-    
+
     /** Index attribute oid */
     private String attributeOid;
-    
+
     /** whether this is a cursor on forward or reverse index */
     private boolean forwardIndex;
-    
+
     /** Index deletes by txns that this cursor depends on */
     private ArrayList<NavigableSet<IndexEntry<Object>>> deletes;
-    
+
     /** True if cursor is positioned */
     private boolean positioned;
-    
+
     /** direction of the move */
     private boolean movingNext = true;
-    
+
     /** Comparator used to order the index entries */
     private IndexComparator<Object> comparator;
-    
+
     /** unsupported operation message */
     private static final String UNSUPPORTED_MSG = I18n.err( I18n.ERR_722 );
-    
+
     /** Last value returned: here to keep memory overhead low */
     private ForwardIndexEntry<Object> lastValue = new ForwardIndexEntry<Object>();
-    
+
     /** Txn Manager */
     TxnManagerInternal txnManager;
-     
-    public IndexCursorWrapper( TxnManagerFactory txnManagerFactory, Dn partitionDn, 
-            IndexCursor<Object> wrappedCursor, IndexComparator<Object> comparator, String attributeOid, boolean forwardIndex, Object onlyValueKey, UUID onlyIDKey )
+
+
+    public IndexCursorWrapper( TxnManagerFactory txnManagerFactory, Dn partitionDn,
+        IndexCursor<Object> wrappedCursor, IndexComparator<Object> comparator, String attributeOid,
+        boolean forwardIndex, Object onlyValueKey, UUID onlyIDKey )
     {
         this.partitionDn = partitionDn;
         this.forwardIndex = forwardIndex;
         this.attributeOid = attributeOid;
         this.comparator = comparator;
-        
-        txnManager = txnManagerFactory.txnManagerInternalInstance();      
-        Transaction curTxn = txnManager.getCurTxn();  
-        List<ReadWriteTxn> toCheck = curTxn.getTxnsToCheck(); 
-        
+
+        txnManager = txnManagerFactory.txnManagerInternalInstance();
+        Transaction curTxn = txnManager.getCurTxn();
+        List<ReadWriteTxn> toCheck = curTxn.getTxnsToCheck();
+
         cursors = new ArrayList<IndexCursor<Object>>( toCheck.size() + 1 );
         values = new ArrayList<IndexEntry<Object>>( toCheck.size() + 1 );
-        cursors.add( ( IndexCursor<Object> )wrappedCursor );
+        cursors.add( ( IndexCursor<Object> ) wrappedCursor );
         values.add( null );
-        
+
         if ( toCheck.size() > 0 )
         {
             deletes = new ArrayList<NavigableSet<IndexEntry<Object>>>( toCheck.size() );
-            
+
             ReadWriteTxn dependentTxn;
-            
+
             for ( int idx = 0; idx < toCheck.size(); idx++ )
             {
                 dependentTxn = toCheck.get( idx );
-                
+
                 if ( curTxn == dependentTxn )
                 {
-                    NavigableSet<IndexEntry<Object>> txnDeletes = dependentTxn.getDeletesFor( partitionDn, attributeOid );
-                    
+                    NavigableSet<IndexEntry<Object>> txnDeletes = dependentTxn
+                        .getDeletesFor( partitionDn, attributeOid );
+
                     if ( txnDeletes != null )
                     {
                         TreeSet<IndexEntry<Object>> clonedDeletes = new TreeSet<IndexEntry<Object>>( comparator );
@@ -140,16 +145,17 @@ public class IndexCursorWrapper extends 
                 {
                     deletes.add( dependentTxn.getDeletesFor( partitionDn, attributeOid ) );
                 }
-                
+
                 values.add( null );
-                
+
                 // This adds a null to the array if the txn does not have any changes for the index
-                cursors.add( getCursorFor( dependentTxn, partitionDn, attributeOid, forwardIndex, onlyValueKey, onlyIDKey, comparator ) );
+                cursors.add( getCursorFor( dependentTxn, partitionDn, attributeOid, forwardIndex, onlyValueKey,
+                    onlyIDKey, comparator ) );
             }
         }
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -159,23 +165,24 @@ public class IndexCursorWrapper extends 
         positioned = true;
         movingNext = true;
         IndexCursor<Object> cursor;
-        
+
         checkNotClosed( "after()" );
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             values.set( idx, null );
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
                 cursor.after( element );
             }
         }
-        
+
         getIndex = -1;
     }
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -185,24 +192,24 @@ public class IndexCursorWrapper extends 
         positioned = true;
         movingNext = true;
         IndexCursor<Object> cursor;
-        
+
         checkNotClosed( "before()" );
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             values.set( idx, null );
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
                 cursor.before( element );
             }
         }
-        
+
         getIndex = -1;
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -212,20 +219,20 @@ public class IndexCursorWrapper extends 
         positioned = true;
         movingNext = true;
         IndexCursor<Object> cursor;
-        
+
         checkNotClosed( "afterValue()" );
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             values.set( idx, null );
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
                 cursor.afterValue( id, value );
             }
         }
-        
+
         getIndex = -1;
     }
 
@@ -239,24 +246,24 @@ public class IndexCursorWrapper extends 
         positioned = true;
         movingNext = true;
         IndexCursor<Object> cursor;
-        
+
         checkNotClosed( "beforeValue()" );
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             values.set( idx, null );
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
                 cursor.beforeValue( id, value );
             }
         }
-        
+
         getIndex = -1;
     }
-   
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -266,20 +273,20 @@ public class IndexCursorWrapper extends 
         positioned = true;
         movingNext = true;
         IndexCursor<Object> cursor;
-        
+
         checkNotClosed( "beforeFirst()" );
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             values.set( idx, null );
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
                 cursor.beforeFirst();
             }
         }
-        
+
         getIndex = -1;
     }
 
@@ -293,24 +300,24 @@ public class IndexCursorWrapper extends 
         positioned = true;
         movingNext = false;
         IndexCursor<Object> cursor;
-        
+
         checkNotClosed( "afterLast()" );
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             values.set( idx, null );
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
-                cursor.afterLast( );
+                cursor.afterLast();
             }
-            
+
         }
-        
+
         getIndex = -1;
     }
-    
+
 
     /**
      * {@inheritDoc}
@@ -318,10 +325,10 @@ public class IndexCursorWrapper extends 
     public boolean first() throws Exception
     {
         beforeFirst();
-        
+
         return next();
     }
-    
+
 
     /**
      * {@inheritDoc}
@@ -329,11 +336,11 @@ public class IndexCursorWrapper extends 
     public boolean last() throws Exception
     {
         afterLast();
-        
+
         return previous();
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -342,10 +349,9 @@ public class IndexCursorWrapper extends 
         IndexCursor<Object> cursor;
         IndexEntry<Object> minValue;
         IndexEntry<Object> value;
-        
+
         checkNotClosed( "next()" );
-        
-        
+
         if ( getIndex >= 0 )
         {
             IndexEntry<Object> indexEntry = values.get( getIndex );
@@ -356,38 +362,38 @@ public class IndexCursorWrapper extends 
         {
             lastValue.setId( null );
         }
-        
+
         int idx;
-        
+
         if ( positioned == false )
         {
             beforeFirst();
         }
-        
+
         /*
          *  If called right after positioning the cursor or changing direction, then do a next call
          *  on every wrapped cursor and recompute the min value.
          */
-        if ((  movingNext == false ) || ( getIndex < 0 ) )
+        if ( ( movingNext == false ) || ( getIndex < 0 ) )
         {
             minValue = null;
             getIndex = -1;
             movingNext = true;
-            
+
             for ( idx = 0; idx < values.size(); idx++ )
             {
                 cursor = cursors.get( idx );
-                
+
                 if ( ( cursor != null ) && cursor.next() )
                 {
                     value = cursor.get();
-                    
+
                     if ( ( getIndex < 0 ) || ( comparator.compare( value, minValue ) < 0 ) )
                     {
                         minValue = value;
                         getIndex = idx;
                     }
-                    
+
                     values.set( idx, value );
                 }
                 else
@@ -399,57 +405,59 @@ public class IndexCursorWrapper extends 
         else
         {
             // Move the last cursor we did a get from and recompute minimum
-           recomputeMinimum();
+            recomputeMinimum();
         }
-        
+
         int txnIdx;
         NavigableSet<IndexEntry<Object>> txnDeletes;
         boolean valueDeleted;
-        
+
         do
         {
             if ( getIndex < 0 )
             {
                 break;
             }
-            
+
             value = values.get( getIndex );
-            
+
             txnIdx = getIndex;
-            
+
             if ( txnIdx > 0 )
             {
                 txnIdx--;
             }
-            
+
             valueDeleted = false;
-            
+
             for ( ; txnIdx < deletes.size(); txnIdx++ )
             {
                 txnDeletes = deletes.get( txnIdx );
-                
+
                 if ( ( txnDeletes != null ) && ( txnDeletes.contains( value ) ) )
                 {
                     valueDeleted = true;
                     break;
                 }
             }
-            
+
             // If the value we get is not deleted and greater than the last value we returned, then we are done
-            if ( ( valueDeleted == false ) && ( ( lastValue.getId() == null ) || ( comparator.compare( value, lastValue ) > 0 ) ) )
+            if ( ( valueDeleted == false )
+                && ( ( lastValue.getId() == null ) || ( comparator.compare( value, lastValue ) > 0 ) ) )
             {
                 break;
             }
-            
+
             // Recompute minimum
             recomputeMinimum();
-            
-        } while ( true );
-        
+
+        }
+        while ( true );
+
         return ( getIndex >= 0 );
-    } 
-    
-    
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -458,9 +466,9 @@ public class IndexCursorWrapper extends 
         IndexCursor<Object> cursor;
         IndexEntry<Object> maxValue;
         IndexEntry<Object> value;
-        
+
         checkNotClosed( "previous()" );
-        
+
         if ( getIndex >= 0 )
         {
             IndexEntry<Object> indexEntry = values.get( getIndex );
@@ -471,15 +479,14 @@ public class IndexCursorWrapper extends 
         {
             lastValue.setId( null );
         }
-        
+
         int idx;
-        
+
         if ( positioned == false )
         {
             afterLast();
         }
-        
-        
+
         /*
          *  If called right after positioning the cursor or changing direction, then do a previous call
          *  on every wrapped cursor and recompute the max value.
@@ -489,21 +496,21 @@ public class IndexCursorWrapper extends 
             maxValue = null;
             getIndex = -1;
             movingNext = false;
-            
+
             for ( idx = 0; idx < values.size(); idx++ )
             {
                 cursor = cursors.get( idx );
-                
+
                 if ( ( cursor != null ) && cursor.previous() )
                 {
                     value = cursor.get();
-                    
+
                     if ( ( getIndex < 0 ) || ( comparator.compare( value, maxValue ) > 0 ) )
                     {
                         maxValue = value;
                         getIndex = idx;
                     }
-                    
+
                     values.set( idx, value );
                 }
                 else
@@ -515,73 +522,75 @@ public class IndexCursorWrapper extends 
         else
         {
             // Move the last cursor we did a get from and recompute maximum
-           recomputeMaximum();
+            recomputeMaximum();
         }
-        
+
         int txnIdx;
         NavigableSet<IndexEntry<Object>> txnDeletes;
         boolean valueDeleted;
-        
+
         do
         {
             if ( getIndex < 0 )
             {
                 break;
             }
-            
+
             value = values.get( getIndex );
-            
+
             txnIdx = getIndex;
-            
+
             if ( txnIdx > 0 )
             {
                 txnIdx--;
             }
-            
+
             valueDeleted = false;
-            
+
             for ( ; txnIdx < deletes.size(); txnIdx++ )
             {
                 txnDeletes = deletes.get( txnIdx );
-                
-                if ( txnDeletes!= null && txnDeletes.contains( value ) )
+
+                if ( txnDeletes != null && txnDeletes.contains( value ) )
                 {
                     valueDeleted = true;
                     break;
                 }
             }
-            
+
             // If the value we get is not deleted and less than the last value we returned, then we are done
-            if ( ( valueDeleted == false ) && ( ( lastValue.getId() == null ) || ( comparator.compare( value, lastValue ) < 0 ) ) )
+            if ( ( valueDeleted == false )
+                && ( ( lastValue.getId() == null ) || ( comparator.compare( value, lastValue ) < 0 ) ) )
             {
                 break;
             }
-            
+
             // Recompute maximum
             recomputeMaximum();
-            
-        } while ( true );
-        
+
+        }
+        while ( true );
+
         return ( getIndex >= 0 );
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
     public IndexEntry<Object> get() throws Exception
     {
         checkNotClosed( "get()" );
-        
+
         if ( getIndex >= 0 )
         {
             IndexEntry<Object> value = values.get( getIndex );
-            
+
             if ( value == null )
             {
                 throw new IllegalStateException( "getIndex points to a null value" );
             }
-            
+
             /*
              * TODO fixme:
              * Upper layers might change the index entry we return. To work around this.
@@ -589,7 +598,7 @@ public class IndexCursorWrapper extends 
              * search engine is changed to avoid modifying index entries.
              */
             IndexEntry<Object> indexEntry;
-            
+
             if ( forwardIndex )
             {
                 indexEntry = new ForwardIndexEntry<Object>();
@@ -598,17 +607,17 @@ public class IndexCursorWrapper extends 
             {
                 indexEntry = new ReverseIndexEntry<Object>();
             }
-            
+
             indexEntry.setId( value.getId() );
             indexEntry.setValue( value.getValue() );
-            
+
             return indexEntry;
         }
 
         throw new InvalidCursorPositionException();
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -616,14 +625,14 @@ public class IndexCursorWrapper extends 
     public void close() throws Exception
     {
         super.close();
-        
+
         IndexCursor<Object> cursor;
         int idx;
-        
+
         for ( idx = 0; idx < cursors.size(); idx++ )
         {
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
                 cursor.close();
@@ -639,22 +648,22 @@ public class IndexCursorWrapper extends 
     public void close( Exception cause ) throws Exception
     {
         super.close( cause );
-        
+
         IndexCursor<Object> cursor;
         int idx;
-        
+
         for ( idx = 0; idx < cursors.size(); idx++ )
         {
             cursor = cursors.get( idx );
-            
+
             if ( cursor != null )
             {
                 cursor.close( cause );
             }
         }
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
@@ -663,7 +672,7 @@ public class IndexCursorWrapper extends 
         return UNSUPPORTED_MSG;
     }
 
-    
+
     /**
      * Do a get on the last cursor we got the value from and recompute the minimum
      *
@@ -675,26 +684,25 @@ public class IndexCursorWrapper extends 
         IndexEntry<Object> minValue;
         IndexEntry<Object> value;
         int idx;
-        
+
         cursor = cursors.get( getIndex );
-        
+
         if ( cursor.next() )
         {
-            values.set( getIndex , cursor.get() );
+            values.set( getIndex, cursor.get() );
         }
         else
         {
             values.set( getIndex, null );
         }
-        
-        
+
         minValue = null;
         getIndex = -1;
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             value = values.get( idx );
-            
+
             if ( value != null )
             {
                 if ( ( getIndex < 0 ) || ( comparator.compare( value, minValue ) < 0 ) )
@@ -705,7 +713,8 @@ public class IndexCursorWrapper extends 
             }
         }
     }
-    
+
+
     /**
      * Do a previous we got the value from and recompute the maximum.
      *
@@ -717,26 +726,25 @@ public class IndexCursorWrapper extends 
         IndexEntry<Object> maxValue;
         IndexEntry<Object> value;
         int idx;
-        
+
         cursor = cursors.get( getIndex );
-        
+
         if ( cursor.previous() )
         {
-            values.set( getIndex , cursor.get() );
+            values.set( getIndex, cursor.get() );
         }
         else
         {
             values.set( getIndex, null );
         }
-        
-        
+
         maxValue = null;
         getIndex = -1;
-        
+
         for ( idx = 0; idx < values.size(); idx++ )
         {
             value = values.get( idx );
-            
+
             if ( value != null )
             {
                 if ( ( getIndex < 0 ) || ( comparator.compare( value, maxValue ) > 0 ) )
@@ -747,7 +755,8 @@ public class IndexCursorWrapper extends 
             }
         }
     }
-    
+
+
     /**
      * Returns a cursor over the changes made by the given txn on the index identified by partitionDn+attributeOid. 
      *
@@ -760,10 +769,11 @@ public class IndexCursorWrapper extends 
      * @param comparator comparator that will be used to order index entries.
      * @return
      */
-    private IndexCursor<Object> getCursorFor( ReadWriteTxn txn, Dn partitionDn, String attributeOid, boolean forwardIndex,
+    private IndexCursor<Object> getCursorFor( ReadWriteTxn txn, Dn partitionDn, String attributeOid,
+        boolean forwardIndex,
         Object onlyValueKey, UUID onlyIDKey, IndexComparator<Object> comparator )
     {
-        NavigableSet<IndexEntry<Object>> changes; 
+        NavigableSet<IndexEntry<Object>> changes;
         TxnIndexCursor txnIndexCursor = null;
 
         if ( forwardIndex )
@@ -774,21 +784,21 @@ public class IndexCursorWrapper extends 
         {
             changes = txn.getReverseIndexChanges( partitionDn, attributeOid );
         }
-        
+
         if ( changes == null || ( changes.size() == 0 ) )
         {
             return null;
         }
-        
+
         Transaction curTxn = txnManager.getCurTxn();
-        
+
         if ( txn == curTxn )
         {
             NavigableSet<IndexEntry<Object>> originalChanges = changes;
             changes = new TreeSet<IndexEntry<Object>>( comparator );
             changes.addAll( originalChanges );
         }
-        
+
         return new TxnIndexCursor( changes, forwardIndex, onlyValueKey, onlyIDKey, comparator );
     }
 

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java?rev=1227712&r1=1227711&r2=1227712&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java Thu Jan  5 17:28:50 2012
@@ -43,7 +43,7 @@ public class TxnManagerFactory
 
     /** log suffix */
     private String LOG_SUFFIX = "log";
-    
+
     private boolean inited;
 
 
@@ -58,7 +58,7 @@ public class TxnManagerFactory
      */
     public TxnManagerFactory( String logFolderPath,
         int logBufferSize, long logFileSize ) throws IOException
-    {       
+    {
         Log log = new DefaultLog();
 
         try
@@ -75,24 +75,25 @@ public class TxnManagerFactory
         txnLogManager = new DefaultTxnLogManager( log, this );
 
         ( ( DefaultTxnManager ) txnManager ).init( txnLogManager );
-        
+
         inited = true;
 
     }
-    
+
+
     public void uninit()
     {
         if ( inited == false )
         {
             return;
         }
-        
+
         ( ( DefaultTxnManager ) txnManager ).uninit();
-        ( (DefaultTxnLogManager) txnLogManager).uninit();
+        ( ( DefaultTxnLogManager ) txnLogManager ).uninit();
         inited = false;
     }
-    
-    
+
+
     public TxnManager txnManagerInstance()
     {
         return txnManager;

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFileManagerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFileManagerTest.java?rev=1227712&r1=1227711&r2=1227712&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFileManagerTest.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFileManagerTest.java Thu Jan  5 17:28:50 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.shared.log;
 
+
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -35,6 +36,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+
 /**
  * Tests for the LogFileManager class
  * 
@@ -45,6 +47,7 @@ public class LogFileManagerTest
     @Rule
     public TemporaryFolder folder = new TemporaryFolder();
 
+
     @Test
     public void testCreateLogFile() throws IOException
     {
@@ -52,13 +55,13 @@ public class LogFileManagerTest
 
         assertNotNull( logFileManager );
         assertFalse( logFileManager.createLogFile( 0L ) );
-        
+
         // Now try to create the same file again :  it should return true (file already exists)
         assertTrue( logFileManager.createLogFile( 0L ) );
     }
 
-    
-    @Test( expected = FileNotFoundException.class )
+
+    @Test(expected = FileNotFoundException.class)
     public void testDeleteLogFile() throws IOException
     {
         LogFileManager logFileManager = new DefaultLogFileManager( folder.getRoot().getAbsolutePath(), "log" );
@@ -66,17 +69,17 @@ public class LogFileManagerTest
         assertNotNull( logFileManager );
         assertFalse( logFileManager.createLogFile( 0L ) );
         assertNotNull( logFileManager.getReaderForLogFile( 0L ) );
-        
+
         // Now try to delete the file
         logFileManager.deleteLogFile( 0L );
-        
+
         // This should throw a FNFE
         logFileManager.getReaderForLogFile( 0L );
-        
+
         fail();
     }
 
-    
+
     @Test
     public void testDeleteNotExistingLogFile() throws IOException
     {
@@ -88,13 +91,13 @@ public class LogFileManagerTest
 
         // Delete the file
         logFileManager.deleteLogFile( 0L );
-        
+
         // Now try to delete a not existing file : it should still be ok
         logFileManager.deleteLogFile( 1L );
     }
 
-    
-    @Test( expected = FileNotFoundException.class )
+
+    @Test(expected = FileNotFoundException.class)
     public void testRenameLogFile() throws IOException
     {
         LogFileManager logFileManager = new DefaultLogFileManager( folder.getRoot().getAbsolutePath(), "log" );
@@ -102,89 +105,89 @@ public class LogFileManagerTest
         assertNotNull( logFileManager );
         assertFalse( logFileManager.createLogFile( 0L ) );
         assertNotNull( logFileManager.getReaderForLogFile( 0L ) );
-        
+
         // Now try to rename the file
         logFileManager.rename( 0L, 1L );
-        
+
         // This should work
         assertNotNull( logFileManager.getReaderForLogFile( 1L ) );
 
         // This should throw a FNFE
         logFileManager.getReaderForLogFile( 0L );
-        
+
         fail();
     }
 
-    
+
     @Test
     public void testTruncateLogFile() throws IOException
     {
         String fileName = folder.getRoot().getAbsolutePath() + File.separatorChar + "log_0.log";
-        
+
         LogFileManager logFileManager = new DefaultLogFileManager( folder.getRoot().getAbsolutePath(), "log" );
 
         assertNotNull( logFileManager );
         assertFalse( logFileManager.createLogFile( 0L ) );
         LogFileWriter logFileWriter = logFileManager.getWriterForLogFile( 0L );
-        
+
         // Write 1024 bytes in the file
         byte[] buffer = new byte[1024];
         logFileWriter.append( buffer, 0, buffer.length );
         logFileWriter.sync();
-        
+
         // Check the file length
         File file = new File( fileName );
         assertEquals( 1024, file.length() );
-        
+
         // Now try to truncate the file
         logFileManager.truncateLogFile( 0L, 512 );
         assertEquals( 512, file.length() );
     }
-    
-    
+
+
     @Test
     public void testLogFileReaderRead() throws IOException
     {
         LogFileManager logFileManager = new DefaultLogFileManager( folder.getRoot().getAbsolutePath(), "log" );
 
         LogFileWriter logFileWriter = logFileManager.getWriterForLogFile( 0L );
-        
+
         // Write 1024 bytes in the file
         byte[] buffer = new byte[1024];
-        Arrays.fill( buffer, (byte)0xAA );
-        
+        Arrays.fill( buffer, ( byte ) 0xAA );
+
         logFileWriter.append( buffer, 0, buffer.length );
         logFileWriter.sync();
-        
+
         // Check the read operation
         LogFileReader logFileReader = logFileManager.getReaderForLogFile( 0L );
-        
+
         byte[] readBuffer = new byte[1024];
         logFileReader.read( readBuffer, 0, 1024 );
-        
+
         assertTrue( Arrays.equals( buffer, readBuffer ) );
     }
-    
-    
+
+
     @Test
     public void testLogFileReaderGetOffset() throws IOException
     {
         LogFileManager logFileManager = new DefaultLogFileManager( folder.getRoot().getAbsolutePath(), "log" );
 
         LogFileWriter logFileWriter = logFileManager.getWriterForLogFile( 0L );
-        
+
         // Write 1024 bytes in the file
         byte[] buffer = new byte[1024];
-        Arrays.fill( buffer, (byte)0xAA );
-        
+        Arrays.fill( buffer, ( byte ) 0xAA );
+
         logFileWriter.append( buffer, 0, buffer.length );
         logFileWriter.sync();
-        
+
         LogFileReader logFileReader = logFileManager.getReaderForLogFile( 0L );
 
         // check the initial offset
         assertEquals( 0L, logFileReader.getOffset() );
-        
+
         // Now, read the file
         byte[] readBuffer = new byte[1024];
         logFileReader.read( readBuffer, 0, 1024 );
@@ -192,79 +195,79 @@ public class LogFileManagerTest
         // And check the offset again
         assertEquals( 1024L, logFileReader.getOffset() );
     }
-    
-    
+
+
     @Test
     public void testLogFileReaderGetLength() throws IOException
     {
         LogFileManager logFileManager = new DefaultLogFileManager( folder.getRoot().getAbsolutePath(), "log" );
 
         LogFileWriter logFileWriter = logFileManager.getWriterForLogFile( 0L );
-        
+
         LogFileReader logFileReader = logFileManager.getReaderForLogFile( 0L );
-        
+
         // Check that the file is empty
         assertEquals( 0, logFileReader.getLength() );
 
         // Write 1024 bytes in the file
         byte[] buffer = new byte[1024];
-        Arrays.fill( buffer, (byte)0xAA );
-        
+        Arrays.fill( buffer, ( byte ) 0xAA );
+
         logFileWriter.append( buffer, 0, buffer.length );
         logFileWriter.sync();
-        
+
         // Now check that the file contains 1024 bytes
         assertEquals( 1024L, logFileReader.getLength() );
     }
-    
-    
+
+
     @Test
     public void testLogFileReaderSeek() throws IOException
     {
         LogFileManager logFileManager = new DefaultLogFileManager( folder.getRoot().getAbsolutePath(), "log" );
 
         LogFileWriter logFileWriter = logFileManager.getWriterForLogFile( 0L );
-        
+
         LogFileReader logFileReader = logFileManager.getReaderForLogFile( 0L );
-        
+
         // Write 1024 bytes in the file
         byte[] buffer = new byte[1024];
         byte[] buffer0 = new byte[256];
         byte[] buffer1 = new byte[256];
         byte[] buffer2 = new byte[256];
         byte[] buffer3 = new byte[256];
-        
+
         // The buffer will contain 0000... 1111... 2222... 3333
-        Arrays.fill( buffer0, (byte)0x00 ); 
-        Arrays.fill( buffer1, (byte)0x01 ); 
-        Arrays.fill( buffer2, (byte)0x02 ); 
-        Arrays.fill( buffer3, (byte)0x03 );
-        
+        Arrays.fill( buffer0, ( byte ) 0x00 );
+        Arrays.fill( buffer1, ( byte ) 0x01 );
+        Arrays.fill( buffer2, ( byte ) 0x02 );
+        Arrays.fill( buffer3, ( byte ) 0x03 );
+
         System.arraycopy( buffer0, 0, buffer, 0, 256 );
         System.arraycopy( buffer1, 0, buffer, 256, 256 );
         System.arraycopy( buffer2, 0, buffer, 512, 256 );
         System.arraycopy( buffer3, 0, buffer, 768, 256 );
-        
+
         logFileWriter.append( buffer, 0, buffer.length );
         logFileWriter.sync();
-        
+
         // Read the third block of 256 bytes
         byte[] readBuffer = new byte[256];
         logFileReader.seek( 512L );
         logFileReader.read( readBuffer, 0, 256 );
-        
+
         assertTrue( Arrays.equals( buffer2, readBuffer ) );
 
         // Read the first block of 256 bytes
         logFileReader.seek( 0L );
         logFileReader.read( readBuffer, 0, 256 );
-        
+
         assertTrue( Arrays.equals( buffer0, readBuffer ) );
 
         // Read the forth block of 256 bytes
         logFileReader.seek( 768L );
         logFileReader.read( readBuffer, 0, 256 );
-        
+
         assertTrue( Arrays.equals( buffer3, readBuffer ) );
     }
 }
\ No newline at end of file

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFlushScanTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFlushScanTest.java?rev=1227712&r1=1227711&r2=1227712&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFlushScanTest.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogFlushScanTest.java Thu Jan  5 17:28:50 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.shared.log;
 
+
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
@@ -37,6 +38,7 @@ import org.junit.rules.TemporaryFolder;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+
 /**
  * Test the LogFlushScan implementation
  * 
@@ -46,16 +48,16 @@ public class LogFlushScanTest
 {
     /** Logger */
     private Log log;
-    
+
     /** Log buffer size : 4096 bytes */
     private int logBufferSize = 1 << 12;
-    
+
     /** Log File Size : 8192 bytes */
     private long logFileSize = 1 << 13;
-    
+
     /** log suffix */
     private static String LOG_SUFFIX = "log";
-    
+
     @Rule
     public TemporaryFolder folder = new TemporaryFolder();
 
@@ -63,11 +65,11 @@ public class LogFlushScanTest
     /**
      * Get the Log folder
      */
-    private String getLogFolder( ) throws IOException
+    private String getLogFolder() throws IOException
     {
         File newFolder = folder.newFolder( LOG_SUFFIX );
         String file = newFolder.getAbsolutePath();
-        
+
         return file;
     }
 
@@ -84,8 +86,8 @@ public class LogFlushScanTest
     public void teardown() throws IOException
     {
     }
-    
-    
+
+
     @Test
     public void testAppendScan()
     {
@@ -94,57 +96,57 @@ public class LogFlushScanTest
         UserLogRecord logRecord = new UserLogRecord();
         byte recordData[] = new byte[dataLength];
         byte userRecord[];
-        
+
         byte writtenCounter = 1;
         byte readCounter = 0;
-        
+
         LogAnchor startingPoint = new LogAnchor();
-        
+
         try
         {
             logRecord.setData( recordData, dataLength );
             log.log( logRecord, false );
-            
+
             // Record the starting point
             startingPoint.resetLogAnchor( logRecord.getLogAnchor() );
-            
-            Arrays.fill( recordData, (byte)writtenCounter );
-            
+
+            Arrays.fill( recordData, ( byte ) writtenCounter );
+
             writtenCounter++;
-            
+
             logRecord.setData( recordData, dataLength );
             log.log( logRecord, true ); //Sync what we logged so far
-            
+
             LogScanner logScanner = log.beginScan( startingPoint );
-            
+
             while ( logScanner.getNextRecord( logRecord ) )
             {
                 userRecord = logRecord.getDataBuffer();
                 assertTrue( logRecord.getDataLength() == dataLength );
-                
+
                 for ( idx = 0; idx < dataLength; idx++ )
                 {
                     assertTrue( userRecord[idx] == readCounter );
                 }
-                
+
                 readCounter++;
             }
-            
+
             assertTrue( writtenCounter == readCounter );
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
             e.printStackTrace();
             fail();
         }
-        catch( InvalidLogException e )
+        catch ( InvalidLogException e )
         {
             e.printStackTrace();
             fail();
         }
     }
-    
-    
+
+
     @Test
     public void testLogSwitchScan()
     {
@@ -153,72 +155,72 @@ public class LogFlushScanTest
         UserLogRecord logRecord = new UserLogRecord();
         byte recordData[] = new byte[dataLength];
         byte userRecord[];
-        
+
         byte writtenCounter = 1;
         byte readCounter = 1;
-        byte maxCounter = 127; 
+        byte maxCounter = 127;
         boolean firstRecord = true;
-        
+
         LogAnchor startingPoint = new LogAnchor();
         LogAnchor endPoint = new LogAnchor();
-        
+
         try
         {
             while ( writtenCounter < maxCounter )
             {
-                Arrays.fill( recordData, (byte)writtenCounter );
-                
+                Arrays.fill( recordData, ( byte ) writtenCounter );
+
                 logRecord.setData( recordData, dataLength );
                 boolean sync = ( ( writtenCounter % 11 ) == 0 ) || ( writtenCounter == ( maxCounter - 1 ) );
                 log.log( logRecord, sync );
-                
+
                 if ( firstRecord )
                 {
-                 // Record the starting point
+                    // Record the starting point
                     startingPoint.resetLogAnchor( logRecord.getLogAnchor() );
                     firstRecord = false;
                 }
-                
+
                 if ( ( writtenCounter == ( maxCounter - 1 ) ) )
                 {
                     endPoint.resetLogAnchor( logRecord.getLogAnchor() );
                 }
-                
+
                 writtenCounter++;
             }
-            
-            assertTrue( endPoint.getLogFileNumber() > startingPoint.getLogFileNumber() ); 
-            
+
+            assertTrue( endPoint.getLogFileNumber() > startingPoint.getLogFileNumber() );
+
             LogScanner logScanner = log.beginScan( startingPoint );
-            
+
             while ( logScanner.getNextRecord( logRecord ) )
             {
                 userRecord = logRecord.getDataBuffer();
                 assertTrue( logRecord.getDataLength() == dataLength );
-                
+
                 for ( idx = 0; idx < dataLength; idx++ )
                 {
                     assertTrue( userRecord[idx] == readCounter );
                 }
-                
+
                 readCounter++;
             }
-            
+
             assertTrue( writtenCounter == readCounter );
-       }
-       catch( IOException e )
-       {
-           e.printStackTrace();
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            fail();
+        }
+        catch ( InvalidLogException e )
+        {
+            e.printStackTrace();
             fail();
         }
-       catch( InvalidLogException e )
-       {
-           e.printStackTrace();
-           fail();
-       }
     }
 
-    
+
     @Test
     public void testMultiThreadedAppend() throws InterruptedException
     {
@@ -227,53 +229,53 @@ public class LogFlushScanTest
         UserLogRecord logRecord = new UserLogRecord();
         byte recordData[] = new byte[dataLength];
         byte userRecord[];
-        
+
         LogAnchor startingPoint = new LogAnchor();
-        
+
         logRecord.setData( recordData, dataLength );
-        
+
         try
         {
             log.log( logRecord, false );
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
             e.printStackTrace();
             fail();
         }
-        catch( InvalidLogException e )
+        catch ( InvalidLogException e )
         {
             e.printStackTrace();
             fail();
         }
-        
+
         startingPoint.resetLogAnchor( logRecord.getLogAnchor() );
-        
+
         byte key = 1;
         int numThreads = 4;
         int numAppends = 64;
         int expectedSum = 0;
         int sum = 0;
         MultiThreadedAppend threads[] = new MultiThreadedAppend[numThreads];
-        
+
         for ( idx = 0; idx < numThreads; idx++ )
         {
-            threads[idx] = new MultiThreadedAppend( key , dataLength, numAppends);
+            threads[idx] = new MultiThreadedAppend( key, dataLength, numAppends );
             expectedSum += key * numAppends;
         }
-        
+
         for ( idx = 0; idx < numThreads; idx++ )
         {
             threads[idx].start();
         }
-        
+
         for ( idx = 0; idx < numThreads; idx++ )
         {
             threads[idx].join();
         }
-        
+
         LogScanner logScanner = log.beginScan( startingPoint );
-        
+
         try
         {
             while ( logScanner.getNextRecord( logRecord ) )
@@ -281,73 +283,74 @@ public class LogFlushScanTest
                 userRecord = logRecord.getDataBuffer();
                 assertTrue( logRecord.getDataLength() == dataLength );
                 key = userRecord[0];
-                
+
                 for ( idx = 0; idx < dataLength; idx++ )
                 {
                     assertTrue( userRecord[idx] == key );
                 }
-                
+
                 sum += key;
             }
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
             e.printStackTrace();
             fail();
         }
-        catch( InvalidLogException e )
+        catch ( InvalidLogException e )
         {
             e.printStackTrace();
             fail();
         }
-        
+
         assertTrue( sum == expectedSum );
     }
-    
-    
+
     class MultiThreadedAppend extends Thread
     {
         byte key;
         int dataLength;
         int numAppends;
-                
+
+
         public MultiThreadedAppend( byte key, int dataLength, int numAppends )
         {
             this.key = key;
             this.dataLength = dataLength;
             this.numAppends = numAppends;
         }
-        
-        public void run() 
+
+
+        public void run()
         {
             UserLogRecord logRecord = new UserLogRecord();
             byte recordData[] = new byte[dataLength];
             int idx;
-            
-            Arrays.fill( recordData, (byte)key );
-            
+
+            Arrays.fill( recordData, ( byte ) key );
+
             logRecord.setData( recordData, dataLength );
-            
+
             try
             {
                 for ( idx = 0; idx < numAppends; idx++ )
                 {
                     boolean sync = false;
-                    
-                    if ( ( ( idx % 3 )  == 0 ) || ( idx == numAppends - 1 ) )
+
+                    if ( ( ( idx % 3 ) == 0 ) || ( idx == numAppends - 1 ) )
                     {
                         sync = true;
                     }
-                    
+
                     log.log( logRecord, sync );
                 }
             }
-            catch( IOException e )
+            catch ( IOException e )
             {
                 e.printStackTrace();
                 fail();
             }
-            catch( InvalidLogException e )
+            catch ( InvalidLogException e )
             {
                 e.printStackTrace();
                 fail();

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogTest.java?rev=1227712&r1=1227711&r2=1227712&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogTest.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/log/LogTest.java Thu Jan  5 17:28:50 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.shared.log;
 
+
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
@@ -36,6 +37,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
+
 /**
  * Test the Log class implementation.
  *
@@ -45,7 +47,7 @@ public class LogTest
 {
     /** Logger */
     private Log log;
-    
+
     /** log suffix */
     private static String LOG_SUFFIX = "log";
 
@@ -56,11 +58,11 @@ public class LogTest
     /**
      * Get the Log folder
      */
-    private String getLogFolder( ) throws IOException
+    private String getLogFolder() throws IOException
     {
         File newFolder = folder.newFolder( LOG_SUFFIX );
         String file = newFolder.getAbsolutePath();
-        
+
         return file;
     }
 
@@ -75,53 +77,53 @@ public class LogTest
         UserLogRecord userLogRecord = new UserLogRecord();
         byte recordData[] = new byte[dataLength];
         LogAnchor startingLogAnchor = new LogAnchor();
-        
+
         try
         {
             // Log 10 buffers
             for ( int i = 0; i < 10; i++ )
             {
-                Arrays.fill( recordData, (byte )i );
-            
+                Arrays.fill( recordData, ( byte ) i );
+
                 userLogRecord.setData( recordData, dataLength );
                 log.log( userLogRecord, false );
             }
-            
+
             // Sync everything
             log.sync( LogAnchor.UNKNOWN_LSN );
-            
+
             LogScanner logScanner = log.beginScan( startingLogAnchor );
             int recordNumber = 0;
-            
+
             while ( logScanner.getNextRecord( userLogRecord ) )
             {
                 recordData = userLogRecord.getDataBuffer();
                 assertTrue( userLogRecord.getDataLength() == dataLength );
-                
+
                 for ( int idx = 0; idx < dataLength; idx++ )
                 {
                     assertTrue( recordData[idx] == recordNumber );
                 }
-                
+
                 recordNumber++;
             }
-            
+
             // Here, the expected number of record read should be 10
             assertEquals( 10, recordNumber );
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
             e.printStackTrace();
             fail();
         }
-        catch( InvalidLogException e )
+        catch ( InvalidLogException e )
         {
             e.printStackTrace();
             fail();
         }
     }
-    
-    
+
+
     @Test
     public void testLogSmallBuffer() throws IOException, InvalidLogException
     {
@@ -132,44 +134,44 @@ public class LogTest
         UserLogRecord userLogRecord = new UserLogRecord();
         byte recordData[] = new byte[dataLength];
         LogAnchor startingLogAnchor = new LogAnchor();
-        
+
         try
         {
             // Log 10 buffers
             for ( int i = 0; i < 10; i++ )
             {
-                Arrays.fill( recordData, (byte )i );
-            
+                Arrays.fill( recordData, ( byte ) i );
+
                 userLogRecord.setData( recordData, dataLength );
                 log.log( userLogRecord, true );
             }
-            
+
             LogScanner logScanner = log.beginScan( startingLogAnchor );
             int recordNumber = 0;
-            
+
             while ( logScanner.getNextRecord( userLogRecord ) )
             {
                 recordData = userLogRecord.getDataBuffer();
                 assertTrue( userLogRecord.getDataLength() == dataLength );
-                
+
                 for ( int idx = 0; idx < dataLength; idx++ )
                 {
                     assertTrue( recordData[idx] == recordNumber );
                 }
-                
+
                 recordNumber++;
             }
-            
+
             // Here, the expected number of record read should be 10, not 8...
             // assertEquals( 10, recordNumber );
             assertEquals( 10, recordNumber );
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
             e.printStackTrace();
             fail();
         }
-        catch( InvalidLogException e )
+        catch ( InvalidLogException e )
         {
             e.printStackTrace();
             fail();



Mime
View raw message