189
|
1 package test.sematest;
|
|
2
|
192
|
3 import java.io.IOException;
|
236
|
4 import java.util.LinkedList;
|
|
5
|
|
6 import rep.REP;
|
|
7 import rep.REPCommand;
|
189
|
8 import rep.SessionManager;
|
192
|
9 import rep.channel.REPLogger;
|
189
|
10 import rep.channel.REPServerSocketChannel;
|
193
|
11
|
189
|
12
|
|
13 public class TestSessionManager {
|
|
14
|
192
|
15 static public REPLogger logger = REPLogger.singleton();
|
236
|
16 protected boolean isStart = false;
|
189
|
17
|
192
|
18 public TestSessionManager(int sm, int ss, int e) {
|
189
|
19 }
|
|
20
|
|
21 private void startTest() {
|
213
|
22 int masterPort = 8766;
|
192
|
23 String[] strs ={String.valueOf(masterPort), String.valueOf(masterPort)};
|
|
24 startSessionManager(strs);
|
231
|
25
|
236
|
26 while(!isStart){
|
|
27 try {
|
|
28 Thread.sleep(50);
|
|
29 } catch (InterruptedException e) {
|
|
30 e.printStackTrace();
|
|
31 }
|
|
32 }
|
231
|
33
|
236
|
34 logger.writeLog("TestSessionManager.startTest()", 1);
|
|
35
|
259
|
36 putTest();
|
|
37 joinTest();
|
236
|
38
|
|
39 }
|
|
40
|
252
|
41 private void joinTest() {
|
|
42 REPCommand command = new REPCommand();
|
|
43 command.setCMD(REP.SMCMD_JOIN);
|
|
44 command.setString("JoinTest");
|
|
45 LinkedList<REPCommand> commands = new LinkedList<REPCommand>();
|
|
46 commands.add(command);
|
|
47
|
|
48 Tester tester = new Tester("JoinTester", "localhost", 8766);
|
|
49 tester.setCommands(commands);
|
|
50 tester.start();
|
|
51 }
|
|
52
|
236
|
53 private void putTest() {
|
|
54 REPCommand command = new REPCommand();
|
|
55 command.setCMD(REP.SMCMD_PUT);
|
|
56 command.setString("PutTest.txt");
|
|
57 LinkedList<REPCommand> commands = new LinkedList<REPCommand>();
|
|
58 commands.add(command);
|
|
59
|
252
|
60 Tester tester = new Tester("PutTester", "localhost", 8766);
|
236
|
61 tester.setCommands(commands);
|
|
62 tester.start();
|
192
|
63 }
|
189
|
64
|
192
|
65 private void startSessionManager(final String[] strs) {
|
|
66 new Thread(new Runnable(){
|
|
67 public void run(){
|
|
68 try {
|
231
|
69
|
|
70 int port = 8766;
|
|
71
|
|
72
|
|
73 if(strs.length > 0){
|
|
74 port = Integer.parseInt(strs[0]);
|
|
75 }
|
|
76
|
|
77 SessionManager sm = new SessionManager(port);
|
|
78 sm.openSelector();
|
|
79 sm.init(port);
|
252
|
80 sm.startGUI(sm);
|
231
|
81 logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager");
|
237
|
82 isStart = true;
|
231
|
83 sm.mainLoop();
|
|
84
|
192
|
85 } catch (InterruptedException e) {
|
|
86 e.printStackTrace();
|
|
87 } catch (IOException e) {
|
|
88 e.printStackTrace();
|
|
89 }
|
|
90 }
|
|
91 }).start();
|
189
|
92 }
|
|
93
|
220
|
94 public static void main(String[] args){
|
|
95 REPServerSocketChannel.isSimulation = false;
|
|
96 TestSessionManager test = new TestSessionManager(1, 0, 2);
|
|
97 logger.setLogLevel(5);
|
|
98 test.startTest();
|
|
99 }
|
|
100
|
189
|
101 }
|