提交 423a9972 authored 作者: Thomas Mueller's avatar Thomas Mueller

Lob in database: storing lob objects was not correctly synchronized. This was…

Lob in database: storing lob objects was not correctly synchronized. This was specially a problem when using Connection.createBlob() / createClob().
上级 b336aba3
...@@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream; ...@@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream;
import java.io.CharArrayReader; import java.io.CharArrayReader;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.sql.Blob; import java.sql.Blob;
...@@ -28,6 +29,7 @@ import org.h2.constant.SysProperties; ...@@ -28,6 +29,7 @@ import org.h2.constant.SysProperties;
import org.h2.store.FileLister; import org.h2.store.FileLister;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles; import org.h2.tools.DeleteDbFiles;
import org.h2.util.Task;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -51,6 +53,7 @@ public class TestLob extends TestBase { ...@@ -51,6 +53,7 @@ public class TestLob extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
testConcurrentCreate();
testLobInLargeResult(); testLobInLargeResult();
testUniqueIndex(); testUniqueIndex();
testConvert(); testConvert();
...@@ -89,6 +92,44 @@ public class TestLob extends TestBase { ...@@ -89,6 +92,44 @@ public class TestLob extends TestBase {
IOUtils.deleteRecursive(TEMP_DIR, true); IOUtils.deleteRecursive(TEMP_DIR, true);
} }
public void testConcurrentCreate() throws Exception {
deleteDb("lob");
final Connection conn1 = getConnection("lob");
final Connection conn2 = getConnection("lob");
conn1.setAutoCommit(false);
conn2.setAutoCommit(false);
final byte[] buffer = new byte[10000];
Task task1 = new Task() {
public void call() throws Exception {
while (!stop) {
Blob b = conn1.createBlob();
OutputStream out = b.setBinaryStream(1);
out.write(buffer);
out.close();
}
}
};
Task task2 = new Task() {
public void call() throws Exception {
while (!stop) {
Blob b = conn2.createBlob();
OutputStream out = b.setBinaryStream(1);
out.write(buffer);
out.close();
}
}
};
task1.execute();
task2.execute();
Thread.sleep(1000);
task1.get();
task2.get();
conn1.close();
conn2.close();
}
private void testLobInLargeResult() throws Exception { private void testLobInLargeResult() throws Exception {
deleteDb("lob"); deleteDb("lob");
Connection conn; Connection conn;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论