Mercurial > hg > RemoteEditor > Eclipse
changeset 105:6c209de0dd99
*** empty log message ***
author | kent |
---|---|
date | Sat, 22 Dec 2007 21:11:01 +0900 |
parents | a2089a730a2e |
children | 8a3880cd858b |
files | src/pathfinder/BlockingQnoSeMa/EditorSimulator.java src/pathfinder/BlockingQnoSeMa/TestMerger.java |
diffstat | 2 files changed, 54 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pathfinder/BlockingQnoSeMa/EditorSimulator.java Sat Dec 22 21:10:46 2007 +0900 +++ b/src/pathfinder/BlockingQnoSeMa/EditorSimulator.java Sat Dec 22 21:11:01 2007 +0900 @@ -5,6 +5,7 @@ import remoteeditor.command.REPCommand; import remoteeditor.network.REP; import sample.merge.Translater; +import sample.merge.TranslaterImp1; public class EditorSimulator extends Thread{ private int eid; @@ -13,7 +14,7 @@ private NetworkSimulator<REPCommand> ns; private ChannelSimulator<REPCommand> cs; private Queue<REPCommand> CmdList; - private Translater translater; + private TranslaterImp1 translater; private Text text; private boolean running=true; @@ -22,7 +23,7 @@ eid = _eid; ns = _ns; CmdList = q; - translater = new Translater(_eid); + translater = new TranslaterImp1(_eid); text = new Text(); cs = ns.connect(); } @@ -43,6 +44,7 @@ // MainLoop, while(running){ REPCommand cmd = cs.read(); + REPCommand[] cmds; //終了条件 if (cmd.eid==eid && cmd.cmd==REP.SMCMD_QUIT){ @@ -51,12 +53,15 @@ running=false; break; } System.out.println("\tEditor"+eid+" catch command:>> "+cmd.toString()); - cmd = translater.transReceiveCmd(cmd); - if (cmd==null) continue; + cmds = translater.transReceiveCmd(cmd); + if (cmds==null) continue; - if (isOwner) cmd.setThroughMaster(true); - text.edit(cmd); - cs.write(cmd); + for (int i=0; i<cmds.length; i++){ + cmd = cmds[i]; + if (isOwner) cmd.setThroughMaster(true); + text.edit(cmd); + cs.write(cmd); + } } System.out.println("Editor"+eid+" finish.");
--- a/src/pathfinder/BlockingQnoSeMa/TestMerger.java Sat Dec 22 21:10:46 2007 +0900 +++ b/src/pathfinder/BlockingQnoSeMa/TestMerger.java Sat Dec 22 21:11:01 2007 +0900 @@ -6,33 +6,43 @@ public class TestMerger { static public int cmdNO[] = { REP.REPCMD_INSERT, REP.REPCMD_REPLACE, REP.REPCMD_DELETE }; - private int N_editor; + //private int N_editor; + //private int N_packet; private NetworkSimulator<REPCommand> ns; private LinkedList<EditorSimulator> editors; - public TestMerger(int editor, int packet){ - N_editor = editor; + public TestMerger(){ + //N_editor = editor; + //N_packet = packet; ns = new NetworkSimulator<REPCommand>(); editors = new LinkedList<EditorSimulator>(); } public static void main(String[] args){ TestMerger tm; - tm = new TestMerger(4, 3); + int i = (args.length>0) ? Integer.parseInt(args[0]) : 2; + System.out.println("number of Editor = "+i); + int j = (args.length>1) ? Integer.parseInt(args[1]) : 3; + System.out.println("number of Packet = "+i); + tm = new TestMerger(); if(true){ - tm.test1cmd(); + tm.createEditors(i, j); }else{ - tm.test3cmd4editor(); + /* tm.test2cmd(); + tm.test1cmd(); + tm.test3cmd4editor(); tm.test0cmd(); + */ } tm.startTest(); tm.printAllTexts(); - if (!tm.checkCS()) - System.out.println("Error!! :some ChannelSimulator still have packet!"); + //if (!tm.checkCS()) + // System.out.println("Error!! :some ChannelSimulator still have packet!"); if (!tm.checkEquality()) System.out.println("Error!! :all Editor's text is NOT mutch!"); + assert tm.checkEquality(); } private void startTest() { @@ -49,6 +59,26 @@ } } + private void createEditors(int ne, int np){ + for (int i=0; i<ne; i++){ + LinkedList<REPCommand> cmds = new LinkedList<REPCommand>(); + // 各エディタが送信するコマンド列を生成 + + for (int j=0; j<np; j++){ + String str = "created by Editor"+i+":"+j; + REPCommand cmd = new REPCommand(REP.REPCMD_INSERT, + 0, i, j, + 10, //Verify.random(text.size()-1), //size-1? + str.length(), str); + cmds.add( cmd); + } + + EditorSimulator ee = new EditorSimulator(i, ns, cmds, "Editor"+i); + if(i==0) ee.setOwner(true); + editors.add(ee); + } + } +/* private void test2cmd(){ for (int i=0; i<N_editor; i++){ int j=0; @@ -100,7 +130,7 @@ editors.add(ee); } } - +*/ private void printAllTexts(){ for(EditorSimulator ee: editors){ @@ -123,7 +153,7 @@ } return true; } - + /* private void test3cmd4editor(){ for (int i=0; i<N_editor; i++){ int j=0; @@ -134,7 +164,7 @@ String str = "Editor"+i+":"+j; REPCommand cmd = new REPCommand(REP.REPCMD_INSERT, 0, i, j++, 10, str.length(), str); cmds.add( cmd); -/* str = "Editor"+i+":"+j; + str = "Editor"+i+":"+j; cmd = new REPCommand(REP.REPCMD_INSERT, 0, i, j++, 10, str.length(), str); cmds.add( cmd); str = "Editor"+i+":"+j; @@ -143,7 +173,6 @@ str = "Editor"+i+":"+j; cmd = new REPCommand(REP.REPCMD_INSERT, 0, i, j++, 10, str.length(), str); cmds.add( cmd); -*/ } EditorSimulator ee = new EditorSimulator(i, ns, cmds, "Editor"+i); @@ -151,4 +180,5 @@ editors.add(ee); } } + */ }