geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r354273 - in /geronimo/gbuild/trunk: gbuild-agent-application/src/conf/ gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ gbuild-agent/src/main/resources/META-INF/plexus/ gbuild-agent/src/test/java/org/apache/geronimo/gbuild/agent/
Date Tue, 06 Dec 2005 03:27:22 GMT
Author: dblevins
Date: Mon Dec  5 19:27:18 2005
New Revision: 354273

URL: http://svn.apache.org/viewcvs?rev=354273&view=rev
Log:
New Extension to kill processes left over after a run.
New Extension to send generic notifications to a topic.
Agent to read notifications from a topic and log them using a configurable format

Added:
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityMonitor.java
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityNotifier.java
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/KillProcessesExtension.java
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
    geronimo/gbuild/trunk/gbuild-agent/src/test/java/org/apache/geronimo/gbuild/agent/KillProcessesExtensionTest.java
Modified:
    geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml
    geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/AbstractContinuumAgentAction.java
    geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml

Modified: geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml?rev=354273&r1=354272&r2=354273&view=diff
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml (original)
+++ geronimo/gbuild/trunk/gbuild-agent-application/src/conf/application.xml Mon Dec  5 19:27:18
2005
@@ -5,7 +5,6 @@
       <role>org.apache.geronimo.gbuild.agent.BuildAgent</role>
       <role-hint>build-executor</role-hint>
     </component>
-<!--
     <component>
       <role>org.apache.geronimo.gbuild.agent.BuildAgent</role>
       <role-hint>build-producer</role-hint>
@@ -18,7 +17,12 @@
       <role>org.apache.geronimo.gbuild.agent.BuildAgent</role>
       <role-hint>ping-monitor</role-hint>
     </component>
+<!--
 -->
+    <component>
+      <role>org.apache.geronimo.gbuild.agent.BuildAgent</role>
+      <role-hint>build-activity</role-hint>
+    </component>
   </load-on-start>
 
   <resources>
@@ -31,7 +35,7 @@
       <implementation>org.apache.geronimo.gbuild.agent.ClientManager</implementation>
       <configuration>
         <broker-url>tcp://ci.gbuild.org:16161</broker-url>
-        <ping-interval>10000</ping-interval>
+        <ping-interval>300000</ping-interval>
         <reconnect-attempts>10</reconnect-attempts>
         <reconnect-delay>600000</reconnect-delay>
       </configuration>

Modified: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/AbstractContinuumAgentAction.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/AbstractContinuumAgentAction.java?rev=354273&r1=354272&r2=354273&view=diff
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/AbstractContinuumAgentAction.java
(original)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/AbstractContinuumAgentAction.java
Mon Dec  5 19:27:18 2005
@@ -42,13 +42,13 @@
 
     public static final String KEY_TRIGGER = "trigger";
 
-    public static final String KEY_HOST_NAME = "hostName";
+    public static final String KEY_HOST_NAME = "host-name";
 
-    public static final String KEY_HOST_ADDRESS = "hostAddress";
+    public static final String KEY_HOST_ADDRESS = "host-address";
 
     public static final String KEY_CONTRIBUTOR = "contributor";
 
-    public static final String KEY_ADMIN_ADDRESS = "adminAddress";
+    public static final String KEY_ADMIN_ADDRESS = "admin-address";
 
     public static final String KEY_OS_VERSION = "os.version";
 

Added: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityMonitor.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityMonitor.java?rev=354273&view=auto
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityMonitor.java
(added)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityMonitor.java
Mon Dec  5 19:27:18 2005
@@ -0,0 +1,111 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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 org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException;
+
+import javax.jms.Session;
+import javax.jms.MessageConsumer;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Connection;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuildActivityMonitor extends AbstractContinuumBuildAgent {
+
+    /**
+     * @plexus.configuration
+     */
+    private String buildActivityTopic;
+
+    /**
+     * @plexus.configuration
+     */
+    private String logFormat;
+    private StringTemplate template;
+
+    public synchronized void start() throws StartingException {
+        template = new StringTemplate(logFormat);
+        super.start();
+    }
+
+    public void execute(Map context) throws Exception {
+        getLogger().info(template.apply(context));
+    }
+
+    public void run() {
+        try {
+            getLogger().info("Build Activity Agent.");
+            getLogger().debug("buildActivityTopic " + buildActivityTopic);
+
+            while (isRunning()) {
+                // Create a Session
+                Client client = getClient();
+
+                Session session = client.getSession();
+
+                MessageConsumer resultsConsumer = createConsumer(session, buildActivityTopic);
+
+                try {
+                    consumeMessages(client, resultsConsumer);
+                } catch (JMSException e) {
+                    getLogger().error("Agent recieved JMS Exception. ("+e.getMessage()+")");
+                }
+            }
+
+        } catch (Exception e) {
+            getLogger().error("Agent failed.", e);
+        }
+    }
+
+    private void consumeMessages(Client client, MessageConsumer resultsConsumer) throws JMSException
{
+        while (client.isConnected() && isRunning()) {
+            // Wait for a message
+            Message message = resultsConsumer.receive(1000);
+
+            if (message == null){
+
+                continue;
+
+            } else if (message instanceof ObjectMessage) {
+
+                try {
+                    Connection connection = client.getConnection();
+                    getLogger().info("Message Received "+ message.getJMSMessageID() +" on
"+ connection.getClientID()+":"+buildActivityTopic);
+
+                    ObjectMessage objectMessage = (ObjectMessage) message;
+
+                    Map context = getMap(objectMessage, message);
+
+                    execute(context);
+
+                    getLogger().info("Finished processing "+ message.getJMSMessageID());
+
+                } catch (Exception e) {
+                    getLogger().error("Failed Processing message "+message.getJMSMessageID());
+                }
+
+            } else {
+                getLogger().warn("Agent received incorrect message type: "+message.getClass().getName());
+            }
+        }
+    }
+}

Added: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityNotifier.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityNotifier.java?rev=354273&view=auto
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityNotifier.java
(added)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/BuildActivityNotifier.java
Mon Dec  5 19:27:18 2005
@@ -0,0 +1,83 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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 org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import javax.jms.ObjectMessage;
+import javax.jms.MessageProducer;
+import javax.jms.JMSException;
+import java.util.Map;
+import java.util.HashMap;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuildActivityNotifier extends AbstractLogEnabled {
+
+    /**
+     * @plexus.requirement
+     */
+    private ClientManager clientManager;
+
+    /**
+     * @plexus.configuration
+     */
+    private String buildActivityTopic;
+
+    
+    public void sendNotification(Map build, String notification) {
+        HashMap map = new HashMap();
+
+        map.putAll(build);
+
+        ContinuumBuildAgent.setSystemProperty(map, ContinuumBuildAgent.KEY_OS_VERSION);
+
+        ContinuumBuildAgent.setSystemProperty(map, ContinuumBuildAgent.KEY_OS_NAME);
+
+        ContinuumBuildAgent.setSystemProperty(map, ContinuumBuildAgent.KEY_JAVA_VERSION);
+
+        ContinuumBuildAgent.setSystemProperty(map, ContinuumBuildAgent.KEY_JAVA_VENDOR);
+
+        try {
+            InetAddress localHost = InetAddress.getLocalHost();
+
+            map.put(ContinuumBuildAgent.KEY_HOST_NAME, localHost.getHostName());
+
+            map.put(ContinuumBuildAgent.KEY_HOST_ADDRESS, localHost.getHostAddress());
+        } catch (UnknownHostException e) {
+            getLogger().warn("Unable to determine local host information", e);
+        }
+
+        map.put("notification", notification);
+
+        try {
+            Client client = clientManager.getClient();
+
+            ObjectMessage message = client.getSession().createObjectMessage(map);
+
+            MessageProducer producer = client.createTopicProducer(buildActivityTopic);
+
+            producer.send(message);
+        } catch (JMSException e1) {
+            getLogger().error("Send failed.", e1);
+        }
+    }
+
+}

Added: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/KillProcessesExtension.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/KillProcessesExtension.java?rev=354273&view=auto
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/KillProcessesExtension.java
(added)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/KillProcessesExtension.java
Mon Dec  5 19:27:18 2005
@@ -0,0 +1,155 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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 org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class KillProcessesExtension extends AbstractLogEnabled implements BuildAgentExtention
{
+
+    /**
+     * @plexus.requirement
+     */
+    private BuildActivityNotifier notifier;
+
+    private String regex;
+
+    public static final String GREP_FOR_PROCESS_IDS = "ps ax | grep 'java.*geronimo-' | perl
-pe 's/^ *([0-9]+) .*/$1/g'";
+
+    public void preProcess(Map build) {
+    }
+
+    public void postProcess(Map build, Map results) {
+        boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+
+        if (isWindows){
+            return;
+        }
+        
+        String[] ids = null;
+
+        List pids = null;
+        try {
+            pids = findProcessIds(regex);
+        } catch (Exception e) {
+            getLogger().warn("Failed to get a list of running processes. ", e);
+            return;
+        }
+
+        String processes = "";
+        for (int i = 0; i < pids.size(); i++) {
+            String pid = (String) pids.get(i);
+            processes += pid +", ";
+        }
+
+        processes = processes.replaceAll(", $","");
+
+        if (pids.size() > 0){
+
+            String message = "Found " + pids.size()+ " processes matching \""+regex+"\" ("
+ processes + ").";
+
+            results.put("header.hung-processes", processes);
+            getLogger().info(message);
+            notifier.sendNotification(build, message);
+
+            try {
+                killProcesses(pids);
+            } catch (Exception e) {
+                getLogger().error("Unable to kill "+pids.size()+" processes matching \""+regex+"\"
(" + processes + ").", e);
+            }
+
+        } else {
+            getLogger().debug("No processes found matching \""+regex+"\".");
+        }
+    }
+
+    public static void killProcesses(List pids) throws Exception {
+        ExecResult res = exec("kill", (String[]) pids.toArray(new String[]{}));
+        if (res.exitCode != 0){
+            throw new IllegalStateException("Command returned error exit code " + res.exitCode
+ ".");
+        }
+    }
+
+    public static List findProcessIds(String regex) throws Exception {
+        ExecResult res = exec("sh", new String[]{"-c","\"ps ax\""});
+        if (res.exitCode != 0){
+            throw new IllegalStateException("Command returned error exit code " + res.exitCode
+ ".");
+        }
+        String stdout = res.getStdout();
+        String[] lines = stdout.split("[\n\r]");
+        List list = new ArrayList();
+        for (int i = 0; i < lines.length; i++) {
+            String line = lines[i];
+            if (line.matches(regex)){
+                line = line.replaceFirst(" *","");
+                String pid = line.split(" +")[0];
+                list.add(pid);
+            }
+        }
+        return list;
+    }
+
+    public static class ExecResult {
+        private final int exitCode;
+        private final String stdout;
+        private final String stderr;
+
+        public ExecResult(int exitCode, String stdout, String stderr) {
+            this.exitCode = exitCode;
+            this.stdout = stdout;
+            this.stderr = stderr;
+        }
+
+        public int getExitCode() {
+            return exitCode;
+        }
+
+        public String getStdout() {
+            return stdout;
+        }
+
+        public String getStderr() {
+            return stderr;
+        }
+    }
+
+    public static ExecResult exec(String cmd, String[] arguments) throws CommandLineException
{
+        Commandline commandline = new Commandline();
+        commandline.setExecutable(cmd);
+        commandline.setWorkingDirectory(new File(".").getAbsolutePath());
+
+        for (int i = 0; i < arguments.length; i++) {
+            commandline.createArgument().setLine(arguments[i]);
+        }
+
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
+        int exitCode = CommandLineUtils.executeCommandLine(commandline, stdout, stderr);
+        return new ExecResult(exitCode, stdout.getOutput(), stderr.getOutput());
+    }
+
+}

Added: geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java?rev=354273&view=auto
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
(added)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/java/org/apache/geronimo/gbuild/agent/ReportActivityExtension.java
Mon Dec  5 19:27:18 2005
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed 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 org.apache.geronimo.gbuild.agent;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReportActivityExtension extends AbstractLogEnabled implements BuildAgentExtention
{
+
+    /**
+     * @plexus.requirement
+     */
+    private BuildActivityNotifier notifier;
+
+    public void preProcess(Map build) {
+        notifier.sendNotification(build, "Started");
+    }
+
+    public void postProcess(Map build, Map results) {
+        notifier.sendNotification(build, "Completed");
+    }
+}

Modified: geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml?rev=354273&r1=354272&r2=354273&view=diff
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml (original)
+++ geronimo/gbuild/trunk/gbuild-agent/src/main/resources/META-INF/plexus/components.xml Mon
Dec  5 19:27:18 2005
@@ -1,22 +1,12 @@
 <component-set>
   <components>
-    <!--
-    <component>
-      <role>org.apache.geronimo.gbuild.Main</role>
-      <implementation>org.apache.geronimo.gbuild.Main</implementation>
-      <requirements>
-        <requirement>
-          <role>org.apache.geronimo.gbuild.BuildAgent</role>
-        </requirement>
-      </requirements>
-    </component>
-    -->
+
     <component>
       <role>org.apache.geronimo.gbuild.agent.ClientManager</role>
       <implementation>org.apache.geronimo.gbuild.agent.ClientManager</implementation>
       <configuration>
         <broker-url>tcp://localhost:61616</broker-url>
-        <ping-interval>10000</ping-interval>
+        <ping-interval>300000</ping-interval>
         <reconnect-attempts>10</reconnect-attempts>
         <reconnect-delay>600000</reconnect-delay>
       </configuration>
@@ -191,6 +181,63 @@
           <role>org.apache.geronimo.gbuild.agent.ClientManager</role>
         </requirement>
       </requirements>
+    </component>
+
+    <!--
+    | Build Activity
+    -->
+    <component>
+      <role>org.apache.geronimo.gbuild.agent.BuildAgent</role>
+      <role-hint>build-activity</role-hint>
+      <implementation>org.apache.geronimo.gbuild.agent.BuildActivityMonitor</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.geronimo.gbuild.agent.ClientManager</role>
+        </requirement>
+      </requirements>
+      <configuration>
+        <log-format>[{host-name}:{host-address}] {project.name}-{project.version} -
{build.name} {build.id} - {notification}</log-format>
+        <build-activity-topic>BUILD.ACTIVITY</build-activity-topic>
+      </configuration>
+    </component>
+
+    <component>
+      <role>org.apache.geronimo.gbuild.agent.BuildActivityNotifier</role>
+      <role-hint>ping-monitor</role-hint>
+      <implementation>org.apache.geronimo.gbuild.agent.BuildActivityNotifier</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.geronimo.gbuild.agent.ClientManager</role>
+        </requirement>
+      </requirements>
+      <configuration>
+        <build-activity-topic>BUILD.ACTIVITY</build-activity-topic>
+      </configuration>
+    </component>
+
+    <component>
+      <role>org.apache.geronimo.gbuild.agent.BuildAgentExtention</role>
+      <role-hint>report-activity</role-hint>
+      <implementation>org.apache.geronimo.gbuild.agent.ReportActivityExtension</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.geronimo.gbuild.agent.BuildActivityNotifier</role>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.apache.geronimo.gbuild.agent.BuildAgentExtention</role>
+      <role-hint>clean-dead-processes</role-hint>
+      <implementation>org.apache.geronimo.gbuild.agent.KillProcessesExtension</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.geronimo.gbuild.agent.BuildActivityNotifier</role>
+        </requirement>
+      </requirements>
+      <configuration>
+        <regex>.*geronimo-tck.*</regex>
+      </configuration>
     </component>
 
   </components>

Added: geronimo/gbuild/trunk/gbuild-agent/src/test/java/org/apache/geronimo/gbuild/agent/KillProcessesExtensionTest.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/gbuild-agent/src/test/java/org/apache/geronimo/gbuild/agent/KillProcessesExtensionTest.java?rev=354273&view=auto
==============================================================================
--- geronimo/gbuild/trunk/gbuild-agent/src/test/java/org/apache/geronimo/gbuild/agent/KillProcessesExtensionTest.java
(added)
+++ geronimo/gbuild/trunk/gbuild-agent/src/test/java/org/apache/geronimo/gbuild/agent/KillProcessesExtensionTest.java
Mon Dec  5 19:27:18 2005
@@ -0,0 +1,34 @@
+package org.apache.geronimo.gbuild.agent;
+/**
+ * @version $Rev$ $Date$
+ */
+
+import junit.framework.*;
+import org.apache.geronimo.gbuild.agent.KillProcessesExtension;
+
+import java.util.List;
+
+public class KillProcessesExtensionTest extends TestCase {
+
+    public void testFindProcessIds() throws Exception {
+        boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+
+        if (isWindows){
+            return;
+        }
+        
+        Runtime runtime = Runtime.getRuntime();
+
+        runtime.exec("sleep 43210");
+        runtime.exec("sleep 43210");
+        runtime.exec("sleep 43210");
+
+        List pids = KillProcessesExtension.findProcessIds(".*sleep 43210.*");
+
+        assertEquals("processes started: pids.size", 3, pids.size());
+        KillProcessesExtension.killProcesses(pids);
+
+        pids = KillProcessesExtension.findProcessIds(".*sleep 43210.*");
+        assertEquals("processes killed: pids.size", 0, pids.size());
+    }
+}
\ No newline at end of file



Mime
View raw message