# HG changeset patch # User one # Date 1262373385 -32400 # Node ID 03ab374605a62adb6773d6939e91d12f5baed59a # Parent c2e4759eddcbabe7d8dd741684aa3ce8333ff4b0 Test program termination. diff -r c2e4759eddcb -r 03ab374605a6 Todo --- a/Todo Sat Jan 02 03:28:26 2010 +0900 +++ b/Todo Sat Jan 02 04:16:25 2010 +0900 @@ -2,6 +2,9 @@ うーん、まだ、だめですね。 + Session Manager の quit protocol って入れてない気がする... + 切れた場合の対処も入れないといけないんだよな。 + Sat Jan 2 00:02:41 JST 2010 Todo: diff -r c2e4759eddcb -r 03ab374605a6 rep/ServerMainLoop.java --- a/rep/ServerMainLoop.java Sat Jan 02 03:28:26 2010 +0900 +++ b/rep/ServerMainLoop.java Sat Jan 02 04:16:25 2010 +0900 @@ -42,6 +42,7 @@ protected int parent_port; protected static final int DEFAULT_PORT = 8766; private SessionManagerEvent execAfterConnect = null; + private boolean running = true; public void setReceivePort(int port) { @@ -58,7 +59,7 @@ } public void mainLoop() throws IOException { - while(true){ + while(running){ manager.checkWaitingCommandInMerge(); if (checkInputEvent() || checkWaitingWrite()) { @@ -97,6 +98,11 @@ } return false; } + + public void serverStop() { + running = false; + selector.wakeup(); + } /** * To avoid dead locks, we write a command one at a time diff -r c2e4759eddcb -r 03ab374605a6 rep/channel/SelectorSimulator.java --- a/rep/channel/SelectorSimulator.java Sat Jan 02 03:28:26 2010 +0900 +++ b/rep/channel/SelectorSimulator.java Sat Jan 02 04:16:25 2010 +0900 @@ -24,18 +24,15 @@ } public int select() throws IOException { - while(true) { - getSelectedKeys(); - if(selectedKeys.isEmpty()) { - try { - synchronized(this) { - wait(); - } - } catch (InterruptedException e) { - throw new IOException(); + getSelectedKeys(); + if(selectedKeys.isEmpty()) { + try { + synchronized(this) { + wait(); } - } else - break; + } catch (InterruptedException e) { + throw new IOException(); + } } return selectedKeys.size(); } diff -r c2e4759eddcb -r 03ab374605a6 test/sematest/TestInterManagerSession.java --- a/test/sematest/TestInterManagerSession.java Sat Jan 02 03:28:26 2010 +0900 +++ b/test/sematest/TestInterManagerSession.java Sat Jan 02 04:16:25 2010 +0900 @@ -61,6 +61,7 @@ startEditor(m); } editors[0].setCommand(editorStartCmds); + new Thread(finishTest).start(); } } ); @@ -152,8 +153,13 @@ */ REPServerSocketChannel.isSimulation = true; // At least 3 TestEditors are required. - TestInterManagerSession test = new TestInterManagerSession(1, 2, 3); + final TestInterManagerSession test = new TestInterManagerSession(1, 2, 3); logger.setLogLevel(5); + test.finishTest = new Runnable() { + public void run() { + test.finishTest(); + } + }; test.startTest(); } diff -r c2e4759eddcb -r 03ab374605a6 test/sematest/TestSessionManager.java --- a/test/sematest/TestSessionManager.java Sat Jan 02 03:28:26 2010 +0900 +++ b/test/sematest/TestSessionManager.java Sat Jan 02 04:16:25 2010 +0900 @@ -17,6 +17,7 @@ public SessionManager sessionManagers[]; public SessionManager slaveSessionManagers[]; public TestEditor editors[]; + public Runnable finishTest; /* * All test is performed in localhost, so all session manager @@ -43,6 +44,7 @@ for(SessionManager slave:slaveSessionManagers) { i = startSessionManager(slave,i,masterPort + i); } + new Thread(finishTest).start(); } }}; @@ -108,6 +110,23 @@ } } + public void finishTest() { + for(TestEditor editor:editors) { + try { + editor.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + for(SessionManager slave:slaveSessionManagers) { + slave.serverStop(); + } + for(SessionManager master:sessionManagers) { + master.serverStop(); + } + } + public static void main(String[] args){ /* * set simulation mode @@ -116,8 +135,14 @@ */ REPServerSocketChannel.isSimulation = true; // At least 3 TestEditors are required. - TestSessionManager test = new TestSessionManager(1, 0, 3); + final TestSessionManager test = new TestSessionManager(1, 0, 3); logger.setLogLevel(5); + + test.finishTest = new Runnable() { + public void run() { + test.finishTest(); + } + }; test.startTest(); }