From 9bb2f5e52422630a98a4ef28badce8d472e10297 Mon Sep 17 00:00:00 2001 From: Hendrik Buschmeier <hbuschme@TechFak.Uni-Bielefeld.DE> Date: Mon, 20 Feb 2012 17:19:11 +0100 Subject: [PATCH] Non-working working version of Java-Python test. --- java/rsb.cfg | 5 ++ java/src/ipaaca/Ipaaca.java | 50 +++++++------- java/src/ipaacademo/PythonCall.java | 54 +++++++++++++++ java/src/ipaacademo/TextPrinter.java | 6 +- java/test/src/ipaaca/IUTestUtil.java | 1 - java/test/src/ipaaca/JavaPythonTest.java | 85 ++++++++++++++++++++++++ 6 files changed, 172 insertions(+), 29 deletions(-) create mode 100644 java/rsb.cfg create mode 100644 java/src/ipaacademo/PythonCall.java create mode 100644 java/test/src/ipaaca/JavaPythonTest.java diff --git a/java/rsb.cfg b/java/rsb.cfg new file mode 100644 index 0000000..c7d8582 --- /dev/null +++ b/java/rsb.cfg @@ -0,0 +1,5 @@ +[transport.spread] +host = localhost # default type is string +port = 4803 # types can be specified in angle brackets +enabled = true + diff --git a/java/src/ipaaca/Ipaaca.java b/java/src/ipaaca/Ipaaca.java index 8cb1eb0..b6d4257 100644 --- a/java/src/ipaaca/Ipaaca.java +++ b/java/src/ipaaca/Ipaaca.java @@ -1,5 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// source: proto/ipaaca.proto +// source: ipaaca.proto package ipaaca; @@ -6278,30 +6278,30 @@ public final class Ipaaca { descriptor; static { java.lang.String[] descriptorData = { - "\n\022proto/ipaaca.proto\022\006ipaaca\"\033\n\nIntMessa" + - "ge\022\r\n\005value\030\001 \002(\021\"(\n\007LinkSet\022\014\n\004type\030\001 \002" + - "(\t\022\017\n\007targets\030\002 \003(\t\"<\n\013PayloadItem\022\013\n\003ke" + - "y\030\001 \002(\t\022\r\n\005value\030\002 \002(\t\022\021\n\004type\030\003 \002(\t:\003st" + - "r\"\310\002\n\002IU\022\013\n\003uid\030\001 \002(\t\022\020\n\010revision\030\002 \002(\r\022" + - "\027\n\010category\030\003 \002(\t:\005undef\022\031\n\014payload_type" + - "\030\004 \002(\t:\003MAP\022\022\n\nowner_name\030\005 \002(\t\022\030\n\tcommi" + - "tted\030\006 \002(\010:\005false\0220\n\013access_mode\030\007 \002(\0162\025" + - ".ipaaca.IU.AccessMode:\004PUSH\022\030\n\tread_only" + - "\030\010 \002(\010:\005false\022$\n\007payload\030\t \003(\0132\023.ipaaca.", - "PayloadItem\022\036\n\005links\030\n \003(\0132\017.ipaaca.Link" + - "Set\"/\n\nAccessMode\022\010\n\004PUSH\020\000\022\n\n\006REMOTE\020\001\022" + - "\013\n\007MESSAGE\020\002\"\236\001\n\017IUPayloadUpdate\022\013\n\003uid\030" + - "\001 \002(\t\022\020\n\010revision\030\002 \002(\r\022&\n\tnew_items\030\003 \003" + - "(\0132\023.ipaaca.PayloadItem\022\026\n\016keys_to_remov" + - "e\030\004 \003(\t\022\027\n\010is_delta\030\005 \002(\010:\005false\022\023\n\013writ" + - "er_name\030\006 \002(\t\"-\n\014IURetraction\022\013\n\003uid\030\001 \002" + - "(\t\022\020\n\010revision\030\002 \002(\r\"B\n\014IUCommission\022\013\n\003" + - "uid\030\001 \002(\t\022\020\n\010revision\030\002 \002(\r\022\023\n\013writer_na" + - "me\030\003 \002(\t\"\251\001\n\014IULinkUpdate\022\013\n\003uid\030\001 \002(\t\022\020", - "\n\010revision\030\002 \002(\r\022\"\n\tnew_links\030\003 \003(\0132\017.ip" + - "aaca.LinkSet\022(\n\017links_to_remove\030\004 \003(\0132\017." + - "ipaaca.LinkSet\022\027\n\010is_delta\030\005 \002(\010:\005false\022" + - "\023\n\013writer_name\030\006 \002(\t" + "\n\014ipaaca.proto\022\006ipaaca\"\033\n\nIntMessage\022\r\n\005" + + "value\030\001 \002(\021\"(\n\007LinkSet\022\014\n\004type\030\001 \002(\t\022\017\n\007" + + "targets\030\002 \003(\t\"<\n\013PayloadItem\022\013\n\003key\030\001 \002(" + + "\t\022\r\n\005value\030\002 \002(\t\022\021\n\004type\030\003 \002(\t:\003str\"\310\002\n\002" + + "IU\022\013\n\003uid\030\001 \002(\t\022\020\n\010revision\030\002 \002(\r\022\027\n\010cat" + + "egory\030\003 \002(\t:\005undef\022\031\n\014payload_type\030\004 \002(\t" + + ":\003MAP\022\022\n\nowner_name\030\005 \002(\t\022\030\n\tcommitted\030\006" + + " \002(\010:\005false\0220\n\013access_mode\030\007 \002(\0162\025.ipaac" + + "a.IU.AccessMode:\004PUSH\022\030\n\tread_only\030\010 \002(\010" + + ":\005false\022$\n\007payload\030\t \003(\0132\023.ipaaca.Payloa", + "dItem\022\036\n\005links\030\n \003(\0132\017.ipaaca.LinkSet\"/\n" + + "\nAccessMode\022\010\n\004PUSH\020\000\022\n\n\006REMOTE\020\001\022\013\n\007MES" + + "SAGE\020\002\"\236\001\n\017IUPayloadUpdate\022\013\n\003uid\030\001 \002(\t\022" + + "\020\n\010revision\030\002 \002(\r\022&\n\tnew_items\030\003 \003(\0132\023.i" + + "paaca.PayloadItem\022\026\n\016keys_to_remove\030\004 \003(" + + "\t\022\027\n\010is_delta\030\005 \002(\010:\005false\022\023\n\013writer_nam" + + "e\030\006 \002(\t\"-\n\014IURetraction\022\013\n\003uid\030\001 \002(\t\022\020\n\010" + + "revision\030\002 \002(\r\"B\n\014IUCommission\022\013\n\003uid\030\001 " + + "\002(\t\022\020\n\010revision\030\002 \002(\r\022\023\n\013writer_name\030\003 \002" + + "(\t\"\251\001\n\014IULinkUpdate\022\013\n\003uid\030\001 \002(\t\022\020\n\010revi", + "sion\030\002 \002(\r\022\"\n\tnew_links\030\003 \003(\0132\017.ipaaca.L" + + "inkSet\022(\n\017links_to_remove\030\004 \003(\0132\017.ipaaca" + + ".LinkSet\022\027\n\010is_delta\030\005 \002(\010:\005false\022\023\n\013wri" + + "ter_name\030\006 \002(\t" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { diff --git a/java/src/ipaacademo/PythonCall.java b/java/src/ipaacademo/PythonCall.java new file mode 100644 index 0000000..09c7093 --- /dev/null +++ b/java/src/ipaacademo/PythonCall.java @@ -0,0 +1,54 @@ +package ipaacademo; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class PythonCall +{ + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException + { + String program = "print 'Hello world'"; + Process p = Runtime.getRuntime().exec(new String[]{"python","-c", program}); + + InputStream in = p.getInputStream(); + BufferedInputStream buf = new BufferedInputStream(in); + InputStreamReader inread = new InputStreamReader(buf); + BufferedReader bufferedreader = new BufferedReader(inread); + // Read the ls output + String line; + while ((line = bufferedreader.readLine()) != null) + { + System.out.println(line); + } + + try + { + if (p.waitFor() != 0) + { + System.err.println("exit value = " + p.exitValue()); + } + } + catch (InterruptedException e) + { + System.err.println(e); + } + + in = p.getErrorStream(); + buf = new BufferedInputStream(in); + inread = new InputStreamReader(buf); + bufferedreader = new BufferedReader(inread); + // Read the ls output + while ((line = bufferedreader.readLine()) != null) + { + System.out.println(line); + } + } +} diff --git a/java/src/ipaacademo/TextPrinter.java b/java/src/ipaacademo/TextPrinter.java index 2e72579..25f6ce8 100644 --- a/java/src/ipaacademo/TextPrinter.java +++ b/java/src/ipaacademo/TextPrinter.java @@ -22,7 +22,7 @@ public class TextPrinter } private static final String CATEGORY = "TEXT"; - private static final double RATE = 1; + private static final double RATE = 0.5; private UpdateThread updateThread; public TextPrinter() @@ -94,7 +94,7 @@ public class TextPrinter try { - Thread.sleep(100); + Thread.sleep(200); } catch (InterruptedException e) { @@ -111,7 +111,7 @@ public class TextPrinter OutputBuffer outBuffer = new OutputBuffer("componentX"); - String[] inputString = {"h","e","l","l","o"," ","w","o","r","l","d","!s"}; + String[] inputString = {"h","e","l","l","o"," ","w","o","r","l","d","!"}; LocalIU predIU = null; for(String str:inputString) { diff --git a/java/test/src/ipaaca/IUTestUtil.java b/java/test/src/ipaaca/IUTestUtil.java index f47149c..aca1b2d 100644 --- a/java/test/src/ipaaca/IUTestUtil.java +++ b/java/test/src/ipaaca/IUTestUtil.java @@ -1,5 +1,4 @@ package ipaaca; -import static org.junit.Assert.*; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; diff --git a/java/test/src/ipaaca/JavaPythonTest.java b/java/test/src/ipaaca/JavaPythonTest.java new file mode 100644 index 0000000..5fe8539 --- /dev/null +++ b/java/test/src/ipaaca/JavaPythonTest.java @@ -0,0 +1,85 @@ +package ipaaca; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Set; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.google.common.collect.ImmutableSet; + +public class JavaPythonTest { + + static { + Initializer.initializeIpaacaRsb(); + } + + private InputBuffer inBuffer; + + @Before + public void setup() + { + Set<String> categories = new ImmutableSet.Builder<String>().add("JavaPythonTest").build(); + inBuffer = new InputBuffer("javaside", categories); + } + + @Ignore + @Test + public void test() throws IOException, InterruptedException { + + String pypr = + "import sys\n" + + "sys.path.append('../python/build/')\n" + + "import ipaaca, time\n" + + "ob = ipaaca.OutputBuffer('pythonside')\n" + + "iu = ipaaca.IU('JavaPythonTest')\n" + + "iu.payload = {'data':'Hello from Python!'}\n" + + "time.sleep(0.1)\n" + + "ob.add(iu)"; + Process p = Runtime.getRuntime().exec(new String[]{"python","-c", pypr}); + InputStream in = p.getInputStream(); + BufferedInputStream buf = new BufferedInputStream(in); + InputStreamReader inread = new InputStreamReader(buf); + BufferedReader bufferedreader = new BufferedReader(inread); + // Read the ls output + String line; + while ((line = bufferedreader.readLine()) != null) + { + System.out.println(line); + } + + try + { + if (p.waitFor() != 0) + { + System.err.println("exit value = " + p.exitValue()); + } + } + catch (InterruptedException e) + { + System.err.println(e); + } + + in = p.getErrorStream(); + buf = new BufferedInputStream(in); + inread = new InputStreamReader(buf); + bufferedreader = new BufferedReader(inread); + // Read the ls output + while ((line = bufferedreader.readLine()) != null) + { + System.out.println(line); + } + + Thread.sleep(200); + assertEquals(1, inBuffer.getIUs().size()); + } + + +} -- GitLab