Yuta HIGUCHI
Committed by Ray Milkey

MapDBLogTest: use Temp file

Change-Id: I7a6647ffa354913d3e6aa08de03f5a15e03753d7
...@@ -22,7 +22,6 @@ import com.google.common.testing.EqualsTester; ...@@ -22,7 +22,6 @@ import com.google.common.testing.EqualsTester;
22 */ 22 */
23 public class MapDBLogTest { 23 public class MapDBLogTest {
24 24
25 - private static final String DB_FILE_NAME = "mapdbTest";
26 private static final StoreSerializer SERIALIZER = ClusterMessagingProtocol.SERIALIZER; 25 private static final StoreSerializer SERIALIZER = ClusterMessagingProtocol.SERIALIZER;
27 private static final Entry TEST_ENTRY1 = new OperationEntry(1, "test1"); 26 private static final Entry TEST_ENTRY1 = new OperationEntry(1, "test1");
28 private static final Entry TEST_ENTRY2 = new OperationEntry(2, "test12"); 27 private static final Entry TEST_ENTRY2 = new OperationEntry(2, "test12");
...@@ -38,26 +37,31 @@ public class MapDBLogTest { ...@@ -38,26 +37,31 @@ public class MapDBLogTest {
38 37
39 private static final long TEST_SNAPSHOT_ENTRY_SIZE = SERIALIZER.encode(TEST_SNAPSHOT_ENTRY).length; 38 private static final long TEST_SNAPSHOT_ENTRY_SIZE = SERIALIZER.encode(TEST_SNAPSHOT_ENTRY).length;
40 39
40 + private String dbFileName;
41 +
42 +
41 @Before 43 @Before
42 public void setUp() throws Exception { 44 public void setUp() throws Exception {
45 + File logFile = File.createTempFile("mapdbTest", null);
46 + dbFileName = logFile.getAbsolutePath();
43 } 47 }
44 48
45 @After 49 @After
46 public void tearDown() throws Exception { 50 public void tearDown() throws Exception {
47 - Files.deleteIfExists(new File(DB_FILE_NAME).toPath()); 51 + Files.deleteIfExists(new File(dbFileName).toPath());
48 - Files.deleteIfExists(new File(DB_FILE_NAME + ".t").toPath()); 52 + Files.deleteIfExists(new File(dbFileName + ".t").toPath());
49 - Files.deleteIfExists(new File(DB_FILE_NAME + ".p").toPath()); 53 + Files.deleteIfExists(new File(dbFileName + ".p").toPath());
50 } 54 }
51 55
52 @Test(expected = IllegalStateException.class) 56 @Test(expected = IllegalStateException.class)
53 public void testAssertOpen() { 57 public void testAssertOpen() {
54 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 58 + Log log = new MapDBLog(dbFileName, SERIALIZER);
55 log.size(); 59 log.size();
56 } 60 }
57 61
58 @Test 62 @Test
59 public void testAppendEntry() throws IOException { 63 public void testAppendEntry() throws IOException {
60 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 64 + Log log = new MapDBLog(dbFileName, SERIALIZER);
61 log.open(); 65 log.open();
62 log.appendEntry(TEST_ENTRY1); 66 log.appendEntry(TEST_ENTRY1);
63 OperationEntry first = log.firstEntry(); 67 OperationEntry first = log.firstEntry();
...@@ -72,7 +76,7 @@ public class MapDBLogTest { ...@@ -72,7 +76,7 @@ public class MapDBLogTest {
72 76
73 @Test 77 @Test
74 public void testAppendEntries() throws IOException { 78 public void testAppendEntries() throws IOException {
75 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 79 + Log log = new MapDBLog(dbFileName, SERIALIZER);
76 log.open(); 80 log.open();
77 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3); 81 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3);
78 OperationEntry first = log.firstEntry(); 82 OperationEntry first = log.firstEntry();
...@@ -90,7 +94,7 @@ public class MapDBLogTest { ...@@ -90,7 +94,7 @@ public class MapDBLogTest {
90 94
91 @Test 95 @Test
92 public void testDelete() throws IOException { 96 public void testDelete() throws IOException {
93 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 97 + Log log = new MapDBLog(dbFileName, SERIALIZER);
94 log.open(); 98 log.open();
95 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2); 99 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2);
96 log.delete(); 100 log.delete();
...@@ -104,7 +108,7 @@ public class MapDBLogTest { ...@@ -104,7 +108,7 @@ public class MapDBLogTest {
104 108
105 @Test 109 @Test
106 public void testGetEntries() throws IOException { 110 public void testGetEntries() throws IOException {
107 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 111 + Log log = new MapDBLog(dbFileName, SERIALIZER);
108 log.open(); 112 log.open();
109 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 113 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
110 Assert.assertEquals( 114 Assert.assertEquals(
...@@ -123,7 +127,7 @@ public class MapDBLogTest { ...@@ -123,7 +127,7 @@ public class MapDBLogTest {
123 127
124 @Test 128 @Test
125 public void testRemoveAfter() throws IOException { 129 public void testRemoveAfter() throws IOException {
126 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 130 + Log log = new MapDBLog(dbFileName, SERIALIZER);
127 log.open(); 131 log.open();
128 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 132 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
129 log.removeAfter(1); 133 log.removeAfter(1);
...@@ -135,7 +139,7 @@ public class MapDBLogTest { ...@@ -135,7 +139,7 @@ public class MapDBLogTest {
135 139
136 @Test 140 @Test
137 public void testAddAfterRemove() throws IOException { 141 public void testAddAfterRemove() throws IOException {
138 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 142 + Log log = new MapDBLog(dbFileName, SERIALIZER);
139 log.open(); 143 log.open();
140 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 144 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
141 log.removeAfter(1); 145 log.removeAfter(1);
...@@ -150,7 +154,7 @@ public class MapDBLogTest { ...@@ -150,7 +154,7 @@ public class MapDBLogTest {
150 154
151 @Test 155 @Test
152 public void testClose() throws IOException { 156 public void testClose() throws IOException {
153 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 157 + Log log = new MapDBLog(dbFileName, SERIALIZER);
154 Assert.assertFalse(log.isOpen()); 158 Assert.assertFalse(log.isOpen());
155 log.open(); 159 log.open();
156 Assert.assertTrue(log.isOpen()); 160 Assert.assertTrue(log.isOpen());
...@@ -160,7 +164,7 @@ public class MapDBLogTest { ...@@ -160,7 +164,7 @@ public class MapDBLogTest {
160 164
161 @Test 165 @Test
162 public void testReopen() throws IOException { 166 public void testReopen() throws IOException {
163 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 167 + Log log = new MapDBLog(dbFileName, SERIALIZER);
164 log.open(); 168 log.open();
165 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 169 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
166 log.close(); 170 log.close();
...@@ -180,7 +184,7 @@ public class MapDBLogTest { ...@@ -180,7 +184,7 @@ public class MapDBLogTest {
180 184
181 @Test 185 @Test
182 public void testCompact() throws IOException { 186 public void testCompact() throws IOException {
183 - Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER); 187 + Log log = new MapDBLog(dbFileName, SERIALIZER);
184 log.open(); 188 log.open();
185 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 189 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
186 log.compact(3, TEST_SNAPSHOT_ENTRY); 190 log.compact(3, TEST_SNAPSHOT_ENTRY);
......