提交 41b3594c authored 作者: noelgrandin's avatar noelgrandin

when closing an MVStore we should clear the filechannel to prevent

(a) any accidental further access to it
(b) throwing an exception if the client code calls close() more than once
上级 e8dbf3a7
...@@ -50,6 +50,7 @@ public class TestMVStore extends TestBase { ...@@ -50,6 +50,7 @@ public class TestMVStore extends TestBase {
testRandom(); testRandom();
testKeyValueClasses(); testKeyValueClasses();
testIterate(); testIterate();
testCloseTwice();
testSimple(); testSimple();
} }
...@@ -771,6 +772,20 @@ public class TestMVStore extends TestBase { ...@@ -771,6 +772,20 @@ public class TestMVStore extends TestBase {
s.close(); s.close();
} }
private void testCloseTwice() {
String fileName = getBaseDir() + "/testCloseTwice.h3";
FileUtils.delete(fileName);
MVStore s = openStore(fileName);
MVMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
for (int i = 0; i < 3; i++) {
m.put(i, "hello " + i);
}
s.store();
// closing twice should be fine
s.close();
s.close();
}
private void testSimple() { private void testSimple() {
String fileName = getBaseDir() + "/testSimple.h3"; String fileName = getBaseDir() + "/testSimple.h3";
FileUtils.delete(fileName); FileUtils.delete(fileName);
......
...@@ -450,8 +450,9 @@ public class MVStore { ...@@ -450,8 +450,9 @@ public class MVStore {
maps.clear(); maps.clear();
mapsChanged.clear(); mapsChanged.clear();
} catch (Exception e) { } catch (Exception e) {
file = null;
throw convert(e); throw convert(e);
} finally {
file = null;
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论