Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B9BA118A5A for ; Thu, 25 Feb 2016 12:44:58 +0000 (UTC) Received: (qmail 27916 invoked by uid 500); 25 Feb 2016 12:44:58 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 27878 invoked by uid 500); 25 Feb 2016 12:44:58 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 27869 invoked by uid 99); 25 Feb 2016 12:44:58 -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; Thu, 25 Feb 2016 12:44:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0E470E3A6E; Thu, 25 Feb 2016 12:44:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gaohoward@apache.org To: commits@activemq.apache.org Message-Id: <9178b1854b484257957c1cb5dc2e0441@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: activemq-artemis git commit: Refactor test to avoid port conflict. Date: Thu, 25 Feb 2016 12:44:58 +0000 (UTC) Repository: activemq-artemis Updated Branches: refs/heads/refactor-openwire 4a0004cda -> 3c9e1cb5e Refactor test to avoid port conflict. Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/3c9e1cb5 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/3c9e1cb5 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/3c9e1cb5 Branch: refs/heads/refactor-openwire Commit: 3c9e1cb5eea134208ad9aa0f7fba4c1a44e428e8 Parents: 4a0004c Author: Howard Gao Authored: Thu Feb 25 20:43:02 2016 +0800 Committer: Howard Gao Committed: Thu Feb 25 20:43:02 2016 +0800 ---------------------------------------------------------------------- .../apache/activemq/broker/BrokerService.java | 56 +++++++++++++++++--- .../artemiswrapper/ArtemisBrokerWrapper.java | 45 ++++++++-------- 2 files changed, 71 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3c9e1cb5/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java index 13d6b96..cbf41e1 100644 --- a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -100,8 +100,8 @@ public class BrokerService implements Service { private BrokerId brokerId; private Throwable startException = null; private boolean startAsync = false; - public Set extraConnectors = new HashSet<>(); - public Set sslConnectors = new HashSet<>(); + public Set extraConnectors = new HashSet<>(); +// public Set sslConnectors = new HashSet<>(); private List transportConnectors = new ArrayList<>(); private File dataDirectoryFile; @@ -494,11 +494,22 @@ public class BrokerService implements Service { this.transportConnectors = transportConnectors; for (TransportConnector connector : transportConnectors) { if (connector.getUri().getScheme().equals("ssl")) { - this.sslConnectors.add(connector.getUri().getPort()); - System.out.println(this + " added ssl connector: " + connector.getUri().getPort()); + boolean added = this.extraConnectors.add(new ConnectorInfo(connector.getUri().getPort(), true)); + if (added) { + System.out.println("added ssl connector " + connector); + } + else { + System.out.println("WARNing! failed to add ssl connector: " + connector); + } } else { - this.extraConnectors.add(connector.getUri().getPort()); + boolean added = this.extraConnectors.add(new ConnectorInfo(connector.getUri().getPort())); + if (added) { + System.out.println("added connector " + connector); + } + else { + System.out.println("WARNing! failed to add connector: " + connector); + } } } } @@ -567,7 +578,7 @@ public class BrokerService implements Service { connector = new FakeTransportConnector(bindAddress); this.transportConnectors.add(connector); - this.extraConnectors.add(port); + this.extraConnectors.add(new ConnectorInfo(port)); return connector; } @@ -752,8 +763,10 @@ public class BrokerService implements Service { URI uri = null; try { if (this.extraConnectors.size() > 0) { - Integer port = extraConnectors.iterator().next(); - uri = new URI("tcp://localhost:" + port); + ConnectorInfo info = extraConnectors.iterator().next(); + Integer port = info.port; + String schema = info.ssl ? "ssl" : "tcp"; + uri = new URI(schema + "://localhost:" + port); } else { uri = new URI(this.getDefaultUri()); } @@ -763,6 +776,33 @@ public class BrokerService implements Service { return uri; } + public static class ConnectorInfo { + + public int port; + public boolean ssl; + + public ConnectorInfo(int port) { + this(port, false); + } + + public ConnectorInfo(int port, boolean ssl) { + this.port = port; + this.ssl = ssl; + } + + @Override + public int hashCode() { + return port; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ConnectorInfo) { + return this.port == ((ConnectorInfo)obj).port; + } + return false; + } + } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3c9e1cb5/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/ArtemisBrokerWrapper.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/ArtemisBrokerWrapper.java b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/ArtemisBrokerWrapper.java index be1713b..83c12db 100644 --- a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/ArtemisBrokerWrapper.java +++ b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/ArtemisBrokerWrapper.java @@ -94,17 +94,13 @@ public class ArtemisBrokerWrapper extends ArtemisBrokerBase { if (bservice.extraConnectors.size() == 0) { serverConfig.addAcceptorConfiguration("home", "tcp://localhost:61616?protocols=OPENWIRE,CORE"); } - if (this.bservice.enableSsl() && bservice.sslConnectors.size() == 0) { + if (this.bservice.enableSsl()) { //default - addSSLAcceptor(serverConfig, 61611); + addServerAcceptor(serverConfig, new BrokerService.ConnectorInfo(61611)); } - for (Integer port : bservice.sslConnectors) { - addSSLAcceptor(serverConfig, port); - } - - for (Integer port : bservice.extraConnectors) { - serverConfig.addAcceptorConfiguration("homePort" + port, "tcp://localhost:" + port + "?protocols=OPENWIRE,CORE"); + for (BrokerService.ConnectorInfo info : bservice.extraConnectors) { + addServerAcceptor(serverConfig, info); } serverConfig.setSecurityEnabled(enableSecurity); @@ -170,21 +166,26 @@ public class ArtemisBrokerWrapper extends ArtemisBrokerBase { } - private void addSSLAcceptor(Configuration serverConfig, Integer port) { - HashMap params = new HashMap(); - params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); - params.put(TransportConstants.PORT_PROP_NAME, port); - params.put(TransportConstants.PROTOCOLS_PROP_NAME, "OPENWIRE"); - params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, bservice.SERVER_SIDE_KEYSTORE); - params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, bservice.KEYSTORE_PASSWORD); - params.put(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME, bservice.storeType); - if (bservice.SERVER_SIDE_TRUSTSTORE != null) { - params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, bservice.SERVER_SIDE_TRUSTSTORE); - params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, bservice.TRUSTSTORE_PASSWORD); - params.put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, bservice.storeType); + private void addServerAcceptor(Configuration serverConfig, BrokerService.ConnectorInfo info) throws Exception { + if (info.ssl) { + HashMap params = new HashMap(); + params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); + params.put(TransportConstants.PORT_PROP_NAME, info.port); + params.put(TransportConstants.PROTOCOLS_PROP_NAME, "OPENWIRE"); + params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, bservice.SERVER_SIDE_KEYSTORE); + params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, bservice.KEYSTORE_PASSWORD); + params.put(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME, bservice.storeType); + if (bservice.SERVER_SIDE_TRUSTSTORE != null) { + params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, bservice.SERVER_SIDE_TRUSTSTORE); + params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, bservice.TRUSTSTORE_PASSWORD); + params.put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, bservice.storeType); + } + TransportConfiguration sslTransportConfig = new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params); + serverConfig.getAcceptorConfigurations().add(sslTransportConfig); + } + else { + serverConfig.addAcceptorConfiguration("homePort" + info.port, "tcp://localhost:" + info.port + "?protocols=OPENWIRE,CORE"); } - TransportConfiguration sslTransportConfig = new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params); - serverConfig.getAcceptorConfigurations().add(sslTransportConfig); } private void translatePolicyMap(Configuration serverConfig, PolicyMap policyMap) {