You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/10/26 17:59:53 UTC
svn commit: r1189279 - in
/directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log:
LogFileManagerTest.java LogFlushScanTest.java LogTest.java
Author: elecharny
Date: Wed Oct 26 15:59:52 2011
New Revision: 1189279
URL: http://svn.apache.org/viewvc?rev=1189279&view=rev
Log:
o Added a test for Log (it's failing, so it's just added to demonstrate the issue)
Added:
directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogTest.java
Modified:
directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFileManagerTest.java
directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java
Modified: directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFileManagerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFileManagerTest.java?rev=1189279&r1=1189278&r2=1189279&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFileManagerTest.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFileManagerTest.java Wed Oct 26 15:59:52 2011
@@ -37,6 +37,7 @@ import static org.junit.Assert.fail;
/**
* Tests for the LogFileManager class
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class LogFileManagerTest
Modified: directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java?rev=1189279&r1=1189278&r2=1189279&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogFlushScanTest.java Wed Oct 26 15:59:52 2011
@@ -32,6 +32,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
/**
+ * Test the LogFlushScan implementation
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
Added: directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogTest.java?rev=1189279&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogTest.java (added)
+++ directory/apacheds/branches/apacheds-txns/core/src/test/java/org/apache/directory/server/core/log/LogTest.java Wed Oct 26 15:59:52 2011
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.core.log;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * Test the Log class implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LogTest
+{
+ /** 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();
+
+
+ /**
+ * Get the Log folder
+ */
+ private String getLogFolder( ) throws IOException
+ {
+ String file = folder.newFolder( LOG_SUFFIX ).getAbsolutePath();
+
+ return file;
+ }
+
+
+ @Before
+ public void setup() throws IOException, InvalidLogException
+ {
+ log = new DefaultLog();
+ log.init( getLogFolder(), LOG_SUFFIX, logBufferSize, logFileSize );
+ }
+
+
+ @Test
+ public void testLog()
+ {
+ int idx;
+ int dataLength = 1024;
+ UserLogRecord userLogRecord = new UserLogRecord();
+ byte recordData[] = new byte[dataLength];
+
+ try
+ {
+ // Log 10 buffers
+ for ( int i = 0; i < 10; i++ )
+ {
+ Arrays.fill( recordData, (byte )i );
+
+ userLogRecord.setData( recordData, dataLength );
+ log.log( userLogRecord, false );
+ }
+
+ LogScanner logScanner = log.beginScan();
+ int recordNumber = 0;
+
+ while ( logScanner.getNextRecord( userLogRecord ) )
+ {
+ recordData = userLogRecord.getDataBuffer();
+ assertTrue( userLogRecord.getDataLength() == dataLength );
+
+ for ( 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( 8, recordNumber );
+ }
+ catch( IOException e )
+ {
+ e.printStackTrace();
+ fail();
+ }
+ catch( InvalidLogException e )
+ {
+ e.printStackTrace();
+ fail();
+ }
+ }
+}