You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/03/31 04:31:30 UTC

[48/69] [abbrv] activemq-artemis git commit: Refactor test to avoid port conflict.

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/46f5d2c6
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/46f5d2c6
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/46f5d2c6

Branch: refs/heads/refactor-openwire
Commit: 46f5d2c6c84ee6845131bf0b578da1edcad8de39
Parents: 028b6ad
Author: Howard Gao <ho...@gmail.com>
Authored: Thu Feb 25 20:43:02 2016 +0800
Committer: Clebert Suconic <cl...@apache.org>
Committed: Wed Mar 30 22:29:44 2016 -0400

----------------------------------------------------------------------
 .../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/46f5d2c6/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<Integer> extraConnectors = new HashSet<>();
-   public Set<Integer> sslConnectors = new HashSet<>();
+   public Set<ConnectorInfo> extraConnectors = new HashSet<>();
+//   public Set<Integer> sslConnectors = new HashSet<>();
 
    private List<TransportConnector> 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/46f5d2c6/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<String, Object> params = new HashMap<String, Object>();
-      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<String, Object> params = new HashMap<String, Object>();
+         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) {