changeset 17:c767e7af4d88

add TestPutAttributeCodeSegmnet and StartJungleCodeSegment
author one
date Fri, 28 Jun 2013 12:36:07 +0900
parents d2436fd71c61
children 2f1132767af2
files src/jungle/test/codesegment/persistence/AliceJournal.java src/jungle/test/codesegment/persistence/TestJungle.java src/jungle/test/codesegment/practice/StartJungleCodeSegment.java src/jungle/test/codesegment/practice/TestPutAttributeCodeSegment.java
diffstat 4 files changed, 172 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/codesegment/persistence/AliceJournal.java	Fri Jun 28 12:36:07 2013 +0900
@@ -0,0 +1,97 @@
+package jungle.test.codesegment.persistence;
+
+import java.nio.ByteBuffer;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result;
+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.operations.NodeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
+import jungle.test.datasegment.store.operations.DefaultNodeOperationContainer;
+import jungle.test.datasegment.store.operations.DefaultTreeOperationContainer;
+
+public class AliceJournal implements Journal {
+	
+	private static final AliceChangeListWriter ALICE_WRITER = new AliceChangeListWriter();
+	private static final AliceChangeListReader ALICE_READER = new AliceChangeListReader();
+	@Override
+	public ChangeListReader getReader() {
+		return ALICE_READER;
+	}
+	@Override
+	public ChangeListWriter getWriter() {
+		return ALICE_WRITER;
+	}
+	
+	private static class AliceChangeListWriter implements ChangeListWriter
+	{
+		@Override
+		public Result write(ChangeList _operations)
+		{
+
+			/*
+			for(TreeOperation op : _operations){
+				DefaultTreeOperationContainer container = new DefaultTreeOperationContainer();
+				container.unconvert(op);
+				
+				cs.ods.update("local", "op", op);
+				
+			}
+			
+*/			
+			
+			
+			
+			
+			for(TreeOperation op : _operations){
+				NodePath p = op.getNodePath();
+				NodeOperation nodeOp = op.getNodeOperation();
+				Command c = nodeOp.getCommand();
+				String args = "";
+				switch(c){
+					case PUT_ATTRIBUTE:
+						String key = nodeOp.getKey();
+						ByteBuffer value = nodeOp.getValue();
+						if(value.limit() < 100){
+							args = String.format("key:%s,value:%s",key,new String(value.array()));
+						}else{
+							args = String.format("key:%s,value:%d",key,value.limit());
+						}
+						break;
+					case DELETE_ATTRIBUTE:
+						args = String.format("key:%s",nodeOp.getKey());
+						break;
+					case APPEND_CHILD:
+						args = String.format("pos:%d",nodeOp.getPosition());
+						break;
+					case DELETE_CHILD:
+						args = String.format("pos:%d",nodeOp.getPosition());
+						break;
+				}
+				System.out.println(String.format("[%s:%s:%s]",c,p,args));
+			}
+			return Result.SUCCESS;
+		}
+	}
+	
+	private static class AliceChangeListReader implements ChangeListReader
+	{
+		@Override
+		public ChangeListReader newReader()
+		{
+			return this;
+		}
+
+		@Override
+		public ChangeList read()
+		{
+			return null;
+		}
+	}
+	
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/codesegment/persistence/TestJungle.java	Fri Jun 28 12:36:07 2013 +0900
@@ -0,0 +1,21 @@
+package jungle.test.codesegment.persistence;
+
+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.TreeEditor;
+import jungle.test.codesegment.practice.JungleManager;
+import jungle.test.codesegment.practice.TestPutAttributeCodeSegment;
+
+public class TestJungle {
+	
+	public static void main(String[] args) {
+		JungleManager jm = new JungleManager();
+		JungleTree tree = jm.createTree("tree1");
+		JungleTreeEditor editor = tree.getTreeEditor();
+
+		new TestPutAttributeCodeSegment().execute();
+		
+	}
+
+}
--- a/src/jungle/test/codesegment/practice/StartJungleCodeSegment.java	Fri Jun 28 12:24:35 2013 +0900
+++ b/src/jungle/test/codesegment/practice/StartJungleCodeSegment.java	Fri Jun 28 12:36:07 2013 +0900
@@ -1,6 +1,13 @@
 package jungle.test.codesegment.practice;
 
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
+import jungle.test.datasegment.store.operations.DefaultTreeOperationContainer;
 import alice.codesegment.CodeSegment;
 
 public class StartJungleCodeSegment {
@@ -9,6 +16,23 @@
 		JungleManager jm = new JungleManager();
 		JungleTree tree = jm.createTree("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);
+
+		DefaultTreeOperationContainer treeOperationContainer = new DefaultTreeOperationContainer();
+		try {
+			treeOperationContainer.unconvert(treeOp);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		 TestPutAttributeCodeSegment cs = new TestPutAttributeCodeSegment();
+		cs.ods.update("local", "log", treeOperationContainer);
 		
 		
 	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/codesegment/practice/TestPutAttributeCodeSegment.java	Fri Jun 28 12:36:07 2013 +0900
@@ -0,0 +1,30 @@
+package jungle.test.codesegment.practice;
+
+import org.msgpack.type.Value;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class TestPutAttributeCodeSegment extends CodeSegment {
+
+	Receiver arg1 = ids.create(CommandType.TAKE);
+	
+	public TestPutAttributeCodeSegment() {
+		arg1.setKey("log");
+	}
+	
+	
+	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());
+
+		
+		
+		
+		
+	}
+
+}