Mercurial > hg > RemoteEditor > REPSessionManager
annotate test/sematest/TestInterManagerSession.java @ 471:d2762d669617
sleep command to wait for singleton prevention
author | one |
---|---|
date | Tue, 12 Oct 2010 10:19:59 +0900 |
parents | 1bb59652d89c |
children |
rev | line source |
---|---|
334 | 1 package test.sematest; |
2 | |
3 | |
342 | 4 import java.util.LinkedList; |
5 | |
6 import rep.REP; | |
7 import rep.REPCommand; | |
334 | 8 import rep.SessionManager; |
9 import rep.channel.REPServerSocketChannel; | |
382
4b87f89b3afd
REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
378
diff
changeset
|
10 import rep.gui.SessionManagerEvent; |
334 | 11 |
12 public class TestInterManagerSession extends TestSessionManager { | |
13 | |
14 /* | |
15 * All test is performed in localhost, so all session manager | |
16 * should have differenct port number each other. | |
17 * Test Pattern List | |
18 * Connect port for each editor | |
19 * Master/client flag for each editor | |
20 * Editor or slave session manager must be started by | |
21 * master session managers using syncExec. | |
22 */ | |
23 | |
335 | 24 public int slavePort[] = {masterPort,masterPort,masterPort}; |
25 public int editorPort[] = {masterPort,masterPort+1,masterPort+2}; | |
342 | 26 public boolean editorMaster[] = {true,false,false,false}; |
27 private LinkedList<REPCommand> editorStartCmds; | |
28 | |
335 | 29 private SessionManagerEvent ev2[] = { |
334 | 30 new SessionManagerEvent() { |
31 public void exec(SessionManager manager) { | |
32 int i = sessionManagers.length; | |
33 for(SessionManager slave:slaveSessionManagers) { | |
336 | 34 if (slave.getParentPort()==masterPort) { |
35 logger.writeLog("Start slave "+slave); | |
334 | 36 i = startSessionManager(slave,i,masterPort + i); |
336 | 37 } |
334 | 38 } |
39 } | |
40 }, | |
41 new SessionManagerEvent() { | |
42 public void exec(SessionManager manager) { | |
378 | 43 manager.connectSessionManager(host); |
334 | 44 } |
45 }, | |
46 new SessionManagerEvent() { | |
364 | 47 public void exec(SessionManager manager) { |
423 | 48 // // try to make a loop |
49 // if (false) { | |
50 // sessionManagers[0].connectSessionManager(host, | |
51 // manager.getPort()); | |
52 // } | |
378 | 53 manager.connectSessionManager(host); |
365
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
54 manager.execAfterConnect( |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
55 new SessionManagerEvent() { |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
56 public void exec(SessionManager manager) { |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
57 for(SessionManager m:sessionManagers) { |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
58 startEditor(m); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
59 } |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
60 for(SessionManager m:slaveSessionManagers) { |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
61 startEditor(m); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
62 } |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
63 editors[0].setCommand(editorStartCmds); |
430 | 64 new Thread(finishTest).start(); |
365
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
65 } |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
66 } |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
67 ); |
334 | 68 } |
365
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
69 |
334 | 70 } |
343 | 71 }; |
385 | 72 //private int inscnt=2; |
342 | 73 |
365
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
74 private void startEditor(SessionManager m) { |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
75 for(TestEditor editor:editors) { |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
76 if(editor.getPort()==m.getPort()) { |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
77 logger.writeLog("Start client "+editor); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
78 editor.start(); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
79 } |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
80 } |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
81 } |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
82 |
334 | 83 /* |
84 * Create all editors, master session managers and slave session | |
85 * managers with specified port. All instances are not started yet. | |
86 */ | |
343 | 87 |
334 | 88 public TestInterManagerSession(int sm, int ss, int e) { |
89 super(sm,ss,e); | |
343 | 90 |
334 | 91 sessionManagers = new SessionManager[sm]; |
92 slaveSessionManagers = new SessionManager[ss]; | |
93 editors = new TestEditor[e]; | |
94 for(int i=0;i<sm;i++) { | |
95 sessionManagers[i] = new SessionManager(); | |
96 } | |
97 for(int i=0;i<ss;i++) { | |
98 int port = slavePort[i%slavePort.length]; | |
99 slaveSessionManagers[i] = new SessionManager(); | |
100 slaveSessionManagers[i].setParentPort(port); | |
101 } | |
102 for(int i=0;i<e;i++) { | |
103 int port = editorPort[i%editorPort.length]; | |
104 boolean master = editorMaster[i%editorMaster.length]; | |
105 // TestEditor extends Thread | |
373 | 106 LinkedList<REPCommand>cmds = new LinkedList<REPCommand>(); |
107 cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,"")); | |
385 | 108 //if (inscnt-->0) cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0")); |
431 | 109 editors[i] = new TestEditor("Editor",host,port,master); |
385 | 110 //editors[i].setCommand(cmds); |
334 | 111 } |
343 | 112 setupEditor0(); |
113 } | |
114 | |
115 private void setupEditor0() { | |
116 /* | |
117 * do not startup Editor0 until SessionManagers are ready. | |
118 * Define pending command and set null command for now. | |
119 */ | |
342 | 120 LinkedList<REPCommand>cmds = new LinkedList<REPCommand>(); |
364 | 121 //cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,"Editor0-file")); |
122 cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,"Editor0-file")); | |
471 | 123 cmds.add(new REPCommand(REP.SMCMD_SLEEP,0,0,0,0,"")); |
401 | 124 cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0")); |
424 | 125 // cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0")); |
411 | 126 cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); |
342 | 127 editorStartCmds = cmds; |
128 LinkedList<REPCommand>nullcmds = new LinkedList<REPCommand>(); | |
129 editors[0].setCommand(nullcmds); | |
334 | 130 } |
131 | |
335 | 132 @Override |
133 public void setSMEvent(SessionManager s,int i) { | |
134 if (i<ev2.length) { | |
135 s.syncExec(ev2[i]); | |
136 } | |
137 return ; | |
138 } | |
334 | 139 |
336 | 140 @Override |
141 protected void startTest() { | |
142 int i = 0; | |
143 for(SessionManager master:sessionManagers) { | |
365
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
144 logger.writeLog("Start master "+i+" "+master); |
336 | 145 i = startSessionManager(master,i, masterPort + i); |
146 } | |
147 } | |
148 | |
334 | 149 public static void main(String[] args){ |
150 /* | |
151 * set simulation mode | |
152 * isSimulation=true thread base simulation for PathFinder | |
153 * isSimulation=false socket based communication mode | |
154 */ | |
426 | 155 REPServerSocketChannel.isSimulation = true; |
334 | 156 // At least 3 TestEditors are required. |
430 | 157 final TestInterManagerSession test = new TestInterManagerSession(1, 2, 3); |
334 | 158 logger.setLogLevel(5); |
430 | 159 test.finishTest = new Runnable() { |
160 public void run() { | |
161 test.finishTest(); | |
162 } | |
163 }; | |
334 | 164 test.startTest(); |
165 } | |
166 | |
167 | |
168 } |