changeset 77:2dba7e1cf9fa

Added NetworknodeOperation and Test
author one
date Tue, 15 Oct 2013 16:01:11 +0900
parents 9e3198bf9547
children 0055d917c796
files src/alice/jungle/operations/NetworkNodeOperation.java src/alice/jungle/operations/NetworkTreeOperation.java src/alice/jungle/persistence/impl/logger/TmpNetworkTreeOperationLog.java src/test/alice/jungle/core/operations/NetworkTreeOperationTest.java src/test/alice/jungle/core/operations/NetworknodeOperationTest.java
diffstat 5 files changed, 200 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /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;
+	}
+}
--- 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;
 	}
--- /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<TreeOperation> list;
+ *	private final int size;
+ */
+	private LinkedList<TreeOperation> list;
+	private int size;
+
+	public TmpNetworkTreeOperationLog()
+	{
+		list = null;
+		size = 0;
+	}
+/*	
+	public NetworkTreeOperationLog(Iterable<TreeOperation> _list,int _size)
+	{
+		list = _list;
+		size = _size;
+	}
+*/	
+	public TmpNetworkTreeOperationLog(LinkedList<TreeOperation> _list)
+	{
+		list = _list;
+		size = list.size();
+	}
+
+	@Override
+	public Iterator<TreeOperation> 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;
+	}
+}
--- /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());
+		
+		
+	}
+	
+}
--- /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());
+
+	}
+
+}