Mercurial > hg > Database > jungle-network
changeset 18:2f1132767af2
implemented TestPutATtributeCodeSegment
author | one |
---|---|
date | Fri, 28 Jun 2013 19:32:52 +0900 |
parents | c767e7af4d88 |
children | 08e283ede7c9 |
files | src/jungle/test/codesegment/practice/JungleManager.java src/jungle/test/codesegment/practice/StartJungleCodeSegment.java src/jungle/test/codesegment/practice/TestPutAttributeCodeSegment.java |
diffstat | 3 files changed, 93 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jungle/test/codesegment/practice/JungleManager.java Fri Jun 28 12:36:07 2013 +0900 +++ b/src/jungle/test/codesegment/practice/JungleManager.java Fri Jun 28 19:32:52 2013 +0900 @@ -18,7 +18,7 @@ return jungle; } - public JungleTree createTree(String name) { + public JungleTree createNewTree(String name) { return jungle.createNewTree(name); }
--- a/src/jungle/test/codesegment/practice/StartJungleCodeSegment.java Fri Jun 28 12:36:07 2013 +0900 +++ b/src/jungle/test/codesegment/practice/StartJungleCodeSegment.java Fri Jun 28 19:32:52 2013 +0900 @@ -13,25 +13,22 @@ public class StartJungleCodeSegment { public static void main(String[] args) { + System.out.println("--StartJungleCodeSegment--"); + JungleManager jm = new JungleManager(); - JungleTree tree = jm.createTree("tree"); + JungleTree tree = jm.createNewTree("tree"); - /* Create TreeOperation */ - String key = "hoge"; - ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); - PutAttributeOperation op = new PutAttributeOperation(key, b); - DefaultNodePath p = new DefaultNodePath(); - p = p.add(1); - DefaultTreeOperation treeOp = new DefaultTreeOperation(p, op); + TestPutAttributeCodeSegment cs = new TestPutAttributeCodeSegment(); + DefaultTreeOperation treeOp = cs.getSampleOperation(); + + DefaultTreeOperationContainer treeOperationContainer = new DefaultTreeOperationContainer(); try { treeOperationContainer.unconvert(treeOp); } catch (IOException e) { e.printStackTrace(); } - - TestPutAttributeCodeSegment cs = new TestPutAttributeCodeSegment(); cs.ods.update("local", "log", treeOperationContainer);
--- a/src/jungle/test/codesegment/practice/TestPutAttributeCodeSegment.java Fri Jun 28 12:36:07 2013 +0900 +++ b/src/jungle/test/codesegment/practice/TestPutAttributeCodeSegment.java Fri Jun 28 19:32:52 2013 +0900 @@ -1,5 +1,26 @@ package jungle.test.codesegment.practice; +import java.io.IOException; +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.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jungle.test.datasegment.store.operations.DefaultTreeOperationContainer; +import jungle.test.datasegment.store.operations.DefaultTreeOperationLogContainer; +import jungle.test.transaction.NetworkDefaultJungleTreeEditor; + import org.msgpack.type.Value; import alice.codesegment.CodeSegment; @@ -16,15 +37,77 @@ public void run() { + + System.out.println("type = " + arg1.type); System.out.println("index = " + arg1.index); System.out.println("data = " + arg1.getVal()); System.out.println(((Value)arg1.getVal()).getType()); + DefaultTreeOperationContainer convertedOpContainer = arg1.asClass(DefaultTreeOperationContainer.class); + TreeOperation convertedOp = null; + try { + convertedOp = convertedOpContainer.convert(); + } catch (IOException e) { + e.printStackTrace(); + } - + Jungle jungle = new JungleManager().getJungle(); + JungleTree tree = jungle.getTreeByName("tree"); + NetworkDefaultJungleTreeEditor editor = (NetworkDefaultJungleTreeEditor) tree.getTreeEditor(); + edit(editor, convertedOp); + editor.success(); } - + + public DefaultTreeOperation getSampleOperation() { + /* Create TreeOperation */ + String key = "hoge"; + ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); + PutAttributeOperation op = new PutAttributeOperation(key, b); + DefaultNodePath p = new DefaultNodePath(); + p = p.add(1); + DefaultTreeOperation treeOp = new DefaultTreeOperation(p, op); + return treeOp; + } + + public void edit(JungleTreeEditor editor, TreeOperation op) { + NodePath path = op.getNodePath(); + NodeOperation nodeOp = op.getNodeOperation(); + Command c = nodeOp.getCommand(); + String str = ""; + String key = ""; + switch (c) { + case PUT_ATTRIBUTE: + key = nodeOp.getKey(); + ByteBuffer value = nodeOp.getValue(); + if (value.limit() < 100) { + str = String.format("key:%s,value:%s", key, + new String(value.array())); + } else { + str = String.format("key:%s,value:%d", key, value.limit()); + } + editor.putAttribute(path, key, value); + break; + case DELETE_ATTRIBUTE: + key = nodeOp.getKey(); + str = String.format("key:%s", nodeOp.getKey()); + editor.deleteAttribute(path, key); + break; + case APPEND_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + editor.addNewChildAt(path, 0); + break; + case DELETE_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + editor.deleteChildAt(path, 0); + break; + } + System.out.println(String.format("[%s:%s]", c, str)); + System.out.println("path:"); + for (int i: path ) { + System.out.println(i); + } + } }