Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 278:f69b2a5a821d
fix error for DifferenceNode
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Sat Dec 17 18:40:36 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Mon Dec 19 02:15:23 2016 +0900 @@ -17,6 +17,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.DifferenceTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Differencial.DifferencialTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; @@ -109,13 +110,13 @@ @Override public JungleTree createNewDifferenceTree(final String name) { - TreeNode rootNode = new DefaultTreeNode(); + TreeNode rootNode = new DifferencialTreeNode(); return createNewDifferenceTree(name, rootNode); } @Override public JungleTree createNewDifferenceTree(final String name, TreeNode rootNode) { - TreeNode unDefineNode = new DefaultTreeNode(); + TreeNode unDefineNode = new DifferencialTreeNode(); TreeNodeChildren children = rootNode.getChildren(); Either<Error, TreeNode> either = children.addNewChildAt(0, unDefineNode); if (either.isA()) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Sat Dec 17 18:40:36 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Mon Dec 19 02:15:23 2016 +0900 @@ -29,15 +29,15 @@ private final TreeOperationLog log; private final TreeNode subTreeRoot; - public DifferenceJungleTreeEditor(TreeNode _root, TransactionManager _txManager, TreeEditor _editor) { - this(_root, _txManager, _editor, new DefaultTreeOperationLog()); + public DifferenceJungleTreeEditor(TreeNode subTreeRoot, TransactionManager txManager, TreeEditor editor) { + this(subTreeRoot, txManager, editor, new DefaultTreeOperationLog()); } - public DifferenceJungleTreeEditor(TreeNode subTreeRoot, TransactionManager _txManager, TreeEditor _editor, TreeOperationLog _log) { - this.txManager = _txManager; - this.editor = _editor; - this.log = _log; + public DifferenceJungleTreeEditor(TreeNode subTreeRoot, TransactionManager txManager, TreeEditor editor, TreeOperationLog log) { + this.txManager = txManager; + this.editor = editor; + this.log = log; this.subTreeRoot = subTreeRoot; } @@ -63,7 +63,7 @@ DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable, newLog.length()); TreeOperationLog newTreeOpLog = log.append(treeOperationLog); - JungleTreeEditor newEditor = new DifferenceJungleTreeEditor(newNode, txManager, editor, newTreeOpLog); + JungleTreeEditor newEditor = new DifferenceJungleTreeEditor(subTreeRoot, txManager, editor, newTreeOpLog); return DefaultEither.newB(newEditor); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNodeChildren.java Sat Dec 17 18:40:36 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNodeChildren.java Mon Dec 19 02:15:23 2016 +0900 @@ -93,7 +93,7 @@ @Override public Either<Error, TreeNode> at(int _pos) { - if (!boundaryCheck(_pos + 1) && _pos > 0 ) { + if (!boundaryCheck(_pos + 1) || _pos < 0 ) { return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNode.java Sat Dec 17 18:40:36 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNode.java Mon Dec 19 02:15:23 2016 +0900 @@ -1,7 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Differencial; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNodeAttribute; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; @@ -35,7 +34,7 @@ @Override public TreeNodeAttributes getAttributes() { - return new DefaultTreeNodeAttribute(null, null); + return new DifferencialTreeNodeAttribute(this, attrs); } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNodeChildren.java Sat Dec 17 18:40:36 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNodeChildren.java Mon Dec 19 02:15:23 2016 +0900 @@ -87,7 +87,7 @@ @Override public Either<Error, TreeNode> at(int _pos) { - if (!boundaryCheck(_pos + 1) && _pos > 0 ) { + if (!boundaryCheck(_pos + 1) || _pos > 0 ) { return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); } TreeNode n = children.get(_pos);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DifferenceListJungleTree.java Sat Dec 17 18:40:36 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DifferenceListJungleTree.java Mon Dec 19 02:15:23 2016 +0900 @@ -3,11 +3,12 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.DefaultTransactionManager; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.DifferenceJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.DifferenceTransactionManager; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import java.util.concurrent.atomic.AtomicReference; @@ -23,7 +24,7 @@ ChangeListWriter writer = super.getWriter(); String uuid = super.getUuid(); TreeEditor treeEditor = super.getTreeEditor(); - DefaultTransactionManager txManager = new DefaultTransactionManager(writer, tc, repository, uuid); + TransactionManager txManager = new DifferenceTransactionManager(writer, tc, repository, uuid); TreeNode root = tc.getRoot(); return new DifferenceJungleTreeEditor(root, txManager, treeEditor); }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/impl/treeeditor/DefaultTreeEditorTest.java Sat Dec 17 18:40:36 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.core.impl.treeeditor; - -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; -import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.AppendChildAt; -import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.PutAttribute; -import jp.ac.u_ryukyu.ie.cr.jungle.tests.util.TestUtil; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultEvaluator; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; -import junit.framework.Assert; -import junit.framework.TestCase; - -import java.nio.ByteBuffer; - -public class DefaultTreeEditorTest extends TestCase { - public DefaultTreeEditor instance() { - DefaultTraverser traverser = new DefaultTraverser(); - return new DefaultTreeEditor(traverser); - } - - public void testEdittingDoesNotEffectToOtherTree() { - TreeNode root = TestUtil.createMockTree(3); - DefaultTreeEditor editor = new DefaultTreeEditor(new DefaultTraverser()); - DefaultNodePath path = new DefaultNodePath().add(0).add(2); - - TreeNode oldRoot = root; - - DefaultTreeEditor currentEditor = editor; - String key = "path"; - - - TreeNode currentRoot = root; - for (DefaultNodePath part : path.inits()) { - String str = part.toString(); - ByteBuffer value = ByteBuffer.wrap(str.getBytes()); - PutAttribute putAttribute = new PutAttribute(key, value); - Either<Error, LoggingNode> editEither = currentEditor.edit(currentRoot, part, putAttribute); - if (editEither.isA()) { - Assert.fail(); - } - currentRoot = editEither.b().getWrap(); - } - - TreeNode newRoot = currentRoot; - DefaultTraverser traverser = new DefaultTraverser(); - - for (DefaultNodePath part : path.inits()) { - Either<Error, Traversal> either = traverser.traverse(newRoot, new DefaultEvaluator(part)); - if (either.isA()) { - Assert.fail(); - } - TreeNode target = either.b().destination(); - String expected = part.toString(); - String actual = new String(target.getAttributes().get(key).array()); - - Assert.assertEquals(expected, actual); - } - for (DefaultNodePath part : path.inits()) { - Either<Error, Traversal> either = traverser.traverse(oldRoot, new DefaultEvaluator(part)); - if (either.isA()) { - Assert.fail(); - } - TreeNode target = either.b().destination(); - ByteBuffer actual = target.getAttributes().get(key); - - Assert.assertNull(actual); - } - - } - - public void testEdit() { - DefaultTreeEditor instance = instance(); - DefaultTreeNode node = new DefaultTreeNode(); - DefaultNodePath path = new DefaultNodePath(); - Either<Error, LoggingNode> either = instance.edit(node, path, new AppendChildAt(0)); - if (either.isA()) { - Assert.fail(); - } - TreeNode newRoot = either.b().getWrap(); - Assert.assertEquals(1, newRoot.getChildren().size()); - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/tree/DefaultTree/DefaultJungleTreeTest.java Sat Dec 17 18:40:36 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.core.tree.DefaultTree; - -import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; -import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; -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.Error.Error; -import junit.framework.Assert; -import junit.framework.TestCase; - -import java.nio.ByteBuffer; - -public class DefaultJungleTreeTest extends TestCase { - public Jungle instance() { - Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); - return j; - } - - public static final String key = "KEY"; - public static final ByteBuffer value = ByteBuffer.wrap(key.getBytes()); - - public void testSampleTest() { - Jungle j = instance(); - j.createNewTree("tree"); - JungleTree tree = j.getTreeByName("tree"); - Assert.assertEquals(0, tree.revision()); - JungleTreeEditor editor1 = tree.getJungleTreeEditor(); - JungleTreeEditor editor2 = tree.getJungleTreeEditor(); - - DefaultNodePath root = new DefaultNodePath(); - - Either<Error, JungleTreeEditor> either = editor1.putAttribute(root, key, value); - if (either.isA()) { - Assert.fail(); - } - editor1 = either.b(); - editor1.success(); - - // check the value ; - TreeNode node = tree.getRootNode(); - ByteBuffer v = node.getAttributes().get(key); - Assert.assertEquals(0, v.compareTo(value)); - Assert.assertEquals(1, tree.revision()); - // editor2 must fail transction - either = editor2.putAttribute(root, key, value); - if (either.isA()) { - Assert.fail(); - } - editor2 = either.b(); - Either<Error, JungleTreeEditor> r = editor2.success(); - Assert.assertTrue(r.isA()); - } - - public void testIsolation() { - - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/tree/DifferencialTree/DefferenceTree.java Sat Dec 17 18:40:36 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.core.tree.DifferencialTree; - -import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; -import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; -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.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; -import org.junit.Test; - -/** - * Created by e115731 on 2016/12/12. - */ -public class DefferenceTree { - @Test - public void DefferenceTreeTest(){ - Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); - JungleTree tree = jungle.createNewDifferenceTree("df"); - JungleTreeEditor editor = tree.getJungleTreeEditor(); - NodePath path = new DefaultNodePath(); - System.out.println("test"); - editor = editor.addNewChildAt(path,0).b(); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/Default/DefaultTreeEditorTest.java Mon Dec 19 02:15:23 2016 +0900 @@ -0,0 +1,88 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.core.treeeditor.Default; + +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.AppendChildAt; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.PutAttribute; +import jp.ac.u_ryukyu.ie.cr.jungle.tests.util.TestUtil; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultEvaluator; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import junit.framework.Assert; +import junit.framework.TestCase; + +import java.nio.ByteBuffer; + +public class DefaultTreeEditorTest extends TestCase { + public DefaultTreeEditor instance() { + DefaultTraverser traverser = new DefaultTraverser(); + return new DefaultTreeEditor(traverser); + } + + public void testEdittingDoesNotEffectToOtherTree() { + TreeNode root = TestUtil.createMockTree(3); + DefaultTreeEditor editor = new DefaultTreeEditor(new DefaultTraverser()); + DefaultNodePath path = new DefaultNodePath().add(0).add(2); + + TreeNode oldRoot = root; + + DefaultTreeEditor currentEditor = editor; + String key = "path"; + + + TreeNode currentRoot = root; + for (DefaultNodePath part : path.inits()) { + String str = part.toString(); + ByteBuffer value = ByteBuffer.wrap(str.getBytes()); + PutAttribute putAttribute = new PutAttribute(key, value); + Either<Error, LoggingNode> editEither = currentEditor.edit(currentRoot, part, putAttribute); + if (editEither.isA()) { + Assert.fail(); + } + currentRoot = editEither.b().getWrap(); + } + + TreeNode newRoot = currentRoot; + DefaultTraverser traverser = new DefaultTraverser(); + + for (DefaultNodePath part : path.inits()) { + Either<Error, Traversal> either = traverser.traverse(newRoot, new DefaultEvaluator(part)); + if (either.isA()) { + Assert.fail(); + } + TreeNode target = either.b().destination(); + String expected = part.toString(); + String actual = new String(target.getAttributes().get(key).array()); + + Assert.assertEquals(expected, actual); + } + for (DefaultNodePath part : path.inits()) { + Either<Error, Traversal> either = traverser.traverse(oldRoot, new DefaultEvaluator(part)); + if (either.isA()) { + Assert.fail(); + } + TreeNode target = either.b().destination(); + ByteBuffer actual = target.getAttributes().get(key); + + Assert.assertNull(actual); + } + + } + + public void testEdit() { + DefaultTreeEditor instance = instance(); + DefaultTreeNode node = new DefaultTreeNode(); + DefaultNodePath path = new DefaultNodePath(); + Either<Error, LoggingNode> either = instance.edit(node, path, new AppendChildAt(0)); + if (either.isA()) { + Assert.fail(); + } + TreeNode newRoot = either.b().getWrap(); + Assert.assertEquals(1, newRoot.getChildren().size()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/Difference/DifferencialJungleTreeEditorTest.java Mon Dec 19 02:15:23 2016 +0900 @@ -0,0 +1,39 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.core.treeeditor.Difference; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +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.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.Error.Error; +import org.junit.Assert; +import org.junit.Test; + +import java.nio.ByteBuffer; + +/** + * Created by e115731 on 2016/12/18. + */ +public class DifferencialJungleTreeEditorTest { + @Test + public void DefaultJungleTreeEditorTests() { + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); + JungleTree tree = jungle.createNewDifferenceTree("df"); + JungleTreeEditor editor = tree.getJungleTreeEditor(); + NodePath path = new DefaultNodePath(); + Either<Error, JungleTreeEditor> addNewChildEither = editor.addNewChildAt(path, 0); + Assert.assertFalse(addNewChildEither.isA()); + JungleTreeEditor childAddedTreeEditor = addNewChildEither.b(); + NodePath putAttributeNodePath = path.add(0); + Either<Error, JungleTreeEditor> putAttributedEither= childAddedTreeEditor.putAttribute(putAttributeNodePath,"key", ByteBuffer.wrap("value".getBytes())); + Assert.assertFalse(putAttributedEither.isA()); + JungleTreeEditor putAttributedTreeEditor = putAttributedEither.b(); + Either<Error, JungleTreeEditor> commitedEither = putAttributedTreeEditor.success(); + Assert.assertFalse(commitedEither.isA()); + JungleTreeEditor commitedTreeEditor = commitedEither.b(); + System.out.println("test"); + } +}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/differencialnode/DifferencialChildrenTest.java Sat Dec 17 18:40:36 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.impl.differencialnode; - -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Differencial.DifferencialTreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; -import org.junit.Assert; -import org.junit.Test; - -/** - * Created by e115731 on 2016/12/17. - */ -public class DifferencialChildrenTest { - @Test - public void DifferencialNodeTest() { - TreeNode node = new DifferencialTreeNode(); - TreeNodeChildren children = node.getChildren(); - Either<Error, TreeNode> either = children.addNewChildAt(0, new DifferencialTreeNode()); //Nodeの追加 - Assert.assertFalse(either.isA()); - TreeNode newNode = either.b(); - Assert.assertEquals(node, newNode); - - either = children.addNewChildAt(3, new DifferencialTreeNode());//追加できない場所へのNodeの追加 - Assert.assertTrue(either.isA()); - - TreeNode child = children.at(0).b(); - either = children.addNewChildAt(0, new DifferencialTreeNode());//Nodeの割り込み挿入 - Assert.assertFalse(either.isA()); - TreeNode child2 = children.at(1).b(); - Assert.assertEquals(child, child2); - - either = children.moveChild(0,"up");//0番目の子ノードを上に動かす(失敗する - Assert.assertTrue(either.isA()); - - children = node.getChildren(); - child = children.at(1).b(); - either = children.moveChild(1,"up");//0番目の子ノードを上に動かす(失敗する - Assert.assertFalse(either.isA()); - child2 = children.at(0).b(); - Assert.assertEquals(child,child2); - - either = children.moveChild(1,"down");//1番目の子ノードを下に動かす(失敗する - Assert.assertTrue(either.isA()); - - child = children.at(0).b(); - either = children.moveChild(0,"down");//0番目の子ノードを上に動かす(失敗する - Assert.assertFalse(either.isA()); - child2 = children.at(1).b(); - Assert.assertEquals(child,child2); - - int expectSize = 2; - int size = children.size(); - Assert.assertEquals(expectSize,size); - - children = node.getChildren(); - either = children.deleteChildAt(4);//存在しないノードを削除 - Assert.assertTrue(either.isA()); - - children = node.getChildren(); - child = children.at(0).b(); - either = children.deleteChildAt(0);//ノードを削除 - Assert.assertFalse(either.isA()); - - for (TreeNode n : node.getChildren()) { //childrenの1番目のノードは削除したので存在しない - Assert.assertNotEquals(n,child); - } - - expectSize = 1; - size = children.size(); - Assert.assertEquals(expectSize,size); - - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/differencialnode/DifferencialTreeNodeAttributesTest.java Mon Dec 19 02:15:23 2016 +0900 @@ -0,0 +1,44 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.impl.differencialnode; + +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Differencial.DifferencialTreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; +import org.junit.Assert; +import org.junit.Test; + +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.LinkedList; + + +public class DifferencialTreeNodeAttributesTest { + @Test + public void DifferencialTreeNodeAttributesTests(){ + TreeNode node = new DifferencialTreeNode(); + TreeNodeAttributes attribute = node.getAttributes(); + for (int i = 0; i < 10 ; i++) { //put test + String key = String.valueOf(i); + ByteBuffer value = ByteBuffer.wrap(key.getBytes()); + attribute.put(key, value); + } + + for (int i = 0; i < 10 ; i++) { // get test & contain test + String key = String.valueOf(i); + ByteBuffer exceptValue = ByteBuffer.wrap(key.getBytes()); + ByteBuffer value = attribute.get(key); + Assert.assertEquals(exceptValue,value); + Assert.assertTrue(attribute.contain(key)); + } + + LinkedList<String> filter = new LinkedList<>(); + filter.add("3"); + + Iterator<String> iterator = attribute.getFilteringKey(filter); //getFilteringKey test + while (iterator.hasNext()) { + Assert.assertNotEquals(iterator.next(),"3"); + } + + attribute.delete("3"); // delete test + Assert.assertFalse(attribute.contain("3")); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/differencialnode/DifferencialTreeNodeChildrenTest.java Mon Dec 19 02:15:23 2016 +0900 @@ -0,0 +1,72 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.impl.differencialnode; + +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Differencial.DifferencialTreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import org.junit.Assert; +import org.junit.Test; + + +public class DifferencialTreeNodeChildrenTest { + @Test + public void DifferencialTreeNodeChildrenTests() { + TreeNode node = new DifferencialTreeNode(); + TreeNodeChildren children = node.getChildren(); + Either<Error, TreeNode> either = children.addNewChildAt(0, new DifferencialTreeNode()); //Nodeの追加 + Assert.assertFalse(either.isA()); + TreeNode newNode = either.b(); + Assert.assertEquals(node, newNode); + + either = children.addNewChildAt(3, new DifferencialTreeNode());//追加できない場所へのNodeの追加 + Assert.assertTrue(either.isA()); + + TreeNode child = children.at(0).b(); + either = children.addNewChildAt(0, new DifferencialTreeNode());//Nodeの割り込み挿入 + Assert.assertFalse(either.isA()); + TreeNode child2 = children.at(1).b(); + Assert.assertEquals(child, child2); + + either = children.moveChild(0,"up");//0番目の子ノードを上に動かす(失敗する + Assert.assertTrue(either.isA()); + + children = node.getChildren(); + child = children.at(1).b(); + either = children.moveChild(1,"up");//0番目の子ノードを上に動かす(失敗する + Assert.assertFalse(either.isA()); + child2 = children.at(0).b(); + Assert.assertEquals(child,child2); + + either = children.moveChild(1,"down");//1番目の子ノードを下に動かす(失敗する + Assert.assertTrue(either.isA()); + + child = children.at(0).b(); + either = children.moveChild(0,"down");//0番目の子ノードを上に動かす(失敗する + Assert.assertFalse(either.isA()); + child2 = children.at(1).b(); + Assert.assertEquals(child,child2); + + int expectSize = 2; + int size = children.size(); + Assert.assertEquals(expectSize,size); + + children = node.getChildren(); + either = children.deleteChildAt(4);//存在しないノードを削除 + Assert.assertTrue(either.isA()); + + children = node.getChildren(); + child = children.at(0).b(); + either = children.deleteChildAt(0);//ノードを削除 + Assert.assertFalse(either.isA()); + + for (TreeNode n : node.getChildren()) { //childrenの1番目のノードは削除したので存在しない + Assert.assertNotEquals(n,child); + } + + expectSize = 1; + size = children.size(); + Assert.assertEquals(expectSize,size); + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DefaultTree/DefaultJungleTreeTest.java Mon Dec 19 02:15:23 2016 +0900 @@ -0,0 +1,61 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.tree.DefaultTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +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.Error.Error; +import junit.framework.Assert; +import junit.framework.TestCase; + +import java.nio.ByteBuffer; + +public class DefaultJungleTreeTest extends TestCase { + public Jungle instance() { + Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); + return j; + } + + public static final String key = "KEY"; + public static final ByteBuffer value = ByteBuffer.wrap(key.getBytes()); + + public void testSampleTest() { + Jungle j = instance(); + j.createNewTree("tree"); + JungleTree tree = j.getTreeByName("tree"); + Assert.assertEquals(0, tree.revision()); + JungleTreeEditor editor1 = tree.getJungleTreeEditor(); + JungleTreeEditor editor2 = tree.getJungleTreeEditor(); + + DefaultNodePath root = new DefaultNodePath(); + + Either<Error, JungleTreeEditor> either = editor1.putAttribute(root, key, value); + if (either.isA()) { + Assert.fail(); + } + editor1 = either.b(); + editor1.success(); + + // check the value ; + TreeNode node = tree.getRootNode(); + ByteBuffer v = node.getAttributes().get(key); + Assert.assertEquals(0, v.compareTo(value)); + Assert.assertEquals(1, tree.revision()); + // editor2 must fail transction + either = editor2.putAttribute(root, key, value); + if (either.isA()) { + Assert.fail(); + } + editor2 = either.b(); + Either<Error, JungleTreeEditor> r = editor2.success(); + Assert.assertTrue(r.isA()); + } + + public void testIsolation() { + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DifferencialTree/DifferencialJungleTreeTest.java Mon Dec 19 02:15:23 2016 +0900 @@ -0,0 +1,19 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.tree.DifferencialTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import org.junit.Assert; +import org.junit.Test; + +public class DifferencialJungleTreeTest { + @Test + public void DefferenceTreeTest(){ + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); + JungleTree tree = jungle.createNewDifferenceTree("df"); + Assert.assertNotNull(tree); + tree = jungle.getTreeByName("df"); + Assert.assertNotNull(tree); + } +}