use of org.h2.store.fs.FilePathMem in project h2database by h2database.
the class TestOutOfMemory method testMVStoreUsingInMemoryFileSystem.
private void testMVStoreUsingInMemoryFileSystem() {
FilePath.register(new FilePathMem());
String fileName = "memFS:" + getTestName();
final AtomicReference<Throwable> exRef = new AtomicReference<>();
MVStore store = new MVStore.Builder().fileName(fileName).backgroundExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
exRef.compareAndSet(null, e);
}
}).open();
try {
Map<Integer, byte[]> map = store.openMap("test");
Random r = new Random(1);
try {
for (int i = 0; i < 100; i++) {
byte[] data = new byte[10 * 1024 * 1024];
r.nextBytes(data);
map.put(i, data);
}
Throwable throwable = exRef.get();
if (throwable instanceof OutOfMemoryError)
throw (OutOfMemoryError) throwable;
if (throwable instanceof IllegalStateException)
throw (IllegalStateException) throwable;
fail();
} catch (OutOfMemoryError | IllegalStateException e) {
// expected
}
try {
store.close();
} catch (IllegalStateException e) {
// expected
}
store.closeImmediately();
store = MVStore.open(fileName);
store.openMap("test");
store.close();
} finally {
// just in case, otherwise if this test suffers a spurious failure,
// succeeding tests will too, because they will OOM
store.closeImmediately();
FileUtils.delete(fileName);
}
}
Aggregations