Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 323:c788d2c2881f
create logDirectory
author | suruga |
---|---|
date | Thu, 13 Apr 2017 19:16:59 +0900 |
parents | d4bcf62ef743 |
children | a0bcbc9a1a46 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/DataReadBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/DataWriteBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/JungleLogCopyBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJournal.java src/test/java/jp/ac/u_ryukyu/ie/cr/data/MsgPack.java src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/DataWriteBufferTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/PersistentJournalTest.java |
diffstat | 7 files changed, 42 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/DataReadBenchMark.java Wed Apr 12 19:30:06 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/DataReadBenchMark.java Thu Apr 13 19:16:59 2017 +0900 @@ -27,7 +27,7 @@ public static void main(String[] args) throws IOException { - PersistentJournal journal1 = new PersistentJournal(new File("./log/commit.log")); + PersistentJournal journal1 = new PersistentJournal("commit.log"); Jungle jungle = new PersistentJungle(journal1, "uuid", new DefaultTreeEditor(new DefaultTraverser())); Jungle jungle2 = new PersistentJungle(journal1, "uuid3", new DefaultTreeEditor(new DefaultTraverser())); Long t1; @@ -57,8 +57,8 @@ System.out.println("write time = " + (t2 - t1)); PersistentJournal journal2 = new PersistentJournal(); - journal2.setInputFile(new File("./log/" + journal1.getLogName())); - journal2.setOutputFile(new File("./log/" + journal1.getLogName())); + journal2.setInputFile(new File( journal1.getLogName())); + journal2.setOutputFile(new File( journal1.getLogName())); ChangeListReader reader = journal2.getReader(); t1 = System.currentTimeMillis();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/DataWriteBenchMark.java Wed Apr 12 19:30:06 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/DataWriteBenchMark.java Thu Apr 13 19:16:59 2017 +0900 @@ -16,7 +16,7 @@ public static void main(String[] args) throws FileNotFoundException { - PersistentJournal journal1 = new PersistentJournal(new File("./log/CommitTest.log")); + PersistentJournal journal1 = new PersistentJournal("CommitTest.log"); Jungle jungle = new PersistentJungle(journal1, "uuid",new DefaultTreeEditor(new DefaultTraverser())); jungle.createNewTree("testTree"); JungleTree tree = jungle.getTreeByName("testTree");
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/JungleLogCopyBenchMark.java Wed Apr 12 19:30:06 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/persistent/JungleLogCopyBenchMark.java Thu Apr 13 19:16:59 2017 +0900 @@ -26,7 +26,7 @@ static int pos = 0; public static void main(String[] args) throws IOException { - PersistentJournal journal1 = new PersistentJournal(new File("./log/commit.log")); + PersistentJournal journal1 = new PersistentJournal("commit.log"); Jungle jungle = new PersistentJungle(journal1, "uuid", new DefaultTreeEditor(new DefaultTraverser())); Long t1; Long t2;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJournal.java Wed Apr 12 19:30:06 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJournal.java Thu Apr 13 19:16:59 2017 +0900 @@ -5,22 +5,39 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; public class PersistentJournal implements NetworkJournal { - private ChangeListWriter WRITER; + private ChangeListReader READER; private OutputStream out; private InputStream in; + public String logDirectory = "log"; private String logFileName; public PersistentJournal() { } + + public PersistentJournal(String logName) throws FileNotFoundException { + init(logDirectory,logName); + } - public PersistentJournal(File file) throws FileNotFoundException { + public PersistentJournal(String dirName, String logName) throws FileNotFoundException { + init(dirName, logName); + } + + public void init(String dirName, String logName) throws FileNotFoundException { + File dir = new File(dirName); + if (! (dir.exists())) { + dir.mkdir(); + } + logDirectory = dirName; + logFileName = logName; + File file = new File(logDirectory + "/" + logFileName); out = new FileOutputStream(file,true); in = new FileInputStream(file); - WRITER = new PersistentChangeListWriter(out); READER = new PersistentChangeListReader(in); } @@ -35,7 +52,7 @@ logFileName = timeStamp + ".log"; OutputStream outStream = null; try { - outStream = new FileOutputStream(new File("./log/"+logFileName)); + outStream = new FileOutputStream(new File(logDirectory+"/"+logFileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } @@ -53,8 +70,7 @@ public void setOutputStream(OutputStream _out) { out = _out; - WRITER = new PersistentChangeListWriter(out); - } + } public OutputStream getOutputStream() { return out; @@ -70,7 +86,7 @@ } public String getLogName(){ - return logFileName; + return logDirectory+"/"+logFileName; } public void close() throws IOException {
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/data/MsgPack.java Wed Apr 12 19:30:06 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/MsgPack.java Thu Apr 13 19:16:59 2017 +0900 @@ -13,8 +13,13 @@ @Test public void MsgPack() throws IOException { + String dirName = "log"; + File dir = new File(dirName); + if (! (dir.exists())) { + dir.mkdir(); + } String timeStamp = Long.toString(System.currentTimeMillis()); - File file = new File("./log/" + timeStamp + ".log"); + File file = new File(dirName +"/"+ timeStamp + ".log"); OutputStream out = new FileOutputStream(file,true); InputStream in = new FileInputStream(file); MessagePack msgpack = new MessagePack();
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/DataWriteBufferTest.java Wed Apr 12 19:30:06 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/DataWriteBufferTest.java Thu Apr 13 19:16:59 2017 +0900 @@ -31,7 +31,7 @@ @Test public void DataWriteBufferTest() throws IOException { - PersistentJournal journal1 = new PersistentJournal(new File("./log/commit.log")); + PersistentJournal journal1 = new PersistentJournal("commit.log"); Jungle jungle = new PersistentJungle(journal1, "uuid", new DefaultTreeEditor(new DefaultTraverser())); jungle.createNewTree("hoge"); JungleTree tree1 = jungle.getTreeByName("hoge"); @@ -48,8 +48,8 @@ Assert.assertFalse(either.isA()); PersistentJournal journal2 = new PersistentJournal(); - journal2.setInputFile(new File("./log/" + journal1.getLogName())); - journal2.setOutputFile(new File("./log/" + journal1.getLogName())); + journal2.setInputFile(new File( journal1.getLogName())); + journal2.setOutputFile(new File( journal1.getLogName())); ChangeListReader reader = journal2.getReader(); Iterator<ChangeList> iterator = reader.iterator(); Assert.assertFalse(iterator.hasNext()); @@ -70,8 +70,8 @@ Assert.assertFalse(either.isA()); PersistentJournal journal3 = new PersistentJournal(); - journal3.setInputFile(new File("./log/" + journal1.getLogName())); - journal3.setOutputFile(new File("./log/" + journal1.getLogName())); + journal3.setInputFile(new File( journal1.getLogName())); + journal3.setOutputFile(new File( journal1.getLogName())); Jungle jungle2 = new PersistentJungle(journal1, "uuid3", new DefaultTreeEditor(new DefaultTraverser())); ChangeListReader reader2 = journal3.getReader(); for (ChangeList chList : reader2) {
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/PersistentJournalTest.java Wed Apr 12 19:30:06 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/PersistentJournalTest.java Thu Apr 13 19:16:59 2017 +0900 @@ -25,7 +25,7 @@ public class PersistentJournalTest extends TestCase { public void testPersistentJounal() throws IOException { - PersistentJournal journal1 = new PersistentJournal(new File("./log/commit.log")); + PersistentJournal journal1 = new PersistentJournal("commit.log"); Jungle jungle = new PersistentJungle(journal1, "uuid",new DefaultTreeEditor(new DefaultTraverser())); jungle.createNewTree("hoge"); JungleTree tree1 = jungle.getTreeByName("hoge"); @@ -44,8 +44,8 @@ assertFalse(either.isA()); PersistentJournal journal2 = new PersistentJournal(); - journal2.setInputFile(new File("./log/"+journal1.getLogName())); - journal2.setOutputFile(new File("./log/"+journal1.getLogName())); + journal2.setInputFile(new File(journal1.getLogName())); + journal2.setOutputFile(new File(journal1.getLogName())); Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTreeEditor(new DefaultTraverser())); ChangeListReader reader = journal2.getReader(); for (ChangeList chList : reader) {