You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/11/05 01:21:36 UTC

[6/8] git commit: Extract portAvailable assertions to NetworkingTestUtils

Extract portAvailable assertions to NetworkingTestUtils

- Adds NetworkingTestUtils
- Cassandra assertions: if available, then log.info which ports were
  checked.
  Seeing strange errors in jenkins where this assertion passes, but
  then it fails with RMI registry port seemingly not being available.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/85d2f022
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/85d2f022
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/85d2f022

Branch: refs/heads/master
Commit: 85d2f0229b30ad49382cedbf4ba774ca9f291d35
Parents: 3eb8653
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 4 23:22:49 2014 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 4 23:24:01 2014 +0000

----------------------------------------------------------------------
 .../cassandra/CassandraNodeIntegrationTest.java | 37 ++---------
 .../java/brooklyn/test/NetworkingTestUtils.java | 68 ++++++++++++++++++++
 2 files changed, 75 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/85d2f022/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraNodeIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraNodeIntegrationTest.java b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraNodeIntegrationTest.java
index fc15c7d..4f780da 100644
--- a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraNodeIntegrationTest.java
+++ b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraNodeIntegrationTest.java
@@ -38,13 +38,10 @@ import brooklyn.entity.trait.Startable;
 import brooklyn.event.basic.PortAttributeSensorAndConfigKey;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.util.exceptions.Exceptions;
+import brooklyn.test.NetworkingTestUtils;
 import brooklyn.util.math.MathPredicates;
-import brooklyn.util.net.Networking;
-import brooklyn.util.time.Duration;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 
 /**
@@ -57,41 +54,21 @@ public class CassandraNodeIntegrationTest extends AbstractCassandraNodeTest {
     private static final Logger LOG = LoggerFactory.getLogger(CassandraNodeIntegrationTest.class);
 
     public static void assertCassandraPortsAvailableEventually() {
-        // If we get into a TCP TIMED-WAIT state, it could take 4 minutes for the port to come available.
-        // Could that be causing our integration tests to fail sometimes when run in the suite?!
-        // Let's wait for the required ports in setup, rather than running+failing the test.
-        Asserts.succeedsEventually(ImmutableMap.of("timeout", Duration.minutes(4)), new Runnable() {
-            private boolean logged = false;
-            public void run() {
-                try {
-                    assertCassandraPortsAvailable();
-                } catch (Throwable t) {
-                    if (!logged) {
-                        LOG.warn("Cassandra Port(s) not available; waiting for up to 4 minutes ("+Exceptions.getFirstInteresting(t)+")");
-                        logged = true;
-                    }
-                    throw Exceptions.propagate(t);
-                }
-            }});
-    }
-    
-    public static void assertCassandraPortsAvailable() {
-        for (Map.Entry<PortAttributeSensorAndConfigKey, Integer> entry : getCassandraDefaultPorts().entrySet()) {
-            String errmsg = entry.getValue()+" not available for cassandra "+entry.getKey();
-            assertTrue(Networking.isPortAvailable(entry.getValue()), errmsg);
-        }
+        Map<String, Integer> ports = getCassandraDefaultPorts();
+        NetworkingTestUtils.assertPortsAvailableEventually(ports);
+        LOG.info("Confirmed Cassandra ports are available: "+ports);
     }
     
-    public static Map<PortAttributeSensorAndConfigKey, Integer> getCassandraDefaultPorts() {
+    public static Map<String, Integer> getCassandraDefaultPorts() {
         List<PortAttributeSensorAndConfigKey> ports = ImmutableList.of(
                 CassandraNode.GOSSIP_PORT, 
                 CassandraNode.SSL_GOSSIP_PORT, 
                 CassandraNode.THRIFT_PORT, 
                 CassandraNode.NATIVE_TRANSPORT_PORT, 
                 CassandraNode.RMI_REGISTRY_PORT);
-        Map<PortAttributeSensorAndConfigKey, Integer> result = Maps.newLinkedHashMap();
+        Map<String, Integer> result = Maps.newLinkedHashMap();
         for (PortAttributeSensorAndConfigKey key : ports) {
-            result.put(key, key.getConfigKey().getDefaultValue().iterator().next());
+            result.put(key.getName(), key.getConfigKey().getDefaultValue().iterator().next());
         }
         return result;
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/85d2f022/usage/test-support/src/main/java/brooklyn/test/NetworkingTestUtils.java
----------------------------------------------------------------------
diff --git a/usage/test-support/src/main/java/brooklyn/test/NetworkingTestUtils.java b/usage/test-support/src/main/java/brooklyn/test/NetworkingTestUtils.java
new file mode 100644
index 0000000..c55b4d3
--- /dev/null
+++ b/usage/test-support/src/main/java/brooklyn/test/NetworkingTestUtils.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.test;
+
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Networking;
+import brooklyn.util.time.Duration;
+
+import com.google.common.collect.ImmutableMap;
+
+public class NetworkingTestUtils {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NetworkingTestUtils.class);
+
+    public static void assertPortsAvailableEventually(final Map<String, Integer> ports) {
+        // If we get into a TCP TIMED-WAIT state, it could take 4 minutes for the port to come available.
+        // Could that be causing our integration tests to fail sometimes when run in the suite?!
+        // Let's wait for the required ports in setup, rather than running+failing the test.
+        assertPortsAvailableEventually(ports, Duration.minutes(4));
+    }
+    
+    public static void assertPortsAvailableEventually(final Map<String, Integer> ports, final Duration timeout) {
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", Duration.minutes(4)), new Runnable() {
+            private boolean logged = false;
+            public void run() {
+                try {
+                    assertPortsAvailable(ports);
+                } catch (Throwable t) {
+                    if (!logged) {
+                        LOG.warn("Port(s) not available; waiting for up to "+timeout+" ("+Exceptions.getFirstInteresting(t)+")");
+                        logged = true;
+                    }
+                    throw Exceptions.propagate(t);
+                }
+            }});
+        LOG.debug("Ports are available: "+ports);
+    }
+    
+    public static void assertPortsAvailable(final Map<String, Integer> ports) {
+        for (Map.Entry<String, Integer> entry : ports.entrySet()) {
+            String errmsg = "port "+entry.getValue()+" not available for "+entry.getKey();
+            assertTrue(Networking.isPortAvailable(entry.getValue()), errmsg);
+        }
+    }
+}