Mercurial > hg > RemoteEditor > REPSessionManager
annotate test/sematest/TestSessionManager.java @ 424:1e58479b4170
TestEditor selectionKeys fix.
author | one |
---|---|
date | Thu, 31 Dec 2009 23:00:55 +0900 |
parents | 5e18919011a8 |
children | 1acc3dfde5d3 |
rev | line source |
---|---|
189 | 1 package test.sematest; |
2 | |
192 | 3 import java.io.IOException; |
384 | 4 |
189 | 5 import rep.SessionManager; |
192 | 6 import rep.channel.REPLogger; |
189 | 7 import rep.channel.REPServerSocketChannel; |
382
4b87f89b3afd
REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
336
diff
changeset
|
8 import rep.gui.SessionManagerEvent; |
4b87f89b3afd
REP Session Manager (Java version)
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
336
diff
changeset
|
9 import rep.gui.SessionManagerGUI; |
193 | 10 |
189 | 11 |
12 public class TestSessionManager { | |
13 | |
192 | 14 static public REPLogger logger = REPLogger.singleton(); |
335 | 15 public int masterPort = 8766; |
16 public String host = "localhost"; | |
17 public SessionManager sessionManagers[]; | |
18 public SessionManager slaveSessionManagers[]; | |
19 public TestEditor editors[]; | |
189 | 20 |
301 | 21 /* |
22 * All test is performed in localhost, so all session manager | |
23 * should have differenct port number each other. | |
24 */ | |
25 | |
26 /* | |
27 * Test Pattern List | |
28 * Connect port for each editor | |
29 * Master/client flag for each editor | |
30 * Editor or slave session manager must be started by | |
303 | 31 * master session managers using syncExec. |
301 | 32 */ |
335 | 33 public int editorPort[] = {masterPort,masterPort,masterPort}; |
34 public boolean editorMaster[] = {true,false,false,false}; | |
35 private SessionManagerEvent ev1[] = { | |
289 | 36 new SessionManagerEvent() { |
37 // executed before first select(); | |
334 | 38 public void exec(SessionManager manager) { |
289 | 39 for(TestEditor editor:editors) { |
40 editor.start(); | |
41 } | |
292 | 42 int i = sessionManagers.length; |
43 for(SessionManager slave:slaveSessionManagers) { | |
44 i = startSessionManager(slave,i,masterPort + i); | |
45 } | |
289 | 46 } |
47 }}; | |
48 | |
301 | 49 /* |
50 * Create all editors, master session managers and slave session | |
303 | 51 * managers with specified port. All instances are not started yet. |
301 | 52 */ |
53 | |
289 | 54 public TestSessionManager(int sm, int ss, int e) { |
55 sessionManagers = new SessionManager[sm]; | |
56 slaveSessionManagers = new SessionManager[ss]; | |
57 editors = new TestEditor[e]; | |
58 for(int i=0;i<sm;i++) { | |
59 sessionManagers[i] = new SessionManager(); | |
236 | 60 } |
289 | 61 for(int i=0;i<ss;i++) { |
62 slaveSessionManagers[i] = new SessionManager(); | |
63 } | |
64 for(int i=0;i<e;i++) { | |
65 int port = editorPort[i%editorPort.length]; | |
66 boolean master = editorMaster[i%editorMaster.length]; | |
301 | 67 // TestEditor extends Thread |
289 | 68 editors[i] = new TestEditor("Editor"+i,host,port,master); |
69 } | |
236 | 70 } |
71 | |
301 | 72 /* |
73 * start session manager. sm.init(port,guit) is a mainloop, so | |
74 * we need Thread here. | |
75 */ | |
415 | 76 public int startSessionManager(final SessionManager sm,int i,int port) { |
290 | 77 final SessionManagerGUI gui = new TestGUI(sm); |
289 | 78 final int port1 = port; |
79 logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); | |
303 | 80 // syncExec does not wake selector, do this before run(). |
336 | 81 sm.setReceivePort(port1); |
335 | 82 setSMEvent(sm,i); |
289 | 83 Runnable start = new Runnable() { |
313 | 84 public void run() { |
85 try { | |
86 sm.init(port1,gui); | |
87 } catch (IOException e) { | |
88 } catch (InterruptedException e) { | |
89 } | |
289 | 90 } |
91 }; | |
336 | 92 new Thread(start).start(); |
289 | 93 return i+1; |
189 | 94 } |
95 | |
310 | 96 |
335 | 97 public void setSMEvent(SessionManager s,int i) { |
98 if (i<ev1.length) { | |
99 s.syncExec(ev1[i]); | |
100 } | |
101 return ; | |
102 } | |
103 | |
334 | 104 protected void startTest() { |
310 | 105 int i = 0; |
106 for(SessionManager master:sessionManagers) { | |
107 i = startSessionManager(master,i, masterPort + i); | |
108 } | |
109 } | |
110 | |
220 | 111 public static void main(String[] args){ |
301 | 112 /* |
113 * set simulation mode | |
114 * isSimulation=true thread base simulation for PathFinder | |
115 * isSimulation=false socket based communication mode | |
116 */ | |
424 | 117 REPServerSocketChannel.isSimulation = false; |
332 | 118 // At least 3 TestEditors are required. |
319 | 119 TestSessionManager test = new TestSessionManager(1, 0, 3); |
220 | 120 logger.setLogLevel(5); |
291 | 121 test.startTest(); |
220 | 122 } |
123 | |
289 | 124 |
189 | 125 } |