Mercurial > hg > RemoteEditor > Eclipse
diff src/pathfinder/mergetest/TestMerger.java @ 113:522c6bd9b11b
Merge test using JAVApathfinder
author | kent |
---|---|
date | Sun, 23 Dec 2007 16:14:06 +0900 |
parents | |
children | f18510fc40e2 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pathfinder/mergetest/TestMerger.java Sun Dec 23 16:14:06 2007 +0900 @@ -0,0 +1,102 @@ +package pathfinder.mergetest; + +import java.util.LinkedList; +import remoteeditor.command.REPCommand; +import remoteeditor.network.REP; + +public class TestMerger { + static public int cmdNO[] = { REP.REPCMD_INSERT, REP.REPCMD_REPLACE, REP.REPCMD_DELETE }; + private NetworkSimulator<REPCommand> ns=null; + private LinkedList<EditorSimulator> editors; + private SeMaSimulator<REPCommand> sema; + + public TestMerger(){ + editors = new LinkedList<EditorSimulator>(); + } + + public static void main(String[] args){ + TestMerger tm; + 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(); + + tm.init(false, i, j); + tm.startTest(); + + tm.printAllTexts(); + //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() { + for (EditorSimulator ee: editors){ + ee.start(); + } + if (sema!=null) sema.start(); + + for (EditorSimulator ee: editors){ + try { + ee.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + if (sema!=null) sema.finish(); + } + + private void init(boolean sm, int ne, int np){ + if (sm){ + ns = new NetworkSimulatorwithSeMa<REPCommand>(); + sema = new SeMaSimulator<REPCommand>(ns, ne); + } else { + ns = new NetworkSimulatorwithoutSeMa<REPCommand>(); + sema = null; + } + + 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 printAllTexts(){ + for(EditorSimulator ee: editors){ + System.out.println("--"+ee.getName()+"------------------------"); + ee.getText().printAllText(); + } + } +/* + private boolean checkCS(){ + return ns.checkAllCS(); + } +*/ + private boolean checkEquality(){ + /* + Text ee0 = editors.remove().getText(); + return editors.remove().getText().equals(ee0); + */ + Text text0 = editors.element().getText(); + for(EditorSimulator ee: editors){ + if (!text0.equals(ee.getText())) return false; + } + return true; + } +}