@Test
public void throttle() throws Exception {
QName name = new QName("testDispatchInOnly");
final ExchangeSink sink = new ExchangeSink(1000);
final Service service = new MockService(name, new InOnlyService(), sink);
final ServiceReference reference = new ServiceReferenceImpl(name, new InOnlyService(), null, null);
final ExchangeDispatcher dispatch = _provider.createDispatcher(reference);
// Set throttling to 1 per second
Throttling throttle = new Throttling().setMaxRequests(1);
ServiceMetadataBuilder.update(reference.getServiceMetadata()).throttling(throttle);
final int NUM_SENDS = 5;
for (int i = 0; i < NUM_SENDS; i++) {
new Thread(new Runnable() {
public void run() {
Exchange exchange = dispatch.createExchange(sink, ExchangePattern.IN_ONLY);
exchange.consumer(reference, reference.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
exchange.provider(service, service.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
Message message = exchange.createMessage();
exchange.send(message);
}
}).start();