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();
|
289
|
14 final int masterPort = 8766;
|
|
15 String host = "localhost";
|
|
16 SessionManager sessionManagers[];
|
|
17 SessionManager slaveSessionManagers[];
|
|
18 TestEditor editors[];
|
189
|
19
|
289
|
20 SessionManagerEvent ev1[] = {
|
|
21 new SessionManagerEvent() {
|
|
22 // executed before first select();
|
|
23 public void exec() {
|
|
24 for(TestEditor editor:editors) {
|
|
25 editor.start();
|
|
26 }
|
|
27 }
|
|
28 }};
|
|
29 int editorPort[] = {masterPort,masterPort};
|
|
30 boolean editorMaster[] = {true,false};
|
|
31
|
|
32 public TestSessionManager(int sm, int ss, int e) {
|
|
33 sessionManagers = new SessionManager[sm];
|
|
34 slaveSessionManagers = new SessionManager[ss];
|
|
35 editors = new TestEditor[e];
|
|
36 for(int i=0;i<sm;i++) {
|
|
37 sessionManagers[i] = new SessionManager();
|
236
|
38 }
|
289
|
39 for(int i=0;i<ss;i++) {
|
|
40 slaveSessionManagers[i] = new SessionManager();
|
|
41 }
|
|
42 for(int i=0;i<e;i++) {
|
|
43 int port = editorPort[i%editorPort.length];
|
|
44 boolean master = editorMaster[i%editorMaster.length];
|
|
45 editors[i] = new TestEditor("Editor"+i,host,port,master);
|
|
46 }
|
236
|
47 }
|
|
48
|
289
|
49 private int startSessionManager(final SessionManager sm,int i,int port) {
|
290
|
50 final SessionManagerGUI gui = new TestGUI(sm);
|
289
|
51 final int port1 = port;
|
|
52 logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager");
|
|
53 if (i<ev1.length)
|
|
54 sm.syncExec(ev1[i]);
|
|
55 Runnable start = new Runnable() {
|
|
56 public void run() { try {
|
|
57 sm.init(port1,gui);
|
|
58 } catch (IOException e) {
|
|
59 } catch (InterruptedException e) {
|
192
|
60 }
|
289
|
61 }
|
|
62 };
|
|
63 new Thread(start).run();
|
|
64 return i+1;
|
189
|
65 }
|
|
66
|
220
|
67 public static void main(String[] args){
|
282
|
68 REPServerSocketChannel.isSimulation = true;
|
220
|
69 TestSessionManager test = new TestSessionManager(1, 0, 2);
|
|
70 logger.setLogLevel(5);
|
291
|
71 test.startTest();
|
220
|
72 }
|
|
73
|
289
|
74
|
291
|
75 private void startTest() {
|
289
|
76 int i = 0;
|
|
77 for(SessionManager master:sessionManagers) {
|
|
78 i = startSessionManager(master,i, masterPort + i);
|
|
79 }
|
|
80 for(SessionManager slave:slaveSessionManagers) {
|
|
81 i = startSessionManager(slave,i,masterPort + i);
|
|
82 }
|
|
83 }
|
|
84
|
|
85
|
189
|
86 }
|