Mercurial > hg > RemoteEditor > REPSessionManager
diff test/sematest/TestSessionManager.java @ 289:d59f4e9e7ad1
*** empty log message ***
author | kono |
---|---|
date | Mon, 29 Sep 2008 06:33:11 +0900 |
parents | 30c993e89286 |
children | 4b773ba03556 |
line wrap: on
line diff
--- a/test/sematest/TestSessionManager.java Mon Sep 29 05:11:49 2008 +0900 +++ b/test/sematest/TestSessionManager.java Mon Sep 29 06:33:11 2008 +0900 @@ -1,10 +1,6 @@ package test.sematest; import java.io.IOException; -import java.util.LinkedList; - -import rep.REP; -import rep.REPCommand; import rep.SessionManager; import rep.SessionManagerEvent; import rep.SessionManagerGUI; @@ -15,104 +11,80 @@ public class TestSessionManager { static public REPLogger logger = REPLogger.singleton(); - protected boolean isStart = false; - - public TestSessionManager(int sm, int ss, int e) { - } + final int masterPort = 8766; + String host = "localhost"; + SessionManager sessionManagers[]; + SessionManager slaveSessionManagers[]; + TestEditor editors[]; - private void startTest() { - int masterPort = 8766; - String[] strs ={String.valueOf(masterPort), String.valueOf(masterPort)}; - startSessionManager(strs); - - while(!isStart){ - try { - Thread.sleep(5); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SessionManagerEvent ev1[] = { + new SessionManagerEvent() { + // executed before first select(); + public void exec() { + for(TestEditor editor:editors) { + editor.start(); + } + } + }}; + int editorPort[] = {masterPort,masterPort}; + boolean editorMaster[] = {true,false}; + + public TestSessionManager(int sm, int ss, int e) { + sessionManagers = new SessionManager[sm]; + slaveSessionManagers = new SessionManager[ss]; + editors = new TestEditor[e]; + for(int i=0;i<sm;i++) { + sessionManagers[i] = new SessionManager(); } - - logger.writeLog("TestSessionManager.startTest()", 1); - - //test1(); - test2(); - - } - - public void test1() { - putTest(); - joinTest(); - } - - public void test2() { - editor(true); - editor(false); - } - - private void editor(boolean master) { - TestEditor e = new TestEditor("Editor", "localhost", 8766, master); - e.start(); + for(int i=0;i<ss;i++) { + slaveSessionManagers[i] = new SessionManager(); + } + for(int i=0;i<e;i++) { + int port = editorPort[i%editorPort.length]; + boolean master = editorMaster[i%editorMaster.length]; + editors[i] = new TestEditor("Editor"+i,host,port,master); + } } - private void joinTest() { - REPCommand command = new REPCommand(); - command.setCMD(REP.SMCMD_JOIN); - command.setString("JoinTest"); - LinkedList<REPCommand> commands = new LinkedList<REPCommand>(); - commands.add(command); - - Tester tester = new Tester("JoinTester", "localhost", 8766); - tester.setCommands(commands); - tester.start(); - } - - private void putTest() { - REPCommand command = new REPCommand(); - command.setCMD(REP.SMCMD_PUT); - command.setString("PutTest.txt"); - LinkedList<REPCommand> commands = new LinkedList<REPCommand>(); - commands.add(command); - - Tester tester = new Tester("PutTester", "localhost", 8766); - tester.setCommands(commands); - tester.start(); - } - - private void startSessionManager(final String[] strs) { - new Thread(new Runnable(){ - public void run(){ - try { - - int port = 8766; - - - if(strs.length > 0){ - port = Integer.parseInt(strs[0]); - } - - SessionManager sm = new SessionManager(); - SessionManagerGUI gui = new testGUI(sm); - logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); - sm.syncExec(new SessionManagerEvent() { - // executed before first select(); - public void exec() { isStart = true; } - }); - sm.init(port,gui); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + private int startSessionManager(final SessionManager sm,int i,int port) { + final SessionManagerGUI gui = new testGUI(sm); + final int port1 = port; + logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); + if (i<ev1.length) + sm.syncExec(ev1[i]); + Runnable start = new Runnable() { + public void run() { try { + sm.init(port1,gui); + } catch (IOException e) { + } catch (InterruptedException e) { } - }).start(); + } + }; + new Thread(start).run(); + return i+1; } public static void main(String[] args){ REPServerSocketChannel.isSimulation = true; TestSessionManager test = new TestSessionManager(1, 0, 2); logger.setLogLevel(5); - test.startTest(); + try { + test.startTest(); + } catch (IOException e) { + } catch (InterruptedException e) { + } } + + private void startTest() throws IOException, InterruptedException { + int i = 0; + for(SessionManager master:sessionManagers) { + i = startSessionManager(master,i, masterPort + i); + } + for(SessionManager slave:slaveSessionManagers) { + i = startSessionManager(slave,i,masterPort + i); + } + } + + }