Mercurial > hg > RemoteEditor > Eclipse
comparison src/pathfinder/mergetest/TestMerger2.java @ 153:6326e5ea4595
*** empty log message ***
author | pin |
---|---|
date | Sat, 23 Aug 2008 11:28:16 +0900 |
parents | 5942e0e3c632 |
children | 6a3c982bd72a |
comparison
equal
deleted
inserted
replaced
152:09ad66f62f4a | 153:6326e5ea4595 |
---|---|
7 public class TestMerger2 { | 7 public class TestMerger2 { |
8 static public int cmdNO[] = { REP.REPCMD_INSERT, REP.REPCMD_REPLACE, REP.REPCMD_DELETE }; | 8 static public int cmdNO[] = { REP.REPCMD_INSERT, REP.REPCMD_REPLACE, REP.REPCMD_DELETE }; |
9 protected NetworkSimulator<REPCommand> ns=null; | 9 protected NetworkSimulator<REPCommand> ns=null; |
10 protected LinkedList<EditorSimulatorWithoutMerger> editors; | 10 protected LinkedList<EditorSimulatorWithoutMerger> editors; |
11 protected SessionManagerSimulatorWithMerger<REPCommand> sema; | 11 protected SessionManagerSimulatorWithMerger<REPCommand> sema; |
12 protected UsersSimulator users; | 12 protected LinkedList<UsersSimulator> users = new LinkedList<UsersSimulator>(); |
13 | |
14 static private String[] text0 = { | |
15 "aaa", "bbb", "ccc", "ddd", "eee", | |
16 "fff", "ggg", "hhh", "iii", "jjj", | |
17 "kkk", "lll", "mmm", "nnn", "ooo", | |
18 "ppp", "qqq", "rrr", "sss", "ttt", | |
19 "uuu", "vvv", "www", "xxx", "yyy", "zzz" | |
20 }; | |
13 | 21 |
14 public TestMerger2(){ | 22 public TestMerger2(){ |
15 editors = new LinkedList<EditorSimulatorWithoutMerger>(); | 23 editors = new LinkedList<EditorSimulatorWithoutMerger>(); |
16 } | 24 } |
17 | 25 |
44 ee.start(); | 52 ee.start(); |
45 } | 53 } |
46 /* start SessionManager if it exist. */ | 54 /* start SessionManager if it exist. */ |
47 if (sema!=null) sema.init(); | 55 if (sema!=null) sema.init(); |
48 if (sema!=null) sema.start(); | 56 if (sema!=null) sema.start(); |
49 users.init(); | 57 |
50 users.start(); | 58 for(UsersSimulator u: users){ |
59 u.start(); | |
60 } | |
61 for(UsersSimulator u: users){ | |
62 try { | |
63 u.join(); | |
64 } catch (InterruptedException e) { } | |
65 } | |
66 | |
51 | 67 |
52 /* wait Editors finish. */ | 68 /* wait Editors finish. */ |
53 for (EditorSimulatorWithoutMerger ee: editors){ | 69 for (EditorSimulatorWithoutMerger ee: editors){ |
54 try { | 70 try { |
55 ee.join(); | 71 ee.join(); |
56 } catch (InterruptedException e) { | 72 } catch (InterruptedException e) { |
57 e.printStackTrace(); | 73 e.printStackTrace(); |
58 } | 74 } |
59 } | 75 } |
60 /* inform SessionManager to finish. */ | 76 /* inform SessionManager to finish. */ |
61 if (sema!=null) sema.finish(); | 77 if (sema!=null) { |
78 sema.finish(); | |
79 try { | |
80 sema.join(); | |
81 } catch (InterruptedException e) { | |
82 // TODO Auto-generated catch block | |
83 e.printStackTrace(); | |
84 } | |
85 } | |
62 } | 86 } |
63 | 87 |
88 LinkedList<REPCommand> userCommand(int eid){ | |
89 LinkedList<REPCommand> cmds = new LinkedList<REPCommand>(); | |
90 cmds .add(new REPCommand(REP.REPCMD_REPLACE, 0, eid, 1, 0, 0, "replaced by editor:" + eid + ":1")); | |
91 cmds .add(new REPCommand(REP.REPCMD_REPLACE, 0, eid, 2, 0, 0, "replaced by editor:" + eid + ":2")); | |
92 cmds .add(new REPCommand(REP.REPCMD_REPLACE, 0, eid, 3, 0, 0, "replaced by editor:" + eid + ":3")); | |
93 if(eid == 0) cmds .add(new REPCommand(REP.SMCMD_QUIT, 0, eid, 4, 0, 0, "replaced by editor:" + eid + ":4")); | |
94 return cmds; | |
95 } | |
96 | |
64 protected void init(boolean sm, int ne, int np, int ll){ | 97 protected void init(boolean sm, int ne, int np, int ll){ |
65 /* create NetworkSimulator, and SessionManager if it's required. */ | 98 /* create NetworkSimulator, and SessionManager if it's required. */ |
66 if (sm){ | 99 if (sm){ |
67 ns = new NetworkSimulatorwithSeMa<REPCommand>(); | 100 ns = new NetworkSimulatorwithSeMa<REPCommand>(); |
68 sema = new SessionManagerSimulatorWithMerger<REPCommand>(ns, ne, 0); | 101 sema = new SessionManagerSimulatorWithMerger<REPCommand>(ns, ne, 0); |
71 sema = null; | 104 sema = null; |
72 } | 105 } |
73 ns.setLogLevel(ll); | 106 ns.setLogLevel(ll); |
74 | 107 |
75 /* create UsersSimulator. */ | 108 /* create UsersSimulator. */ |
76 users = new UsersSimulator(ns, ne, np*ne); | 109 for(int i = 0; i < ne; i++){ |
110 ChannelSimulator<REPCommand> channel = ns.getAcceptedSession(i); | |
111 users.add(new UsersSimulator(channel, userCommand(i))); | |
112 } | |
77 | 113 |
78 /* create ne Editors and np commands. */ | 114 /* create ne Editors and np commands. */ |
79 for (int i=0; i<ne; i++){ | 115 for (int i=0; i<ne; i++){ |
80 LinkedList<REPCommand> cmds = new LinkedList<REPCommand>(); | 116 //LinkedList<REPCommand> cmds = new LinkedList<REPCommand>(); |
81 // 各エディタが送信するコマンド列を生成 | 117 // 各エディタが送信するコマンド列を生成 |
82 | 118 |
83 /* create command list. */ | 119 /* create command list. */ |
84 /* | 120 /* |
85 for (int j=0; j<np; j++){ | 121 for (int j=0; j<np; j++){ |
91 cmds.add( cmd); | 127 cmds.add( cmd); |
92 } | 128 } |
93 */ | 129 */ |
94 | 130 |
95 /* create a Editor, and pass command list to it. */ | 131 /* create a Editor, and pass command list to it. */ |
96 EditorSimulatorWithoutMerger ee = new EditorSimulatorWithoutMerger(i, ns, cmds, "Editor"+i); | 132 EditorSimulatorWithoutMerger ee = new EditorSimulatorWithoutMerger(i, ns, i==0?text0:null, "Editor"+i); |
97 if(i==0) ee.setOwner(true); | 133 if(i==0) ee.setOwner(true); |
98 editors.add(ee); | 134 editors.add(ee); |
99 } | 135 } |
100 } | 136 } |
101 | 137 |