# HG changeset patch
# User nozomi
# Date 1505287951 -32400
# Node ID 3fc39bff7a6721118264b9556452045e7f597391
# Parent a8794548f5c9631ee9a74543d7d0c55a59b539a3# Parent 441c9edcb6b08ebac5d272a516e20736e2ff3344
merge
diff -r a8794548f5c9 -r 3fc39bff7a67 .idea/gradle.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/gradle.xml Wed Sep 13 16:32:31 2017 +0900
@@ -0,0 +1,23 @@
+
+
+
+
+
+
\ No newline at end of file
diff -r a8794548f5c9 -r 3fc39bff7a67 .idea/modules.xml
--- a/.idea/modules.xml Tue Aug 29 11:33:54 2017 +0900
+++ b/.idea/modules.xml Wed Sep 13 16:32:31 2017 +0900
@@ -2,12 +2,7 @@
-
-
-
-
-
\ No newline at end of file
diff -r a8794548f5c9 -r 3fc39bff7a67 .idea/vcs.xml
--- a/.idea/vcs.xml Tue Aug 29 11:33:54 2017 +0900
+++ b/.idea/vcs.xml Wed Sep 13 16:32:31 2017 +0900
@@ -2,7 +2,5 @@
-
-
\ No newline at end of file
diff -r a8794548f5c9 -r 3fc39bff7a67 jungle-core.iml
--- a/jungle-core.iml Tue Aug 29 11:33:54 2017 +0900
+++ b/jungle-core.iml Wed Sep 13 16:32:31 2017 +0900
@@ -1,12 +1,126 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff -r a8794548f5c9 -r 3fc39bff7a67 src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/bbs/BBSTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/bbs/BBSTest.java Wed Sep 13 16:32:31 2017 +0900
@@ -0,0 +1,185 @@
+package jp.ac.u_ryukyu.ie.cr.jungle.bbs;
+
+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.core.Attributes;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultOperationLog;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor;
+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.transaction.node.TreeNodeAttributes;
+import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Created by one on 2017/09/13.
+ */
+public class BBSTest {
+
+ private AtomicInteger requestCounter;
+ protected Jungle jungle;
+ protected String _board;
+ protected String _author;
+ protected String _message;
+ protected String _editKey;
+
+ public BBSTest(){
+ requestCounter = new AtomicInteger();
+ jungle = new DefaultJungle(null, "hoge");
+ _board = "Board";
+ _author = "Alice";
+ _message = "Hello";
+ _editKey = "key";
+ jungle.createNewTree(_board);
+ }
+
+ public BBSTest(Jungle jungle){
+ requestCounter = new AtomicInteger();
+ this.jungle = jungle;
+ _board = "Board";
+ _author = "Alice";
+ _message = "Hello";
+ _editKey = "key";
+ jungle.createNewTree(_board);
+ }
+
+ public static void main(String args[]){
+ BBSTest bbs = new BBSTest();
+ bbs.createBoard();
+ bbs.createMessage();
+ bbs.createMessage();
+
+ bbs.checkMessage();
+ }
+
+ void createBoard(){
+
+ requestCounter.incrementAndGet();
+ JungleTree tree = jungle.getTreeByName(_board);
+ if (tree == null) {
+ throw new IllegalStateException();
+ }
+
+ Either either;
+ final long timestamp = System.currentTimeMillis();
+ final ByteBuffer tBuffer = ByteBuffer.allocate(16);
+ tBuffer.putLong(timestamp);
+ do {
+
+ TreeNode node = tree.getRootNode();
+ int size = node.getChildren().size();
+ DefaultNodePath path = new DefaultNodePath();
+
+ JungleTreeEditor editor = tree.getJungleTreeEditor();
+ either = editor.addNewChildAt(path, size);
+ if (either.isA()) {
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+
+ NodeEditor e = new NodeEditor() {
+ public Either edit(TreeNode node) {
+ LoggingNode logNode = wrap(node, null, new DefaultOperationLog());
+ logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
+ logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
+ logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
+ logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
+ return DefaultEither.newB(logNode);
+ }
+
+ @Override
+ public LoggingNode wrap(TreeNode node,TreeNode node1, OperationLog op) {
+ return new LoggingNode(node, op);
+ }
+ };
+ path = path.add(size);
+ either = editor.edit(path, e);
+ if (either.isA()) {
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+ either = editor.success();
+ } while (either.isA());
+ }
+
+ void createMessage(){
+ requestCounter.incrementAndGet();
+ JungleTree tree = jungle.getTreeByName(_board);
+ if (tree == null) {
+ throw new IllegalStateException();
+ }
+
+ Either either;
+ final long timestamp = System.currentTimeMillis();
+ final ByteBuffer tBuffer = ByteBuffer.allocate(16);
+ tBuffer.putLong(timestamp);
+ do {
+
+ TreeNode node = tree.getRootNode();
+ int size = node.getChildren().size();
+ DefaultNodePath path = new DefaultNodePath();
+
+ JungleTreeEditor editor = tree.getJungleTreeEditor();
+ either = editor.addNewChildAt(path, size);
+ if (either.isA()) {
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+
+ NodeEditor e = new NodeEditor() {
+ public Either edit(TreeNode node) {
+ LoggingNode logNode = wrap(node, null, new DefaultOperationLog());
+ logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
+ logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
+ logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
+ logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
+ return DefaultEither.newB(logNode);
+ }
+
+ @Override
+ public LoggingNode wrap(TreeNode node,TreeNode node1, OperationLog op) {
+ return new LoggingNode(node, op);
+ }
+ };
+ path = path.add(size);
+ either = editor.edit(path, e);
+ if (either.isA()) {
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+ either = editor.success();
+ } while (either.isA());
+
+ }
+
+ void checkMessage(){
+ JungleTree tree = jungle.getTreeByName(_board);
+ TreeNode node = tree.getRootNode();
+ for (TreeNode child : node.getChildren()){
+ TreeNodeAttributes attr = child.getAttributes();
+ for (Iterator it = attr.getKeys(); it.hasNext();){
+ String key = it.next();
+ System.out.print( key + " = ");
+ try {
+ System.out.write(attr.get(key).array());
+ System.out.print(" ");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ System.out.println(" ");
+ }
+
+
+ }
+ }
+}