brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/2] git commit: Fix failing tests (from jenkins)
Date Thu, 02 Oct 2014 07:48:32 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master ff11b4fc0 -> fb3c9970d


Fix failing tests (from jenkins)

- EntityExecutionManagerTest.testGetTasksAndGcBoringTags
- LocalhostMachineProvisioningLocationTest.obtainTwoAddressesInRangeThenDontObtain
- LocalhostMachineProvisioningLocationTest.obtainPortFailsIfInUse
- ApplicationResourceTest.testDeployApplication


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

Branch: refs/heads/master
Commit: 2f3b82208d1e4d2d259d7fa3f9f0e1d6c30b0ac2
Parents: 8a1fd77
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Oct 2 00:21:55 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Oct 2 00:32:55 2014 +0100

----------------------------------------------------------------------
 .../java/brooklyn/entity/basic/Entities.java    |  2 ++
 .../brooklyn/entity/basic/EntityPredicates.java | 18 ++++++++++
 .../LocalhostMachineProvisioningLocation.java   |  2 +-
 .../entity/basic/EntityPredicatesTest.java      |  6 ++++
 ...ocalhostMachineProvisioningLocationTest.java | 22 +++++++++++-
 .../internal/EntityExecutionManagerTest.java    | 13 ++++---
 .../rest/resources/ApplicationResourceTest.java | 36 ++++++++++++--------
 .../rest/testing/BrooklynRestResourceTest.java  |  2 +-
 .../rest/testing/mocks/NameMatcherGroup.java    | 30 ++++++++++++++++
 .../testing/mocks/NameMatcherGroupImpl.java     | 32 +++++++++++++++++
 10 files changed, 141 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/core/src/main/java/brooklyn/entity/basic/Entities.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/Entities.java b/core/src/main/java/brooklyn/entity/basic/Entities.java
index 516fbfa..0708d6d 100644
--- a/core/src/main/java/brooklyn/entity/basic/Entities.java
+++ b/core/src/main/java/brooklyn/entity/basic/Entities.java
@@ -295,6 +295,8 @@ public class Entities {
     public static void dumpInfo(Entity e, Writer out, String currentIndentation, String tab)
throws IOException {
         out.append(currentIndentation+e.toString()+" "+e.getId()+"\n");
 
+        out.append(currentIndentation+tab+tab+"displayName = "+e.getDisplayName()+"\n");
+
         out.append(currentIndentation+tab+tab+"locations = "+e.getLocations()+"\n");
 
         Set<ConfigKey<?>> keys = Sets.newLinkedHashSet( ((EntityInternal)e).getConfigMap().getLocalConfig().keySet()
);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java b/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
index b200cf2..367bc98 100644
--- a/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
+++ b/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
@@ -52,6 +52,24 @@ public class EntityPredicates {
         };
     }
     
+    public static Predicate<Entity> displayNameMatches(final String val) {
+        return new DisplayNameMatches(val);
+    }
+    private static class DisplayNameMatches implements SerializablePredicate<Entity>
{
+        private final String val;
+        DisplayNameMatches(String val) {
+            this.val = val;
+        }
+        @Override
+        public boolean apply(@Nullable Entity input) {
+            return (input != null && input.getDisplayName() != null) && input.getDisplayName().matches(val);
+        }
+        @Override
+        public String toString() {
+            return "DisplayNameMatches("+val+")";
+        }
+    };
+    
     public static Predicate<Entity> applicationIdEqualTo(final String val) {
         return new SerializablePredicate<Entity>() {
             @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
b/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
index 64a9345..4e24ba1 100644
--- a/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
@@ -205,7 +205,7 @@ public class LocalhostMachineProvisioningLocation extends FixedListMachineProvis
             if (LOG.isDebugEnabled()) LOG.debug("Skipping system availability check for privileged
localhost port "+portNumber);
             return true;
         }
-        return Networking.isPortAvailable(portNumber);
+        return Networking.isPortAvailable(localAddress, portNumber);
     }
     public static int obtainPort(PortRange range) {
         return obtainPort(getLocalhostInetAddress(), range);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java b/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
index fcf046f..549aada 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityPredicatesTest.java
@@ -79,6 +79,12 @@ public class EntityPredicatesTest extends BrooklynAppUnitTestSupport {
     }
     
     @Test
+    public void testDisplayNameMatches() throws Exception {
+        assertTrue(EntityPredicates.displayNameMatches(entity.getDisplayName()).apply(entity));
+        assertFalse(EntityPredicates.applicationIdEqualTo("wrongname").apply(entity));
+    }
+    
+    @Test
     public void testIsChildOf() throws Exception {
         assertTrue(EntityPredicates.isChildOf(app).apply(entity));
         assertFalse(EntityPredicates.isChildOf(entity).apply(entity));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/core/src/test/java/brooklyn/location/basic/LocalhostMachineProvisioningLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/LocalhostMachineProvisioningLocationTest.java
b/core/src/test/java/brooklyn/location/basic/LocalhostMachineProvisioningLocationTest.java
index e43ffa1..f80851b 100644
--- a/core/src/test/java/brooklyn/location/basic/LocalhostMachineProvisioningLocationTest.java
+++ b/core/src/test/java/brooklyn/location/basic/LocalhostMachineProvisioningLocationTest.java
@@ -120,8 +120,18 @@ public class LocalhostMachineProvisioningLocationTest {
     public void obtainTwoAddressesInRangeThenDontObtain() throws Exception {
         LocalhostMachineProvisioningLocation p = newLocalhostProvisioner();
         SshMachineLocation m = p.obtain();
+
+        // Find two ports that are free, rather than risk false-negatives if a port was left
open by something else.
         int start = 48311;
+        while (true) {
+            if (Networking.isPortAvailable(m.getAddress(), start) && Networking.isPortAvailable(m.getAddress(),
start+1)) {
+                break;
+            } else {
+                start++;
+            }
+        }
         PortRange r = PortRanges.fromString(""+start+"-"+(start+1));
+        
         try {
             int i1 = m.obtainPort(r);
             Assert.assertEquals(i1, start);
@@ -161,11 +171,21 @@ public class LocalhostMachineProvisioningLocationTest {
     public void obtainPortFailsIfInUse() throws Exception {
         LocalhostMachineProvisioningLocation p = newLocalhostProvisioner();
         SshMachineLocation m = p.obtain();
+        
+        // Find two ports that are free, rather than risk false-negatives if a port was left
open by something else.
         int start = 48311;
+        while (true) {
+            if (Networking.isPortAvailable(m.getAddress(), start) && Networking.isPortAvailable(m.getAddress(),
start+1)) {
+                break;
+            } else {
+                start++;
+            }
+        }
         PortRange r = PortRanges.fromString(""+start+"-"+(start+1));
+
         ServerSocket ss = null;
         try {
-            ss = new ServerSocket(start);
+            ss = new ServerSocket(start, 0, m.getAddress());
             int i1 = m.obtainPort(r);
             Assert.assertEquals(i1, start+1);
         } finally {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
b/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
index 0e79b97..d8a0a53 100644
--- a/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
+++ b/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
@@ -141,12 +141,17 @@ public class EntityExecutionManagerTest {
         app = TestApplication.Factory.newManagedInstanceForTests();
         e = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         
-        Task<?> task = runEmptyTaskWithNameAndTags(e, "should-be-kept", ManagementContextInternal.NON_TRANSIENT_TASK_TAG);
+        final Task<?> task = runEmptyTaskWithNameAndTags(e, "should-be-kept", ManagementContextInternal.NON_TRANSIENT_TASK_TAG);
         runEmptyTaskWithNameAndTags(e, "should-be-gcd", ManagementContextInternal.TRANSIENT_TASK_TAG);
         
-        // dead task (and initialization task) should have been GC'd on completion
-        Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(),
e);
-        assertEquals(tasks, ImmutableList.of(task), "Mismatched tasks, got: "+tasks);
+        // Dead task (and initialization task) should have been GC'd on completion.
+        // However, the GC'ing happens in a listener, executed in a different thread - the
task.get()
+        // doesn't block for it. Therefore can't guarantee it will be GC'ed by now.
+        Asserts.succeedsEventually(new Runnable() {
+            public void run() {
+                Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(),
e);
+                assertEquals(tasks, ImmutableList.of(task), "Mismatched tasks, got: "+tasks);
+            }});
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
index 4018758..e009302 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
@@ -34,8 +34,6 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.map.JsonMappingException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
@@ -63,7 +61,7 @@ import brooklyn.rest.domain.SensorSummary;
 import brooklyn.rest.domain.TaskSummary;
 import brooklyn.rest.testing.BrooklynRestResourceTest;
 import brooklyn.rest.testing.mocks.CapitalizePolicy;
-import brooklyn.rest.testing.mocks.EverythingGroup;
+import brooklyn.rest.testing.mocks.NameMatcherGroup;
 import brooklyn.rest.testing.mocks.RestMockApp;
 import brooklyn.rest.testing.mocks.RestMockAppBuilder;
 import brooklyn.rest.testing.mocks.RestMockSimpleEntity;
@@ -79,7 +77,6 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
-import com.sun.jersey.api.client.ClientHandlerException;
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.GenericType;
 import com.sun.jersey.api.client.UniformInterfaceException;
@@ -89,12 +86,28 @@ import com.sun.jersey.core.util.MultivaluedMapImpl;
 @Test(singleThreaded = true)
 public class ApplicationResourceTest extends BrooklynRestResourceTest {
 
+    /*
+     * In simpleSpec, not using EverythingGroup because caused problems! The group is a child
of the
+     * app, and the app is a member of the group. It failed in jenkins with:
+     *   BasicApplicationImpl{id=GSPjBCe4} GSPjBCe4
+     *     service.isUp: true
+     *     service.problems: {service-lifecycle-indicators-from-children-and-members=Required
entity not healthy: EverythingGroupImpl{id=KQ4mSEOJ}}
+     *     service.state: on-fire
+     *     service.state.expected: running @ 1412003485617 / Mon Sep 29 15:11:25 UTC 2014
+     *   EverythingGroupImpl{id=KQ4mSEOJ} KQ4mSEOJ
+     *     service.isUp: true
+     *     service.problems: {service-lifecycle-indicators-from-children-and-members=Required
entities not healthy: BasicApplicationImpl{id=GSPjBCe4}, EverythingGroupImpl{id=KQ4mSEOJ}}
+     *     service.state: on-fire
+     * I'm guessing there's a race: the app was not yet healthy because EverythingGroup hadn't
set itself to running; 
+     * but then the EverythingGroup would never transition to healthy because one of its
members was not healthy.
+     */
+
     private static final Logger log = LoggerFactory.getLogger(ApplicationResourceTest.class);
     
-  private final ApplicationSpec simpleSpec = ApplicationSpec.builder().name("simple-app")
+    private final ApplicationSpec simpleSpec = ApplicationSpec.builder().name("simple-app")
           .entities(ImmutableSet.of(
                   new EntitySpec("simple-ent", RestMockSimpleEntity.class.getName()),
-                  new EntitySpec("simple-group", EverythingGroup.class.getName())
+                  new EntitySpec("simple-group", NameMatcherGroup.class.getName(), ImmutableMap.of("namematchergroup.regex",
"simple-ent"))
           ))
           .locations(ImmutableSet.of("localhost"))
           .build();
@@ -135,7 +148,7 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest
{
   }
   
   @Test
-  public void testDeployApplication() throws InterruptedException, TimeoutException, JsonGenerationException,
JsonMappingException, UniformInterfaceException, ClientHandlerException, IOException {
+  public void testDeployApplication() throws Exception {
     ClientResponse response = clientDeploy(simpleSpec);
     
     HttpTestUtils.assertHealthyStatusCode(response.getStatus());
@@ -351,13 +364,9 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest
{
     Assert.assertNull(groupDetails.get("children"));
     
     Collection entityGroupIds = (Collection) entityDetails.get("groupIds");
-    Collection groupGroupIds = (Collection) groupDetails.get("groupIds");
     Assert.assertNotNull(entityGroupIds);
-    Assert.assertNotNull(groupGroupIds);
     Assert.assertEquals(entityGroupIds.size(), 1);
     Assert.assertEquals(entityGroupIds.iterator().next(), groupDetails.get("id"));
-    Assert.assertEquals(groupGroupIds.size(), 1);
-    Assert.assertEquals(groupGroupIds.iterator().next(), groupDetails.get("id"));
     
     Collection groupMembers = (Collection) groupDetails.get("members");
     Assert.assertNotNull(groupMembers);
@@ -367,13 +376,10 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest
{
     }
     log.info("MEMBERS: "+groupMembers);
     
-    Assert.assertEquals(groupMembers.size(), 3); // includes the app too?!
+    Assert.assertEquals(groupMembers.size(), 1);
     Map entityMemberDetails = (Map) Iterables.find(groupMembers, withValueForKey("name",
"simple-ent"), null);
-    Map groupMemberDetails = (Map) Iterables.find(groupMembers, withValueForKey("name", "simple-group"),
null);
     Assert.assertNotNull(entityMemberDetails);
-    Assert.assertNotNull(groupMemberDetails);
     Assert.assertEquals(entityMemberDetails.get("id"), entityDetails.get("id"));
-    Assert.assertEquals(groupMemberDetails.get("id"), groupDetails.get("id"));
   }
 
   @Test(dependsOnMethods = "testDeployApplication")

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/usage/rest-server/src/test/java/brooklyn/rest/testing/BrooklynRestResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/testing/BrooklynRestResourceTest.java
b/usage/rest-server/src/test/java/brooklyn/rest/testing/BrooklynRestResourceTest.java
index d1296c4..485d5a8 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/testing/BrooklynRestResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/testing/BrooklynRestResourceTest.java
@@ -97,7 +97,7 @@ public abstract class BrooklynRestResourceTest extends BrooklynRestApiTest
{
                         return status == Status.RUNNING;
                     }
                 })
-                .every(Duration.millis(100))
+                .backoffTo(Duration.ONE_SECOND)
                 .limitTimeTo(timeout)
                 .run();
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroup.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroup.java
b/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroup.java
new file mode 100644
index 0000000..87d445c
--- /dev/null
+++ b/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroup.java
@@ -0,0 +1,30 @@
+/*
+ * 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.rest.testing.mocks;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ConfigKeys;
+import brooklyn.entity.proxying.ImplementedBy;
+
+@ImplementedBy(NameMatcherGroupImpl.class)
+public interface NameMatcherGroup extends Group {
+
+    public static final ConfigKey<String> NAME_REGEX = ConfigKeys.newStringConfigKey("namematchergroup.regex");
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f3b8220/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroupImpl.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroupImpl.java
b/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroupImpl.java
new file mode 100644
index 0000000..ee1c270
--- /dev/null
+++ b/usage/rest-server/src/test/java/brooklyn/rest/testing/mocks/NameMatcherGroupImpl.java
@@ -0,0 +1,32 @@
+/*
+ * 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.rest.testing.mocks;
+
+import brooklyn.entity.basic.DynamicGroupImpl;
+import brooklyn.entity.basic.EntityPredicates;
+
+public class NameMatcherGroupImpl extends DynamicGroupImpl implements NameMatcherGroup {
+
+    @Override
+    public void init() {
+        super.init();
+        setConfig(ENTITY_FILTER, EntityPredicates.displayNameMatches(getConfig(NAME_REGEX)));
+        rescanEntities();
+    }
+}


Mime
View raw message