# HG changeset patch # User one # Date 1396216811 -32400 # Node ID 6954add9eea9fcdc960ee1274f403e04c2c04775 # Parent 24fca21a576ea7fa624611a9b78544b882c45d8d make Read test trial diff -r 24fca21a576e -r 6954add9eea9 src/main/java/example/ReadThread.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/example/ReadThread.java Mon Mar 31 07:00:11 2014 +0900 @@ -0,0 +1,65 @@ +package example; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TraversableNodeWrapper; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traversal; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import junit.framework.Assert; + +public class ReadThread extends Thread { + public static final String key = "name"; + int roopCount; + Jungle j; + + ReadThread(Jungle j, int roopCount) { + this.roopCount = roopCount; + this.j = j; + } + + public void run() { + JungleTree tree = j.getTreeByName("tree"); + for (int count = 0; count < roopCount; count++) { + for (int x = 0; x < 2; x++) { + DefaultNodePath path = new DefaultNodePath(); + path = path.add(x); + DefaultEvaluator evaluator = new DefaultEvaluator(path); + DefaultTraverser traverser = new DefaultTraverser(); + TraversableNodeWrapper traversable = new TraversableNodeWrapper( + tree.getRootNode()); + Either>> result = traverser + .traverse(traversable, evaluator); + if (result.isA()) { + Assert.fail(); + } + Traversal> traversal = result.b(); + TraversableNodeWrapper target = traversal.destination(); + ByteBuffer value = target.getWrapped().getAttributes().get(key); + String actual = new String(value.array()); + //System.out.println("値=" + actual); + for (int y = 0; y < 2; y++) { + path = new DefaultNodePath(); + path = path.add(x).add(y); + evaluator = new DefaultEvaluator(path); + + result = traverser.traverse(traversable, evaluator); + if (result.isA()) { + Assert.fail(); + } + traversal = result.b(); + target = traversal.destination(); + value = target.getWrapped().getAttributes().get(key); + actual = new String(value.array()); + } + } + } + // ここまで処理 + } +} diff -r 24fca21a576e -r 6954add9eea9 src/main/java/example/SimpleJungleRead.java --- a/src/main/java/example/SimpleJungleRead.java Sun Mar 30 23:21:59 2014 +0900 +++ b/src/main/java/example/SimpleJungleRead.java Mon Mar 31 07:00:11 2014 +0900 @@ -18,27 +18,29 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import junit.framework.Assert; - public class SimpleJungleRead extends Thread { public static final String key = "name"; public static final String valueString = "kanagawsa"; - public static final ByteBuffer value = ByteBuffer.wrap(valueString.getBytes()); + public static final ByteBuffer value = ByteBuffer.wrap(valueString + .getBytes()); public static void main(String[] args) { - System.out.println("タスク数"+args[0]); - System.out.println("CPU数"+args[1]); + System.out.println("タスク数" + args[0]); + System.out.println("CPU数" + args[1]); int roopCount = Integer.parseInt(args[0]); int threadCount = Integer.parseInt(args[1]); - - WriteThread[] wt = new WriteThread[threadCount]; - Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser())); + + ReadThread[] wt = new ReadThread[threadCount]; + Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor( + new DefaultTraverser())); j.createNewTree("tree");// 木を作った JungleTree tree = j.getTreeByName("tree");// 名前を取得 JungleTreeEditor editor1 = tree.getTreeEditor();// editorの取得 NodePath root = new DefaultNodePath();// パスの取得 // eitherに値を入れる - Either either = editor1.putAttribute(root,key, value); + Either either = editor1.putAttribute(root, + key, value); if (either.isA()) {// 失敗した場合Aが出てくる Assert.fail(); } @@ -50,24 +52,16 @@ ByteBuffer v = node.getAttributes().get(key); System.out.println(new String(v.array())); - // ------以下子ノードの値変更 - editor1 = tree.getTreeEditor();// Treeのeditorを作成 - either = editor1.addNewChildAt(root, 0);// 新しく入れるところへのパス - if (either.isA()) {// ちゃんとパスを指定できたかチェック - Assert.fail(); - } - editor1 = either.b();// 成功した場合パスを入れる - NodePath childPath = root.add(0); - either = editor1.success(); - if (either.isA()) {// ちゃんとパスを指定できたかチェック - Assert.fail(); - } - // そしてここで子ノードに値を入れる + // ------子ノードの追加 + CreateTree(tree); + // ここまでノードの追加 long t1 = System.currentTimeMillis();// 時間の測定開始 + + // ここで処理を行う + for (int count = 0; count < threadCount; count++) { - wt[count] = new WriteThread(j, childPath, - (roopCount / threadCount), count); + wt[count] = new ReadThread(j,(roopCount / threadCount)); } for (int count = 0; count < threadCount; count++) { wt[count].start(); @@ -79,13 +73,19 @@ } catch (InterruptedException e) { } } - + + long t2 = System.currentTimeMillis(); System.out.println(t2 - t1 + "s"); node = tree.getRootNode(); Children children = node.getChildren(); - Either either2 = children.at(0); + Either either2 = children.at(1); + // ここからしたまでテスト + Node childNod = either2.b(); + children = childNod.getChildren(); + either2 = children.at(1); + // ここまでてすと if (either2.isA()) { Assert.fail(); } @@ -94,33 +94,61 @@ ByteBuffer v2 = childNode.getAttributes().get(key); System.out.println(new String(v2.array())); } - + + public static DefaultTreeNode factory = new DefaultTreeNode( + new DefaultNode()); + + public static void CreateTree(JungleTree tree) { + NodePath root = new DefaultNodePath(); + JungleTreeEditor editor1;// Treeのeditorを作成 + Either either; - public static DefaultTreeNode factory = new DefaultTreeNode(new DefaultNode()); - - public DefaultTreeNode createTree(int _curX,int _curY,int _maxHeight,NodePath _address) - { - DefaultTreeNode parent = factory.createNewNode(); - Either either = parent.getAttributes().put(key,ByteBuffer.wrap(_address.toString().getBytes())); - if(either.isA()){ - Assert.fail(); - } - parent = either.b(); - - if(_curY == _maxHeight){ - return parent; - } - - for(int i = 0;i < _curY + 1;i ++){ - DefaultTreeNode ch = createTree(i,_curY + 1,_maxHeight,_address.add(i)); - either = parent.getChildren().addNewChildAt(i,ch); - if(either.isA()){ + for (int x = 0; x < 2; x++) { + // ノードの追加 + editor1 = tree.getTreeEditor(); + either = editor1.addNewChildAt(root, x);// 新しく入れるところへのパス + if (either.isA()) {// ちゃんとパスを指定できたかチェック + Assert.fail(); + } + editor1 = either.b();// 成功した場合パスを入れる + // NodePath childPath = root.add(x); + either = editor1.success(); + if (either.isA()) {// SUCCESSがちゃんと成功したかを調べる Assert.fail(); } - - parent = either.b(); + // ここまでノードの追加 + NodePath childPath = root.add(x); + JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 + either = editor.putAttribute(childPath, key, + ByteBuffer.wrap("Blazblue".getBytes())); + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + for (int y = 0; y < 2; y++) { + editor1 = tree.getTreeEditor(); + either = editor1.addNewChildAt(root.add(x), y);// 新しく入れるところへのパス + if (either.isA()) {// ちゃんとパスを指定できたかチェック + Assert.fail(); + } + editor1 = either.b();// 成功した場合パスを入れる + // childPath = root.add(y); + either = editor1.success(); + if (either.isA()) {// SUCCESSがちゃんと成功したかを調べる + Assert.fail(); + } + childPath = root.add(x).add(y); + editor = tree.getTreeEditor();// Treeのeditorを作成 + either = editor.putAttribute(childPath, key, + ByteBuffer.wrap("Blazblues".getBytes())); + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + } } - - return parent; + } }