# HG changeset patch # User one # Date 1381820471 -32400 # Node ID 2dba7e1cf9fa0704b67a4cea205caf5e532cafeb # Parent 9e3198bf954727b568493475e7f7760dc2b8bfb9 Added NetworknodeOperation and Test diff -r 9e3198bf9547 -r 2dba7e1cf9fa src/alice/jungle/operations/NetworkNodeOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/jungle/operations/NetworkNodeOperation.java Tue Oct 15 16:01:11 2013 +0900 @@ -0,0 +1,66 @@ +package alice.jungle.operations; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; + +import org.msgpack.annotation.Message; + + +@Message +public class NetworkNodeOperation { + + public int pos; + public String key = null; + public ByteBuffer value = null; + public Command command = null; + + public NetworkNodeOperation() { + pos = -2; + } + + public NetworkNodeOperation(NodeOperation _op) { + pos = _op.getPosition(); + key = _op.getKey(); + value = _op.getValue(); + command= _op.getCommand(); + + } + + public NetworkNodeOperation(int _pos, Command _command) { + pos = _pos; + command = _command; + } + + public NetworkNodeOperation(String _key, Command _command) { + key = _key; + command = _command; + } + + public NetworkNodeOperation(String _key, ByteBuffer _value, Command _command) { + key = _key; + value = _value; + command = _command; + } + + public NetworkNodeOperation(Command _command) { + command = _command; + } + + public int getPosition() { + return pos; + } + + public String getKey() { + return key; + } + + public ByteBuffer getValue() { + return value; + } + + public Command getCommand() { + return command; + } +} diff -r 9e3198bf9547 -r 2dba7e1cf9fa src/alice/jungle/operations/NetworkTreeOperation.java --- a/src/alice/jungle/operations/NetworkTreeOperation.java Tue Oct 15 15:53:36 2013 +0900 +++ b/src/alice/jungle/operations/NetworkTreeOperation.java Tue Oct 15 16:01:11 2013 +0900 @@ -36,7 +36,8 @@ path = _p; operation = _op; } - @Override + + @Override public NodePath getNodePath() { return path; } diff -r 9e3198bf9547 -r 2dba7e1cf9fa src/alice/jungle/persistence/impl/logger/TmpNetworkTreeOperationLog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/jungle/persistence/impl/logger/TmpNetworkTreeOperationLog.java Tue Oct 15 16:01:11 2013 +0900 @@ -0,0 +1,77 @@ +package alice.jungle.persistence.impl.logger; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; + +import org.msgpack.annotation.Message; + +import alice.jungle.operations.NetworkTreeOperation; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +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.DefaultTreeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; + + + +@Message +public class TmpNetworkTreeOperationLog implements TreeOperationLog +{ +/* MessagePack cannnot handle final. + * + * private final Iterable list; + * private final int size; + */ + private LinkedList list; + private int size; + + public TmpNetworkTreeOperationLog() + { + list = null; + size = 0; + } +/* + public NetworkTreeOperationLog(Iterable _list,int _size) + { + list = _list; + size = _size; + } +*/ + public TmpNetworkTreeOperationLog(LinkedList _list) + { + list = _list; + size = list.size(); + } + + @Override + public Iterator iterator() + { + return list.iterator(); + } + + @Override + public TreeOperationLog add(NodePath _p, NodeOperation _op) + { + TreeOperation op = new NetworkTreeOperation(_p,_op); + list.add(op); + return new TmpNetworkTreeOperationLog(list); + } + + @Override + public TreeOperationLog append(TreeOperationLog _log) + { + for(TreeOperation treeOp: _log) { + list.add(treeOp); + } + return new TmpNetworkTreeOperationLog(list); + } + + @Override + public int length() + { + return size; + } +} diff -r 9e3198bf9547 -r 2dba7e1cf9fa src/test/alice/jungle/core/operations/NetworkTreeOperationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/alice/jungle/core/operations/NetworkTreeOperationTest.java Tue Oct 15 16:01:11 2013 +0900 @@ -0,0 +1,29 @@ +package test.alice.jungle.core.operations; + +import java.io.IOException; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import alice.jungle.operations.NetworkAppendChildAtOperation; +import alice.jungle.operations.NetworkNodePath; +import alice.jungle.operations.NetworkTreeOperation; +import junit.framework.TestCase; + +public class NetworkTreeOperationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + NetworkNodePath path = new NetworkNodePath(); + path.add(1).add(2); + NetworkTreeOperation treeOp = new NetworkTreeOperation(path, op); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(treeOp); + NetworkTreeOperation mOp = msgpack.convert(v, NetworkTreeOperation.class); + assertNotNull(mOp.getNodePath()); + assertEquals(op.getCommand(), mOp.getNodeOperation().getCommand()); + + + } + +} diff -r 9e3198bf9547 -r 2dba7e1cf9fa src/test/alice/jungle/core/operations/NetworknodeOperationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/alice/jungle/core/operations/NetworknodeOperationTest.java Tue Oct 15 16:01:11 2013 +0900 @@ -0,0 +1,26 @@ +package test.alice.jungle.core.operations; + +import java.io.IOException; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import alice.jungle.operations.NetworkAppendChildAtOperation; +import alice.jungle.operations.NetworkNodeOperation; +import junit.framework.TestCase; + +public class NetworknodeOperationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + NetworkNodeOperation nOp = new NetworkNodeOperation(op); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(nOp); + NetworkNodeOperation mOp = msgpack.convert(v, NetworkNodeOperation.class); + assertEquals(op.getCommand(), mOp.getCommand()); + assertEquals(op.getPosition(), 1); + assertEquals(op.getPosition(), mOp.getPosition()); + + } + +}