annotate src/pathfinder/mergetest/TestMerger.java @ 125:34b15dfcb83e

UsersSimulator
author kent
date Tue, 25 Dec 2007 20:07:37 +0900
parents f18510fc40e2
children b56b5950cb18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
1 package pathfinder.mergetest;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
2
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
3 import java.util.LinkedList;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
4 import remoteeditor.command.REPCommand;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
5 import remoteeditor.network.REP;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
6
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
7 public class TestMerger {
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
8 static public int cmdNO[] = { REP.REPCMD_INSERT, REP.REPCMD_REPLACE, REP.REPCMD_DELETE };
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
9 private NetworkSimulator<REPCommand> ns=null;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
10 private LinkedList<EditorSimulator> editors;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
11 private SeMaSimulator<REPCommand> sema;
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
12 private UsersSimulator users;
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
13
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
14 public TestMerger(){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
15 editors = new LinkedList<EditorSimulator>();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
16 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
17
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
18 public static void main(String[] args){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
19 TestMerger tm;
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
20 /* get the number of Editors. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
21 int i = (args.length>0) ? Integer.parseInt(args[0]) : 2;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
22 System.out.println("number of Editor = "+i);
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
23 /* get the number of Command. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
24 int j = (args.length>1) ? Integer.parseInt(args[1]) : 3;
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
25 System.out.println("number of Packet = "+j);
f18510fc40e2 refactor
kent
parents: 113
diff changeset
26
f18510fc40e2 refactor
kent
parents: 113
diff changeset
27 /* create, initialize and start test. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
28 tm = new TestMerger();
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
29 tm.init(true, i, j);
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
30 tm.startTest();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
31
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
32 //tm.printAllTexts();
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
33 //if (!tm.checkCS())
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
34 // System.out.println("Error!! :some ChannelSimulator still have packet!");
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
35 if (!tm.checkEquality())
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
36 System.out.println("Error!! :all Editor's text is NOT mutch!");
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
37 assert tm.checkEquality();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
38 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
39
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
40 private void startTest() {
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
41 /* start all Editors. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
42 for (EditorSimulator ee: editors){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
43 ee.start();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
44 }
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
45 /* start SessionManager if it exist. */
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
46 if (sema!=null) sema.init();
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
47 if (sema!=null) sema.start();
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
48 users.init();
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
49 users.start();
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
50
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
51 /* wait Editors finish. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
52 for (EditorSimulator ee: editors){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
53 try {
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
54 ee.join();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
55 } catch (InterruptedException e) {
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
56 e.printStackTrace();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
57 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
58 }
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
59 /* inform SessionManager to finish. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
60 if (sema!=null) sema.finish();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
61 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
62
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
63 private void init(boolean sm, int ne, int np){
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
64 /* create NetworkSimulator, and SessionManager if it's required. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
65 if (sm){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
66 ns = new NetworkSimulatorwithSeMa<REPCommand>();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
67 sema = new SeMaSimulator<REPCommand>(ns, ne);
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
68 } else {
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
69 ns = new NetworkSimulatorwithoutSeMa<REPCommand>();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
70 sema = null;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
71 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
72
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
73 /* create UsersSimulator. */
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
74 users = new UsersSimulator(ns, ne, np*ne);
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
75
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
76 /* create ne Editors and np commands. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
77 for (int i=0; i<ne; i++){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
78 LinkedList<REPCommand> cmds = new LinkedList<REPCommand>();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
79 // 各エディタが送信するコマンド列を生成
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
80
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
81 /* create command list. */
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
82 /*
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
83 for (int j=0; j<np; j++){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
84 String str = "created by Editor"+i+":"+j;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
85 REPCommand cmd = new REPCommand(REP.REPCMD_INSERT,
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
86 0, i, j,
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
87 10, //Verify.random(text.size()-1), //size-1?
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
88 str.length(), str);
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
89 cmds.add( cmd);
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
90 }
125
34b15dfcb83e UsersSimulator
kent
parents: 124
diff changeset
91 */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
92
124
f18510fc40e2 refactor
kent
parents: 113
diff changeset
93 /* create a Editor, and pass command list to it. */
113
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
94 EditorSimulator ee = new EditorSimulator(i, ns, cmds, "Editor"+i);
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
95 if(i==0) ee.setOwner(true);
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
96 editors.add(ee);
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
97 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
98 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
99
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
100 private void printAllTexts(){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
101 for(EditorSimulator ee: editors){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
102 System.out.println("--"+ee.getName()+"------------------------");
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
103 ee.getText().printAllText();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
104 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
105 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
106 /*
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
107 private boolean checkCS(){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
108 return ns.checkAllCS();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
109 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
110 */
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
111 private boolean checkEquality(){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
112 /*
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
113 Text ee0 = editors.remove().getText();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
114 return editors.remove().getText().equals(ee0);
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
115 */
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
116 Text text0 = editors.element().getText();
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
117 for(EditorSimulator ee: editors){
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
118 if (!text0.equals(ee.getText())) return false;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
119 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
120 return true;
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
121 }
522c6bd9b11b Merge test using JAVApathfinder
kent
parents:
diff changeset
122 }