Mercurial > hg > RemoteEditor > REPSessionManager
comparison test/sematest/TestSessionManager.java @ 289:d59f4e9e7ad1
*** empty log message ***
author | kono |
---|---|
date | Mon, 29 Sep 2008 06:33:11 +0900 |
parents | 30c993e89286 |
children | 4b773ba03556 |
comparison
equal
deleted
inserted
replaced
288:d93b062eadaa | 289:d59f4e9e7ad1 |
---|---|
1 package test.sematest; | 1 package test.sematest; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.util.LinkedList; | |
5 | |
6 import rep.REP; | |
7 import rep.REPCommand; | |
8 import rep.SessionManager; | 4 import rep.SessionManager; |
9 import rep.SessionManagerEvent; | 5 import rep.SessionManagerEvent; |
10 import rep.SessionManagerGUI; | 6 import rep.SessionManagerGUI; |
11 import rep.channel.REPLogger; | 7 import rep.channel.REPLogger; |
12 import rep.channel.REPServerSocketChannel; | 8 import rep.channel.REPServerSocketChannel; |
13 | 9 |
14 | 10 |
15 public class TestSessionManager { | 11 public class TestSessionManager { |
16 | 12 |
17 static public REPLogger logger = REPLogger.singleton(); | 13 static public REPLogger logger = REPLogger.singleton(); |
18 protected boolean isStart = false; | 14 final int masterPort = 8766; |
15 String host = "localhost"; | |
16 SessionManager sessionManagers[]; | |
17 SessionManager slaveSessionManagers[]; | |
18 TestEditor editors[]; | |
19 | 19 |
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 | |
20 public TestSessionManager(int sm, int ss, int e) { | 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(); | |
38 } | |
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 } | |
21 } | 47 } |
22 | 48 |
23 private void startTest() { | 49 private int startSessionManager(final SessionManager sm,int i,int port) { |
24 int masterPort = 8766; | 50 final SessionManagerGUI gui = new testGUI(sm); |
25 String[] strs ={String.valueOf(masterPort), String.valueOf(masterPort)}; | 51 final int port1 = port; |
26 startSessionManager(strs); | 52 logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); |
27 | 53 if (i<ev1.length) |
28 while(!isStart){ | 54 sm.syncExec(ev1[i]); |
29 try { | 55 Runnable start = new Runnable() { |
30 Thread.sleep(5); | 56 public void run() { try { |
57 sm.init(port1,gui); | |
58 } catch (IOException e) { | |
31 } catch (InterruptedException e) { | 59 } catch (InterruptedException e) { |
32 e.printStackTrace(); | |
33 } | 60 } |
34 } | |
35 | |
36 logger.writeLog("TestSessionManager.startTest()", 1); | |
37 | |
38 //test1(); | |
39 test2(); | |
40 | |
41 } | |
42 | |
43 public void test1() { | |
44 putTest(); | |
45 joinTest(); | |
46 } | |
47 | |
48 public void test2() { | |
49 editor(true); | |
50 editor(false); | |
51 } | |
52 | |
53 private void editor(boolean master) { | |
54 TestEditor e = new TestEditor("Editor", "localhost", 8766, master); | |
55 e.start(); | |
56 } | |
57 | |
58 private void joinTest() { | |
59 REPCommand command = new REPCommand(); | |
60 command.setCMD(REP.SMCMD_JOIN); | |
61 command.setString("JoinTest"); | |
62 LinkedList<REPCommand> commands = new LinkedList<REPCommand>(); | |
63 commands.add(command); | |
64 | |
65 Tester tester = new Tester("JoinTester", "localhost", 8766); | |
66 tester.setCommands(commands); | |
67 tester.start(); | |
68 } | |
69 | |
70 private void putTest() { | |
71 REPCommand command = new REPCommand(); | |
72 command.setCMD(REP.SMCMD_PUT); | |
73 command.setString("PutTest.txt"); | |
74 LinkedList<REPCommand> commands = new LinkedList<REPCommand>(); | |
75 commands.add(command); | |
76 | |
77 Tester tester = new Tester("PutTester", "localhost", 8766); | |
78 tester.setCommands(commands); | |
79 tester.start(); | |
80 } | |
81 | |
82 private void startSessionManager(final String[] strs) { | |
83 new Thread(new Runnable(){ | |
84 public void run(){ | |
85 try { | |
86 | |
87 int port = 8766; | |
88 | |
89 | |
90 if(strs.length > 0){ | |
91 port = Integer.parseInt(strs[0]); | |
92 } | |
93 | |
94 SessionManager sm = new SessionManager(); | |
95 SessionManagerGUI gui = new testGUI(sm); | |
96 logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); | |
97 sm.syncExec(new SessionManagerEvent() { | |
98 // executed before first select(); | |
99 public void exec() { isStart = true; } | |
100 }); | |
101 sm.init(port,gui); | |
102 } catch (InterruptedException e) { | |
103 e.printStackTrace(); | |
104 } catch (IOException e) { | |
105 e.printStackTrace(); | |
106 } | |
107 } | 61 } |
108 }).start(); | 62 }; |
63 new Thread(start).run(); | |
64 return i+1; | |
109 } | 65 } |
110 | 66 |
111 public static void main(String[] args){ | 67 public static void main(String[] args){ |
112 REPServerSocketChannel.isSimulation = true; | 68 REPServerSocketChannel.isSimulation = true; |
113 TestSessionManager test = new TestSessionManager(1, 0, 2); | 69 TestSessionManager test = new TestSessionManager(1, 0, 2); |
114 logger.setLogLevel(5); | 70 logger.setLogLevel(5); |
115 test.startTest(); | 71 try { |
72 test.startTest(); | |
73 } catch (IOException e) { | |
74 } catch (InterruptedException e) { | |
75 } | |
116 } | 76 } |
117 | 77 |
78 | |
79 private void startTest() throws IOException, InterruptedException { | |
80 int i = 0; | |
81 for(SessionManager master:sessionManagers) { | |
82 i = startSessionManager(master,i, masterPort + i); | |
83 } | |
84 for(SessionManager slave:slaveSessionManagers) { | |
85 i = startSessionManager(slave,i,masterPort + i); | |
86 } | |
87 } | |
88 | |
89 | |
118 } | 90 } |