Mercurial > hg > Members > nobuyasu > jungle-network
view src/jungle/test/codesegment/log/practice/TestCodeSegment.java @ 75:87ec5dd0dc27
Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
author | one |
---|---|
date | Tue, 15 Oct 2013 14:43:29 +0900 |
parents | bf3dc481cc9b |
children |
line wrap: on
line source
package jungle.test.codesegment.log.practice; import java.io.IOException; import java.nio.ByteBuffer; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; 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.core.Node; 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.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; import alice.jungle.core.NetworkDefaultJungle; import alice.jungle.datasegment.store.container.DefaultTreeOperationLogContainer; import alice.jungle.transaction.NetworkDefaultJungleTreeEditor; import alice.test.topology.aquarium.FishPoint; import org.msgpack.MessagePack; import org.msgpack.type.Value; public class TestCodeSegment extends CodeSegment { static Jungle jungle = new NetworkDefaultJungle(null,"hoge",new DefaultTreeEditor(new DefaultTraverser()), "serverName"); // create input datasegment arg1 Receiver arg1 = ids.create(CommandType.PEEK); public TestCodeSegment() { arg1.setKey("log"); jungle.createNewTree("tree"); } @Override 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()); DefaultTreeOperationLogContainer convertedLogContainer = arg1.asClass(DefaultTreeOperationLogContainer.class); TreeOperationLog convertedLog = null; try { convertedLog = convertedLogContainer.convert(); } catch (IOException e) { e.printStackTrace(); } printLog(convertedLog); JungleTree tree = jungle.getTreeByName("tree"); NetworkDefaultJungleTreeEditor editor = (NetworkDefaultJungleTreeEditor) tree.getTreeEditor(); /* JungleTreeEditor tEditor = editor.setNewLogAndGetEditor(convertedLog); Either<Error,JungleTreeEditor> either = tEditor.success(); if (either.isA()) { throw new IllegalStateException(); } */ System.exit(0); } public void printLog(TreeOperationLog log) { for (TreeOperation treeOp : log) { NodePath path = treeOp.getNodePath(); NodeOperation nodeOp = treeOp.getNodeOperation(); Command c = nodeOp.getCommand(); String str = ""; switch (c) { case PUT_ATTRIBUTE: String k = nodeOp.getKey(); ByteBuffer value = nodeOp.getValue(); if (value.limit() < 100) { str = String.format("key:%s,value:%s", k, new String(value.array())); } else { str = String.format("key:%s,value:%d", k, value.limit()); } break; case DELETE_ATTRIBUTE: str = String.format("key:%s", nodeOp.getKey()); break; case APPEND_CHILD: str = String.format("pos:%d", nodeOp.getPosition()); break; case DELETE_CHILD: str = String.format("pos:%d", nodeOp.getPosition()); break; } System.out.println(String.format("[%s:%s]", c, str)); System.out.println("path:"); for (int i: path ) { System.out.println(i); } } } }