|
| 1 | +/** |
| 2 | + * @author Thomas Modeneis |
| 3 | + */ |
| 4 | +package soujava |
| 5 | + |
| 6 | +import io.gatling.core.Predef._ |
| 7 | +import io.gatling.http.Predef._ |
| 8 | + |
| 9 | +class BenchmarkSOAPGeneric extends Simulation { |
| 10 | + |
| 11 | + //Definitions for the endpoint 1 |
| 12 | + def threads_ = System.getProperty("NUM_THREADS") |
| 13 | + |
| 14 | + def rampup_ = System.getProperty("RAMP_TIME") |
| 15 | + |
| 16 | + def duration_ = System.getProperty("DURATION") |
| 17 | + |
| 18 | + def target = System.getProperty("TARGET") |
| 19 | + |
| 20 | + def endpoint_ = System.getProperty("ENDPOINT") |
| 21 | + |
| 22 | + def endpointName_ = System.getProperty("ENDPOINT_NAME") |
| 23 | + |
| 24 | + def testFile = System.getProperty("TEST_FILE") |
| 25 | + |
| 26 | + def statusCheck = System.getProperty("STATUS_CHECK") |
| 27 | + |
| 28 | + val IntStatusCheck = Integer.getInteger("statusCheck", statusCheck.toInt).toInt |
| 29 | + |
| 30 | + def regexCheck = System.getProperty("REGEX_CHECK") |
| 31 | + |
| 32 | + //Definitions for the Switch |
| 33 | + def randomSwitch_Target1 = System.getProperty("TARGET1_SWITCH") |
| 34 | + |
| 35 | + //Definitions for the test itself (basics) |
| 36 | + val threads = Integer.getInteger("threads", threads_.toInt) |
| 37 | + val rampup = Integer.getInteger("rampup", rampup_.toInt).toInt |
| 38 | + val duration = Integer.getInteger("duration", duration_.toInt).toInt |
| 39 | + |
| 40 | + def randSwitch1 = randomSwitch_Target1.toDouble |
| 41 | + |
8000
| 42 | + val httpConf = http |
| 43 | + .baseURL(target) |
| 44 | + |
| 45 | + def extractMessage(str: String, session: Session): String = { |
| 46 | + println("extractMessage "+str) |
| 47 | + var ID = str |
| 48 | + println("---- ID --------------------------------------------------------------") |
| 49 | + println(ID) |
| 50 | + println("---- ID --------------------------------------------------------------") |
| 51 | + ID |
| 52 | + } |
| 53 | + |
| 54 | + def generateMessage(session: Session): String = { |
| 55 | + val myID = session("myID").as[String] |
| 56 | + |
| 57 | + var message = |
| 58 | + """ |
| 59 | + <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><xml xmlns="http://schema.soujava.org.br/webservice/wsdl/1.1">"""+myID+"""</xml></soap:Body></soap:Envelope> |
| 60 | + """ |
| 61 | + |
| 62 | + println("---- Message --------------------------------------------------------------") |
| 63 | + println(message) |
| 64 | + println("---- message --------------------------------------------------------------") |
| 65 | + |
| 66 | + message |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + val get_endpoint = |
| 71 | + exec(http(endpointName_).post(endpoint_).body(RawFileBody(testFile)).check(status.is(IntStatusCheck)) |
| 72 | + .check(regex(regexCheck).exists) |
| 73 | + .check(xpath( |
| 74 | + "/soap:Envelope/soap:Body/w:WebServiceInvocationResult/w:message/text()", |
| 75 | + List( |
| 76 | + ("w", "http://schema.soujava.org.br/webservice/wsdl/1.1"), |
| 77 | + ("soap", "http://schemas.xmlsoap.org/soap/envelope/") |
| 78 | + )) |
| 79 | + .find |
| 80 | + .transform((m, session) => |
| 81 | + extractMessage(m,session) |
| 82 | + ).saveAs("myID"))) |
| 83 | + .exec(http(endpointName_).post(endpoint_).body(StringBody(session => "" + generateMessage(session))).asXML.check(status.is(IntStatusCheck)) |
| 84 | + .check(regex(regexCheck).exists)) |
| 85 | + |
| 86 | + val scn = scenario(endpointName_) |
| 87 | + .forever("counter") { |
| 88 | + randomSwitch( |
| 89 | + randSwitch1 -> get_endpoint |
| 90 | + ) |
| 91 | + } |
| 92 | + setUp(scn.inject(rampUsers(threads) over rampup)) |
| 93 | + .protocols(httpConf) |
| 94 | + .maxDuration(duration) |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | + |
0 commit comments