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