Madan Jampani

Simpler way to construct MapDBLog

...@@ -2,7 +2,6 @@ package org.onlab.onos.store.service.impl; ...@@ -2,7 +2,6 @@ package org.onlab.onos.store.service.impl;
2 2
3 import static org.slf4j.LoggerFactory.getLogger; 3 import static org.slf4j.LoggerFactory.getLogger;
4 4
5 -import java.io.File;
6 import java.util.ArrayList; 5 import java.util.ArrayList;
7 import java.util.Arrays; 6 import java.util.Arrays;
8 import java.util.List; 7 import java.util.List;
...@@ -129,7 +128,7 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService { ...@@ -129,7 +128,7 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService {
129 // Chronicle + OSGi issue 128 // Chronicle + OSGi issue
130 //Log consensusLog = new ChronicleLog(LOG_FILE_PREFIX + "_" + thisNode.id()); 129 //Log consensusLog = new ChronicleLog(LOG_FILE_PREFIX + "_" + thisNode.id());
131 //Log consensusLog = new KryoRegisteredInMemoryLog(); 130 //Log consensusLog = new KryoRegisteredInMemoryLog();
132 - Log consensusLog = new MapDBLog(new File(LOG_FILE_PREFIX + localNode.id()), 131 + Log consensusLog = new MapDBLog(LOG_FILE_PREFIX + localNode.id(),
133 ClusterMessagingProtocol.SERIALIZER); 132 ClusterMessagingProtocol.SERIALIZER);
134 133
135 copycat = new Copycat(stateMachine, consensusLog, cluster, copycatMessagingProtocol); 134 copycat = new Copycat(stateMachine, consensusLog, cluster, copycatMessagingProtocol);
......
...@@ -35,8 +35,8 @@ public class MapDBLog implements Log { ...@@ -35,8 +35,8 @@ public class MapDBLog implements Log {
35 private static final String LOG_NAME = "log"; 35 private static final String LOG_NAME = "log";
36 private static final String SIZE_FIELD_NAME = "size"; 36 private static final String SIZE_FIELD_NAME = "size";
37 37
38 - public MapDBLog(File dbFile, StoreSerializer serializer) { 38 + public MapDBLog(String dbFileName, StoreSerializer serializer) {
39 - this.dbFile = dbFile; 39 + this.dbFile = new File(dbFileName);
40 this.serializer = serializer; 40 this.serializer = serializer;
41 } 41 }
42 42
......
...@@ -51,13 +51,13 @@ public class MapDBLogTest { ...@@ -51,13 +51,13 @@ public class MapDBLogTest {
51 51
52 @Test(expected = IllegalStateException.class) 52 @Test(expected = IllegalStateException.class)
53 public void testAssertOpen() { 53 public void testAssertOpen() {
54 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 54 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
55 log.size(); 55 log.size();
56 } 56 }
57 57
58 @Test 58 @Test
59 public void testAppendEntry() throws IOException { 59 public void testAppendEntry() throws IOException {
60 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 60 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
61 log.open(); 61 log.open();
62 log.appendEntry(TEST_ENTRY1); 62 log.appendEntry(TEST_ENTRY1);
63 OperationEntry first = log.firstEntry(); 63 OperationEntry first = log.firstEntry();
...@@ -72,7 +72,7 @@ public class MapDBLogTest { ...@@ -72,7 +72,7 @@ public class MapDBLogTest {
72 72
73 @Test 73 @Test
74 public void testAppendEntries() throws IOException { 74 public void testAppendEntries() throws IOException {
75 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 75 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
76 log.open(); 76 log.open();
77 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3); 77 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3);
78 OperationEntry first = log.firstEntry(); 78 OperationEntry first = log.firstEntry();
...@@ -90,7 +90,7 @@ public class MapDBLogTest { ...@@ -90,7 +90,7 @@ public class MapDBLogTest {
90 90
91 @Test 91 @Test
92 public void testDelete() throws IOException { 92 public void testDelete() throws IOException {
93 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 93 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
94 log.open(); 94 log.open();
95 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2); 95 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2);
96 log.delete(); 96 log.delete();
...@@ -104,7 +104,7 @@ public class MapDBLogTest { ...@@ -104,7 +104,7 @@ public class MapDBLogTest {
104 104
105 @Test 105 @Test
106 public void testGetEntries() throws IOException { 106 public void testGetEntries() throws IOException {
107 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 107 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
108 log.open(); 108 log.open();
109 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 109 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
110 Assert.assertEquals( 110 Assert.assertEquals(
...@@ -123,7 +123,7 @@ public class MapDBLogTest { ...@@ -123,7 +123,7 @@ public class MapDBLogTest {
123 123
124 @Test 124 @Test
125 public void testRemoveAfter() throws IOException { 125 public void testRemoveAfter() throws IOException {
126 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 126 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
127 log.open(); 127 log.open();
128 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 128 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
129 log.removeAfter(1); 129 log.removeAfter(1);
...@@ -135,7 +135,7 @@ public class MapDBLogTest { ...@@ -135,7 +135,7 @@ public class MapDBLogTest {
135 135
136 @Test 136 @Test
137 public void testAddAfterRemove() throws IOException { 137 public void testAddAfterRemove() throws IOException {
138 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 138 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
139 log.open(); 139 log.open();
140 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 140 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
141 log.removeAfter(1); 141 log.removeAfter(1);
...@@ -150,7 +150,7 @@ public class MapDBLogTest { ...@@ -150,7 +150,7 @@ public class MapDBLogTest {
150 150
151 @Test 151 @Test
152 public void testClose() throws IOException { 152 public void testClose() throws IOException {
153 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 153 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
154 Assert.assertFalse(log.isOpen()); 154 Assert.assertFalse(log.isOpen());
155 log.open(); 155 log.open();
156 Assert.assertTrue(log.isOpen()); 156 Assert.assertTrue(log.isOpen());
...@@ -160,7 +160,7 @@ public class MapDBLogTest { ...@@ -160,7 +160,7 @@ public class MapDBLogTest {
160 160
161 @Test 161 @Test
162 public void testReopen() throws IOException { 162 public void testReopen() throws IOException {
163 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 163 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
164 log.open(); 164 log.open();
165 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 165 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
166 log.close(); 166 log.close();
...@@ -180,7 +180,7 @@ public class MapDBLogTest { ...@@ -180,7 +180,7 @@ public class MapDBLogTest {
180 180
181 @Test 181 @Test
182 public void testCompact() throws IOException { 182 public void testCompact() throws IOException {
183 - Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER); 183 + Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
184 log.open(); 184 log.open();
185 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4); 185 log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
186 log.compact(3, TEST_SNAPSHOT_ENTRY); 186 log.compact(3, TEST_SNAPSHOT_ENTRY);
......