Madan Jampani

Simpler way to construct MapDBLog

......@@ -2,7 +2,6 @@ package org.onlab.onos.store.service.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -129,7 +128,7 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService {
// Chronicle + OSGi issue
//Log consensusLog = new ChronicleLog(LOG_FILE_PREFIX + "_" + thisNode.id());
//Log consensusLog = new KryoRegisteredInMemoryLog();
Log consensusLog = new MapDBLog(new File(LOG_FILE_PREFIX + localNode.id()),
Log consensusLog = new MapDBLog(LOG_FILE_PREFIX + localNode.id(),
ClusterMessagingProtocol.SERIALIZER);
copycat = new Copycat(stateMachine, consensusLog, cluster, copycatMessagingProtocol);
......
......@@ -35,8 +35,8 @@ public class MapDBLog implements Log {
private static final String LOG_NAME = "log";
private static final String SIZE_FIELD_NAME = "size";
public MapDBLog(File dbFile, StoreSerializer serializer) {
this.dbFile = dbFile;
public MapDBLog(String dbFileName, StoreSerializer serializer) {
this.dbFile = new File(dbFileName);
this.serializer = serializer;
}
......@@ -277,4 +277,4 @@ public class MapDBLog implements Log {
}
});
}
}
\ No newline at end of file
}
......
......@@ -51,13 +51,13 @@ public class MapDBLogTest {
@Test(expected = IllegalStateException.class)
public void testAssertOpen() {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.size();
}
@Test
public void testAppendEntry() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntry(TEST_ENTRY1);
OperationEntry first = log.firstEntry();
......@@ -72,7 +72,7 @@ public class MapDBLogTest {
@Test
public void testAppendEntries() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3);
OperationEntry first = log.firstEntry();
......@@ -90,7 +90,7 @@ public class MapDBLogTest {
@Test
public void testDelete() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntries(TEST_ENTRY1, TEST_ENTRY2);
log.delete();
......@@ -104,7 +104,7 @@ public class MapDBLogTest {
@Test
public void testGetEntries() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
Assert.assertEquals(
......@@ -123,7 +123,7 @@ public class MapDBLogTest {
@Test
public void testRemoveAfter() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
log.removeAfter(1);
......@@ -135,7 +135,7 @@ public class MapDBLogTest {
@Test
public void testAddAfterRemove() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
log.removeAfter(1);
......@@ -150,7 +150,7 @@ public class MapDBLogTest {
@Test
public void testClose() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
Assert.assertFalse(log.isOpen());
log.open();
Assert.assertTrue(log.isOpen());
......@@ -160,7 +160,7 @@ public class MapDBLogTest {
@Test
public void testReopen() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
log.close();
......@@ -180,7 +180,7 @@ public class MapDBLogTest {
@Test
public void testCompact() throws IOException {
Log log = new MapDBLog(new File(DB_FILE_NAME), SERIALIZER);
Log log = new MapDBLog(DB_FILE_NAME, SERIALIZER);
log.open();
log.appendEntries(TEST_ENTRY1, TEST_ENTRY2, TEST_ENTRY3, TEST_ENTRY4);
log.compact(3, TEST_SNAPSHOT_ENTRY);
......