提交 e97c0d21 authored 作者: Thomas Mueller's avatar Thomas Mueller

The database file locking mechanism "FS" (;FILE_LOCK=FS) did not work on Linux…

The database file locking mechanism "FS" (;FILE_LOCK=FS) did not work on Linux since version 1.3.161.
上级 473bfee0
......@@ -489,7 +489,7 @@ public class FileStore {
public synchronized boolean tryLock() {
try {
lock = file.tryLock();
return true;
return lock != null;
} catch (Exception e) {
// ignore OverlappingFileLockException
return false;
......
......@@ -132,6 +132,7 @@ import org.h2.test.unit.TestDateIso8601;
import org.h2.test.unit.TestExit;
import org.h2.test.unit.TestFile;
import org.h2.test.unit.TestFileLock;
import org.h2.test.unit.TestFileLockProcess;
import org.h2.test.unit.TestFileLockSerialized;
import org.h2.test.unit.TestFileSystem;
import org.h2.test.unit.TestFtp;
......@@ -344,18 +345,15 @@ java org.h2.test.TestAll timer
System.setProperty("h2.delayWrongPasswordMax", "0");
System.setProperty("h2.useThreadContextClassLoader", "true");
int testing;
// System.setProperty("h2.modifyOnWrite", "true");
int testWith_TCP_PROTOCOL_VERSION_10;
int todoSupportTrailingSemicolonsInDatabaseUrl;
// System.setProperty("h2.storeLocalTime", "true");
// speedup
// System.setProperty("h2.syncMethod", "");
int testMultiThreadedBackup;
/*
recovery tests with small freeList pages, page size 64
......@@ -672,6 +670,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestExit().runTest(this);
new TestFile().runTest(this);
new TestFileLock().runTest(this);
new TestFileLockProcess().runTest(this);
new TestFileLockSerialized().runTest(this);
new TestFtp().runTest(this);
new TestFileSystem().runTest(this);
......
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import org.h2.test.TestBase;
import org.h2.test.utils.SelfDestructor;
import org.h2.util.New;
/**
* Tests database file locking.
* A new process is started.
*/
public class TestFileLockProcess extends TestBase {
/**
* This method is called when executing this application from the command
* line.
*
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
SelfDestructor.startCountdown(60);
if (args.length == 0) {
TestBase.createCaller().init().test();
return;
}
String url = args[0];
TestFileLockProcess app = new TestFileLockProcess();
app.execute(url);
}
private void execute(String url) {
org.h2.Driver.load();
try {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(url);
System.out.println("!");
conn.close();
} catch (Exception e) {
// failed - expected
}
}
public void test() throws Exception {
if (config.codeCoverage || config.networked) {
return;
}
if (getBaseDir().indexOf(':') > 0) {
return;
}
deleteDb("lock");
String url = "jdbc:h2:"+getBaseDir()+"/lock";
test(50, url);
println("socket");
test(4, url + ";file_lock=socket");
println("fs");
test(4, url + ";file_lock=fs");
deleteDb("lock");
}
public void test(int count, String url) throws Exception {
Connection conn = DriverManager.getConnection(url);
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = { "java", selfDestruct,
"-cp", getClassPath(),
getClass().getName(), url };
ArrayList<Process> processes = New.arrayList();
for (int i = 0; i < count; i++) {
Thread.sleep(100);
if (i % 10 == 0) {
println(i + "/" + count);
}
Process proc = Runtime.getRuntime().exec(procDef);
processes.add(proc);
}
for (int i = 0; i < count; i++) {
Process proc = processes.get(i);
StringBuilder buff = new StringBuilder();
while (true) {
int ch = proc.getErrorStream().read();
if (ch < 0) {
break;
}
System.out.print((char) ch);
buff.append((char) ch);
}
while (true) {
int ch = proc.getInputStream().read();
if (ch < 0) {
break;
}
System.out.print((char) ch);
buff.append((char) ch);
}
proc.waitFor();
assertEquals(0, proc.exitValue());
assertTrue(buff.toString(), buff.length() == 0);
}
Thread.sleep(100);
conn.close();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论