]> source.dussan.org Git - jackcess.git/commitdiff
more test speedups
authorJames Ahlborn <jtahlborn@yahoo.com>
Sun, 24 Aug 2014 03:24:22 +0000 (03:24 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Sun, 24 Aug 2014 03:24:22 +0000 (03:24 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@867 f203690c-595d-4dc9-a70b-905162fa7fd2

src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java
src/test/java/com/healthmarketscience/jackcess/CursorTest.java
src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java
src/test/java/com/healthmarketscience/jackcess/IndexTest.java
src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java

index 048555750eabd716c36c048b492e6d9f4791f545..d0564f05d10b04f72c4b653808d4c5006e6caae4 100644 (file)
@@ -74,7 +74,7 @@ public class BigIndexTest extends TestCase {
       assertEquals(0, index.getIndexData().getEntryCount());
       db.close();
 
-      DatabaseTest._autoSync = false;
+      DatabaseTest.setTestAutoSync(false);
       try {
 
         String extraText = " some random text to fill out the index and make it fill up pages with lots of extra bytes so i will keep typing until i think that i probably have enough text in the index entry so that i do not need to add as many entries in order";
@@ -203,7 +203,7 @@ public class BigIndexTest extends TestCase {
         db.close();
 
       } finally {
-        DatabaseTest._autoSync = Database.DEFAULT_AUTO_SYNC;
+        DatabaseTest.clearTestAutoSync();
       }
     }
   }
index cf55e2b6dbc3cb55d542fc08437cc8f1de73cf99..d8beff37c42b24ceb0bb62bec513d756a49bf38a 100644 (file)
@@ -60,6 +60,16 @@ public class CursorTest extends TestCase {
     super(name);
   }
 
+  @Override
+  protected void setUp() {
+    DatabaseTest.setTestAutoSync(false);
+  }
+
+  @Override
+  protected void tearDown() {
+    DatabaseTest.clearTestAutoSync();
+  }
+
   private static List<Map<String,Object>> createTestTableData()
     throws Exception
   {
index 3a45f39fb6f36c80acf7dce4dde8d663b094ea35..e146aef7839c483f701ffba24dfb2a061a762cb9 100644 (file)
@@ -85,13 +85,27 @@ public class DatabaseTest extends TestCase
   public static final TimeZone TEST_TZ =
     TimeZone.getTimeZone("America/New_York");
   
-  static boolean _autoSync = Database.DEFAULT_AUTO_SYNC;
+  private static final ThreadLocal<Boolean> _autoSync =         
+    new ThreadLocal<Boolean>();
 
 
   public DatabaseTest(String name) throws Exception {
     super(name);
   }
 
+  static void setTestAutoSync(boolean autoSync) {
+    _autoSync.set(autoSync);
+  }
+
+  static void clearTestAutoSync() {
+    _autoSync.remove();
+  }
+
+  static boolean getTestAutoSync() {
+    Boolean autoSync = _autoSync.get();
+    return ((autoSync != null) ? autoSync : Database.DEFAULT_AUTO_SYNC);
+  }
+
   public static Database open(FileFormat fileFormat, File file) 
     throws Exception 
   {
@@ -105,7 +119,7 @@ public class DatabaseTest extends TestCase
     FileChannel channel = (inMem ? MemFileChannel.newChannel(file, "r") 
                            : null);
     final Database db = new DatabaseBuilder(file).setReadOnly(true)
-      .setAutoSync(_autoSync).setChannel(channel).open();
+      .setAutoSync(getTestAutoSync()).setChannel(channel).open();
     assertEquals("Wrong JetFormat.", 
                  DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), 
                  ((DatabaseImpl)db).getFormat());
@@ -141,7 +155,7 @@ public class DatabaseTest extends TestCase
   {
     FileChannel channel = (inMem ? MemFileChannel.newChannel() : null);
     return new DatabaseBuilder(createTempFile(keep)).setFileFormat(fileFormat)
-      .setAutoSync(_autoSync).setChannel(channel).create();
+      .setAutoSync(getTestAutoSync()).setChannel(channel).create();
   }
 
 
@@ -167,7 +181,7 @@ public class DatabaseTest extends TestCase
   {
     File tmp = createTempFile(keep);
     copyFile(file, tmp);
-    Database db = new DatabaseBuilder(tmp).setAutoSync(_autoSync).open();
+    Database db = new DatabaseBuilder(tmp).setAutoSync(getTestAutoSync()).open();
     assertEquals("Wrong JetFormat.", 
                  DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(),
                  ((DatabaseImpl)db).getFormat());
@@ -644,7 +658,7 @@ public class DatabaseTest extends TestCase
     assertTrue(!bogusFile.exists());
     try {
       new DatabaseBuilder(bogusFile).setReadOnly(true).
-        setAutoSync(_autoSync).open();
+        setAutoSync(getTestAutoSync()).open();
       fail("FileNotFoundException should have been thrown");
     } catch(FileNotFoundException e) {
     }
index c2d058ae7b95b2098d2de03694dc3d0952add5ad..95cb2bea1cf1fb67ec47b56f4aca44ffc6b6a1ea 100644 (file)
@@ -56,6 +56,16 @@ public class IndexTest extends TestCase {
     super(name);
   }
 
+  @Override
+  protected void setUp() {
+    DatabaseTest.setTestAutoSync(false);
+  }
+
+  @Override
+  protected void tearDown() {
+    DatabaseTest.clearTestAutoSync();
+  }
+
   public void testByteOrder() throws Exception {
     byte b1 = (byte)0x00;
     byte b2 = (byte)0x01;
index e680fd9ead04ed88f33f6e367d125fefb22a3344..1db19b55c65dce5848060364821432c6dcc6ab18 100644 (file)
@@ -34,16 +34,13 @@ import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
 import java.util.Iterator;
-import java.util.Map;
 
 import com.healthmarketscience.jackcess.ColumnBuilder;
 import com.healthmarketscience.jackcess.Cursor;
-import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
 import com.healthmarketscience.jackcess.DatabaseBuilder;
 import com.healthmarketscience.jackcess.DatabaseTest;
-import com.healthmarketscience.jackcess.DatabaseTest;
 import com.healthmarketscience.jackcess.IndexBuilder;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
@@ -125,10 +122,16 @@ public class CodecHandlerTest extends TestCase
   private static void writeData(Table t1, Table t2, int start, int end)
     throws Exception
   {
+    Database db = t1.getDatabase();
+    ((DatabaseImpl)db).getPageChannel().startWrite();
+    try {
       for(int i = start; i < end; ++i) {
         t1.addRow(null, "rowdata-" + i + DatabaseTest.createString(100));
         t2.addRow(null, "rowdata-" + i + DatabaseTest.createString(100));
       }
+    } finally {
+      ((DatabaseImpl)db).getPageChannel().finishWrite();
+    }
 
       Cursor c1 = t1.newCursor().setIndex(t1.getPrimaryKeyIndex())
         .toCursor();
@@ -140,17 +143,22 @@ public class CodecHandlerTest extends TestCase
 
       int t1rows = 0;
       int t2rows = 0;
-      while(i1.hasNext() || i2.hasNext()) {
-        if(i1.hasNext()) {
-          checkRow(i1.next());
-          i1.remove();
-          ++t1rows;
-        }
-        if(i2.hasNext()) {
-          checkRow(i2.next());
-          i2.remove();
-          ++t2rows;
+      ((DatabaseImpl)db).getPageChannel().startWrite();
+      try {
+        while(i1.hasNext() || i2.hasNext()) {
+          if(i1.hasNext()) {
+            checkRow(i1.next());
+            i1.remove();
+            ++t1rows;
+          }
+          if(i2.hasNext()) {
+            checkRow(i2.next());
+            i2.remove();
+            ++t2rows;
+          }
         }
+      } finally {
+        ((DatabaseImpl)db).getPageChannel().finishWrite();
       }
 
       assertEquals(100, t1rows);