# HG changeset patch # User Shoshi TAMAKI # Date 1289317011 -32400 # Node ID 8d733b98c5de320c6541167236f1ff767f489501 # Parent 174bc0d217124ad3f0a89256d9a7f3b774425c4c added Node API setLinkedNode,getLinkedNode for create link to other node. but not implemented yet. diff -r 174bc0d21712 -r 8d733b98c5de CHANGELOG --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CHANGELOG Wed Nov 10 00:36:51 2010 +0900 @@ -0,0 +1,11 @@ +CHANGELOG + +2010/11/10 +added Node API + setLinkedNode,getLinkedNode for create link to other node. + but not implemented yet. + +2010/11/09 +added CHANGELOG +added Editor API + merge,update,discard,checkUpdate \ No newline at end of file diff -r 174bc0d21712 -r 8d733b98c5de src/treecms/proto/api/Node.java --- a/src/treecms/proto/api/Node.java Tue Nov 09 18:13:54 2010 +0900 +++ b/src/treecms/proto/api/Node.java Wed Nov 10 00:36:51 2010 +0900 @@ -16,7 +16,6 @@ public void up(Node _child); public void down(Node _child); - public String getTitle(); public void setTitle(String _title); @@ -25,4 +24,7 @@ public NodeID getID(); public Node cloneNode(); + + public Node getLinkedNode(); + public void setLinkedNode(Node _node); } \ No newline at end of file diff -r 174bc0d21712 -r 8d733b98c5de src/treecms/proto/simple/SimpleNode.java --- a/src/treecms/proto/simple/SimpleNode.java Tue Nov 09 18:13:54 2010 +0900 +++ b/src/treecms/proto/simple/SimpleNode.java Wed Nov 10 00:36:51 2010 +0900 @@ -146,4 +146,16 @@ // TODO Auto-generated method stub m_class = _class; } + + @Override + public Node getLinkedNode() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setLinkedNode(Node node) { + // TODO Auto-generated method stub + + } } diff -r 174bc0d21712 -r 8d733b98c5de src/treecms/proto/test/IncrementalNodeIDTest1.java --- a/src/treecms/proto/test/IncrementalNodeIDTest1.java Tue Nov 09 18:13:54 2010 +0900 +++ b/src/treecms/proto/test/IncrementalNodeIDTest1.java Wed Nov 10 00:36:51 2010 +0900 @@ -1,14 +1,27 @@ package treecms.proto.test; +/** + * IncrementalNodeIDTest1 + * + * testIDstartsWithZero() + * the id must be start from zero. + * + * testUpdateIDFromLatestID() + * check that id able to update correctly from latest node id. + * + * testUpdateIDFromOldID() + * check that id able to update correctly from old node id. + * + * testMultiThreadUpdateID() + * execute concurrent update using shared object. + */ + import java.util.concurrent.ExecutorService; - import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; - import org.junit.Test; import org.junit.Assert; import org.junit.runner.JUnitCore; - import treecms.proto.api.NodeID; import treecms.proto.id.IncrementalNodeID; @@ -60,17 +73,17 @@ @Test public void testMultiThreadedUpdateID() { - final int threads = 10; - final int count = 100; + final int threads = 10; //number of threads + final int count = 100; //modification count ExecutorService service = Executors.newFixedThreadPool(threads); final NodeID id = new IncrementalNodeID(); + for(int i = 0;i < threads;i ++){ service.execute(new Runnable(){ @Override public void run() { - // TODO Auto-generated method stub for(int j = 0;j < count;j ++){ id.update(); } @@ -81,9 +94,8 @@ service.shutdown(); try { - service.awaitTermination(1,TimeUnit.HOURS); + service.awaitTermination(Long.MAX_VALUE,TimeUnit.DAYS); } catch (InterruptedException e) { - // TODO Auto-generated catch block e.printStackTrace(); } diff -r 174bc0d21712 -r 8d733b98c5de src/treecms/proto/test/LinkedListTest1.java --- a/src/treecms/proto/test/LinkedListTest1.java Tue Nov 09 18:13:54 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package treecms.proto.test; - -import java.util.LinkedList; - -public class LinkedListTest1 -{ - public static void main(String _args[]) - { - LinkedList list1 = new LinkedList(); - list1.add(1); - list1.add(2); - list1.add(3); - - @SuppressWarnings("unchecked") - LinkedList list2 = (LinkedList) list1.clone(); - list2.remove(1); - - for(Integer num : list1){ - System.out.println(num); - } - } -} diff -r 174bc0d21712 -r 8d733b98c5de src/treecms/proto/test/SimpleEditorTest1.java --- a/src/treecms/proto/test/SimpleEditorTest1.java Tue Nov 09 18:13:54 2010 +0900 +++ b/src/treecms/proto/test/SimpleEditorTest1.java Wed Nov 10 00:36:51 2010 +0900 @@ -1,3 +1,9 @@ +/** + * SimpleEditorTest1 + * + * testClone + * test monotonic-tree modification + */ package treecms.proto.test; import org.junit.Test; @@ -19,7 +25,7 @@ public SimpleEditorTest1() { - + //create tree Node root = new SimpleNode(); root.setTitle("root"); @@ -33,7 +39,9 @@ Node child12 = child1.addChild(new SimpleNode()); child12.setTitle("child12"); + //AtomicReference to use CompareAndSet m_root = new AtomicReference(root); + m_target1 = child2; m_target2 = child11; } diff -r 174bc0d21712 -r 8d733b98c5de src/treecms/proto/test/SimpleEditorTest2.java --- a/src/treecms/proto/test/SimpleEditorTest2.java Tue Nov 09 18:13:54 2010 +0900 +++ b/src/treecms/proto/test/SimpleEditorTest2.java Wed Nov 10 00:36:51 2010 +0900 @@ -1,5 +1,12 @@ package treecms.proto.test; +/** + * SimpleEditorTest2 + * + * testMultiThread + * test concurrent monotonic-tree modification + */ + import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -50,7 +57,7 @@ @Test public void testMultiThread() { - int threads = 10; + int threads = 10; //number of threads. final int modifyCount = 100; ExecutorService service = Executors.newFixedThreadPool(threads); @@ -60,18 +67,26 @@ @Override public void run() { - // TODO Auto-generated method stub SimpleEditor editor = new SimpleEditor(m_contents); Random random = new Random(); for(int i = 0;i < modifyCount;i ++){ List nodeList = transform(new PreOrderTreeWalker(m_contents.get())); + + //get random target from nodelist Node target = nodeList.get(Math.abs(random.nextInt(nodeList.size()))); + + //edit target editor.edit(target); - editor.commit(false); + + //force commit. + editor.commit(true); } } + /* + * convert iterator to list + */ public List transform(PreOrderTreeWalker _walker) { LinkedList nodeList = new LinkedList();