Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 126:f81ec544a155
add index push but bad compete
author | one |
---|---|
date | Thu, 09 Oct 2014 18:15:14 +0900 |
parents | a0c4a4b8ad10 |
children | b2c1fd513feb |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/IndexPushThread.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java |
diffstat | 6 files changed, 55 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Wed Oct 08 02:47:17 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Thu Oct 09 18:15:14 2014 +0900 @@ -41,7 +41,7 @@ } @Override - public JungleTreeEditor getIndexTreeEditor() + public IndexJungleTreeEditor getIndexTreeEditor() { TreeContext tc = repository.get(); DefaultTransactionManager txManager = new DefaultTransactionManager(writer,tc,repository,uuid);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Wed Oct 08 02:47:17 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Thu Oct 09 18:15:14 2014 +0900 @@ -5,6 +5,7 @@ import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; @@ -15,5 +16,5 @@ public JungleTreeEditor getLocalTreeEditor(); public TreeNode getRootNode(); public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex(); - public JungleTreeEditor getIndexTreeEditor(); + public IndexJungleTreeEditor getIndexTreeEditor(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Wed Oct 08 02:47:17 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Thu Oct 09 18:15:14 2014 +0900 @@ -143,7 +143,7 @@ @Override public Either<Error,JungleTreeEditor> success() { - Either<Error,TransactionManager> either = txManager.commit(root,log,null); + Either<Error,TransactionManager> either = txManager.commit(root,log,index); if(either.isA()){ return DefaultEither.newA(either.a()); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Wed Oct 08 02:47:17 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Thu Oct 09 18:15:14 2014 +0900 @@ -19,6 +19,7 @@ InterfaceTraverser traverser; TreeNode node; TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { return index; } @@ -66,7 +67,7 @@ Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(searchValue); if (opList.isNone()) - return null; + return null;//空のIteratorを返す final List<Pair<TreeNode, NodePath>> list = opList.some(); return list.iterator();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/IndexPushThread.java Thu Oct 09 18:15:14 2014 +0900 @@ -0,0 +1,33 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.query; + +import javax.swing.tree.DefaultTreeCellEditor.EditorContainer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; +import fj.data.List; +import fj.data.TreeMap; + +public class IndexPushThread extends Thread { + + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + JungleTree tree; + + public IndexPushThread(TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,JungleTree tree) { + this.index = index; + this.tree = tree; + } + + public void run() { + while (true) { + IndexJungleTreeEditor editor = tree.getIndexTreeEditor(); + editor.setIndex(index); + if (editor.success().isB()) + break; + } + } + +}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java Wed Oct 08 02:47:17 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java Thu Oct 09 18:15:14 2014 +0900 @@ -37,6 +37,9 @@ JungleTree tree = jungle.getTreeByName("tree"); createTree(tree); InterfaceTraverser ifTraverser = tree.getTraverser(); + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> cheackIndex = ifTraverser.getIndex(); + Assert.assertTrue(cheackIndex.isEmpty()); + Iterator<Pair<TreeNode, NodePath>> searchNode = ifTraverser.find( (TreeNode node) -> { ByteBuffer attribute = node.getAttributes().get(key); @@ -50,33 +53,25 @@ } ,key,"<-1,0,1>"); + while (searchNode.hasNext()){ Assert.assertTrue(compare(searchNode.next().left(),"<-1,0,1>")); } - - searchNode = ifTraverser.find( - (TreeNode node) -> { - ByteBuffer attribute = node.getAttributes().get(key); - if(attribute != null){ - byte[] byteAttribute = attribute.array(); - String str = new String(byteAttribute); - System.out.println("attribute = " + str); - return str.equals("<-1,0,0>"); - } - return false; - } - ,key,"<-1,0,0>"); - - while (searchNode.hasNext()){ - Pair<TreeNode, NodePath> pathNode = searchNode.next(); - System.out.println("last = "+pathNode.left().getAttributes().getString(key)); - Assert.assertTrue(compare(pathNode.left(),"<-1,0,0>")); - System.out.println(pathNode.left().getAttributes().getString(key)); - } - + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = ifTraverser.getIndex(); Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> opIndex = index.get(key); Assert.assertTrue(!opIndex.isNone()); + TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = opIndex.some(); + Assert.assertTrue(!innerIndex.get("<-1,0,0>").isNone()); + + IndexPushThread wt = new IndexPushThread(index, tree); + wt.start(); + + JungleTree newTree = jungle.getTreeByName("tree"); + InterfaceTraverser newIfTraverser = newTree.getTraverser(); + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = newIfTraverser.getIndex(); + Assert.assertFalse(newIndex.isEmpty()); + }