提交 aa55aed2 authored 作者: Noel Grandin's avatar Noel Grandin

implement support for partial writes when testing MVStore

上级 fdc5aa12
......@@ -11,7 +11,6 @@ import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.MVStoreTool;
import org.h2.store.fs.FilePath;
......@@ -129,6 +128,7 @@ public class TestReorderWrites extends TestBase {
private void testFileSystem() throws IOException {
FilePathReorderWrites fs = FilePathReorderWrites.register();
FilePathReorderWrites.setPartialWrites(true);
String fileName = "reorder:memFS:test";
ByteBuffer empty = ByteBuffer.allocate(1024);
Random r = new Random(1);
......
......@@ -71,11 +71,11 @@ public class FilePathReorderWrites extends FilePathWrapper {
*
* @param partialWrites true to enable
*/
public void setPartialWrites(boolean partialWrites) {
public static void setPartialWrites(boolean partialWrites) {
FilePathReorderWrites.partialWrites = partialWrites;
}
boolean getPartialWrites() {
static boolean getPartialWrites() {
return partialWrites;
}
......@@ -261,13 +261,26 @@ class FileReorderWrites extends FileBase {
@Override
public int write(ByteBuffer src) throws IOException {
return addOperation(new FileWriteOperation(id++, readBase.position(), src));
return write(src, readBase.position());
}
@Override
public int write(ByteBuffer src, long position) throws IOException {
if (FilePathReorderWrites.getPartialWrites() && src.remaining() > 2) {
ByteBuffer buf1 = src.slice();
ByteBuffer buf2 = src.slice();
int len1 = src.remaining() / 2;
int len2 = src.remaining() - len1;
buf1.limit(buf1.limit() - len2);
buf2.position(buf2.position() + len1);
int x = addOperation(new FileWriteOperation(id++, position, buf1));
x += addOperation(
new FileWriteOperation(id++, position + len1, buf2));
return x;
} else {
return addOperation(new FileWriteOperation(id++, position, src));
}
}
private void checkError() throws IOException {
if (closed) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论