Mercurial > hg > RemoteEditor > REPSessionManager
view test/sematest/TestInterManagerSession.java @ 502:49b689b17d06 default tip
merged TestEditor to REPEditor
author | suika6039 |
---|---|
date | Tue, 21 Dec 2010 18:01:15 +0900 |
parents | d2762d669617 |
children |
line wrap: on
line source
package test.sematest; import java.util.LinkedList; import rep.REP; import rep.REPCommand; import rep.SessionManager; import rep.channel.REPServerSocketChannel; import rep.gui.SessionManagerEvent; public class TestInterManagerSession extends TestSessionManager { /* * 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 slavePort[] = {masterPort,masterPort,masterPort}; public int editorPort[] = {masterPort,masterPort+1,masterPort+2}; public boolean editorMaster[] = {true,false,false,false}; private LinkedList<REPCommand> editorStartCmds; private SessionManagerEvent ev2[] = { new SessionManagerEvent() { public void exec(SessionManager manager) { int i = sessionManagers.length; for(SessionManager slave:slaveSessionManagers) { if (slave.getParentPort()==masterPort) { logger.writeLog("Start slave "+slave); i = startSessionManager(slave,i,masterPort + i); } } } }, new SessionManagerEvent() { public void exec(SessionManager manager) { manager.connectSessionManager(host); } }, new SessionManagerEvent() { public void exec(SessionManager manager) { // // try to make a loop // if (false) { // sessionManagers[0].connectSessionManager(host, // manager.getPort()); // } manager.connectSessionManager(host); manager.execAfterConnect( new SessionManagerEvent() { public void exec(SessionManager manager) { for(SessionManager m:sessionManagers) { startEditor(m); } for(SessionManager m:slaveSessionManagers) { startEditor(m); } editors[0].setCommand(editorStartCmds); new Thread(finishTest).start(); } } ); } } }; //private int inscnt=2; private void startEditor(SessionManager m) { for(TestEditor editor:editors) { if(editor.getPort()==m.getPort()) { logger.writeLog("Start client "+editor); editor.start(); } } } /* * Create all editors, master session managers and slave session * managers with specified port. All instances are not started yet. */ public TestInterManagerSession(int sm, int ss, int e) { super(sm,ss,e); sessionManagers = new SessionManager[sm]; slaveSessionManagers = new SessionManager[ss]; editors = new TestEditor[e]; for(int i=0;i<sm;i++) { sessionManagers[i] = new SessionManager(); } for(int i=0;i<ss;i++) { int port = slavePort[i%slavePort.length]; slaveSessionManagers[i] = new SessionManager(); slaveSessionManagers[i].setParentPort(port); } for(int i=0;i<e;i++) { int port = editorPort[i%editorPort.length]; boolean master = editorMaster[i%editorMaster.length]; // TestEditor extends Thread LinkedList<REPCommand>cmds = new LinkedList<REPCommand>(); cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,"")); //if (inscnt-->0) cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0")); editors[i] = new TestEditor("Editor",host,port,master); //editors[i].setCommand(cmds); } setupEditor0(); } private void setupEditor0() { /* * do not startup Editor0 until SessionManagers are ready. * Define pending command and set null command for now. */ LinkedList<REPCommand>cmds = new LinkedList<REPCommand>(); //cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,"Editor0-file")); cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,"Editor0-file")); cmds.add(new REPCommand(REP.SMCMD_SLEEP,0,0,0,0,"")); cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0")); // cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0")); cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); editorStartCmds = cmds; LinkedList<REPCommand>nullcmds = new LinkedList<REPCommand>(); editors[0].setCommand(nullcmds); } @Override public void setSMEvent(SessionManager s,int i) { if (i<ev2.length) { s.syncExec(ev2[i]); } return ; } @Override protected void startTest() { int i = 0; for(SessionManager master:sessionManagers) { logger.writeLog("Start master "+i+" "+master); 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 = true; // At least 3 TestEditors are required. final TestInterManagerSession test = new TestInterManagerSession(1, 2, 3); logger.setLogLevel(5); test.finishTest = new Runnable() { public void run() { test.finishTest(); } }; test.startTest(); } }