I'm playing with AsyncHTTPBuilder (v0.5.1) however, I can't get it working so it's execute requests asynchronously. Please, check the code below. Looks like all requests are done from the same thread:
@Test public void testPoolsizeAndQueueing() {
def http = new AsyncHTTPBuilder( poolSize : 5 ,
uri : 'http://ajax.googleapis.com/ajax/services/search/web' )
def responses = []
/* With one thread in the pool, responses will be sequential but should
* queue up w/o being rejected. */
10.times {
responses << http.get( query : [q:'Groovy', v:'1.0'] ) { return Thread.currentThread().name }
responses << http.get( query : [q:'Ruby', v:'1.0'] ) { return Thread.currentThread().name }
responses << http.get( query : [q:'Scala', v:'1.0'] ) { return Thread.currentThread().name }
}
def timeout = 60000
def time = 0
while ( true ) {
if ( responses.every{ it.done ? it.get() : 0 } ) break
print '.'
Thread.sleep 2000
time += 2000
if ( time > timeout ) assert false
}
responses.each { println it.get() }
http.shutdown()
}
Output: ..pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1 pool-3-thread-1