changeset 111:29ed7feebf2a

add API test for in()out() and update().
author kazz
date Fri, 20 Aug 2010 21:22:51 +0900
parents 8ae522e1a4bf
children 27874f473d48
files src/fdl/test/api/inout/InOutClient.java src/fdl/test/api/inout/InOutMetaEngine.java src/fdl/test/api/update/UpdateClient.java src/fdl/test/api/update/UpdateMetaEngine.java src/fdl/test/debug2/TupleId.java src/fdl/test/topology/FDLindaNode.java
diffstat 6 files changed, 220 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/api/inout/InOutClient.java	Fri Aug 20 21:22:51 2010 +0900
@@ -0,0 +1,40 @@
+package fdl.test.api.inout;
+
+import java.io.IOException;
+import fdl.test.topology.FDLindaNode;
+
+public class InOutClient {
+	private static int localPort = 10001;
+	private static String host = "localhost";
+	private static int port = 10000;
+	private static int count = 1;
+	private static String usageString = "Usage: InOutClient [-host hostname] [-port portnum] [-count countnum]";
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		for (int i = 0; i < args.length; i++) {
+			if ("-host".equals(args[i])) {
+				host  = args[++i];
+			} else if ("-port".equals(args[i])) {
+				port = Integer.parseInt(args[++i]);
+			} else if ("-count".equals(args[i])) {
+				count = Integer.parseInt(args[++i]);
+			} else if ("-d".equals(args[i])) {
+				FDLindaNode.debug = true;
+			} else {
+				System.err.println(usageString);
+			}
+		}
+		
+		try {
+			FDLindaNode node = new FDLindaNode(localPort);
+			InOutMetaEngine me = InOutMetaEngine.create(node.getMetaLinda(), host, port, count);
+			node.setMetaEngine(me);
+			node.mainLoop();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/api/inout/InOutMetaEngine.java	Fri Aug 20 21:22:51 2010 +0900
@@ -0,0 +1,68 @@
+package fdl.test.api.inout;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Date;
+
+import fdl.MetaEngine;
+import fdl.MetaLinda;
+import fdl.PSXLinda;
+import fdl.PSXReply;
+
+public class InOutMetaEngine implements MetaEngine {
+	private final static int targetId = 1000;
+
+	private String host;
+	private int port;
+	private int maxCount, count = 0;
+	private MetaLinda ml;
+	private PSXLinda linda;
+	private PSXReply reply;
+	private Date startTime, endTime;
+	
+	private InOutMetaEngine(MetaLinda metaLinda, String host, int port, int count) {
+		this.ml = metaLinda;
+		this.host = host;
+		this.port = port;
+		this.maxCount = count;
+	}
+
+	private void connect() {
+		try {
+			linda = ml.open(host, port);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public void mainLoop(MetaLinda ml) {
+		if (count >= maxCount) {
+			endTime = new Date();
+			Long resultTime = new Long(endTime.getTime() - startTime.getTime()); 
+			System.out.println(resultTime);
+			System.exit(0);
+		}
+		if (reply == null) {
+			reply = linda.in(targetId);
+			linda.out(targetId, ByteBuffer.wrap("test".getBytes()));
+			return;
+		}
+		if (reply.ready()) {
+			reply = null;
+			count++;
+		}
+	}
+	
+	public static InOutMetaEngine create(MetaLinda metaLinda, String host, int port, int count) {
+		InOutMetaEngine iome = new InOutMetaEngine(metaLinda, host, port, count);
+		iome.connect();
+		iome.linda.out(targetId, ByteBuffer.wrap("test".getBytes()));
+		try {
+			iome.linda.sync();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		iome.startTime = new Date();
+		return iome;
+	} 
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/api/update/UpdateClient.java	Fri Aug 20 21:22:51 2010 +0900
@@ -0,0 +1,40 @@
+package fdl.test.api.update;
+
+import java.io.IOException;
+import fdl.test.topology.FDLindaNode;
+
+public class UpdateClient {
+	private static int localPort = 10001;
+	private static String host = "localhost";
+	private static int port = 10000;
+	private static int count = 1;
+	private static String usageString = "Usage: UpdateClient [-host hostname] [-port portnum] [-count countnum]";
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		for (int i = 0; i < args.length; i++) {
+			if ("-host".equals(args[i])) {
+				host  = args[++i];
+			} else if ("-port".equals(args[i])) {
+				port = Integer.parseInt(args[++i]);
+			} else if ("-count".equals(args[i])) {
+				count = Integer.parseInt(args[++i]);
+			} else if ("-d".equals(args[i])) {
+				FDLindaNode.debug = true;
+			} else {
+				System.err.println(usageString);
+			}
+		}
+		
+		try {
+			FDLindaNode node = new FDLindaNode(localPort);
+			UpdateMetaEngine me = UpdateMetaEngine.create(node.getMetaLinda(), host, port, count);
+			node.setMetaEngine(me);
+			node.mainLoop();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/api/update/UpdateMetaEngine.java	Fri Aug 20 21:22:51 2010 +0900
@@ -0,0 +1,67 @@
+package fdl.test.api.update;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Date;
+
+import fdl.MetaEngine;
+import fdl.MetaLinda;
+import fdl.PSXLinda;
+import fdl.PSXReply;
+
+public class UpdateMetaEngine implements MetaEngine {
+	private final static int targetId = 1001;
+
+	private String host;
+	private int port;
+	private int maxCount, count = 0;
+	private MetaLinda ml;
+	private PSXLinda linda;
+	private PSXReply reply;
+	private Date startTime, endTime;
+	
+	private UpdateMetaEngine(MetaLinda metaLinda, String host, int port, int count) {
+		this.ml = metaLinda;
+		this.host = host;
+		this.port = port;
+		this.maxCount = count;
+	}
+
+	private void connect() {
+		try {
+			linda = ml.open(host, port);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public void mainLoop(MetaLinda ml) {
+		if (count >= maxCount) {
+			endTime = new Date();
+			Long resultTime = new Long(endTime.getTime() - startTime.getTime()); 
+			System.out.println(resultTime);
+			System.exit(0);
+		}
+		if (reply == null) {
+			reply = linda.update(targetId, ByteBuffer.wrap("test".getBytes()));
+			return;
+		}
+		if (reply.ready()) {
+			reply = null;
+			count++;
+		}
+	}
+	
+	public static UpdateMetaEngine create(MetaLinda metaLinda, String host, int port, int count) {
+		UpdateMetaEngine iome = new UpdateMetaEngine(metaLinda, host, port, count);
+		iome.connect();
+		iome.linda.out(targetId, ByteBuffer.wrap("test".getBytes()));
+		try {
+			iome.linda.sync();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		iome.startTime = new Date();
+		return iome;
+	} 
+}
--- a/src/fdl/test/debug2/TupleId.java	Wed Aug 04 21:41:39 2010 +0900
+++ b/src/fdl/test/debug2/TupleId.java	Fri Aug 20 21:22:51 2010 +0900
@@ -32,6 +32,7 @@
 //		}
 		return hash.get(id);
 	}
+	
 	static {
 		for (TupleId tid : TupleId.values()) {
 			hash.put(tid.id, tid);
--- a/src/fdl/test/topology/FDLindaNode.java	Wed Aug 04 21:41:39 2010 +0900
+++ b/src/fdl/test/topology/FDLindaNode.java	Fri Aug 20 21:22:51 2010 +0900
@@ -31,7 +31,10 @@
 	}
 	
 	@Override public void mainLoop() {
-		me.mainLoop(ml);
+		while (true) { // loop
+			me.mainLoop(ml);
+			ml.sync();
+		}
 	}
 	public void setMetaEngine(MetaEngine me) {
 		this.me = me; 
@@ -39,7 +42,6 @@
 	public MetaLinda getMetaLinda() {
 		return ml;
 	}
-	
 	// main routine
 	public static void main(String[] args) {
 		for (int i = 0; i < args.length; i++) {