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