Mercurial > hg > Database > jungle-network
comparison src/test/java/alice/jungle/log/example/FindMatrixTest.java @ 180:4493dd7692ce
add FindMatrixTest
author | tatsuki |
---|---|
date | Mon, 15 Sep 2014 14:04:22 +0900 |
parents | |
children | bf08205d5c5f |
comparison
equal
deleted
inserted
replaced
179:2828205bdc3a | 180:4493dd7692ce |
---|---|
1 package alice.jungle.log.example; | |
2 | |
3 import java.io.File; | |
4 import java.io.IOException; | |
5 import java.nio.ByteBuffer; | |
6 import java.util.Iterator; | |
7 | |
8 import fj.Ord; | |
9 import fj.data.List; | |
10 import fj.data.TreeMap; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; | |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; | |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; | |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; | |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; | |
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; | |
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; | |
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultJungleTreeEditor; | |
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; | |
23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; | |
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; | |
27 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query; | |
28 import junit.framework.TestCase; | |
29 import alice.jungle.operations.NetworkNodePath; | |
30 import alice.jungle.persistent.PersistentJournal; | |
31 import alice.jungle.persistent.PersistentJungle; | |
32 import alice.jungle.transaction.JungleUpdater; | |
33 import app.bbs.NetworkBulletinBoard; | |
34 import app.bbs.NetworkJungleBulletinBoard; | |
35 | |
36 public class FindMatrixTest extends TestCase { | |
37 | |
38 public class SearchQuery implements Query{ | |
39 | |
40 private String key; | |
41 private String searchAttribute; | |
42 | |
43 public SearchQuery (String key, String searchAttribute){ | |
44 this.key = key; | |
45 this.searchAttribute = searchAttribute; | |
46 } | |
47 | |
48 @Override | |
49 public boolean condition(TreeNode _node) { | |
50 ByteBuffer attribute = _node.getAttributes().get(key); | |
51 if(attribute != null){ | |
52 byte[] byteAttribute = attribute.array(); | |
53 String str = new String(byteAttribute); | |
54 System.out.println(str); | |
55 return str.equals(searchAttribute); | |
56 } | |
57 return false; | |
58 } | |
59 | |
60 @Override | |
61 public List<Pair<String, String>> indexCondition() { | |
62 // TODO Auto-generated method stub | |
63 return null; | |
64 } | |
65 | |
66 }; | |
67 | |
68 public static void main(String[] args) throws IOException { | |
69 PersistentJournal journal1 = new PersistentJournal(); | |
70 journal1.setInputFile(new File("./log/1410589309338.log")); | |
71 journal1.setOutputFile(new File("./log/test.log")); | |
72 Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTreeEditor(new DefaultTraverser())); | |
73 ChangeListReader reader = journal1.getReader(); | |
74 int roopCount = 0; | |
75 String treeName = null; | |
76 for (ChangeList chList : reader) { | |
77 roopCount++; | |
78 treeName = chList.getTreeName(); | |
79 JungleTree tree2 = jungle2.getTreeByName(treeName); | |
80 if(tree2 == null) { | |
81 tree2 = jungle2.createNewTree(treeName); | |
82 } | |
83 JungleTreeEditor editor2 = tree2.getTreeEditor(); | |
84 Either<Error, JungleTreeEditor> either2 = JungleUpdater.edit(editor2, chList); | |
85 assertFalse(either2.isA()); | |
86 editor2 = either2.b(); | |
87 editor2.success(); | |
88 } | |
89 | |
90 | |
91 JungleTree tree2 = jungle2.getTreeByName(treeName); | |
92 TreeNode root = tree2.getRootNode(); | |
93 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = TreeMap.empty(Ord.stringOrd); | |
94 DefaultTraverser traverser = new DefaultTraverser(); | |
95 DefaultTreeEditor treeEditor = new DefaultTreeEditor(traverser); | |
96 JungleTreeEditor editor = new DefaultJungleTreeEditor(root,null,treeEditor,null); | |
97 InterfaceTraverser ifTraverser = new InterfaceTraverser(root,index,editor); | |
98 String key = "mes"; | |
99 String attribute = "株式会社フタコ放送"; | |
100 | |
101 Query query = new FindMatrixTest().new SearchQuery(key, attribute); | |
102 Iterator<Pair<TreeNode, NodePath>> searchNode = ifTraverser.find(query); | |
103 TreeNode node = searchNode.next().left(); | |
104 byte[] nodeAttibute = node.getAttributes().get(key).array(); | |
105 System.out.println(new String(nodeAttibute)); | |
106 } | |
107 } |