Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DF274200D19 for ; Fri, 6 Oct 2017 22:58:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DDB4D1609E1; Fri, 6 Oct 2017 20:58:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D442E1609D0 for ; Fri, 6 Oct 2017 22:58:23 +0200 (CEST) Received: (qmail 42848 invoked by uid 500); 6 Oct 2017 20:58:23 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 42833 invoked by uid 99); 6 Oct 2017 20:58:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Oct 2017 20:58:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 32E8AF5CD2; Fri, 6 Oct 2017 20:58:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kwall@apache.org To: commits@qpid.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: qpid-broker-j git commit: QPID-7953: [Java Tests] [Stress Test Tool] Change RestStressTest to bind using the operation and expect response objects rather than lists. Date: Fri, 6 Oct 2017 20:58:20 +0000 (UTC) archived-at: Fri, 06 Oct 2017 20:58:25 -0000 Repository: qpid-broker-j Updated Branches: refs/heads/master 024f9a21a -> cb28e4854 QPID-7953: [Java Tests] [Stress Test Tool] Change RestStressTest to bind using the operation and expect response objects rather than lists. Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/cb28e485 Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/cb28e485 Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/cb28e485 Branch: refs/heads/master Commit: cb28e4854deb036ff220757b39355de89772aea8 Parents: 024f9a2 Author: Keith Wall Authored: Fri Oct 6 21:56:35 2017 +0100 Committer: Keith Wall Committed: Fri Oct 6 21:57:59 2017 +0100 ---------------------------------------------------------------------- tools/pom.xml | 19 +++ .../apache/qpid/tools/RestStressTestClient.java | 118 ++++++++++++++----- 2 files changed, 110 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/cb28e485/tools/pom.xml ---------------------------------------------------------------------- diff --git a/tools/pom.xml b/tools/pom.xml index 9b7f670..9045938 100644 --- a/tools/pom.xml +++ b/tools/pom.xml @@ -167,5 +167,24 @@ + + rest-stress-test + + + reststresstest + + + + + + org.codehaus.mojo + exec-maven-plugin + + org.apache.qpid.tools.RestStressTestClient + + + + + http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/cb28e485/tools/src/main/java/org/apache/qpid/tools/RestStressTestClient.java ---------------------------------------------------------------------- diff --git a/tools/src/main/java/org/apache/qpid/tools/RestStressTestClient.java b/tools/src/main/java/org/apache/qpid/tools/RestStressTestClient.java index d97d5fd..fc0b616 100644 --- a/tools/src/main/java/org/apache/qpid/tools/RestStressTestClient.java +++ b/tools/src/main/java/org/apache/qpid/tools/RestStressTestClient.java @@ -30,6 +30,9 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -42,6 +45,10 @@ import java.util.Set; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import javax.xml.bind.DatatypeConverter; import com.fasterxml.jackson.core.type.TypeReference; @@ -68,7 +75,7 @@ public class RestStressTestClient parser.usage(Arguments.class, Arguments.REQUIRED); System.out.println("\nRun examples:" ); System.out.println(" Using Basic authentication:" ); - System.out.println(" java -cp qpid-tools.jar:commons-codec.jar:jackson-core.jar:jackson-mapper.jar \\" ); + System.out.println(" java \\" ); System.out.println(" -Djavax.net.ssl.trustStore=java_client_truststore.jks \\"); System.out.println(" -Djavax.net.ssl.trustStorePassword=password \\"); System.out.println(" org.apache.qpid.tools.RestStressTestClient \\"); @@ -76,7 +83,7 @@ public class RestStressTestClient System.out.println(" virtualHost=default virtualHostNode=default createQueue=true bindQueue=true \\"); System.out.println(" deleteQueue=true uniqueQueues=true queueName=boo exchangeName=amq.fanout" ); System.out.println(" Using CRAM-MD5 SASL authentication:" ); - System.out.println(" java -cp qpid-tools.jar:commons-codec.jar:jackson-core.jar:jackson-mapper.jar \\" ); + System.out.println(" java \\" ); System.out.println(" org.apache.qpid.tools.RestStressTestClient saslMechanism=CRAM-MD5 \\"); System.out.println(" repetitions=10 brokerUrl=http://localhost:8080 username=admin password=admin \\"); System.out.println(" virtualHost=default virtualHostNode=default createQueue=true bindQueue=true \\"); @@ -91,12 +98,48 @@ public class RestStressTestClient public void run(Arguments arguments) throws IOException { log(arguments.toString()); + if (arguments.isTrustAll()) + { + configureTrustAll(); + } for (int i = 0; i < arguments.getRepetitions(); i++) { runIteration(arguments, i); } } + private void configureTrustAll() + { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() + { + public X509Certificate[] getAcceptedIssuers() + { + return null; + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) + { + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) + { + } + } + }; + + try + { + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + catch (NoSuchAlgorithmException | KeyManagementException e) + { + throw new RuntimeException("Failed to configure trust-all trust manager", e); + } + } + private void runIteration(Arguments arguments, int iteration) throws IOException { log("Iteration " + iteration); @@ -105,8 +148,8 @@ public class RestStressTestClient client.authenticateIfSaslAuthenticationRequested(); try { - List> brokerData = client.get("/api/latest/broker?depth=0"); - log(" Connected to broker " + brokerData.get(0).get("name")); + Map brokerData = client.get("/api/latest/broker?depth=0"); + log(" Connected to broker " + brokerData.get("name")); createAndBindQueueIfRequired(arguments, client, iteration); } finally @@ -167,7 +210,7 @@ public class RestStressTestClient if (result != RestClient.RESPONSE_PUT_CREATE_OK) { - throw new RuntimeException("Failure to create queue " + queueName); + throw new RuntimeException(String.format("Failure (%d) to create queue '%s'", result, queueName)); } } @@ -182,7 +225,7 @@ public class RestStressTestClient int result = client.delete(getQueueServiceUrl(virtualHostNode, virtualHost, queueName)); if (result != RestClient.RESPONSE_PUT_UPDATE_OK) { - throw new RuntimeException("Failure to delete queue " + queueName); + throw new RuntimeException(String.format("Failure (%d) to delete queue '%s'", result, queueName)); } } @@ -196,27 +239,22 @@ public class RestStressTestClient log(" Bind queue " + queueName + " to " + exchangeName + " using binding key " + queueName); - String bindingUrl = "/api/latest/binding/" + virtualHostNode + "/" + virtualHost + "/" + exchangeName + "/" + queueName + "/" + queueName; + String args = "/api/latest/exchange/" + virtualHostNode + "/" + virtualHost + "/" + exchangeName + "/bind"; - Map bindingData = new HashMap<>(); - bindingData.put("name", queueName); - bindingData.put("queue", queueName); - bindingData.put("exchange", exchangeName); + Map bindingData = new HashMap<>(); + bindingData.put("bindingKey", queueName); + bindingData.put("destination", queueName); - int result = client.put(bindingUrl, bindingData); + int result = client.post(args, bindingData); - if (result != RestClient.RESPONSE_PUT_CREATE_OK) + if (result != RestClient.RESPONSE_OK) { - throw new RuntimeException("Failure to bind queue " + queueName + " to " + exchangeName); + throw new RuntimeException(String.format("Failure (%d) to to bind queue '%s' to exchange '%s'", result, queueName, exchangeName)); } } public static class RestClient { - private static final TypeReference>> TYPE_LIST_OF_LINKED_HASH_MAPS = new TypeReference>>() - { - }; - private static final TypeReference> TYPE_HASH_MAP = new TypeReference>() { }; @@ -253,7 +291,7 @@ public class RestStressTestClient } } - public List> get(String restServiceUrl) throws IOException + public Map get(String restServiceUrl) throws IOException { HttpURLConnection connection = createConnection("GET", restServiceUrl, _cookies); try @@ -261,7 +299,7 @@ public class RestStressTestClient connection.connect(); byte[] data = readConnectionInputStream(connection); checkResponseCode(connection); - return _mapper.readValue(new ByteArrayInputStream(data), TYPE_LIST_OF_LINKED_HASH_MAPS); + return _mapper.readValue(new ByteArrayInputStream(data), TYPE_HASH_MAP); } finally { @@ -305,7 +343,7 @@ public class RestStressTestClient public int post(String restServiceUrl, Map postData) throws IOException { - HttpURLConnection connection = createConnectionAndPostData(restServiceUrl, postData, _cookies); + HttpURLConnection connection = createConnectionAndPostObject(restServiceUrl, postData, _cookies); try { checkResponseCode(connection); @@ -317,13 +355,31 @@ public class RestStressTestClient } } + private HttpURLConnection createConnectionAndPostObject(final String restServiceUrl, + final Object postData, + final List cookies) throws IOException + { + HttpURLConnection connection = createConnection("POST", restServiceUrl, cookies); + try (OutputStream os = connection.getOutputStream()) + { + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(os, postData); + os.flush(); + } + catch (IOException e) + { + connection.disconnect(); + throw e; + } + return connection; + } + private HttpURLConnection createConnectionAndPostData(String restServiceUrl, Map postData, List cookies) throws IOException { String postParameters = getPostDataString(postData); HttpURLConnection connection = createConnection("POST", restServiceUrl, cookies); - try + try (OutputStream os = connection.getOutputStream()) { - OutputStream os = connection.getOutputStream(); os.write(postParameters.getBytes(US_ASCII)); os.flush(); } @@ -353,7 +409,7 @@ public class RestStressTestClient while (iterator.hasNext()) { String key = iterator.next(); - sb.append(key + "=" + postData.get(key)); + sb.append(key).append("=").append(postData.get(key)); if (iterator.hasNext()) { sb.append("&"); @@ -485,10 +541,10 @@ public class RestStressTestClient private String toHex(byte[] data) { - StringBuffer hash = new StringBuffer(); - for (int i = 0; i < data.length; i++) + StringBuilder hash = new StringBuilder(); + for (final byte aData : data) { - String hex = Integer.toHexString(0xFF & data[i]); + String hex = Integer.toHexString(0xFF & aData); if (hex.length() == 1) { hash.append('0'); @@ -542,6 +598,8 @@ public class RestStressTestClient private boolean logout = true; + private boolean trustAll = false; + public Arguments() { } @@ -643,6 +701,11 @@ public class RestStressTestClient return saslMechanism; } + public boolean isTrustAll() + { + return trustAll; + } + public boolean isLogout() { return logout; @@ -665,6 +728,7 @@ public class RestStressTestClient ", deleteQueue=" + deleteQueue + ", uniqueQueues=" + uniqueQueues + ", bindQueue=" + bindQueue + + ", trustAll=" + trustAll + ", logout=" + logout + '}'; } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org