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/12/22 15:07:43 UTC

[4/7] incubator-brooklyn git commit: Add tests for Postgres restart/rebind

Add tests for Postgres restart/rebind

- And changes Postgres connectSensors() to use
  connectServiceUpIsRunning(), given that was all
  the feed was doing anyway.


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

Branch: refs/heads/master
Commit: ccea3ecd889707c5bb4dab24b1ee9fd277d42ef4
Parents: 99a2d2a
Author: Aled Sage <al...@gmail.com>
Authored: Tue Dec 16 21:05:48 2014 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Dec 16 22:52:27 2014 +0000

----------------------------------------------------------------------
 .../database/postgresql/PostgreSqlNodeImpl.java | 30 +------
 .../PostgreSqlRebindIntegrationTest.java        | 59 +++++++++++++
 .../PostgreSqlRestartIntegrationTest.java       | 91 ++++++++++++++++++++
 3 files changed, 152 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ccea3ecd/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeImpl.java b/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeImpl.java
index 8b0f636..71f63d9 100644
--- a/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeImpl.java
+++ b/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlNodeImpl.java
@@ -23,20 +23,12 @@ import org.slf4j.LoggerFactory;
 
 import brooklyn.entity.basic.SoftwareProcessImpl;
 import brooklyn.entity.effector.EffectorBody;
-import brooklyn.event.feed.ssh.SshFeed;
-import brooklyn.event.feed.ssh.SshPollConfig;
-import brooklyn.location.basic.Locations;
-import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.util.config.ConfigBag;
-import brooklyn.util.guava.Maybe;
-import brooklyn.util.time.Duration;
 
 public class PostgreSqlNodeImpl extends SoftwareProcessImpl implements PostgreSqlNode {
 
     private static final Logger LOG = LoggerFactory.getLogger(PostgreSqlNodeImpl.class);
 
-    private SshFeed feed;
-
     public Class<?> getDriverInterface() {
         return PostgreSqlDriver.class;
     }
@@ -68,31 +60,13 @@ public class PostgreSqlNodeImpl extends SoftwareProcessImpl implements PostgreSq
     @Override
     protected void connectSensors() {
         super.connectSensors();
+        connectServiceUpIsRunning();
         setAttribute(DATASTORE_URL, String.format("postgresql://%s:%s/", getAttribute(HOSTNAME), getAttribute(POSTGRESQL_PORT)));
-
-        Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations());
-
-        if (machine.isPresent()) {
-            String cmd = getDriver().getStatusCmd();
-
-            feed = SshFeed.builder()
-                    .entity(this)
-                    .machine(machine.get())
-                    .period(Duration.millis(getConfig(POLL_PERIOD)))
-                    .poll(new SshPollConfig<Boolean>(SERVICE_UP)
-                            .command(cmd)
-                            .setOnSuccess(true)
-                            .setOnFailureOrException(false))
-                    .build();
-        } else {
-            LOG.warn("Location set {} does not an ssh-machine location, so not polling for status; setting serviceUp immediately", getLocations());
-            setAttribute(SERVICE_UP, true);
-        }
     }
 
     @Override
     protected void disconnectSensors() {
-        if (feed != null) feed.stop();
+        disconnectServiceUpIsRunning();
         super.disconnectSensors();
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ccea3ecd/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java b/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java
new file mode 100644
index 0000000..bff1cd2
--- /dev/null
+++ b/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRebindIntegrationTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.entity.database.postgresql;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.rebind.RebindTestFixtureWithApp;
+import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
+import brooklyn.test.EntityTestUtils;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
+public class PostgreSqlRebindIntegrationTest extends RebindTestFixtureWithApp {
+
+    private LocalhostMachineProvisioningLocation loc;
+    
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        loc = origApp.newLocalhostProvisioningLocation();
+    }
+
+    @Test(groups = {"Integration"})
+    public void testRebind() throws Exception {
+        origApp.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
+                .configure("mongodbConfTemplateUrl", "classpath:///test-mongodb.conf"));
+        origApp.start(ImmutableList.of(loc));
+
+        // rebind
+        rebind();
+        final PostgreSqlNode newEntity = (PostgreSqlNode) Iterables.find(newApp.getChildren(), Predicates.instanceOf(PostgreSqlNode.class));
+
+        // confirm effectors still work on entity
+        EntityTestUtils.assertAttributeEqualsEventually(newEntity, PostgreSqlNode.SERVICE_UP, true);
+        newEntity.stop();
+        EntityTestUtils.assertAttributeEqualsEventually(newEntity, PostgreSqlNode.SERVICE_UP, false);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ccea3ecd/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java b/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java
new file mode 100644
index 0000000..ea15b79
--- /dev/null
+++ b/software/database/src/test/java/brooklyn/entity/database/postgresql/PostgreSqlRestartIntegrationTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.entity.database.postgresql;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.BrooklynAppLiveTestSupport;
+import brooklyn.entity.Effector;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.SoftwareProcess.RestartSoftwareParameters;
+import brooklyn.entity.basic.SoftwareProcess.StopSoftwareParameters;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.util.collections.CollectionFunctionals;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests restart of the software *process* (as opposed to the VM).
+ */
+public class PostgreSqlRestartIntegrationTest extends BrooklynAppLiveTestSupport {
+    
+    // TODO Remove duplication from TomcatServerRestartIntegrationTest, MySqlRestartIntegrationTest
+    
+    @SuppressWarnings("unused")
+    private static final Logger LOG = LoggerFactory.getLogger(PostgreSqlRestartIntegrationTest.class);
+
+    @Test(groups="Integration")
+    public void testStopProcessAndRestart() throws Exception {
+        runStopProcessAndRestart(
+                PostgreSqlNode.RESTART, 
+                ImmutableMap.of(RestartSoftwareParameters.RESTART_MACHINE.getName(), RestartSoftwareParameters.RestartMachineMode.FALSE));
+    }
+    
+    // TODO The second start() will fail because customize operations forbidden while there is existing data:
+    //      "If you want to create a new database system, either remove or empty".
+    // I haven't checked whether it damaged the data in the database though!
+    @Test(enabled=false, groups={"Integration", "WIP"})
+    public void testStopProcessAndStart() throws Exception {
+        runStopProcessAndRestart(
+                PostgreSqlNode.START, 
+                ImmutableMap.of("locations", ImmutableList.of()));
+    }
+    
+    protected void runStopProcessAndRestart(Effector<?> restartEffector, Map<String, ?> args) throws Exception {
+        LocalhostMachineProvisioningLocation loc = app.newLocalhostProvisioningLocation();
+        PostgreSqlNode entity = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class));
+        app.start(ImmutableList.of(loc));
+        
+        Entities.invokeEffector(app, entity, PostgreSqlNode.STOP, ImmutableMap.of(
+                StopSoftwareParameters.STOP_MACHINE.getName(), false))
+                .get();
+        EntityTestUtils.assertAttributeEqualsEventually(entity, PostgreSqlNode.SERVICE_UP, false);
+        EntityTestUtils.assertAttributeEqualsEventually(entity, PostgreSqlNode.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED);
+        EntityTestUtils.assertAttributeEqualsEventually(entity, PostgreSqlNode.SERVICE_PROCESS_IS_RUNNING, false);
+        EntityTestUtils.assertAttributeEventually(entity, ServiceStateLogic.SERVICE_NOT_UP_INDICATORS, CollectionFunctionals.<String>mapSizeEquals(1));
+        
+        Entities.invokeEffector(app, entity, restartEffector, args).get();
+        EntityTestUtils.assertAttributeEqualsEventually(entity, PostgreSqlNode.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(entity, PostgreSqlNode.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+        EntityTestUtils.assertAttributeEqualsEventually(entity, PostgreSqlNode.SERVICE_PROCESS_IS_RUNNING, true);
+        EntityTestUtils.assertAttributeEqualsEventually(entity, ServiceStateLogic.SERVICE_NOT_UP_INDICATORS, ImmutableMap.<String, Object>of());
+
+        EntityTestUtils.assertAttributeEqualsEventually(app, PostgreSqlNode.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(app, PostgreSqlNode.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+    }
+}