提交 0302903b authored 作者: Thomas Mueller's avatar Thomas Mueller

Additional tests for the new LOB storage

上级 7648963e
......@@ -6,6 +6,7 @@
*/
package org.h2.test;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
......@@ -1499,5 +1500,40 @@ public abstract class TestBase {
throw new RuntimeException(e);
}
}
/**
* Construct a stream of 20 KB that fails while reading with the provided
* exception.
*
* @param e the exception
* @return the stream
*/
public static ByteArrayInputStream createFailingStream(final Exception e) {
return new ByteArrayInputStream(new byte[20 * 1024]) {
@Override
public int read(byte[] buffer, int off, int len) {
if (this.pos > 10 * 1024) {
throwException(e);
}
return super.read(buffer, off, len);
}
};
}
/**
* Throw a checked exception, without having to declare the method as
* throwing a checked exception.
*
* @param e the exception to throw
*/
public static void throwException(Throwable e) {
TestBase.<RuntimeException>throwThis(e);
}
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throwThis(Throwable e) throws E {
throw (E) e;
}
}
......@@ -21,6 +21,7 @@ import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.jdbc.JdbcConnection;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.db.TransactionStore;
import org.h2.store.fs.FileUtils;
......@@ -75,9 +76,37 @@ public class TestMVTableEngine extends TestBase {
}
private void testGarbageCollectionForLOB() throws SQLException {
// TODO Auto-generated method stub
FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn;
Statement stat;
String url = "mvstore;MV_STORE=TRUE";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id int, data blob)");
stat.execute("insert into test select x, repeat('0', 10000) from system_range(1, 10)");
stat.execute("drop table test");
stat.equals("call @temp := cast(repeat('0', 10000) as blob)");
stat.execute("create table test2(id int, data blob)");
PreparedStatement prep = conn.prepareStatement("insert into test2 values(?, ?)");
prep.setInt(1, 1);
assertThrows(ErrorCode.IO_EXCEPTION_1, prep).
setBinaryStream(1, createFailingStream(new IOException()));
prep.setInt(1, 2);
assertThrows(ErrorCode.IO_EXCEPTION_1, prep).
setBinaryStream(1, createFailingStream(new IllegalStateException()));
conn.close();
MVStore s = MVStore.open(getBaseDir()+ "/mvstore.mv.db");
assertTrue(s.hasMap("lobData"));
MVMap<Long, byte[]> lobData = s.openMap("lobData");
assertEquals(0, lobData.sizeAsLong());
assertTrue(s.hasMap("lobMap"));
MVMap<Long, byte[]> lobMap = s.openMap("lobMap");
assertEquals(0, lobMap.sizeAsLong());
assertTrue(s.hasMap("lobRef"));
MVMap<Long, byte[]> lobRef = s.openMap("lobRef");
assertEquals(0, lobRef.sizeAsLong());
s.close();
}
private void testSpatial() throws SQLException {
......
......@@ -61,34 +61,13 @@ public class TestStreamStore extends TestBase {
StreamStore s = new StreamStore(map);
s.setMaxBlockSize(1024);
assertThrows(IOException.class, s).
put(failingStream(new IOException()));
put(createFailingStream(new IOException()));
assertEquals(0, map.size());
// the runtime exception is converted to an IOException
assertThrows(IOException.class, s).
put(failingStream(new IllegalStateException()));
put(createFailingStream(new IllegalStateException()));
assertEquals(0, map.size());
}
static void throwUnchecked(Throwable e) {
TestStreamStore.<RuntimeException>throwThis(e);
}
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throwThis(Throwable e) throws E {
throw (E) e;
}
private static ByteArrayInputStream failingStream(final Exception e) {
return new ByteArrayInputStream(new byte[20 * 1024]) {
@Override
public int read(byte[] buffer, int off, int len) {
if (this.pos > 10 * 1024) {
throwUnchecked(e);
}
return super.read(buffer, off, len);
}
};
}
private void testReadCount() throws IOException {
String fileName = getBaseDir() + "/testReadCount.h3";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论