Mercurial > hg > Members > nobuyasu > jungle-network
annotate 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 |
rev | line source |
---|---|
14 | 1 package jungle.test.codesegment.log.practice; |
2 | 2 |
9 | 3 import java.io.IOException; |
4 import java.nio.ByteBuffer; | |
5 | |
11 | 6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; | |
9 | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
10 | 13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; |
11 | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; |
13 | 15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; |
9 | 16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
11 | 19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; |
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
2 | 22 import alice.codesegment.CodeSegment; |
23 import alice.datasegment.CommandType; | |
24 import alice.datasegment.Receiver; | |
31 | 25 import alice.jungle.core.NetworkDefaultJungle; |
75
87ec5dd0dc27
Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
one
parents:
45
diff
changeset
|
26 import alice.jungle.datasegment.store.container.DefaultTreeOperationLogContainer; |
31 | 27 import alice.jungle.transaction.NetworkDefaultJungleTreeEditor; |
13 | 28 import alice.test.topology.aquarium.FishPoint; |
9 | 29 |
30 import org.msgpack.MessagePack; | |
2 | 31 import org.msgpack.type.Value; |
32 | |
33 public class TestCodeSegment extends CodeSegment { | |
34 | |
45 | 35 static Jungle jungle = new NetworkDefaultJungle(null,"hoge",new DefaultTreeEditor(new DefaultTraverser()), "serverName"); |
16 | 36 |
2 | 37 // create input datasegment arg1 |
38 Receiver arg1 = ids.create(CommandType.PEEK); | |
39 | |
11 | 40 public TestCodeSegment() { |
13 | 41 arg1.setKey("log"); |
16 | 42 jungle.createNewTree("tree"); |
11 | 43 } |
44 | |
2 | 45 @Override |
46 public void run() { | |
47 System.out.println("type = " + arg1.type); | |
48 System.out.println("index = " + arg1.index); | |
49 System.out.println("data = " + arg1.getVal()); | |
14 | 50 System.out.println(((Value)arg1.getVal()).getType()); |
2 | 51 |
13 | 52 DefaultTreeOperationLogContainer convertedLogContainer = arg1.asClass(DefaultTreeOperationLogContainer.class); |
9 | 53 TreeOperationLog convertedLog = null; |
54 try { | |
55 convertedLog = convertedLogContainer.convert(); | |
56 } catch (IOException e) { | |
57 e.printStackTrace(); | |
2 | 58 } |
11 | 59 printLog(convertedLog); |
60 | |
61 JungleTree tree = jungle.getTreeByName("tree"); | |
62 NetworkDefaultJungleTreeEditor editor = (NetworkDefaultJungleTreeEditor) tree.getTreeEditor(); | |
45 | 63 /* |
11 | 64 JungleTreeEditor tEditor = editor.setNewLogAndGetEditor(convertedLog); |
45 | 65 |
11 | 66 Either<Error,JungleTreeEditor> either = tEditor.success(); |
67 if (either.isA()) { | |
68 throw new IllegalStateException(); | |
69 } | |
45 | 70 */ |
11 | 71 System.exit(0); |
72 } | |
73 | |
74 public void printLog(TreeOperationLog log) { | |
75 for (TreeOperation treeOp : log) { | |
9 | 76 NodePath path = treeOp.getNodePath(); |
77 NodeOperation nodeOp = treeOp.getNodeOperation(); | |
78 Command c = nodeOp.getCommand(); | |
79 String str = ""; | |
80 switch (c) { | |
81 case PUT_ATTRIBUTE: | |
82 String k = nodeOp.getKey(); | |
83 ByteBuffer value = nodeOp.getValue(); | |
84 if (value.limit() < 100) { | |
85 str = String.format("key:%s,value:%s", k, | |
86 new String(value.array())); | |
87 } else { | |
88 str = String.format("key:%s,value:%d", k, value.limit()); | |
89 } | |
90 break; | |
91 case DELETE_ATTRIBUTE: | |
92 str = String.format("key:%s", nodeOp.getKey()); | |
93 break; | |
94 case APPEND_CHILD: | |
95 str = String.format("pos:%d", nodeOp.getPosition()); | |
96 break; | |
97 case DELETE_CHILD: | |
98 str = String.format("pos:%d", nodeOp.getPosition()); | |
99 break; | |
100 } | |
101 System.out.println(String.format("[%s:%s]", c, str)); | |
102 System.out.println("path:"); | |
103 for (int i: path ) { | |
104 System.out.println(i); | |
105 } | |
11 | 106 } |
2 | 107 } |
108 | |
109 } |