brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] git commit: Updates monit test to explicitly start process (vi) rather than assume 'cron' is running, uses 'rest of line' for status, rather than next word
Date Thu, 16 Oct 2014 23:55:15 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master c91119d21 -> bfc8f5818


Updates monit test to explicitly start process (vi) rather than assume 'cron' is running,
uses 'rest of line' for status, rather than next word


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

Branch: refs/heads/master
Commit: 42bdf30d331db43c374165d9b2f005a4e2e4d194
Parents: 16d47d4
Author: Martin Harris <github@nakomis.com>
Authored: Wed Oct 15 14:00:01 2014 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Wed Oct 15 14:00:01 2014 +0100

----------------------------------------------------------------------
 .../entity/monitoring/monit/MonitNodeImpl.java  |  3 +-
 .../monitoring/monit/MonitIntegrationTest.java  | 45 +++++++++-----------
 .../entity/monitoring/monit/monit.monitrc       |  4 +-
 .../main/java/brooklyn/util/text/Strings.java   | 16 +++++++
 .../java/brooklyn/util/text/StringsTest.java    | 16 +++++++
 5 files changed, 54 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42bdf30d/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitNodeImpl.java
b/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitNodeImpl.java
index 30e5ceb..ef4d944 100644
--- a/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitNodeImpl.java
+++ b/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitNodeImpl.java
@@ -93,8 +93,7 @@ public class MonitNodeImpl extends SoftwareProcessImpl implements MonitNode
{
                     .onSuccess(new Function<SshPollValue, String>() {
                         @Override
                         public String apply(SshPollValue input) {
-                            String status = Strings.getFirstWordAfter(input.getStdout(),
"status");
-                            return status;
+                            return Strings.trim(Strings.getRemainderOfLineAfter(input.getStdout(),
"status"));
                         }
                     })
                     .setOnFailureOrException(null))

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42bdf30d/software/monitoring/src/test/java/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/monitoring/src/test/java/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java
b/software/monitoring/src/test/java/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java
index 258440d..6f8479c 100644
--- a/software/monitoring/src/test/java/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java
+++ b/software/monitoring/src/test/java/brooklyn/entity/monitoring/monit/MonitIntegrationTest.java
@@ -29,6 +29,7 @@ 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;
 
@@ -49,37 +50,29 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.io.Files;
 
 public class MonitIntegrationTest extends BrooklynAppLiveTestSupport {
-    
-    /*
-     * FIXME Has the monit node output changed? Now it is listing 'cron' as well as system.
-     * It keeps reporting "Does" rather than "Running" as the status.
-     * Should we be getting the rest of the line after "status" (and trimming), rather than
-     * just the first word?
-
-    input=The Monit daemon 5.9 uptime: 0m
-            Process 'cron'
-              status                            Does not exist
-              monitoring status                 Monitored
-              data collected                    Mon, 13 Oct 2014 21:27:01
-            System 'aleds-macbook-pro.local'
-              status                            Running
-              monitoring status                 Monitored
-              load average                      [5.16] [4.73] [4.45]
-              cpu                               7.1%us 5.7%sy
-              memory usage                      11.6 GB [72.3%]
-              swap usage                        3.0 GB [74.7%]
-              data collected                    Mon, 13 Oct 2014 21:27:01
 
-     */
-    
     private static final Logger LOG = LoggerFactory.getLogger(MonitIntegrationTest.class);
     
     LocalhostMachineProvisioningLocation loc;
+    Process testProcess;
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
         super.setUp();
         loc = app.newLocalhostProvisioningLocation();
+        testProcess = (new ProcessBuilder()).command("vi", "monittest").start();
+    }
+
+    @AfterMethod(alwaysRun = true)
+    @Override
+    public void tearDown() throws Exception {
+        try {
+            super.tearDown();
+        } finally {
+            if (testProcess != null) {
+                testProcess.destroy();
+            }
+        }
     }
     
     @Test(groups = "Integration")
@@ -88,7 +81,7 @@ public class MonitIntegrationTest extends BrooklynAppLiveTestSupport {
             .configure(MonitNode.CONTROL_FILE_URL, "classpath:///brooklyn/entity/monitoring/monit/monit.monitrc"));
         app.start(ImmutableSet.of(loc));
         LOG.info("Monit started");
-        EntityTestUtils.assertAttributeEqualsEventually(monitNode,  MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
+        EntityTestUtils.assertAttributeEqualsEventually(monitNode, MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
     }
     
     @Test(groups = "Integration")
@@ -109,7 +102,7 @@ public class MonitIntegrationTest extends BrooklynAppLiveTestSupport {
         Entities.manage(monitNode);
         app.start(ImmutableSet.of(loc));
         LOG.info("Monit and MySQL started");
-        EntityTestUtils.assertAttributeEqualsEventually(monitNode,  MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
+        EntityTestUtils.assertAttributeEqualsEventually(monitNode, MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
         mySqlNode.stop();
         Asserts.succeedsEventually(new Runnable() {
             @Override
@@ -120,7 +113,7 @@ public class MonitIntegrationTest extends BrooklynAppLiveTestSupport {
             }
         });
         mySqlNode.restart();
-        EntityTestUtils.assertAttributeEqualsEventually(monitNode,  MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
+        EntityTestUtils.assertAttributeEqualsEventually(monitNode, MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
     }
     
     @Test(groups = "Integration")
@@ -173,7 +166,7 @@ public class MonitIntegrationTest extends BrooklynAppLiveTestSupport {
             }
         });
         mySqlNode.stop();
-        EntityTestUtils.assertAttributeEqualsEventually(monitNode,  MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
+        EntityTestUtils.assertAttributeEqualsEventually(monitNode, MonitNode.MONIT_TARGET_PROCESS_STATUS,
"Running");
 
         // NOTE: Do not manually restart the mySqlNode, it should be restarted by monit
         Asserts.succeedsEventually(new Runnable() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42bdf30d/software/monitoring/src/test/resources/brooklyn/entity/monitoring/monit/monit.monitrc
----------------------------------------------------------------------
diff --git a/software/monitoring/src/test/resources/brooklyn/entity/monitoring/monit/monit.monitrc
b/software/monitoring/src/test/resources/brooklyn/entity/monitoring/monit/monit.monitrc
index 99588dd..4a8bbe2 100644
--- a/software/monitoring/src/test/resources/brooklyn/entity/monitoring/monit/monit.monitrc
+++ b/software/monitoring/src/test/resources/brooklyn/entity/monitoring/monit/monit.monitrc
@@ -24,7 +24,7 @@ set daemon 5
 set pidfile ${driver.runDir}/pid.txt
 set logfile ${driver.runDir}/monit.log
 
-check process cron
-	matching "cron"
+check process vi
+	matching "vi monittest"
 	group test
 	
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42bdf30d/utils/common/src/main/java/brooklyn/util/text/Strings.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/text/Strings.java b/utils/common/src/main/java/brooklyn/util/text/Strings.java
index 528fa72..4c275c9 100644
--- a/utils/common/src/main/java/brooklyn/util/text/Strings.java
+++ b/utils/common/src/main/java/brooklyn/util/text/Strings.java
@@ -537,6 +537,22 @@ public class Strings {
         return getFirstWord(context.substring(index + phrase.length()));
     }
 
+   /**
+    * searches in context for the given phrase, and returns the <b>untrimmed</b>
remainder of the first line
+    * on which the phrase is found
+    */
+    public static String getRemainderOfLineAfter(String context, String phrase) {
+        if (context == null || phrase == null) return null;
+        int index = context.indexOf(phrase);
+        if (index < 0) return null;
+        int lineEndIndex = context.indexOf("\n", index);
+        if (lineEndIndex <= 0) {
+            return context.substring(index + phrase.length());
+        } else {
+            return context.substring(index + phrase.length(), lineEndIndex);
+        }
+    }
+
     /** @deprecated use {@link Time#makeTimeStringRounded(long)} */
     @Deprecated
     public static String makeTimeString(long utcMillis) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42bdf30d/utils/common/src/test/java/brooklyn/util/text/StringsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/brooklyn/util/text/StringsTest.java b/utils/common/src/test/java/brooklyn/util/text/StringsTest.java
index 9fea095..c86c03b 100644
--- a/utils/common/src/test/java/brooklyn/util/text/StringsTest.java
+++ b/utils/common/src/test/java/brooklyn/util/text/StringsTest.java
@@ -339,4 +339,20 @@ public class StringsTest extends FixedLocaleTest {
         Assert.assertEquals(Strings.maxlenWithEllipsis("hello world", 7, "--"), "hello--");
     }
 
+    @Test
+    public void testGetRemainderOfLineAfter() {
+        // Basic test (also tests start is trimmed)
+        Assert.assertEquals(Strings.getRemainderOfLineAfter("the message is hello", "is"),
" hello");
+        Assert.assertEquals(Strings.getRemainderOfLineAfter("the message is is hello", "is"),
" is hello");
+        // Trim spaces from end
+        Assert.assertEquals(Strings.getRemainderOfLineAfter("the message is is hello    ",
"is"), " is hello    ");
+        // Trim non-matching lines from start
+        Assert.assertEquals(Strings.getRemainderOfLineAfter("one\ntwo\nthree\nthe message
is is hello    ", "is"), " is hello    ");
+        // Trim lines from end
+        Assert.assertEquals(Strings.getRemainderOfLineAfter("one\ntwo\nthree\nthe message
is is hello    \nfour\nfive\nsix\nis not seven", "is"), " is hello    ");
+        // Play nicely with null / non-match
+        Assert.assertEquals(Strings.getRemainderOfLineAfter(null, "is"), null);
+        Assert.assertEquals(Strings.getRemainderOfLineAfter("the message is hello", null),
null);
+        Assert.assertEquals(Strings.getRemainderOfLineAfter("the message is hello", "foo"),
null);
+    }
 }


Mime
View raw message