Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 354:ee69ae1ab1a2
rename Persistent
author | kono |
---|---|
date | Mon, 25 Sep 2017 20:11:49 +0900 |
parents | 15061909f4da |
children | 173b053379e0 |
files | src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/Persistent/PersistentDefaultJournalTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/Persistent/PersistentDifferentialJournalTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentDefaultJournalTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentDifferentialJournalTest.java |
diffstat | 4 files changed, 195 insertions(+), 195 deletions(-) [+] |
line wrap: on
line diff
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/Persistent/PersistentDefaultJournalTest.java Mon Sep 25 19:52:20 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungleNetwork.Persistent; - -import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; -import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; -import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListReader; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJournal; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJungle; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater; -import junit.framework.TestCase; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; - -public class PersistentDefaultJournalTest extends TestCase { - - public void testPersistentJounal() throws IOException { - PersistentJournal journal1 = new PersistentJournal("commit.log"); - Jungle jungle = new PersistentJungle(journal1, "uuid", new DefaultTraverser()); - jungle.createNewTree("hoge"); - JungleTree tree1 = jungle.getTreeByName("hoge"); - JungleTreeEditor editor = tree1.getJungleTreeEditor(); - NetworkNodePath path = new NetworkNodePath(); - String key = "key"; - ByteBuffer value = ByteBuffer.wrap("value".getBytes()); - int pos = 0; - Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, pos); - NodePath childPath = path.add(pos); - assertFalse(either.isA()); - editor = either.b(); - either = editor.putAttribute(childPath, key, value); - JungleTreeEditor e = either.b(); - either = e.success(); - assertFalse(either.isA()); - - PersistentJournal journal2 = new PersistentJournal(); - journal2.setInputFile(new File( journal1.getLogName())); - journal2.setOutputFile(new File(journal1.getLogName())); - Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTraverser()); - ChangeListReader reader = journal2.getReader(); - for (ChangeList chList : reader) { - String treeName = chList.getTreeName(); - JungleTree tree2 = jungle2.getTreeByName(treeName); - int treeType = chList.getTreeType(); - if (tree2 == null) { - tree2 = jungle2.createNewTree(treeName); - } - JungleTreeEditor editor2 = tree2.getJungleTreeEditor(); - Either<Error, JungleTreeEditor> either2 = JungleUpdater.edit(editor2, chList, treeType); - Either<Error, JungleTreeEditor> either3 = either2.b().success(); - assertFalse(either3.isA()); - } - JungleTree tree2 = jungle2.getTreeByName("hoge"); - TreeNode node1 = tree1.getRootNode(); - TreeNode node2 = tree2.getRootNode(); - Children child1 = node1.getChildren(); - Children child2 = node2.getChildren(); - assertEquals(child1.size(), child2.size()); - Either<Error, TreeNode> either1 = child1.at(pos); - Either<Error, TreeNode> either2 = child1.at(pos); - assertFalse(either1.isA()); - assertFalse(either2.isA()); - - TreeNode nodeA = either1.b(); - TreeNode nodeB = either2.b(); - ByteBuffer bb1 = nodeA.getAttributes().get(key); - ByteBuffer bb2 = nodeB.getAttributes().get(key); - String strA = new String(bb1.array()); - String strB = new String(bb2.array()); - assertTrue(strA.equals(strB)); - journal1.close(); - journal2.close(); - } - -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/Persistent/PersistentDifferentialJournalTest.java Mon Sep 25 19:52:20 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungleNetwork.Persistent; - -import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.jungle.core.Attributes; -import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; -import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; -import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListReader; -import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; -import jp.ac.u_ryukyu.ie.cr.jungle.tree.TreeType; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJournal; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJungle; -import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater; -import junit.framework.TestCase; -import org.junit.Assert; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Iterator; - - -public class PersistentDifferentialJournalTest extends TestCase { - - public void testPersistentJounal() throws IOException { - PersistentJournal journal1 = new PersistentJournal("commit.log"); - Jungle jungle = new PersistentJungle(journal1, "uuid", new DefaultTraverser()); - jungle.createNewDifferenceTree("hoge"); - JungleTree tree1 = jungle.getTreeByName("hoge"); - - for (int i = 0 ; i < 3 ; i++) { - JungleTreeEditor editor = tree1.getJungleTreeEditor(); - NetworkNodePath path = new NetworkNodePath(); - String key = "key"; - ByteBuffer value = ByteBuffer.wrap("value".getBytes()); - int pos = 0; - Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, pos); - NodePath childPath = path.add(pos); - assertFalse(either.isA()); - editor = either.b(); - either = editor.putAttribute(childPath, key, value); - JungleTreeEditor e = either.b(); - either = e.success(); - assertFalse(either.isA()); - } - PersistentJournal journal2 = new PersistentJournal(); - journal2.setInputFile(new File(journal1.getLogName())); - journal2.setOutputFile(new File(journal1.getLogName())); - Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTraverser()); - ChangeListReader reader = journal2.getReader(); - for (ChangeList chList : reader) { - String treeName = chList.getTreeName(); - JungleTree tree2 = jungle2.getTreeByName(treeName); - int treeType = chList.getTreeType(); - if (tree2 == null) { - Assert.assertEquals(treeType, TreeType.DIFFERENCE); - tree2 = jungle2.createNewDifferenceTree(treeName); - } - JungleTreeEditor editor2 = tree2.getJungleTreeEditor(); - Either<Error, JungleTreeEditor> either2 = JungleUpdater.edit(editor2, chList); - Either<Error, JungleTreeEditor> either3 = either2.b().success(); - assertFalse(either3.isA()); - } - JungleTree tree2 = jungle2.getTreeByName("hoge"); - - - InterfaceTraverser traverser1 = tree1.getTraverser(true); - Iterator<TreeNode> allNodeIterator1 = traverser1.find((TreeNode n) -> { - return true; - }); - - InterfaceTraverser traverser2 = tree2.getTraverser(true); - Iterator<TreeNode> allNodeIterator2 = traverser2.find((TreeNode n) -> { - return true; - }); - - while (allNodeIterator1.hasNext() || allNodeIterator2.hasNext()) { - TreeNode node1 = allNodeIterator1.next(); - TreeNode node2 = allNodeIterator2.next(); - Children children1 = node1.getChildren(); - Children children2 = node2.getChildren(); - int childrenCount1 = children1.size(); - int childrenCount2 = children2.size(); - Assert.assertEquals(childrenCount1,childrenCount2); - Attributes attribute1 = node1.getAttributes(); - Attributes attribute2 = node2.getAttributes(); - Iterator<String> keys1 = attribute1.getKeys(); - Iterator<String> keys2 = attribute2.getKeys(); - while (keys1.hasNext() || keys2.hasNext()) { - String key1 = keys1.next(); - String key2 = keys2.next(); - Assert.assertEquals(key1,key2); - ByteBuffer value1 = attribute1.get(key1); - ByteBuffer value2 = attribute2.get(key2); - Assert.assertEquals(value1,value2); - } - - } - journal1.close(); - journal2.close(); - } - -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentDefaultJournalTest.java Mon Sep 25 20:11:49 2017 +0900 @@ -0,0 +1,84 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListReader; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJournal; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJungle; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater; +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; + +public class PersistentDefaultJournalTest extends TestCase { + + public void testPersistentJounal() throws IOException { + PersistentJournal journal1 = new PersistentJournal("commit.log"); + Jungle jungle = new PersistentJungle(journal1, "uuid", new DefaultTraverser()); + jungle.createNewTree("hoge"); + JungleTree tree1 = jungle.getTreeByName("hoge"); + JungleTreeEditor editor = tree1.getJungleTreeEditor(); + NetworkNodePath path = new NetworkNodePath(); + String key = "key"; + ByteBuffer value = ByteBuffer.wrap("value".getBytes()); + int pos = 0; + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, pos); + NodePath childPath = path.add(pos); + assertFalse(either.isA()); + editor = either.b(); + either = editor.putAttribute(childPath, key, value); + JungleTreeEditor e = either.b(); + either = e.success(); + assertFalse(either.isA()); + + PersistentJournal journal2 = new PersistentJournal(); + journal2.setInputFile(new File( journal1.getLogName())); + journal2.setOutputFile(new File(journal1.getLogName())); + Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTraverser()); + ChangeListReader reader = journal2.getReader(); + for (ChangeList chList : reader) { + String treeName = chList.getTreeName(); + JungleTree tree2 = jungle2.getTreeByName(treeName); + int treeType = chList.getTreeType(); + if (tree2 == null) { + tree2 = jungle2.createNewTree(treeName); + } + JungleTreeEditor editor2 = tree2.getJungleTreeEditor(); + Either<Error, JungleTreeEditor> either2 = JungleUpdater.edit(editor2, chList, treeType); + Either<Error, JungleTreeEditor> either3 = either2.b().success(); + assertFalse(either3.isA()); + } + JungleTree tree2 = jungle2.getTreeByName("hoge"); + TreeNode node1 = tree1.getRootNode(); + TreeNode node2 = tree2.getRootNode(); + Children child1 = node1.getChildren(); + Children child2 = node2.getChildren(); + assertEquals(child1.size(), child2.size()); + Either<Error, TreeNode> either1 = child1.at(pos); + Either<Error, TreeNode> either2 = child1.at(pos); + assertFalse(either1.isA()); + assertFalse(either2.isA()); + + TreeNode nodeA = either1.b(); + TreeNode nodeB = either2.b(); + ByteBuffer bb1 = nodeA.getAttributes().get(key); + ByteBuffer bb2 = nodeB.getAttributes().get(key); + String strA = new String(bb1.array()); + String strB = new String(bb2.array()); + assertTrue(strA.equals(strB)); + journal1.close(); + journal2.close(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentDifferentialJournalTest.java Mon Sep 25 20:11:49 2017 +0900 @@ -0,0 +1,111 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.core.Attributes; +import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListReader; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.TreeType; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJournal; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJungle; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater; +import junit.framework.TestCase; +import org.junit.Assert; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Iterator; + + +public class PersistentDifferentialJournalTest extends TestCase { + + public void testPersistentJounal() throws IOException { + PersistentJournal journal1 = new PersistentJournal("commit.log"); + Jungle jungle = new PersistentJungle(journal1, "uuid", new DefaultTraverser()); + jungle.createNewDifferenceTree("hoge"); + JungleTree tree1 = jungle.getTreeByName("hoge"); + + for (int i = 0 ; i < 3 ; i++) { + JungleTreeEditor editor = tree1.getJungleTreeEditor(); + NetworkNodePath path = new NetworkNodePath(); + String key = "key"; + ByteBuffer value = ByteBuffer.wrap("value".getBytes()); + int pos = 0; + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, pos); + NodePath childPath = path.add(pos); + assertFalse(either.isA()); + editor = either.b(); + either = editor.putAttribute(childPath, key, value); + JungleTreeEditor e = either.b(); + either = e.success(); + assertFalse(either.isA()); + } + PersistentJournal journal2 = new PersistentJournal(); + journal2.setInputFile(new File(journal1.getLogName())); + journal2.setOutputFile(new File(journal1.getLogName())); + Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTraverser()); + ChangeListReader reader = journal2.getReader(); + for (ChangeList chList : reader) { + String treeName = chList.getTreeName(); + JungleTree tree2 = jungle2.getTreeByName(treeName); + int treeType = chList.getTreeType(); + if (tree2 == null) { + Assert.assertEquals(treeType, TreeType.DIFFERENCE); + tree2 = jungle2.createNewDifferenceTree(treeName); + } + JungleTreeEditor editor2 = tree2.getJungleTreeEditor(); + Either<Error, JungleTreeEditor> either2 = JungleUpdater.edit(editor2, chList); + Either<Error, JungleTreeEditor> either3 = either2.b().success(); + assertFalse(either3.isA()); + } + JungleTree tree2 = jungle2.getTreeByName("hoge"); + + + InterfaceTraverser traverser1 = tree1.getTraverser(true); + Iterator<TreeNode> allNodeIterator1 = traverser1.find((TreeNode n) -> { + return true; + }); + + InterfaceTraverser traverser2 = tree2.getTraverser(true); + Iterator<TreeNode> allNodeIterator2 = traverser2.find((TreeNode n) -> { + return true; + }); + + while (allNodeIterator1.hasNext() || allNodeIterator2.hasNext()) { + TreeNode node1 = allNodeIterator1.next(); + TreeNode node2 = allNodeIterator2.next(); + Children children1 = node1.getChildren(); + Children children2 = node2.getChildren(); + int childrenCount1 = children1.size(); + int childrenCount2 = children2.size(); + Assert.assertEquals(childrenCount1,childrenCount2); + Attributes attribute1 = node1.getAttributes(); + Attributes attribute2 = node2.getAttributes(); + Iterator<String> keys1 = attribute1.getKeys(); + Iterator<String> keys2 = attribute2.getKeys(); + while (keys1.hasNext() || keys2.hasNext()) { + String key1 = keys1.next(); + String key2 = keys2.next(); + Assert.assertEquals(key1,key2); + ByteBuffer value1 = attribute1.get(key1); + ByteBuffer value2 = attribute2.get(key2); + Assert.assertEquals(value1,value2); + } + + } + journal1.close(); + journal2.close(); + } + +} +