blob: ac5d35314598bcfbfb49089065bfc2f7d5e6df51 [file] [log] [blame]
HIGUCHI Yuta8eb6ba12016-05-21 15:01:41 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.persistence.impl;
17
18import org.junit.After;
19import org.junit.Before;
20import org.junit.Rule;
21import org.junit.rules.TemporaryFolder;
22import org.mapdb.DB;
23import org.mapdb.DBMaker;
24
25/**
26 * Utils for Tests using MapDB.
27 */
28public abstract class MapDBTest {
29
30 @Rule
31 public TemporaryFolder tmpFolder = new TemporaryFolder();
32
33 protected DB fakeDB = null;
34
35 /**
36 * Set up the database.
37 *
38 * @throws Exception if instantiation fails
39 */
40 @Before
41 public void setUpDB() throws Exception {
42 // Creates a db
43 fakeDB = DBMaker
44 .newFileDB(tmpFolder.newFile())
45 .asyncWriteEnable()
46 .commitFileSyncDisable()
47 .mmapFileEnableIfSupported()
48 .closeOnJvmShutdown()
49 .deleteFilesAfterClose()
50 .make();
51 }
52
53 /**
54 * Closes the database.
55 *
56 * @throws Exception if shutdown fails
57 */
58 @After
59 public void tearDownDB() throws Exception {
60 fakeDB.close();
61 }
62}