*/
public void testSubSubPub() {
try {
boolean consumable = true;
int session = 1;
Client pub1 = new Client(this.global, "pub1", responses);
pub1.init("testConsumableQueue", null, consumable, session);
Client sub1 = new Client(this.global, "sub1", responses);
sub1.init(null, "testConsumableQueue", consumable, session);
Client sub2 = new Client(this.global, "sub2", responses);
sub2.init(null, "testConsumableQueue", consumable, session);
Client deadMsg = new Client(this.global, "deadMsg", responses);
deadMsg.init(null, "__sys__deadMessage", !consumable, session);
assertEquals("wrong number of initial responses", 0, responses.size());
synchronized(responses) {
pub1.publish("firstMessage");
for (int i=0; i < 1; i++) responses.wait(WAIT_DELAY);
Thread.sleep(200L); // wait in case an unexpected update comes in betweeen
assertEquals("wrong number of updates", 1, responses.size());
}
responses.clear();
synchronized(responses) {
sub1.setUpdateException(new XmlBlasterException(this.global, ErrorCode.USER_UPDATE_ERROR, "testSubSubPub"));
pub1.publish("firstMessage");
for (int i=0; i < 2; i++) responses.wait(WAIT_DELAY);
Thread.sleep(200L); // wait in case an unexpected update comes in betweeen
assertEquals("wrong number of updates", 2, responses.size());
assertEquals("update should be a dead message", "deadMsg", responses.get(1));
}
responses.clear();
synchronized(responses) {
sub1.setUpdateException(null);
sub2.setUpdateException(new XmlBlasterException(this.global, ErrorCode.USER_UPDATE_ERROR, "testSubSubPub"));
pub1.publish("firstMessage");
for (int i=0; i < 1; i++) responses.wait(WAIT_DELAY);
Thread.sleep(200L); // wait in case an unexpected update comes in betweeen
assertEquals("wrong number of updates, since the first sub receives, so it should not even try the second", 1, responses.size());
}
/** only one dead message here since the first gives up delivery */
responses.clear();
synchronized(responses) {
sub1.setUpdateException(new XmlBlasterException(this.global, ErrorCode.USER_UPDATE_ERROR, "testSubSubPub"));
sub2.setUpdateException(new XmlBlasterException(this.global, ErrorCode.USER_UPDATE_ERROR, "testSubSubPub"));
pub1.publish("firstMessage");
for (int i=0; i < 2; i++) responses.wait(WAIT_DELAY);
Thread.sleep(200L); // wait in case an unexpected update comes in betweeen
assertEquals("wrong number of updates", 2, responses.size());
assertEquals("update should be a dead message", "deadMsg", responses.get(1));
}
sub1.shutdown(false);
sub2.shutdown(false);
pub1.shutdown(true);
deadMsg.shutdown(false);
}
catch (Exception ex) {
ex.printStackTrace();
assertTrue(false);
}