aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjestin2012-05-13 08:54:38 +0000
committerjestin2012-05-13 08:54:38 +0000
commite854a58a81ec90e419a4b3effa5a83caac05df90 (patch)
tree16eb84a66b62ff38e744c8cd474df81561436b9f /tests
parent4ffe8b84071babe544086f94c66431380d301d59 (diff)
downloadivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.zip
ivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.tar.gz
ivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.tar.bz2
ivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.tar.xz
Modified the tests to remove bus.getDomain(null)
make Waiter and WaiterClient sons of WaitFor Added a few tests into svn
Diffstat (limited to 'tests')
-rw-r--r--tests/AsyncAPI.java2
-rw-r--r--tests/BenchLocal.java2
-rw-r--r--tests/DieSender.java4
-rw-r--r--tests/Filter.java73
-rw-r--r--tests/Makefile14
-rw-r--r--tests/NewLine.java2
-rw-r--r--tests/ProbeBench.java4
-rw-r--r--tests/SendNow.java61
-rw-r--r--tests/SendNowSelf.java46
-rw-r--r--tests/SwingIvy.java112
-rw-r--r--tests/TestNetSwing.java7
-rw-r--r--tests/TestReady.java2
-rw-r--r--tests/Unitaire.java32
13 files changed, 345 insertions, 16 deletions
diff --git a/tests/AsyncAPI.java b/tests/AsyncAPI.java
index 2b85745..e174929 100644
--- a/tests/AsyncAPI.java
+++ b/tests/AsyncAPI.java
@@ -103,7 +103,7 @@ class AsyncAPI {
public static final String helpmsg = "usage: java "+SENDNAME+" [options]\n\t-b domain\n\t-r\t to enable async reception\n\t-x to enable async sending\n\t-l loop count (default "+NBITER+")\n\t-s msgsize\t int value (default "+MSGSIZE+")\n\t-d delay in milliseconds (default "+DELAYMS+")\n\t-q \tquiet\n\t-e\tsend bus stop at the end\n\t-h\thelp\n\n";
public static void main(String[] args) throws IvyException {
Getopt opt = new Getopt(SENDNAME,args,"b:l:d:s:xrqeh");
- String domain=Ivy.getDomain(null); // default bus
+ String domain=null;
int nb = NBITER, delay = DELAYMS, c, size = MSGSIZE;
boolean doasyncSend=false, doasyncBind=false, verbose=true, exit=false;
while ((c = opt.getopt()) != -1) switch (c) {
diff --git a/tests/BenchLocal.java b/tests/BenchLocal.java
index ef0e4c7..ef80052 100644
--- a/tests/BenchLocal.java
+++ b/tests/BenchLocal.java
@@ -27,7 +27,7 @@ class BenchLocal {
public static void main(String[] args) throws IvyException {
Getopt opt = new Getopt("BenchLocal",args,"t:b:d:h");
- String domain=Ivy.getDomain(null);
+ String domain=null;
int delay=2000;
int c;
int testtoperform=1;
diff --git a/tests/DieSender.java b/tests/DieSender.java
index c44446b..a19854f 100644
--- a/tests/DieSender.java
+++ b/tests/DieSender.java
@@ -33,10 +33,10 @@ public class DieSender extends IvyApplicationAdapter {
public static void main(String[] args) throws IvyException {
String mtokill = DEFAULTTOKILL;
- String domain = Ivy.getDomain(null);
+ String domain = Domain.getDomainArgs("DieSender",args);
System.out.println("will kill each and every " + mtokill + " on the " + domain +" bus");
Ivy bus = new Ivy("DieSender","DieSender ready",null);
- bus.start(Ivy.getDomain(null));
+ bus.start(domain);
new DieSender(bus,mtokill);
}
diff --git a/tests/Filter.java b/tests/Filter.java
new file mode 100644
index 0000000..92ef190
--- /dev/null
+++ b/tests/Filter.java
@@ -0,0 +1,73 @@
+/**
+ * Another Ivy java library API tester: filters
+ *
+ * @author Yannick Jestin <mailto:jestin@cena.fr>
+ *
+ * (c) CENA
+ *
+ * usage: java Request
+ *
+ * Changelog
+ * 1.2.16 : first release
+ *
+ * rationale:
+ * Filter limits the bounded sends to toto and blah
+ * Remote subscribes to (.*), unbounded, and truc, bounded
+ * Filter sends truc ble bli (should have one hit only )
+ * Filter sends TOTO rules, one hit
+ * total should be 3 (ready message)
+ *
+ */
+import fr.dgac.ivy.*;
+
+class Filter {
+
+ public static void main(String[] args) throws IvyException {
+ String domain=Ivy.getDomainArgs("FilterTest",args);
+ new Filter(domain);
+ }
+
+ int nb=0;
+ private Ivy bus;
+ private String[] filterStrings = { "toto", "blah" };
+
+ public Filter(String domain) throws IvyException {
+ bus = new Ivy("FilterTest","FilterTest ready", null);
+ bus.setFilter(filterStrings);
+ bus.start(domain);
+ new Remote(domain);
+ IvyClient remote = bus.waitForClient("Remote", 0);
+ bus.sendMsg("truc ble bli");
+ bus.sendMsg("TOTO rules");
+ remote.sendDie("goodbye");
+ bus.stop();
+ if (nb != 3) {
+ System.out.println("n = "+nb+" should be 3");
+ System.exit(-1);
+ }
+ System.out.println("Filter test successful");
+ }
+
+ private class Remote implements IvyMessageListener {
+ Ivy bus;
+ String name;
+ public Remote(String domain) throws IvyException {
+ bus = new Ivy("Remote","Remote ready",null);
+ bus.bindMsg("^truc (.*)",this);
+ bus.bindMsg("(.*)", new IvyMessageListener() {
+ public void receive(IvyClient ic,String[] args) {
+ System.out.println("something received: "+args[0]);
+ nb++;
+ }
+ });
+ bus.start(domain);
+ }
+
+ public void receive(IvyClient ic,String[] args) {
+ System.out.println("truc received"+args[0]);
+ nb++;
+ }
+
+ }
+
+}
diff --git a/tests/Makefile b/tests/Makefile
index d8a6e8e..b313a50 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -4,7 +4,7 @@
include ../java.mk # in this file you can change your java compiler and VM
IVYPATH=../build/jar/ivy-java.jar
-CLASSPATH=-classpath classes:$(IVYPATH):$(GNUPATH)
+CLASSPATH=-classpath ../build/testclasses:$(IVYPATH):$(GNUPATH)
SRC = *.java
# Warning TestNetSwing.java cant build with jdk1.1
@@ -26,7 +26,7 @@ all:
$(JAVAC) -d classes $(JAVACOPTS) $(CLASSPATH) $(SRC)
@echo "all modules built. run make run"
-run: sendnow sendnowself nl api unitaires probe stop request test1 async test2
+run: sendnow sendnowself nl api filter unitaires probe stop request test1 async test2
request:
@echo "*****************************"
@@ -120,6 +120,16 @@ unitaires:
@echo "*****************************"
@echo "\n\n\n"
+filter:
+ @echo "*****************************"
+ @echo "TEST FILTER MESSAGES"
+ @echo "*****************************"
+ $(JAVA) $(DEBUG) $(JAVAOPTS) $(CLASSPATH) Filter $(DOMAIN)
+ @echo "*****************************"
+ @echo "TEST FILTER SUCCESSFUL"
+ @echo "*****************************"
+ @echo "\n\n\n"
+
test1: $(OBJ)
@echo "*****************************"
@echo "TEST Bench"
diff --git a/tests/NewLine.java b/tests/NewLine.java
index 8381379..82ccdd1 100644
--- a/tests/NewLine.java
+++ b/tests/NewLine.java
@@ -7,7 +7,7 @@ class NewLine {
public static void main(String[] args) throws IvyException {
Getopt opt = new Getopt("NewLine",args,"b:n:");
- String domain=Ivy.getDomain(null);
+ String domain=null;
int c;
int nb = 10000;
while ((c = opt.getopt()) != -1) switch (c) {
diff --git a/tests/ProbeBench.java b/tests/ProbeBench.java
index 246014d..e9e3dbb 100644
--- a/tests/ProbeBench.java
+++ b/tests/ProbeBench.java
@@ -16,14 +16,14 @@ public class ProbeBench {
public void test1() throws IvyException {
Probe p = new Probe(new BufferedReader(new InputStreamReader(System.in)),true,false,true);
Ivy bus1 = new Ivy("ProbeTest","ProbeTest ready",null);
- bus1.start(Ivy.getDomain(null));
+ bus1.start(null);
System.out.println("starting the probe");
p.start(bus1);
System.out.println("sleeping 5 seconds");
try { Thread.sleep(5000); } catch (InterruptedException ie) { }
Ivy bus2 = new Ivy("ProbeKiller","ProbeKiller ready",null);
- bus2.start(Ivy.getDomain(null));
+ bus2.start(null);
System.out.println("starting the probe killer");
new DieSender(bus2,"ProbeTest");
System.out.println("sleeping 5 seconds");
diff --git a/tests/SendNow.java b/tests/SendNow.java
new file mode 100644
index 0000000..093ee19
--- /dev/null
+++ b/tests/SendNow.java
@@ -0,0 +1,61 @@
+/**
+ * Ivy java library API tester.
+ *
+ * @author Yannick Jestin <mailto:yannick.jestin@enac.fr>
+ *
+ * (c) ENAC
+ *
+ * usage: java Unitaire
+ *
+ */
+import fr.dgac.ivy.*;
+
+public class SendNow {
+
+ Ivy bus;
+
+ public SendNow (String args[]) throws IvyException {
+ bus = new Ivy("ReceiveNow",null,null);
+ bus.bindMsg("^hop hop",new IvyMessageListener() {
+ public void receive(IvyClient ic,String args[]){
+ System.out.println("hop hop received ! quitting");
+ bus.stop();
+ }
+ });
+ System.out.println("starting receiver");
+ bus.start(Ivy.getDomainArgs("IvyTest" , args));
+ }
+
+ public static void main(final String[] args) throws IvyException,InterruptedException {
+ Ivy sendbus = new Ivy("SendNow" , null, null);
+ new SendNow(args);
+ //Thread.sleep(10);
+ // no sleep
+ try {
+ System.out.println("starting sender");
+ sendbus.start(Ivy.getDomainArgs("IvyTest" , args));
+ System.out.println("sending");
+ // THIS IS WRONG ON PURPOSE, to test a race condidition on startup
+ // Correct code to add is
+ // sendbus.waitForClient("ReceiveNow",0);
+ int i = sendbus.sendMsg("hop hop");
+ System.out.println("stopping");
+ sendbus.stop();
+ System.out.println("end stopping");
+ if (i==0) {
+ // it can fail in the following case:
+ // SendNow has started, sent "hop hop", and starts closing *before*
+ // the hanshake is initiated. There's no way of knowing if somebody
+ // else is joining the bus
+ // we could add something at the JVM level, but it's no use for inter
+ // process anyway. 200ms before close + lock is long enough
+ System.out.println("race condition: the Receiver has not received our message, quitting anyway");
+ System.exit(-1);
+ }
+ } catch (IvyException ie) {
+ System.out.println("Ivy main test error");
+ ie.printStackTrace();
+ }
+ }
+
+}
diff --git a/tests/SendNowSelf.java b/tests/SendNowSelf.java
new file mode 100644
index 0000000..ef3df0c
--- /dev/null
+++ b/tests/SendNowSelf.java
@@ -0,0 +1,46 @@
+/**
+ * Ivy java library API tester.
+ * TODO does not work if there is anotehr agent on the bus ...? FIXME
+ *
+ * @author Yannick Jestin <mailto:yannick.jestin@enac.fr>
+ *
+ * (c) ENAC
+ *
+ * usage: java Unitaire
+ *
+ */
+import fr.dgac.ivy.*;
+
+public class SendNowSelf {
+
+ Ivy bus;
+
+ public SendNowSelf(String domain) {
+ bus = new Ivy("SendNowSelf" , null, null);
+ try {
+ System.out.println("starting sender");
+ bus.sendToSelf(true);
+ bus.bindMsg("^hop hop", new IvyMessageListener() {
+ public void receive(IvyClient ic, String args[]){
+ System.out.println("stopping");
+ bus.stop();
+ System.out.println("end stopping");
+ }
+ });
+ bus.start(domain);
+ System.out.println("sending");
+ if ( bus.sendMsg("hop hop") != 1) {
+ System.out.println("error, lock, hop hop not received");
+ System.exit(-1);
+ }
+ } catch (IvyException ie) {
+ System.out.println("Ivy main test error");
+ ie.printStackTrace();
+ }
+ }
+
+ public static void main(final String[] args) throws IvyException,InterruptedException {
+ new SendNowSelf(Ivy.getDomainArgs("SendNowSelf" , args));
+ }
+
+}
diff --git a/tests/SwingIvy.java b/tests/SwingIvy.java
new file mode 100644
index 0000000..afe27f0
--- /dev/null
+++ b/tests/SwingIvy.java
@@ -0,0 +1,112 @@
+/**
+ * Ivy java library API tester.
+ *
+ * @author Yannick Jestin <mailto:yannick.jestin@enac.fr>
+ *
+ * (c) ENAC
+ *
+ */
+import fr.dgac.ivy.*;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class SwingIvy implements Runnable {
+
+ private Ivy bus;
+ private final static int DODO = 2000;
+ private final static String BLAH = "ivy blah blah blah";
+ private final String[] data = {"one","two","three","four"};
+
+ DefaultListModel model = new DefaultListModel();
+ JFrame f = new JFrame("Test Ivy Swing");
+ JSlider scale = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);
+ JTextArea text = new JTextArea("type anything inside this area");
+ JToggleButton startstop = new JToggleButton("trigger ivy messages");
+ JList list = new JList(model);
+ volatile Thread runThread = null;
+ boolean doSend = false;
+
+ public SwingIvy(String domain) {
+ int index=0;
+ for (String s : data) { model.add(index++,s); }
+ f.getContentPane().add( scale, BorderLayout.PAGE_START );
+ f.getContentPane().add( text, BorderLayout.CENTER );
+ f.getContentPane().add( list, BorderLayout.LINE_END );
+ f.getContentPane().add( startstop, BorderLayout.PAGE_END );
+ f.addWindowListener(new WindowAdapter(){
+ public void windowClosing(WindowEvent e){
+ System.out.println("closing gracefully");
+ f.dispose();
+ bus.stop();
+ Thread t = runThread;
+ runThread = null;
+ //if (t!=null) t.interrupt();
+ t.interrupt();
+ }
+ });
+ text.setRows(25);
+ text.setColumns(40);
+ startstop.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e){
+ doSend = startstop.isSelected();
+ }
+ });
+ f.pack();
+ f.setVisible(true);
+ runThread = new Thread(this);
+ runThread.start();
+ try {
+ bus = new Ivy("SwingIvy",null, null);
+ bus.bindAsyncMsg("^AddList (.*)", new IvyMessageListener() {
+ public void receive(IvyClient c,String[] args) {
+ //System.out.println("SetText received");
+ model.add(model.getSize() , args[0]);
+ }
+ }, BindType.SWING);
+ bus.bindAsyncMsg("^SetText (.*)", new IvyMessageListener() {
+ public void receive(IvyClient c,String[] args) {
+ //System.out.println("SetText received");
+ text.append(args[0]+"\n");
+ }
+ }, BindType.SWING);
+ bus.bindAsyncMsg("^SetRange ([0-9]+)", new IvyMessageListener() {
+ public void receive(IvyClient c,String[] args) {
+ int i = Integer.parseInt(args[0]);
+ scale.setValue(i);
+ //System.out.println("SetRange received: "+i);
+ }
+ }, BindType.SWING);
+ bus.sendToSelf(true);
+ bus.start(domain);
+ } catch (IvyException ie) {
+ ie.printStackTrace();
+ }
+ }
+
+ public void run() {
+ int intRange=0;
+ Thread thisThread=Thread.currentThread();
+ while(runThread ==thisThread) {
+ try {
+ Thread.sleep(DODO);
+ intRange++;
+ if (doSend) {
+ if (intRange>99) intRange=0;
+ bus.sendMsg("SetRange "+intRange);
+ bus.sendMsg("SetText "+BLAH);
+ bus.sendMsg("AddList "+intRange);
+ }
+ } catch (IvyException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ if (thisThread!=runThread) { break ;}
+ }
+ }
+ }
+
+ public static void main(String[] args) throws IvyException {
+ new SwingIvy(Ivy.getDomainArgs("SwingIvy",args));
+ }
+
+}
diff --git a/tests/TestNetSwing.java b/tests/TestNetSwing.java
index 7aed6e2..a153636 100644
--- a/tests/TestNetSwing.java
+++ b/tests/TestNetSwing.java
@@ -141,11 +141,6 @@ class TestNetSwing implements Runnable {
e.printStackTrace();
System.exit(0);
}
- try {
- broadcast.setSoTimeout(Ivy.TIMEOUTLENGTH);
- } catch ( java.net.SocketException jns ) {
- System.out.println("IvyWatcher setSoTimeout error" + jns.getMessage() );
- }
watcherThread = new Thread(this);
watcherThread.start();
}
@@ -216,7 +211,7 @@ class TestNetSwing implements Runnable {
public static void main(String[] args) throws IvyException {
Getopt opt = new Getopt("TestNetSwing",args,"b:h");
int c;
- String domainstring = Ivy.getDomain(null);
+ String domainstring = null;
while ((c = opt.getopt()) != -1) switch (c) {
case 'b':
domainstring=opt.getOptarg();
diff --git a/tests/TestReady.java b/tests/TestReady.java
index 49d9336..f083f72 100644
--- a/tests/TestReady.java
+++ b/tests/TestReady.java
@@ -87,7 +87,7 @@ class TestReady implements IvyApplicationListener {
public static void main(String args[]) {
Getopt opt = new Getopt("TestReady",args,"b:o");
- String domain=Ivy.getDomain(null);
+ String domain=null;
int c;
boolean swap = false;
while ((c = opt.getopt()) != -1) switch (c) {
diff --git a/tests/Unitaire.java b/tests/Unitaire.java
new file mode 100644
index 0000000..894bb88
--- /dev/null
+++ b/tests/Unitaire.java
@@ -0,0 +1,32 @@
+/**
+ * Ivy java library API tester.
+ *
+ * @author Yannick Jestin <mailto:yannick.jestin@enac.fr>
+ *
+ * (c) ENAC
+ *
+ * usage: java Unitaire
+ *
+ */
+import fr.dgac.ivy.*;
+
+public class Unitaire {
+
+ public static void main(final String[] args) {
+ Ivy bus = new Ivy("Test Unitaire" , "TU ready" , null);
+ final int PORT_TEST = 5000;
+ try {
+ bus.start(Ivy.getDomainArgs("IvyTest" , args));
+ System.out.println("waiting 5 seconds for a coucou");
+ System.out.println(((bus.waitForMsg("^coucou" , PORT_TEST)) != null) ? "coucou received" : "coucou not received");
+ System.out.println("waiting 5 seconds for IvyProbe");
+ System.out.println(((bus.waitForClient("IVYPROBE" , PORT_TEST)) != null) ? "Ivyprobe joined the bus" : "nobody came");
+ System.out.println("random values: " + bus.getWBUId() + ", " + bus.getWBUId() + ", " + bus.getWBUId());
+ bus.stop();
+ } catch (IvyException ie) {
+ System.out.println("Ivy main test error");
+ ie.printStackTrace();
+ }
+ }
+
+}