annotate test/sematest/TestSessionManager.java @ 291:9e162e0a114f

*** empty log message ***
author kono
date Mon, 29 Sep 2008 06:34:13 +0900
parents 4b773ba03556
children 975383c0548e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
1 package test.sematest;
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
2
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
3 import java.io.IOException;
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
4 import rep.SessionManager;
281
c3969dd625b2 GUIless test routine.
kono
parents: 280
diff changeset
5 import rep.SessionManagerEvent;
c3969dd625b2 GUIless test routine.
kono
parents: 280
diff changeset
6 import rep.SessionManagerGUI;
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
7 import rep.channel.REPLogger;
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
8 import rep.channel.REPServerSocketChannel;
193
311847db7429 *** empty log message ***
pin
parents: 192
diff changeset
9
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
10
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
11 public class TestSessionManager {
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
12
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
13 static public REPLogger logger = REPLogger.singleton();
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
14 final int masterPort = 8766;
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
15 String host = "localhost";
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
16 SessionManager sessionManagers[];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
17 SessionManager slaveSessionManagers[];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
18 TestEditor editors[];
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
19
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
20 SessionManagerEvent ev1[] = {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
21 new SessionManagerEvent() {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
22 // executed before first select();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
23 public void exec() {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
24 for(TestEditor editor:editors) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
25 editor.start();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
26 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
27 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
28 }};
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
29 int editorPort[] = {masterPort,masterPort};
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
30 boolean editorMaster[] = {true,false};
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
31
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
32 public TestSessionManager(int sm, int ss, int e) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
33 sessionManagers = new SessionManager[sm];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
34 slaveSessionManagers = new SessionManager[ss];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
35 editors = new TestEditor[e];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
36 for(int i=0;i<sm;i++) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
37 sessionManagers[i] = new SessionManager();
236
2abd1dc12453 *** empty log message ***
pin
parents: 231
diff changeset
38 }
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
39 for(int i=0;i<ss;i++) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
40 slaveSessionManagers[i] = new SessionManager();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
41 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
42 for(int i=0;i<e;i++) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
43 int port = editorPort[i%editorPort.length];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
44 boolean master = editorMaster[i%editorMaster.length];
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
45 editors[i] = new TestEditor("Editor"+i,host,port,master);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
46 }
236
2abd1dc12453 *** empty log message ***
pin
parents: 231
diff changeset
47 }
2abd1dc12453 *** empty log message ***
pin
parents: 231
diff changeset
48
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
49 private int startSessionManager(final SessionManager sm,int i,int port) {
290
4b773ba03556 *** empty log message ***
kono
parents: 289
diff changeset
50 final SessionManagerGUI gui = new TestGUI(sm);
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
51 final int port1 = port;
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
52 logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager");
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
53 if (i<ev1.length)
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
54 sm.syncExec(ev1[i]);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
55 Runnable start = new Runnable() {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
56 public void run() { try {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
57 sm.init(port1,gui);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
58 } catch (IOException e) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
59 } catch (InterruptedException e) {
192
6fb97c7a0b42 *** empty log message ***
pin
parents: 189
diff changeset
60 }
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
61 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
62 };
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
63 new Thread(start).run();
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
64 return i+1;
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
65 }
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
66
220
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
67 public static void main(String[] args){
282
c410eda661e8 *** empty log message ***
kono
parents: 281
diff changeset
68 REPServerSocketChannel.isSimulation = true;
220
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
69 TestSessionManager test = new TestSessionManager(1, 0, 2);
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
70 logger.setLogLevel(5);
291
9e162e0a114f *** empty log message ***
kono
parents: 290
diff changeset
71 test.startTest();
220
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
72 }
216d64cd5f3a *** empty log message ***
pin
parents: 218
diff changeset
73
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
74
291
9e162e0a114f *** empty log message ***
kono
parents: 290
diff changeset
75 private void startTest() {
289
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
76 int i = 0;
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
77 for(SessionManager master:sessionManagers) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
78 i = startSessionManager(master,i, masterPort + i);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
79 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
80 for(SessionManager slave:slaveSessionManagers) {
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
81 i = startSessionManager(slave,i,masterPort + i);
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
82 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
83 }
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
84
d59f4e9e7ad1 *** empty log message ***
kono
parents: 286
diff changeset
85
189
d03e34861a26 *** empty log message ***
pin
parents:
diff changeset
86 }