Mercurial > hg > RemoteEditor > Eclipse
view src/pathfinder/mergetest/TestMerger.java @ 125:34b15dfcb83e
UsersSimulator
author | kent |
---|---|
date | Tue, 25 Dec 2007 20:07:37 +0900 |
parents | f18510fc40e2 |
children | b56b5950cb18 |
line wrap: on
line source
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; private UsersSimulator users; public TestMerger(){ editors = new LinkedList<EditorSimulator>(); } public static void main(String[] args){ TestMerger tm; /* get the number of Editors. */ int i = (args.length>0) ? Integer.parseInt(args[0]) : 2; System.out.println("number of Editor = "+i); /* get the number of Command. */ int j = (args.length>1) ? Integer.parseInt(args[1]) : 3; System.out.println("number of Packet = "+j); /* create, initialize and start test. */ tm = new TestMerger(); tm.init(true, 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() { /* start all Editors. */ for (EditorSimulator ee: editors){ ee.start(); } /* start SessionManager if it exist. */ if (sema!=null) sema.init(); if (sema!=null) sema.start(); users.init(); users.start(); /* wait Editors finish. */ for (EditorSimulator ee: editors){ try { ee.join(); } catch (InterruptedException e) { e.printStackTrace(); } } /* inform SessionManager to finish. */ if (sema!=null) sema.finish(); } private void init(boolean sm, int ne, int np){ /* create NetworkSimulator, and SessionManager if it's required. */ if (sm){ ns = new NetworkSimulatorwithSeMa<REPCommand>(); sema = new SeMaSimulator<REPCommand>(ns, ne); } else { ns = new NetworkSimulatorwithoutSeMa<REPCommand>(); sema = null; } /* create UsersSimulator. */ users = new UsersSimulator(ns, ne, np*ne); /* create ne Editors and np commands. */ for (int i=0; i<ne; i++){ LinkedList<REPCommand> cmds = new LinkedList<REPCommand>(); // 各エディタが送信するコマンド列を生成 /* create command list. */ /* 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); } */ /* create a Editor, and pass command list to it. */ 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; } }