# HG changeset patch
# User kono
# Date 1222584102 -32400
# Node ID 30c993e89286ef96260cd316d00d61310739e9b6
# Parent b468f24c3e090b278622282bd9eb1c9eeff565d7
TestEditor
diff -r b468f24c3e09 -r 30c993e89286 rep/SessionManager.java
--- 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();
diff -r b468f24c3e09 -r 30c993e89286 rep/channel/ChannelSimulator.java
--- 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
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
diff -r b468f24c3e09 -r 30c993e89286 test/sematest/TestEditor.java
--- 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 cmds;
- private int eid;
- private int sid;
+ private int eid = 0;
+ private int sid = 0;
REPSocketChannel channel;
boolean running = true;
long timeout = 1;
@@ -39,9 +39,9 @@
ns = REPLogger.singleton();
this.master = master;
myid = editorNo++;
+ cmds = new LinkedList();
if (master) {
text = new Text(text1d);
- cmds = new LinkedList();
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;
}
}
}
diff -r b468f24c3e09 -r 30c993e89286 test/sematest/TestSessionManager.java
--- 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() {
diff -r b468f24c3e09 -r 30c993e89286 test/sematest/Tester.java
--- 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 channel;