public void testSendSyncOnSameComponent() throws Exception {
// Retrieve a delivery channel
TestComponent component = new TestComponent(new QName("service"), "endpoint");
container.activateComponent(new ActivationSpec("component", component));
final DeliveryChannel channel = component.getChannel();
final AtomicBoolean success = new AtomicBoolean(false);
final AtomicBoolean done = new AtomicBoolean(false);
// Create another thread
Thread t = new Thread() {
public void run() {
try {
InOut me = (InOut) channel.accept(5000);
NormalizedMessage nm = me.createMessage();
nm.setContent(new StringSource("<response/>"));
me.setOutMessage(nm);
channel.sendSync(me);
success.set(true);
done.set(true);
} catch (MessagingException e) {
LOG.error(e.getMessage(), e);
success.set(false);
done.set(true);
}
}
};
t.start();
MessageExchangeFactory factory = channel.createExchangeFactoryForService(new QName("service"));
InOut me = factory.createInOutExchange();
NormalizedMessage nm = me.createMessage();
nm.setContent(new StringSource("<request/>"));
me.setInMessage(nm);
channel.sendSync(me);
assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
me.setStatus(ExchangeStatus.DONE);
channel.send(me);
if (!done.get()) {
synchronized (done) {
done.wait(5000);
}