Mercurial > hg > RemoteEditor > REPSessionManager
diff test/editortest/TestSessionManager2.java @ 414:784a4d67e6a5
(no commit message)
author | one |
---|---|
date | Tue, 09 Dec 2008 15:44:28 +0900 |
parents | |
children | b7f42fc75a36 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/editortest/TestSessionManager2.java Tue Dec 09 15:44:28 2008 +0900 @@ -0,0 +1,127 @@ +package test.editortest; + +import java.io.IOException; + +import rep.SessionManager; +import rep.channel.REPLogger; +import rep.channel.REPServerSocketChannel; +import rep.gui.SessionManagerEvent; +import rep.gui.SessionManagerGUI; +import test.sematest.TestGUI; + + +public class TestSessionManager2 { + + static public REPLogger logger = REPLogger.singleton(); + public int masterPort = 8766; + public String host = "localhost"; + public SessionManager sessionManagers[]; + public SessionManager slaveSessionManagers[]; + public TestEditor2 editors[]; + + /* + * All test is performed in localhost, so all session manager + * should have differenct port number each other. + */ + + /* + * Test Pattern List + * Connect port for each editor + * Master/client flag for each editor + * Editor or slave session manager must be started by + * master session managers using syncExec. + */ + public int editorPort[] = {masterPort,masterPort,masterPort}; + public boolean editorMaster[] = {true,false,false,false}; + private SessionManagerEvent ev1[] = { + new SessionManagerEvent() { + // executed before first select(); + public void exec(SessionManager manager) { + for(TestEditor2 editor:editors) { + editor.start(); + } + int i = sessionManagers.length; + for(SessionManager slave:slaveSessionManagers) { + i = startSessionManager(slave,i,masterPort + i); + } + } + }}; + + /* + * Create all editors, master session managers and slave session + * managers with specified port. All instances are not started yet. + */ + + public TestSessionManager2(int sm, int ss, int e) { + sessionManagers = new SessionManager[sm]; + slaveSessionManagers = new SessionManager[ss]; + editors = new TestEditor2[e]; + for(int i=0;i<sm;i++) { + sessionManagers[i] = new SessionManager(); + } + 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]; + // TestEditor extends Thread + editors[i] = new TestEditor2("Editor"+i,host,port,master); + } + } + + /* + * start session manager. sm.init(port,guit) is a mainloop, so + * we need Thread here. + */ + public 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"); + // syncExec does not wake selector, do this before run(). + sm.setReceivePort(port1); + setSMEvent(sm,i); + Runnable start = new Runnable() { + public void run() { + try { + sm.init(port1,gui); + } catch (IOException e) { + } catch (InterruptedException e) { + } + } + }; + new Thread(start).start(); + return i+1; + } + + + public void setSMEvent(SessionManager s,int i) { + if (i<ev1.length) { + s.syncExec(ev1[i]); + } + return ; + } + + protected void startTest() { + int i = 0; + for(SessionManager master:sessionManagers) { + i = startSessionManager(master,i, masterPort + i); + } + } + + public static void main(String[] args){ + /* + * set simulation mode + * isSimulation=true thread base simulation for PathFinder + * isSimulation=false socket based communication mode + */ + REPServerSocketChannel.isSimulation = false; + //Editor.noMergeMode = true; + // At least 3 TestEditors are required. + TestSessionManager2 test = new TestSessionManager2(1, 0, 3); + logger.setLogLevel(5); + test.startTest(); + } + + +}