aboutsummaryrefslogtreecommitdiff
path: root/tests/TestApi.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/TestApi.java')
-rw-r--r--tests/TestApi.java48
1 files changed, 31 insertions, 17 deletions
diff --git a/tests/TestApi.java b/tests/TestApi.java
index 4902c82..3fa936a 100644
--- a/tests/TestApi.java
+++ b/tests/TestApi.java
@@ -25,47 +25,58 @@ class TestApi implements IvyMessageListener, IvyApplicationListener {
bus.addApplicationListener(this);
bus.bindMsg("^"+TestMsg+"$",this);
bus.start(this.domain=domain);
- new Sender(domain) ;
+ bus.sendToSelf(true);
+ bus.bindMsg("^go$",new Self(domain));
+ System.out.println("sending go ...");
+ try { bus.sendMsg("go"); } catch (IvyException ie) { }
+ System.out.println("go sent");
}
public void receive(IvyClient ic,String[] args) {
- System.out.println("[X] received message");
- test++;
+ String s = "[X] received message";
+ for (int i=0;i<args.length;i++) s+=": "+args[i];
+ System.out.println(s);test++;
}
public void connect(IvyClient ic) {
if (ic.getApplicationName().compareTo("Sender")!=0) return;
- System.out.println("[X] Sender connected");
- test++;
+ System.out.println("[X] Sender connected");test++;
}
public void disconnect(IvyClient ic) {
if (ic.getApplicationName().compareTo("Sender")!=0) return;
- System.out.println("[X] Sender disconnected");
- test++;
+ System.out.println("[X] Sender disconnected");test++;
}
public void directMessage(IvyClient ic,int id,String arg) {
if (id!=1) return;
- System.out.println("[X] Direct message received, ID=1");
- test++;
+ System.out.println("[X] Direct message received, ID=1");test++;
}
- public void die(IvyClient ic,int reason) {
- System.out.println("[X] Die received");
- test++;
- System.out.println(test+ "/5 tests successful, good bye");
+ public void die(IvyClient ic,int reason,String msg) {
+ System.out.println("[X] Die received "+msg);test++;
+ System.out.println(test+" tests successful, good bye");
System.out.println("TestApi leaving the bus");
bus.stop();
System.out.println("TestApi has left");
}
+ class Self implements IvyMessageListener {
+ private String domain;
+ public Self(String domain) {this.domain=domain;}
+ public void receive(IvyClient c,String[] args){
+ System.out.println("[X] received my own go message");test++;
+ bus.sendToSelf(false);
+ new Sender(domain) ;
+ }
+ }
+
class Sender implements IvyMessageListener {
private Ivy sbus;
private String domain;
public Sender(String domain) {
try {
- System.out.println("Sender joining the bus");
+ System.out.println("starting Sender on domain "+domain);
sbus = new Ivy("Sender","Sender ready", null);
sbus.bindMsg("^"+TestApiReadyMsg+"$",this);
sbus.start(this.domain=domain);
@@ -74,8 +85,11 @@ class TestApi implements IvyMessageListener, IvyApplicationListener {
}
}
public void receive(IvyClient c,String[] args) {
- sbus.sendMsg(TestMsg);
- c.sendDirectMsg(1,"bye bye");
+ try {
+ sbus.sendMsg(TestMsg);
+ c.sendDirectMsg(1,"bye bye");
+ } catch (IvyException ie) {
+ }
System.out.println("Sender leaving the bus");
sbus.stop();
System.out.println("Sender has left the bus");
@@ -104,7 +118,7 @@ class TestApi implements IvyMessageListener, IvyApplicationListener {
}
public static void main(String[] args) throws IvyException {
- new TestApi(null);
+ new TestApi(Ivy.getDomain(null));
}
}