Created
January 26, 2012 18:06
-
-
Save neodevelop/1684096 to your computer and use it in GitHub Desktop.
Wants a lil' of traffic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1' ) | |
import groovyx.net.http.* | |
import static groovyx.net.http.ContentType.* | |
import static groovyx.net.http.Method.* | |
import static groovyx.gpars.GParsPool.withPool | |
import java.util.Random | |
def peticiones = [] | |
def urls = [ | |
"http://neodevelop.jelastic.servint.net/" | |
] | |
1.upto(10000){ | |
Random rand = new Random() | |
peticiones << urls[rand.nextInt(urls.size())] | |
} | |
withPool{ | |
peticiones.eachParallel{ job -> | |
llamada(job) | |
} | |
} | |
llamada() | |
def llamada(url){ | |
def http = new HTTPBuilder(url) | |
http.request(GET,TEXT) { req -> | |
headers.'User-Agent' = 'Mozilla/5.0' | |
response.success = { resp, reader -> | |
assert resp.status == 200 | |
//println "My response handler got response: ${resp.statusLine}" | |
//println "Response length: ${resp.headers.'Content-Length'}" | |
//System.out << reader // print response reader | |
} | |
// called only for a 404 (not found) status code: | |
response.'404' = { resp -> | |
println 'Not found' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment