aboutsummaryrefslogtreecommitdiff
path: root/tests/SendNow.java
diff options
context:
space:
mode:
authorjestin2012-05-13 08:54:38 +0000
committerjestin2012-05-13 08:54:38 +0000
commite854a58a81ec90e419a4b3effa5a83caac05df90 (patch)
tree16eb84a66b62ff38e744c8cd474df81561436b9f /tests/SendNow.java
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/SendNow.java')
-rw-r--r--tests/SendNow.java61
1 files changed, 61 insertions, 0 deletions
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();
+ }
+ }
+
+}