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";
db.close();
} finally {
- DatabaseTest._autoSync = Database.DEFAULT_AUTO_SYNC;
+ DatabaseTest.clearTestAutoSync();
}
}
}
super(name);
}
+ @Override
+ protected void setUp() {
+ DatabaseTest.setTestAutoSync(false);
+ }
+
+ @Override
+ protected void tearDown() {
+ DatabaseTest.clearTestAutoSync();
+ }
+
private static List<Map<String,Object>> createTestTableData()
throws Exception
{
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
{
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());
{
FileChannel channel = (inMem ? MemFileChannel.newChannel() : null);
return new DatabaseBuilder(createTempFile(keep)).setFileFormat(fileFormat)
- .setAutoSync(_autoSync).setChannel(channel).create();
+ .setAutoSync(getTestAutoSync()).setChannel(channel).create();
}
{
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());
assertTrue(!bogusFile.exists());
try {
new DatabaseBuilder(bogusFile).setReadOnly(true).
- setAutoSync(_autoSync).open();
+ setAutoSync(getTestAutoSync()).open();
fail("FileNotFoundException should have been thrown");
} catch(FileNotFoundException e) {
}
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;
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;
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();
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);