annotate test/sematest/TestSessionManager.java @ 301:d12aac5ab798

*** empty log message ***
author kono
date Wed, 01 Oct 2008 16:51:01 +0900
parents 51419ad73785
children 41f05c8ff02b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
1 package test.sematest;
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
2
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
3 import java.io.IOException;
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
4 import rep.SessionManager;
281
c3969dd625b2 GUIless test routine.
kono
parents: 280
diff changeset
5 import rep.SessionManagerEvent;
c3969dd625b2 GUIless test routine.
kono
parents: 280
diff changeset
6 import rep.SessionManagerGUI;
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
7 import rep.channel.REPLogger;
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
8 import rep.channel.REPServerSocketChannel;
193
311847db7429 *** empty log message ***
pin
parents: 192
diff changeset
9
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
10
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
11 public class TestSessionManager {
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
12
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
13 static public REPLogger logger = REPLogger.singleton();
293
51419ad73785 *** empty log message ***
kono
parents: 292
diff changeset
14 int masterPort = 8766;
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
15 String host = "localhost";
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
16 SessionManager sessionManagers[];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
17 SessionManager slaveSessionManagers[];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
18 TestEditor editors[];
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
19
301
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
20 /*
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
21 * All test is performed in localhost, so all session manager
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
22 * should have differenct port number each other.
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
23 */
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
24
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
25 /*
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
26 * Test Pattern List
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
27 * Connect port for each editor
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
28 * Master/client flag for each editor
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
29 * Editor or slave session manager must be started by
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
30 * master session manager using syncExec.
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
31 */
292
975383c0548e *** empty log message ***
kono
parents: 291
diff changeset
32 int editorPort[] = {masterPort,masterPort};
975383c0548e *** empty log message ***
kono
parents: 291
diff changeset
33 boolean editorMaster[] = {true,false};
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
34 SessionManagerEvent ev1[] = {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
35 new SessionManagerEvent() {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
36 // executed before first select();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
37 public void exec() {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
38 for(TestEditor editor:editors) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
39 editor.start();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
40 }
292
975383c0548e *** empty log message ***
kono
parents: 291
diff changeset
41 int i = sessionManagers.length;
975383c0548e *** empty log message ***
kono
parents: 291
diff changeset
42 for(SessionManager slave:slaveSessionManagers) {
975383c0548e *** empty log message ***
kono
parents: 291
diff changeset
43 i = startSessionManager(slave,i,masterPort + i);
975383c0548e *** empty log message ***
kono
parents: 291
diff changeset
44 }
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
45 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
46 }};
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
47
301
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
48 /*
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
49 * Create all editors, master session managers and slave session
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
50 * managers with specfied port. All instances are not started yet.
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
51 */
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
52
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
53 public TestSessionManager(int sm, int ss, int e) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
54 sessionManagers = new SessionManager[sm];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
55 slaveSessionManagers = new SessionManager[ss];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
56 editors = new TestEditor[e];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
57 for(int i=0;i<sm;i++) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
58 sessionManagers[i] = new SessionManager();
236
2abd1dc12453 *** empty log message ***
pin
parents: 231
diff changeset
59 }
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
60 for(int i=0;i<ss;i++) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
61 slaveSessionManagers[i] = new SessionManager();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
62 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
63 for(int i=0;i<e;i++) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
64 int port = editorPort[i%editorPort.length];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
65 boolean master = editorMaster[i%editorMaster.length];
301
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
66 // TestEditor extends Thread
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
67 editors[i] = new TestEditor("Editor"+i,host,port,master);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
68 }
236
2abd1dc12453 *** empty log message ***
pin
parents: 231
diff changeset
69 }
2abd1dc12453 *** empty log message ***
pin
parents: 231
diff changeset
70
301
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
71 /*
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
72 * start session manager. sm.init(port,guit) is a mainloop, so
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
73 * we need Thread here.
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
74 */
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
75 private int startSessionManager(final SessionManager sm,int i,int port) {
290
4b773ba03556 *** empty log message ***
kono
parents: 289
diff changeset
76 final SessionManagerGUI gui = new TestGUI(sm);
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
77 final int port1 = port;
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
78 logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager");
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
79 if (i<ev1.length)
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
80 sm.syncExec(ev1[i]);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
81 Runnable start = new Runnable() {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
82 public void run() { try {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
83 sm.init(port1,gui);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
84 } catch (IOException e) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
85 } catch (InterruptedException e) {
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
86 }
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
87 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
88 };
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
89 new Thread(start).run();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
90 return i+1;
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
91 }
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
92
220
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
93 public static void main(String[] args){
301
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
94 /*
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
95 * set simulation mode
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
96 * isSimulation=true thread base simulation for PathFinder
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
97 * isSimulation=false socket based communication mode
d12aac5ab798 *** empty log message ***
kono
parents: 293
diff changeset
98 */
282
c410eda661e8 *** empty log message ***
kono
parents: 281
diff changeset
99 REPServerSocketChannel.isSimulation = true;
220
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
100 TestSessionManager test = new TestSessionManager(1, 0, 2);
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
101 logger.setLogLevel(5);
291
9e162e0a114f *** empty log message ***
kono
parents: 290
diff changeset
102 test.startTest();
220
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
103 }
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
104
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
105
291
9e162e0a114f *** empty log message ***
kono
parents: 290
diff changeset
106 private void startTest() {
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
107 int i = 0;
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
108 for(SessionManager master:sessionManagers) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
109 i = startSessionManager(master,i, masterPort + i);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
110 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
111 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
112
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
113
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
114 }