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