From e854a58a81ec90e419a4b3effa5a83caac05df90 Mon Sep 17 00:00:00 2001 From: jestin Date: Sun, 13 May 2012 08:54:38 +0000 Subject: Modified the tests to remove bus.getDomain(null) make Waiter and WaiterClient sons of WaitFor Added a few tests into svn --- tests/SendNow.java | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/SendNow.java (limited to 'tests/SendNow.java') 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 + * + * (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(); + } + } + +} -- cgit v1.1