changeset 286:30c993e89286

TestEditor
author kono
date Sun, 28 Sep 2008 15:41:42 +0900
parents b468f24c3e09
children 1ff8bfc0a99a
files rep/SessionManager.java rep/channel/ChannelSimulator.java test/sematest/TestEditor.java test/sematest/TestSessionManager.java test/sematest/Tester.java
diffstat 5 files changed, 67 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rep/SessionManager.java	Sun Sep 28 14:50:46 2008 +0900
+++ b/rep/SessionManager.java	Sun Sep 28 15:41:42 2008 +0900
@@ -552,6 +552,7 @@
 			sendCommand.setCMD(REP.SMCMD_JOIN_ACK);
 			sendCommand.setEID(editor.getEID());
 			sendCommand.setSID(sid);
+			sendCommand.string = "";
 			channel.write(sendCommand);
 		}else {
 			sid = event.getSID();
--- a/rep/channel/ChannelSimulator.java	Sun Sep 28 14:50:46 2008 +0900
+++ b/rep/channel/ChannelSimulator.java	Sun Sep 28 15:41:42 2008 +0900
@@ -2,6 +2,7 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.NotYetConnectedException;
 import java.nio.channels.SelectableChannel;
@@ -65,6 +66,11 @@
 	public boolean connect(InetSocketAddress ip){
 		return ns.connect(ip, this); // ns.connectはotherEndを返した方がよいか?
 	}
+	
+	public boolean connect(SocketAddress ip){
+		return ns.connect((InetSocketAddress)ip, this);
+	}
+	
 	void setOtherEnd(ChannelSimulator<P> other){
 		otherEnd = other;
 	}
@@ -95,6 +101,11 @@
 	public SelectionKey keyFor(Selector selector2) {
 		return ((SelectorSimulator) selector2).getKey(this);
 	}
+
+	@SuppressWarnings("unchecked")
+	public SelectionKey keyFor(REPSelector<?> sel) {
+		return (SelectionKey)((SelectorSimulator) sel).getKey(this);
+	}
 	
 	@SuppressWarnings("unchecked")
 	@Override
--- a/test/sematest/TestEditor.java	Sun Sep 28 14:50:46 2008 +0900
+++ b/test/sematest/TestEditor.java	Sun Sep 28 15:41:42 2008 +0900
@@ -23,8 +23,8 @@
 	public static int editorNo = 0;
 	public Text text;
 	public LinkedList<REPCommand> cmds;
-	private int eid;
-	private int sid;
+	private int eid = 0;
+	private int sid = 0;
 	REPSocketChannel<REPCommand> channel;
 	boolean running = true;
 	long timeout = 1;
@@ -39,9 +39,9 @@
 		ns = REPLogger.singleton();
 		this.master = master;
 		myid = editorNo++;
+		cmds = new LinkedList<REPCommand>();
 		if (master) {
 			text = new Text(text1d);
-			cmds = new LinkedList<REPCommand>();
 			cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0"));
 			cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"m0"));
 			cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,""));
@@ -114,7 +114,41 @@
 	private void handle(REPCommand cmd) {
 		ns.writeLog("editor-"+myid+" read "+cmd);
 		switch(cmd.cmd) {
-		
+		 case REPCMD_INSERT	:
+			 break;
+		 case REPCMD_INSERT_ACK	:
+			 break;
+		 case REPCMD_DELETE	:
+			 break;
+		 case REPCMD_DELETE_ACK	:
+			 break;
+		 case REPCMD_CLOSE	:
+		 case REPCMD_CLOSE_2	:
+			 break;
+		 case REPCMD_NOP		:
+			 break;
+		 case SMCMD_JOIN_ACK	:
+			 sid = cmd.sid;
+			 eid = cmd.eid;
+			 break;
+		 case SMCMD_PUT_ACK	:
+			 sid = cmd.sid;
+			 eid = cmd.eid;
+			 break;
+		 case SMCMD_QUIT		:
+		 case SMCMD_QUIT_ACK	:
+			 break;
+		 case SMCMD_START_MERGE :
+		 case SMCMD_START_MERGE_ACK :
+			 break;
+		 case SMCMD_END_MERGE :
+			 break;
+		 case SMCMD_QUIT_2 :
+			 running = false;
+			 break;
+		 default:
+			 assert(false);
+		 	 break;
 		}
 	}
 }
--- a/test/sematest/TestSessionManager.java	Sun Sep 28 14:50:46 2008 +0900
+++ b/test/sematest/TestSessionManager.java	Sun Sep 28 15:41:42 2008 +0900
@@ -35,9 +35,24 @@
 		
 		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();
 	}
 
 	private void joinTest() {
--- a/test/sematest/Tester.java	Sun Sep 28 14:50:46 2008 +0900
+++ b/test/sematest/Tester.java	Sun Sep 28 15:41:42 2008 +0900
@@ -2,7 +2,6 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 import java.util.List;
 
 import rep.REP;
@@ -12,7 +11,7 @@
 import rep.channel.REPSocketChannel;
 
 public class Tester extends Thread{
-	private SocketAddress semaIP;
+	private InetSocketAddress semaIP;
 	protected REPLogger ns;
 	private boolean running = true;
 	protected REPSocketChannel<REPCommand> channel;