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/Filter.java | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/Filter.java (limited to 'tests/Filter.java') 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 + * + * (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++; + } + + } + +} -- cgit v1.1