brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [6/9] git commit: Cassandra integration tests: better logging on port not available
Date Mon, 03 Nov 2014 14:24:58 GMT
Cassandra integration tests: better logging on port not available

- In setup+tearDown of each integration test, check that the standard 
  Cassandra ports are available. If they are not then wait for 
  4 mins (in case of TIMED-WAIT state), and then fail.
- This will show us which Cassandra test left the port open, if any.

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

Branch: refs/heads/master
Commit: 5bef6866daf455e4abf2c69d02bb73b23ed36097
Parents: cc0980c
Author: Aled Sage <aled.sage@gmail.com>
Authored: Mon Nov 3 12:10:37 2014 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Mon Nov 3 12:10:37 2014 +0000

----------------------------------------------------------------------
 .../CassandraDatacenterIntegrationTest.java     | 12 +++-
 ...assandraDatacenterRebindIntegrationTest.java | 12 +++-
 .../cassandra/CassandraNodeIntegrationTest.java | 70 +++++++++++++++++++-
 3 files changed, 89 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5bef6866/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterIntegrationTest.java
b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterIntegrationTest.java
index 426c545..b74d5cd 100644
--- a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterIntegrationTest.java
+++ b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterIntegrationTest.java
@@ -26,6 +26,7 @@ import java.math.BigInteger;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -60,13 +61,22 @@ public class CassandraDatacenterIntegrationTest extends BrooklynAppLiveTestSuppo
     protected Location testLocation;
     protected CassandraDatacenter cluster;
 
-    @Override
     @BeforeMethod(alwaysRun = true)
+    @Override
     public void setUp() throws Exception {
+        CassandraNodeIntegrationTest.assertCassandraPortsAvailableEventually();
         super.setUp();
         testLocation = app.newLocalhostProvisioningLocation();
     }
 
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        CassandraNodeIntegrationTest.assertCassandraPortsAvailableEventually();
+    }
+    
+
     @Test(groups = "Integration")
     public void testStartAndShutdownClusterSizeOne() throws Exception {
         EntitySpec<CassandraDatacenter> spec = EntitySpec.create(CassandraDatacenter.class)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5bef6866/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java
b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java
index eff0011..0b53216 100644
--- a/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java
+++ b/software/nosql/src/test/java/brooklyn/entity/nosql/cassandra/CassandraDatacenterRebindIntegrationTest.java
@@ -25,7 +25,7 @@ import java.util.Set;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -35,8 +35,6 @@ import brooklyn.entity.rebind.RebindTestFixtureWithApp;
 import brooklyn.entity.trait.Startable;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.util.time.Duration;
-import brooklyn.util.time.Time;
 
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
@@ -52,10 +50,18 @@ public class CassandraDatacenterRebindIntegrationTest extends RebindTestFixtureW
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
+        CassandraNodeIntegrationTest.assertCassandraPortsAvailableEventually();
         super.setUp();
         localhostProvisioningLocation = origApp.newLocalhostProvisioningLocation();
     }
 
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        CassandraNodeIntegrationTest.assertCassandraPortsAvailableEventually();
+    }
+    
     /**
      * Test that Brooklyn can rebind to a single node datacenter.
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5bef6866/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 06686dd..fc15c7d 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
@@ -22,18 +22,30 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.nosql.cassandra.AstyanaxSupport.AstyanaxSample;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.trait.Startable;
+import brooklyn.event.basic.PortAttributeSensorAndConfigKey;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
-import brooklyn.util.collections.MutableMap;
+import brooklyn.util.exceptions.Exceptions;
 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;
 
 /**
  * Cassandra integration tests.
@@ -42,6 +54,62 @@ import com.google.common.collect.ImmutableList;
  */
 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);
+        }
+    }
+    
+    public static Map<PortAttributeSensorAndConfigKey, 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();
+        for (PortAttributeSensorAndConfigKey key : ports) {
+            result.put(key, key.getConfigKey().getDefaultValue().iterator().next());
+        }
+        return result;
+    }
+
+    @BeforeMethod(alwaysRun = true)
+    @Override
+    public void setUp() throws Exception {
+        assertCassandraPortsAvailableEventually();
+        super.setUp();
+    }
+    
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        assertCassandraPortsAvailableEventually();
+    }
+    
     /**
      * Test that a node starts and sets SERVICE_UP correctly.
      */


Mime
View raw message