changeset 48:e457d6c8907a FederatedLinda_test_two_connent

(no commit message)
author axmo
date Fri, 05 Dec 2008 19:20:22 +0900
parents 8803561e61aa
children 282d42692403
files src/fdl/test/transfer/ProtocolEngine.java src/fdl/test/transfer/Server.java src/fdl/test/transfer/TestSend.java src/fdl/test/transfer/TestTransfer.java
diffstat 4 files changed, 151 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/transfer/ProtocolEngine.java	Fri Dec 05 19:20:22 2008 +0900
@@ -0,0 +1,73 @@
+package fdl.test.transfer;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import fdl.FederatedLinda;
+import fdl.PSXLinda;
+import fdl.PSXReply;
+
+
+public class ProtocolEngine extends Thread{
+	private PSXLinda psx;
+	private String name;
+	FederatedLinda fdl1;
+	String host = "127.0.0.1";
+	int port1 = 10001;
+	int port2 = 10002;
+	private int id = 10;
+	private PSXLinda psx1;
+	private boolean running;
+	private ByteBuffer data2 = ByteBuffer.allocate(10);
+
+	public ProtocolEngine(String string, int port1, int port2) {
+		this.name = string;
+		this.port1 = port1;
+		this.port2 = port2;
+	}
+
+	public void run(){
+		fdl1 = FederatedLinda.init();
+		try {
+			System.out.println(name);
+			psx = fdl1.open(host,port1);
+			System.out.println("Connect Host1");
+			psx1 = fdl1.open(host,port2);
+			System.out.println("Connect Host2");
+			// Host1にデータを送信する。
+			testSend(psx);
+			// psxにデータを用意
+			transfer(psx,psx1);
+			
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	private void testSend(PSXLinda psx2) throws IOException {
+		ByteBuffer send = ByteBuffer.allocate(10);
+		send.putInt(12);
+		send.flip();
+		psx2.out(id, send);
+		psx2.sync();
+	}
+	
+
+	private void transfer(PSXLinda psx2, PSXLinda psx12) throws IOException {
+		PSXReply in = psx2.in(id);
+		while (running) {
+			if(in.ready()){
+				//psx1にデータを書き出し
+				data2 = in.getData();
+				psx12.out(id,data2);
+				//runningフラグをfalseする
+				running = false;
+				fdl1.sync(0);
+				break;
+			}
+			fdl1.sync();
+		}
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/transfer/Server.java	Fri Dec 05 19:20:22 2008 +0900
@@ -0,0 +1,20 @@
+package fdl.test.transfer;
+
+import fdl.FDLindaServ;
+
+public class Server extends Thread {
+	int port;
+	private String name;
+
+	public Server(String string, int i) {
+		port = i;
+		name = string;
+	}
+
+	public void run(){
+		String[] args = {"-p",Integer.toString(port)};
+		System.out.println(name);
+		FDLindaServ.main(args);
+	}
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/transfer/TestSend.java	Fri Dec 05 19:20:22 2008 +0900
@@ -0,0 +1,33 @@
+package fdl.test.transfer;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import fdl.FederatedLinda;
+import fdl.PSXLinda;
+
+public class TestSend extends Thread {
+	PSXLinda psxsend;
+	FederatedLinda fdlsend;
+	
+	public void run(){
+		int id = 10;
+		int port = 10001;
+		String host = "127.0.0.1";
+		ByteBuffer send = ByteBuffer.allocate(1024);
+		send.putInt(12);
+		send.flip();
+		fdlsend = FederatedLinda.init();
+		try{
+			psxsend = fdlsend.open(host,port);
+			System.out.println("Connect Host1");
+			psxsend.out(id, send);
+			fdlsend.sync();
+			System.out.println("Send Data");
+		}catch (IOException e) {
+			System.out.println("例外:" + e);
+		}
+		
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/transfer/TestTransfer.java	Fri Dec 05 19:20:22 2008 +0900
@@ -0,0 +1,25 @@
+package fdl.test.transfer;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+
+public class TestTransfer {
+	@Test
+	public void testTransfer() {
+		int port1 = 10001;
+		int port2 = 10002;
+		Server server1 = new Server("Server1",port1);
+		server1.start();
+		Server server2 = new Server("Server2",port2);
+		server2.start();
+		ProtocolEngine pe = new ProtocolEngine("ProtocolEngine",port1,port2);
+		pe.start();
+		try {
+			pe.join();
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+		assertEquals(1,1);
+	}
+}